~ubuntu-branches/ubuntu/quantal/zeroc-ice/quantal

« back to all changes in this revision

Viewing changes to .pc/ice_for_gcc4.7.patch/cpp/test/Glacier2/ssl/Server.cpp

  • Committer: Package Import Robot
  • Author(s): Michael Ziegler
  • Date: 2012-07-07 15:24:30 UTC
  • mfrom: (6.1.25 sid)
  • Revision ID: package-import@ubuntu.com-20120707152430-kktx4mfmywkz382j
Tags: 3.4.2-8.1
* Non-maintainer upload.
* Revert the patch 'fixing' the FTBFS with gcc-4.7 that breaks ABI, and
  add force_gcc_4.6.patch.  We need to do this all in the upstream makefile
  because it has a silly check for the intel icpc compiler that we need to
  patch around or the build will fail with anything but c++ as the compiler,
  and we can't just override CXX in /rules because the wonderful 3.0 (quilt)
  system will revert that patch before the clean target is run ensuring that
  hilarious fail is guaranteed.
  Closes: #672066

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// **********************************************************************
2
 
//
3
 
// Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
4
 
//
5
 
// This copy of Ice is licensed to you under the terms described in the
6
 
// ICE_LICENSE file included in this distribution.
7
 
//
8
 
// **********************************************************************
9
 
 
10
 
#include <Ice/Application.h>
11
 
#include <Glacier2/PermissionsVerifier.h>
12
 
#include <Glacier2/Session.h>
13
 
#include <TestCommon.h>
14
 
#include <IceSSL/Plugin.h>
15
 
 
16
 
using namespace std;
17
 
 
18
 
namespace
19
 
{
20
 
 
21
 
void testContext(bool ssl, const Ice::Context& context)
22
 
{
23
 
    Ice::Context ctx = context;
24
 
    if(!ssl)
25
 
    {
26
 
        test(ctx["_con.type"] == "tcp");
27
 
        test(ctx["_con.localPort"] == "12347");
28
 
    }
29
 
    else
30
 
    {
31
 
        test(ctx["_con.type"] == "ssl");
32
 
        test(ctx["_con.localPort"] == "12348");
33
 
    }
34
 
    test(ctx["_con.localAddress"] == "127.0.0.1");
35
 
    test(ctx["_con.remotePort"] != "");
36
 
    test(ctx["_con.remoteAddress"] == "127.0.0.1");
37
 
}
38
 
 
39
 
}
40
 
 
41
 
class PermissionsVerifierI : public Glacier2::PermissionsVerifier
42
 
{
43
 
public:
44
 
 
45
 
    virtual bool
46
 
    checkPermissions(const string& userId, const string& password, string& reason, const Ice::Current& current) const
47
 
    {
48
 
        testContext(userId == "ssl", current.ctx);
49
 
        return true;
50
 
    }
51
 
};
52
 
 
53
 
class SSLPermissionsVerifierI : public Glacier2::SSLPermissionsVerifier
54
 
{
55
 
public:
56
 
 
57
 
    virtual bool
58
 
    authorize(const Glacier2::SSLInfo& info, string&, const Ice::Current& current) const
59
 
    {
60
 
        testContext(true, current.ctx);
61
 
 
62
 
        IceSSL::CertificatePtr cert = IceSSL::Certificate::decode(info.certs[0]);
63
 
        test(cert->getIssuerDN() == IceSSL::DistinguishedName(
64
 
            "emailAddress=info@zeroc.com,CN=ZeroC Test CA,OU=Ice,O=ZeroC\\, Inc.,"
65
 
             "L=Palm Beach Gardens,ST=Florida,C=US"));
66
 
        test(cert->getSubjectDN() == IceSSL::DistinguishedName(
67
 
            "CN=Client,emailAddress=info@zeroc.com,OU=Ice,O=ZeroC\\, Inc.,ST=Florida,C=US"));
68
 
        test(cert->checkValidity());
69
 
 
70
 
        return true;
71
 
    }
72
 
};
73
 
 
74
 
class SessionI : public Glacier2::Session
75
 
