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
|
// **********************************************************************
//
// Copyright (c) 2003-2016 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 <IceUtil/Thread.h>
#include <TestI.h>
#include <TestCommon.h>
#include <IceSSL/Plugin.h>
using namespace std;
using namespace Ice;
ServerI::ServerI(const CommunicatorPtr& communicator) :
_communicator(communicator)
{
}
void
ServerI::noCert(const Ice::Current& c)
{
try
{
IceSSL::NativeConnectionInfoPtr info = ICE_DYNAMIC_CAST(IceSSL::NativeConnectionInfo, c.con->getInfo());
test(info->nativeCerts.size() == 0);
}
catch(const Ice::LocalException& ex)
{
cerr << ex << endl;
test(false);
}
}
void
ServerI::checkCert(ICE_IN(string) subjectDN, ICE_IN(string) issuerDN, const Ice::Current& c)
{
try
{
IceSSL::NativeConnectionInfoPtr info = ICE_DYNAMIC_CAST(IceSSL::NativeConnectionInfo, c.con->getInfo());
test(info->verified);
test(info->nativeCerts.size() == 2);
if(c.ctx.find("uwp") != c.ctx.end())
{
//
// UWP client just provide the subject and issuer CN, and not the full Subject and Issuer DN
//
string subject(info->nativeCerts[0]->getSubjectDN());
test(subject.find(subjectDN) != string::npos);
string issuer(info->nativeCerts[0]->getIssuerDN());
test(issuer.find(issuerDN) != string::npos);
}
else
{
test(info->nativeCerts[0]->getSubjectDN() == IceSSL::DistinguishedName(subjectDN));
test(info->nativeCerts[0]->getIssuerDN() == IceSSL::DistinguishedName(issuerDN));
}
}
catch(const Ice::LocalException&)
{
test(false);
}
}
void
ServerI::checkCipher(ICE_IN(string) cipher, const Ice::Current& c)
{
try
{
IceSSL::NativeConnectionInfoPtr info = ICE_DYNAMIC_CAST(IceSSL::NativeConnectionInfo, c.con->getInfo());
test(info->cipher.compare(0, cipher.size(), cipher) == 0);
}
catch(const Ice::LocalException&)
{
test(false);
}
}
void
ServerI::destroy()
{
_communicator->destroy();
}
ServerFactoryI::ServerFactoryI(const string& defaultDir) : _defaultDir(defaultDir)
{
}
Test::ServerPrxPtr
ServerFactoryI::createServer(ICE_IN(Test::Properties) props, const Current&)
{
InitializationData initData;
initData.properties = createProperties();
for(Test::Properties::const_iterator p = props.begin(); p != props.end(); ++p)
{
initData.properties->setProperty(p->first, p->second);
}
initData.properties->setProperty("IceSSL.DefaultDir", _defaultDir);
CommunicatorPtr communicator = initialize(initData);
ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("ServerAdapter", "ssl");
ServerIPtr server = ICE_MAKE_SHARED(ServerI, communicator);
ObjectPrxPtr obj = adapter->addWithUUID(server);
_servers[obj->ice_getIdentity()] = server;
adapter->activate();
return ICE_UNCHECKED_CAST(Test::ServerPrx, obj);
}
void
ServerFactoryI::destroyServer(ICE_IN(Test::ServerPrxPtr) srv, const Ice::Current&)
{
map<Identity, ServerIPtr>::iterator p = _servers.find(srv->ice_getIdentity());
if(p != _servers.end())
{
p->second->destroy();
_servers.erase(p);
}
}
void
ServerFactoryI::shutdown(const Ice::Current& current)
{
test(_servers.empty());
current.adapter->getCommunicator()->shutdown();
}
|