1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
// **********************************************************************
//
// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
#include <Ice/Ice.h>
#include <IceSSL/RSACertificateGen.h>
#include <IceSSL/RSAKeyPair.h>
#include <IceSSL/Plugin.h>
#include <Pinger.h>
using namespace std;
using namespace Test;
class KeyManagerI : public KeyManager
{
public:
KeyManagerI(const IceSSL::RSAKeyPairPtr&, const IceSSL::RSAKeyPairPtr&,
const IceSSL::RSAKeyPairPtr&, const IceSSL::RSAKeyPairPtr&,
const Ice::CommunicatorPtr&);
virtual void getServerCerts(Ice::ByteSeq&, Ice::ByteSeq&, const ::Ice::Current&);
virtual void getTrustedClientKeys(Ice::ByteSeq&, Ice::ByteSeq&, const ::Ice::Current&);
virtual void getUntrustedClientKeys(Ice::ByteSeq&, Ice::ByteSeq&, const ::Ice::Current&);
virtual void shutdown(const ::Ice::Current&);
protected:
IceSSL::RSAKeyPairPtr _serverTrusted;
IceSSL::RSAKeyPairPtr _serverUntrusted;
IceSSL::RSAKeyPairPtr _clientTrusted;
IceSSL::RSAKeyPairPtr _clientUntrusted;
Ice::CommunicatorPtr _communicator;
};
KeyManagerI::KeyManagerI(const IceSSL::RSAKeyPairPtr& serverTrusted,
const IceSSL::RSAKeyPairPtr& serverUntrusted,
const IceSSL::RSAKeyPairPtr& clientTrusted,
const IceSSL::RSAKeyPairPtr& clientUntrusted,
const Ice::CommunicatorPtr& communicator) :
_serverTrusted(serverTrusted), _serverUntrusted(serverUntrusted),
_clientTrusted(clientTrusted), _clientUntrusted(clientUntrusted),
_communicator(communicator)
{
}
void
KeyManagerI::getServerCerts(Ice::ByteSeq& trusted, Ice::ByteSeq& untrusted, const ::Ice::Current&)
{
_serverTrusted->certToByteSeq(trusted);
_serverUntrusted->certToByteSeq(untrusted);
}
void
KeyManagerI::getTrustedClientKeys(Ice::ByteSeq& key, Ice::ByteSeq& cert, const ::Ice::Current&)
{
_clientTrusted->keyToByteSeq(key);
_clientTrusted->certToByteSeq(cert);
}
void
KeyManagerI::getUntrustedClientKeys(Ice::ByteSeq& key, Ice::ByteSeq& cert, const ::Ice::Current&)
{
_clientUntrusted->keyToByteSeq(key);
_clientUntrusted->certToByteSeq(cert);
}
void
KeyManagerI::shutdown(const ::Ice::Current&)
{
_communicator->shutdown();
}
class PingerI : public Pinger
{
public:
PingerI();
virtual void ping(const ::Ice::Current&);
};
PingerI::PingerI()
{
}
void
PingerI::ping(const ::Ice::Current&)
{
}
int
run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator)
{
Ice::PropertiesPtr properties = communicator->getProperties();
std::string certPath = properties->getProperty("TestSSL.Server.CertPath");
properties->setProperty("IceSSL.Server.CertPath", certPath);
properties->setProperty("Ice.Warn.Connections", "0");
properties->setProperty("IceSSL.Server.Config", "sslconfig_8.xml");
Ice::PluginPtr plugin = communicator->getPluginManager()->getPlugin("IceSSL");
IceSSL::PluginPtr sslPlugin = IceSSL::PluginPtr::dynamicCast(plugin);
sslPlugin->configure(IceSSL::Server);
IceSSL::RSACertificateGen certGen;
IceSSL::RSACertificateGenContext certGenContext;
// Base setup.
certGenContext.setCountry("US");
certGenContext.setStateProvince("DC");
certGenContext.setLocality("Washington");
certGenContext.setOrganization("Some Company Inc.");
certGenContext.setOrgainizationalUnit("Sales");
certGenContext.setBitStrength(1024);
certGenContext.setSecondsValid(IceSSL::RSACertificateGenContext::hoursToSeconds(1));
IceSSL::RSAKeyPairPtr serverTrusted;
IceSSL::RSAKeyPairPtr serverUntrusted;
IceSSL::RSAKeyPairPtr clientTrusted;
IceSSL::RSAKeyPairPtr clientUntrusted;
certGenContext.setCommonName("Server Trusted");
serverTrusted = certGen.generate(certGenContext);
certGenContext.setCommonName("Server Untrusted");
serverUntrusted = certGen.generate(certGenContext);
certGenContext.setCommonName("Client Trusted");
clientTrusted = certGen.generate(certGenContext);
certGenContext.setCommonName("Client Untrusted");
clientUntrusted = certGen.generate(certGenContext);
Ice::ObjectPtr object = new KeyManagerI(serverTrusted, serverUntrusted,
clientTrusted, clientUntrusted,
communicator);
Ice::ByteSeq trustedCertificate;
Ice::ByteSeq serverCertificate;
Ice::ByteSeq serverKey;
clientTrusted->certToByteSeq(trustedCertificate);
serverTrusted->certToByteSeq(serverCertificate);
serverTrusted->keyToByteSeq(serverKey);
sslPlugin->addTrustedCertificate(IceSSL::Server, trustedCertificate);
sslPlugin->setRSAKeys(IceSSL::Server, serverKey, serverCertificate);
if(properties->getProperty("TestSSL.Server.CertificateVerifier") == "singleCert")
{
IceSSL::CertificateVerifierPtr certVerifier = sslPlugin->getSingleCertVerifier(trustedCertificate);
sslPlugin->setCertificateVerifier(IceSSL::Server, certVerifier);
}
properties->setProperty("KeyManagerAdapter.Endpoints", "tcp -p 12344 -t 10000");
bool printAdapterReady = properties->getPropertyAsInt("Ice.PrintAdapterReady") > 0;
properties->setProperty("Ice.PrintAdapterReady", "0");
Ice::ObjectAdapterPtr kmAdapter = communicator->createObjectAdapter("KeyManagerAdapter");
kmAdapter->add(object, Ice::stringToIdentity("keyManager"));
kmAdapter->activate();
const string pingerEndpoints =
"ssl -p 12345 -t 10000"
":ssl -p 12346 -t 10000"
":ssl -p 12347 -t 10000"
":ssl -p 12348 -t 10000"
":ssl -p 12349 -t 10000";
if(printAdapterReady)
{
properties->setProperty("Ice.PrintAdapterReady", "1");
}
properties->setProperty("PingerAdapter.Endpoints", pingerEndpoints);
Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("PingerAdapter");
adapter->add(new PingerI(), Ice::stringToIdentity("pinger"));
adapter->activate();
communicator->waitForShutdown();
return EXIT_SUCCESS;
}
int
main(int argc, char* argv[])
{
int status;
Ice::CommunicatorPtr communicator;
try
{
communicator = Ice::initialize(argc, argv);
Ice::PropertiesPtr properties = communicator->getProperties();
Ice::StringSeq args = Ice::argsToStringSeq(argc, argv);
args = properties->parseCommandLineOptions("TestSSL", args);
Ice::stringSeqToArgs(args, argc, argv);
status = run(argc, argv, communicator);
}
catch(const Ice::Exception& ex)
{
cerr << ex << endl;
status = EXIT_FAILURE;
}
if(communicator)
{
try
{
communicator->destroy();
}
catch(const Ice::Exception& ex)
{
cerr << ex << endl;
status = EXIT_FAILURE;
}
}
return status;
}
|