{
76
 
public:
77
 
 
78
 
    SessionI(bool shutdown, bool ssl) : _shutdown(shutdown), _ssl(ssl)
79
 
    {
80
 
    }
81
 
 
82
 
    virtual void
83
 
    destroy(const Ice::Current& current)
84
 
    {
85
 
        testContext(_ssl, current.ctx);
86
 
 
87
 
        if(_ssl && _shutdown)
88
 
        {
89
 
            // DEPRECATED
90
 
            Ice::Context::const_iterator p = current.ctx.find("SSL.Active");
91
 
            assert(p != current.ctx.end() && p->second == "1");
92
 
        }
93
 
 
94
 
        current.adapter->remove(current.id);
95
 
        if(_shutdown)
96
 
        {
97
 
            current.adapter->getCommunicator()->shutdown();
98
 
        }
99
 
    }
100
 
 
101
 
    virtual void
102
 
    ice_ping(const Ice::Current& current)
103
 
    {
104
 
        testContext(_ssl, current.ctx);
105
 
    }
106
 
 
107
 
private:
108
 
 
109
 
    const bool _shutdown;
110
 
    const bool _ssl;
111
 
};
112
 
 
113
 
class SessionManagerI : public Glacier2::SessionManager
114
 
{
115
 
public:
116
 
 
117
 
    virtual Glacier2::SessionPrx
118
 
    create(const string& userId, const Glacier2::SessionControlPrx&, const Ice::Current& current)
119
 
    {
120
 
        testContext(userId == "ssl", current.ctx);
121
 
 
122
 
        Glacier2::SessionPtr session = new SessionI(false, userId == "ssl");
123
 
        return Glacier2::SessionPrx::uncheckedCast(current.adapter->addWithUUID(session));
124
 
    }
125
 
};
126
 
 
127
 
class SSLSessionManagerI : public Glacier2::SSLSessionManager
128
 
{
129
 
public:
130
 
 
131
 
    virtual Glacier2::SessionPrx
132
 
    create(const Glacier2::SSLInfo& info, const Glacier2::SessionControlPrx&, const Ice::Current& current)
133
 
    {
134
 
        testContext(true, current.ctx);
135
 
 
136
 
        test(info.remoteHost == "127.0.0.1");
137
 
        test(info.localHost == "127.0.0.1");
138
 
        test(info.localPort == 12348);
139
 
 
140
 
        try
141
 
        {
142
 
            IceSSL::CertificatePtr cert = IceSSL::Certificate::decode(info.certs[0]);
143
 
            test(cert->getIssuerDN() == IceSSL::DistinguishedName(
144
 
                "emailAddress=info@zeroc.com,CN=ZeroC Test CA,OU=Ice,O=ZeroC\\, Inc.,L=Palm Beach Gardens,"
145
 
                "ST=Florida,C=US"));
146
 
            test(cert->getSubjectDN() == IceSSL::DistinguishedName(
147
 
                "CN=Client,emailAddress=info@zeroc.com,OU=Ice,O=ZeroC\\, Inc.,ST=Florida,C=US"));
148
 
            test(cert->checkValidity());
149
 
        }
150
 
        catch(const IceSSL::CertificateReadException&)
151
 
        {
152
 
            test(false);
153
 
        }
154
 
 
155
 
        Glacier2::SessionPtr session = new SessionI(true, true);
156
 
        return Glacier2::SessionPrx::uncheckedCast(current.adapter->addWithUUID(session));
157
 
    }
158
 
};
159
 
 
160
 
class SessionServer : public Ice::Application
161
 
{
162
 
public:
163
 
 
164
 
    virtual int run(int, char*[]);
165
 
};
166
 
 
167
 
int
168
 
main(int argc, char* argv[])
169
 
{
170
 
    SessionServer app;
171
 
    return app.main(argc, argv);
172
 
}
173
 
 
174
 
int
175
 
SessionServer::run(int argc, char* argv[])
176
 
{
177
 
    Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapterWithEndpoints(
178
 
        "SessionServer", "tcp -h 127.0.0.1 -p 12350");
179
 
    adapter->add(new PermissionsVerifierI, communicator()->stringToIdentity("verifier"));
180
 
    adapter->add(new SSLPermissionsVerifierI, communicator()->stringToIdentity("sslverifier"));
181
 
    adapter->add(new SessionManagerI, communicator()->stringToIdentity("sessionmanager"));
182
 
    adapter->add(new SSLSessionManagerI, communicator()->stringToIdentity("sslsessionmanager"));
183
 
    adapter->activate();
184
 
    communicator()->waitForShutdown();
185
 
    return EXIT_SUCCESS;
186
 
}