Line 0
Link Here
|
|
|
1 |
--- cpp/src/IceGrid/InternalRegistryI.cpp.orig Wed Jun 15 19:43:59 2011 |
2 |
+++ cpp/src/IceGrid/InternalRegistryI.cpp Tue Jul 12 15:32:00 2011 |
3 |
@@ -19,6 +19,8 @@ |
4 |
#include <IceGrid/ReplicaSessionI.h> |
5 |
#include <IceGrid/ReplicaSessionManager.h> |
6 |
#include <IceGrid/FileCache.h> |
7 |
+#include <IceSSL/IceSSL.h> |
8 |
+#include <IceSSL/RFC2253.h> |
9 |
|
10 |
using namespace std; |
11 |
using namespace IceGrid; |
12 |
@@ -38,6 +40,8 @@ InternalRegistryI::InternalRegistryI(const RegistryIPtr& registry, |
13 |
Ice::PropertiesPtr properties = database->getCommunicator()->getProperties(); |
14 |
_nodeSessionTimeout = properties->getPropertyAsIntWithDefault("IceGrid.Registry.NodeSessionTimeout", 30); |
15 |
_replicaSessionTimeout = properties->getPropertyAsIntWithDefault("IceGrid.Registry.ReplicaSessionTimeout", 30); |
16 |
+ _requireNodeCertCN = properties->getPropertyAsIntWithDefault("IceGrid.Registry.RequireNodeCertCN", 0); |
17 |
+ _requireReplicaCertCN = properties->getPropertyAsIntWithDefault("IceGrid.Registry.RequireNodeCertCN", 0); |
18 |
} |
19 |
|
20 |
InternalRegistryI::~InternalRegistryI() |
21 |
@@ -50,7 +54,56 @@ InternalRegistryI::registerNode(const InternalNodeInfoPtr& info, |
22 |
const LoadInfo& load, |
23 |
const Ice::Current& current) |
24 |
{ |
25 |
- const Ice::LoggerPtr logger = _database->getTraceLevels()->logger; |
26 |
+ const TraceLevelsPtr traceLevels = _database->getTraceLevels(); |
27 |
+ const Ice::LoggerPtr logger = traceLevels->logger; |
28 |
+ if(!info || !node) |
29 |
+ { |
30 |
+ return 0; |
31 |
+ } |
32 |
+ |
33 |
+ if(_requireNodeCertCN) |
34 |
+ { |
35 |
+ try |
36 |
+ { |
37 |
+ IceSSL::ConnectionInfoPtr sslConnInfo = IceSSL::ConnectionInfoPtr::dynamicCast(current.con->getInfo()); |
38 |
+ if(sslConnInfo) |
39 |
+ { |
40 |
+ if (sslConnInfo->certs.empty() || |
41 |
+ !IceSSL::Certificate::decode(sslConnInfo->certs[0])->getSubjectDN().match("CN=" + info->name)) |
42 |
+ { |
43 |
+ if(traceLevels->node > 0) |
44 |
+ { |
45 |
+ Ice::Trace out(logger, traceLevels->nodeCat); |
46 |
+ out << "certificate CN doesn't match node name `" << info->name << "'"; |
47 |
+ } |
48 |
+ throw PermissionDeniedException("certificate CN doesn't match node name `" + info->name + "'"); |
49 |
+ } |
50 |
+ } |
51 |
+ else |
52 |
+ { |
53 |
+ if(traceLevels->node > 0) |
54 |
+ { |
55 |
+ Ice::Trace out(logger, traceLevels->nodeCat); |
56 |
+ out << "node certificate for `" << info->name << "' is required to connect to this registry"; |
57 |
+ } |
58 |
+ throw PermissionDeniedException("node certificate is required to connect to this registry"); |
59 |
+ } |
60 |
+ } |
61 |
+ catch(const PermissionDeniedException& ex) |
62 |
+ { |
63 |
+ throw ex; |
64 |
+ } |
65 |
+ catch(const IceUtil::Exception&) |
66 |
+ { |
67 |
+ if(traceLevels->node > 0) |
68 |
+ { |
69 |
+ Ice::Trace out(logger, traceLevels->nodeCat); |
70 |
+ out << "unexpected exception while verifying certificate for node `" << info->name << "'"; |
71 |
+ } |
72 |
+ throw PermissionDeniedException("unable to verify certificate for node `" + info->name + "'"); |
73 |
+ } |
74 |
+ } |
75 |
+ |
76 |
try |
77 |
{ |
78 |
NodeSessionIPtr session = new NodeSessionI(_database, node, info, _nodeSessionTimeout, load); |
79 |
@@ -68,7 +121,56 @@ InternalRegistryI::registerReplica(const InternalReplicaInfoPtr& info, |
80 |
const InternalRegistryPrx& prx, |
81 |
const Ice::Current& current) |
82 |
{ |
83 |
- const Ice::LoggerPtr logger = _database->getTraceLevels()->logger; |
84 |
+ const TraceLevelsPtr traceLevels = _database->getTraceLevels(); |
85 |
+ const Ice::LoggerPtr logger = traceLevels->logger; |
86 |
+ if(!info || !prx) |
87 |
+ { |
88 |
+ return 0; |
89 |
+ } |
90 |
+ |
91 |
+ if(_requireReplicaCertCN) |
92 |
+ { |
93 |
+ try |
94 |
+ { |
95 |
+ IceSSL::ConnectionInfoPtr sslConnInfo = IceSSL::ConnectionInfoPtr::dynamicCast(current.con->getInfo()); |
96 |
+ if(sslConnInfo) |
97 |
+ { |
98 |
+ if (sslConnInfo->certs.empty() || |
99 |
+ !IceSSL::Certificate::decode(sslConnInfo->certs[0])->getSubjectDN().match("CN=" + info->name)) |
100 |
+ { |
101 |
+ if(traceLevels->replica > 0) |
102 |
+ { |
103 |
+ Ice::Trace out(logger, traceLevels->replicaCat); |
104 |
+ out << "certificate CN doesn't match replica name `" << info->name << "'"; |
105 |
+ } |
106 |
+ throw PermissionDeniedException("certificate CN doesn't match replica name `" + info->name + "'"); |
107 |
+ } |
108 |
+ } |
109 |
+ else |
110 |
+ { |
111 |
+ if(traceLevels->replica > 0) |
112 |
+ { |
113 |
+ Ice::Trace out(logger, traceLevels->replicaCat); |
114 |
+ out << "replica certificate for `" << info->name << "' is required to connect to this registry"; |
115 |
+ } |
116 |
+ throw PermissionDeniedException("replica certificate is required to connect to this registry"); |
117 |
+ } |
118 |
+ } |
119 |
+ catch(const PermissionDeniedException& ex) |
120 |
+ { |
121 |
+ throw ex; |
122 |
+ } |
123 |
+ catch(const IceUtil::Exception&) |
124 |
+ { |
125 |
+ if(traceLevels->replica > 0) |
126 |
+ { |
127 |
+ Ice::Trace out(logger, traceLevels->replicaCat); |
128 |
+ out << "unexpected exception while verifying certificate for replica `" << info->name << "'"; |
129 |
+ } |
130 |
+ throw PermissionDeniedException("unable to verify certificate for replica `" + info->name + "'"); |
131 |
+ } |
132 |
+ } |
133 |
+ |
134 |
try |
135 |
{ |
136 |
ReplicaSessionIPtr s = new ReplicaSessionI(_database, _wellKnownObjects, info, prx, _replicaSessionTimeout); |