diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2015-05-05 15:52:01 -0230 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2015-05-05 15:52:01 -0230 |
commit | b61582b1c6b16be4339aa0bded3ad8f542a01df9 (patch) | |
tree | 2040386a942217e2412e48c1e56465817ecac3d5 /python | |
parent | Missing export declarations (diff) | |
download | ice-b61582b1c6b16be4339aa0bded3ad8f542a01df9.tar.bz2 ice-b61582b1c6b16be4339aa0bded3ad8f542a01df9.tar.xz ice-b61582b1c6b16be4339aa0bded3ad8f542a01df9.zip |
ICE-6471 Add support for IceSSL endpoint/connection info to Python/Ruby/PHP
Diffstat (limited to 'python')
-rw-r--r-- | python/config/Make.rules | 2 | ||||
-rw-r--r-- | python/modules/IcePy/ConnectionInfo.cpp | 207 | ||||
-rw-r--r-- | python/modules/IcePy/EndpointInfo.cpp | 144 | ||||
-rw-r--r-- | python/python/Ice.py | 6 | ||||
-rw-r--r-- | python/test/Ice/info/AllTests.py | 9 | ||||
-rw-r--r-- | python/test/Ice/info/TestI.py | 2 |
6 files changed, 364 insertions, 6 deletions
diff --git a/python/config/Make.rules b/python/config/Make.rules index 7bafb323543..718e634b5d8 100644 --- a/python/config/Make.rules +++ b/python/config/Make.rules @@ -135,7 +135,7 @@ else ICE_LIB_DIR = -L$(ice_dir)/$(libsubdir) ICE_FLAGS = -I$(ice_dir)/include endif -ICE_LIBS = $(ICE_LIB_DIR) -lIce -lSlice -lIceUtil +ICE_LIBS = $(ICE_LIB_DIR) -lIceSSL -lIce -lSlice -lIceUtil CPPFLAGS = ICECPPFLAGS = -I$(slicedir) diff --git a/python/modules/IcePy/ConnectionInfo.cpp b/python/modules/IcePy/ConnectionInfo.cpp index bac83235083..2b7750c1cf8 100644 --- a/python/modules/IcePy/ConnectionInfo.cpp +++ b/python/modules/IcePy/ConnectionInfo.cpp @@ -14,6 +14,8 @@ #include <EndpointInfo.h> #include <Util.h> #include <Ice/Object.h> +#include <IceSSL/ConnectionInfo.h> + using namespace std; using namespace IcePy; @@ -178,6 +180,69 @@ wsConnectionInfoGetHeaders(ConnectionInfoObject* self) return result.release(); } +#ifdef WIN32 +extern "C" +#endif +static PyObject* +sslConnectionInfoGetCipher(ConnectionInfoObject* self) +{ + IceSSL::ConnectionInfoPtr info = IceSSL::ConnectionInfoPtr::dynamicCast(*self->connectionInfo); + assert(info); + return createString(info->cipher); +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* +sslConnectionInfoGetCerts(ConnectionInfoObject* self) +{ + IceSSL::ConnectionInfoPtr info = IceSSL::ConnectionInfoPtr::dynamicCast(*self->connectionInfo); + assert(info); + PyObject* certs = PyList_New(0); + stringSeqToList(info->certs, certs); + return certs; +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* +sslConnectionInfoGetVerified(ConnectionInfoObject* self) +{ + IceSSL::ConnectionInfoPtr info = IceSSL::ConnectionInfoPtr::dynamicCast(*self->connectionInfo); + assert(info); + PyObject* result = info->incoming ? getTrue() : getFalse(); + Py_INCREF(result); + return result; +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* +wssConnectionInfoGetHeaders(ConnectionInfoObject* self) +{ + IceSSL::WSSConnectionInfoPtr info = IceSSL::WSSConnectionInfoPtr::dynamicCast(*self->connectionInfo); + assert(info); + + PyObjectHandle result = PyDict_New(); + if(result.get()) + { + for(Ice::HeaderDict::iterator p = info->headers.begin(); p != info->headers.end(); ++p) + { + PyObjectHandle key = createString(p->first); + PyObjectHandle val = createString(p->second); + if(!val.get() || PyDict_SetItem(result.get(), key.get(), val.get()) < 0) + { + return 0; + } + } + } + + return result.release(); +} + static PyGetSetDef ConnectionInfoGetters[] = { { STRCAST("incoming"), reinterpret_cast<getter>(connectionInfoGetIncoming), 0, @@ -220,6 +285,24 @@ static PyGetSetDef WSConnectionInfoGetters[] = { 0, 0 } /* sentinel */ }; +static PyGetSetDef SSLConnectionInfoGetters[] = +{ + { STRCAST("cipher"), reinterpret_cast<getter>(sslConnectionInfoGetCipher), 0, + PyDoc_STR(STRCAST("negotiated cipher suite")), 0 }, + { STRCAST("certs"), reinterpret_cast<getter>(sslConnectionInfoGetCerts), 0, + PyDoc_STR(STRCAST("certificate chain")), 0 }, + { STRCAST("verified"), reinterpret_cast<getter>(sslConnectionInfoGetVerified), 0, + PyDoc_STR(STRCAST("certificate chain verification status")), 0 }, + { 0, 0 } /* sentinel */ +}; + +static PyGetSetDef WSSConnectionInfoGetters[] = +{ + { STRCAST("headers"), reinterpret_cast<getter>(wssConnectionInfoGetHeaders), 0, + PyDoc_STR(STRCAST("request headers")), 0 }, + { 0, 0 } /* sentinel */ +}; + namespace IcePy { @@ -458,6 +541,100 @@ PyTypeObject WSConnectionInfoType = 0, /* tp_is_gc */ }; +PyTypeObject SSLConnectionInfoType = +{ + /* The ob_type field must be initialized in the module init function + * to be portable to Windows without using C++. */ + PyVarObject_HEAD_INIT(0, 0) + STRCAST("IcePy.SSLConnectionInfo"),/* tp_name */ + sizeof(ConnectionInfoObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + /* methods */ + (destructor)connectionInfoDealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + 0, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + SSLConnectionInfoGetters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + (newfunc)connectionInfoNew, /* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc */ +}; + +PyTypeObject WSSConnectionInfoType = +{ + /* The ob_type field must be initialized in the module init function + * to be portable to Windows without using C++. */ + PyVarObject_HEAD_INIT(0, 0) + STRCAST("IcePy.WSSConnectionInfo"),/* tp_name */ + sizeof(ConnectionInfoObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + /* methods */ + (destructor)connectionInfoDealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + 0, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + WSSConnectionInfoGetters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + (newfunc)connectionInfoNew, /* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc */ +}; + } bool @@ -517,6 +694,28 @@ IcePy::initConnectionInfo(PyObject* module) return false; } + SSLConnectionInfoType.tp_base = &IPConnectionInfoType; // Force inheritance from IPConnectionInfoType. + if(PyType_Ready(&SSLConnectionInfoType) < 0) + { + return false; + } + type = &SSLConnectionInfoType; // Necessary to prevent GCC's strict-alias warnings. + if(PyModule_AddObject(module, STRCAST("SSLConnectionInfo"), reinterpret_cast<PyObject*>(type)) < 0) + { + return false; + } + + WSSConnectionInfoType.tp_base = &SSLConnectionInfoType; // Force inheritance from IPConnectionType. + if(PyType_Ready(&WSSConnectionInfoType) < 0) + { + return false; + } + type = &WSSConnectionInfoType; // Necessary to prevent GCC's strict-alias warnings. + if(PyModule_AddObject(module, STRCAST("WSSConnectionInfo"), reinterpret_cast<PyObject*>(type)) < 0) + { + return false; + } + return true; } @@ -544,6 +743,14 @@ IcePy::createConnectionInfo(const Ice::ConnectionInfoPtr& connectionInfo) { type = &UDPConnectionInfoType; } + else if(IceSSL::WSSConnectionInfoPtr::dynamicCast(connectionInfo)) + { + type = &WSSConnectionInfoType; + } + else if(IceSSL::ConnectionInfoPtr::dynamicCast(connectionInfo)) + { + type = &SSLConnectionInfoType; + } else if(Ice::IPConnectionInfoPtr::dynamicCast(connectionInfo)) { type = &IPConnectionInfoType; diff --git a/python/modules/IcePy/EndpointInfo.cpp b/python/modules/IcePy/EndpointInfo.cpp index 1106390b20a..9df2eaae114 100644 --- a/python/modules/IcePy/EndpointInfo.cpp +++ b/python/modules/IcePy/EndpointInfo.cpp @@ -12,6 +12,7 @@ #endif #include <EndpointInfo.h> #include <Util.h> +#include <IceSSL/EndpointInfo.h> using namespace std; using namespace IcePy; @@ -209,6 +210,17 @@ wsEndpointInfoGetResource(EndpointInfoObject* self) extern "C" #endif static PyObject* +wssEndpointInfoGetResource(EndpointInfoObject* self) +{ + IceSSL::WSSEndpointInfoPtr info = IceSSL::WSSEndpointInfoPtr::dynamicCast(*self->endpointInfo); + assert(info); + return createString(info->resource); +} + +#ifdef WIN32 +extern "C" +#endif +static PyObject* opaqueEndpointInfoGetRawBytes(EndpointInfoObject* self) { Ice::OpaqueEndpointInfoPtr info = Ice::OpaqueEndpointInfoPtr::dynamicCast(*self->endpointInfo); @@ -280,6 +292,13 @@ static PyGetSetDef WSEndpointInfoGetters[] = { 0, 0 } /* sentinel */ }; +static PyGetSetDef WSSEndpointInfoGetters[] = +{ + { STRCAST("resource"), reinterpret_cast<getter>(wssEndpointInfoGetResource), 0, + PyDoc_STR(STRCAST("resource")), 0 }, + { 0, 0 } /* sentinel */ +}; + static PyGetSetDef OpaqueEndpointInfoGetters[] = { { STRCAST("rawBytes"), reinterpret_cast<getter>(opaqueEndpointInfoGetRawBytes), 0, @@ -527,6 +546,100 @@ PyTypeObject WSEndpointInfoType = 0, /* tp_is_gc */ }; +PyTypeObject SSLEndpointInfoType = +{ + /* The ob_type field must be initialized in the module init function + * to be portable to Windows without using C++. */ + PyVarObject_HEAD_INIT(0, 0) + STRCAST("IcePy.SSLEndpointInfo"),/* tp_name */ + sizeof(EndpointInfoObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + /* methods */ + reinterpret_cast<destructor>(endpointInfoDealloc), /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + 0, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + reinterpret_cast<newfunc>(endpointInfoNew), /* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc */ +}; + +PyTypeObject WSSEndpointInfoType = +{ + /* The ob_type field must be initialized in the module init function + * to be portable to Windows without using C++. */ + PyVarObject_HEAD_INIT(0, 0) + STRCAST("IcePy.WSSEndpointInfo"), /* tp_name */ + sizeof(EndpointInfoObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + /* methods */ + reinterpret_cast<destructor>(endpointInfoDealloc), /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + 0, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + WSSEndpointInfoGetters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + reinterpret_cast<newfunc>(endpointInfoNew), /* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc */ +}; + PyTypeObject OpaqueEndpointInfoType = { /* The ob_type field must be initialized in the module init function @@ -633,6 +746,28 @@ IcePy::initEndpointInfo(PyObject* module) return false; } + SSLEndpointInfoType.tp_base = &IPEndpointInfoType; // Force inheritance from IPEndpointInfoType. + if(PyType_Ready(&SSLEndpointInfoType) < 0) + { + return false; + } + type = &SSLEndpointInfoType; // Necessary to prevent GCC's strict-alias warnings. + if(PyModule_AddObject(module, STRCAST("SSLEndpointInfo"), reinterpret_cast<PyObject*>(type)) < 0) + { + return false; + } + + WSSEndpointInfoType.tp_base = &SSLEndpointInfoType; // Force inheritance from SSLEndpointInfoType. + if(PyType_Ready(&WSSEndpointInfoType) < 0) + { + return false; + } + type = &WSSEndpointInfoType; // Necessary to prevent GCC's strict-alias warnings. + if(PyModule_AddObject(module, STRCAST("WSSEndpointInfo"), reinterpret_cast<PyObject*>(type)) < 0) + { + return false; + } + OpaqueEndpointInfoType.tp_base = &EndpointInfoType; // Force inheritance from EndpointType. if(PyType_Ready(&OpaqueEndpointInfoType) < 0) { @@ -671,6 +806,14 @@ IcePy::createEndpointInfo(const Ice::EndpointInfoPtr& endpointInfo) { type = &UDPEndpointInfoType; } + else if(IceSSL::WSSEndpointInfoPtr::dynamicCast(endpointInfo)) + { + type = &WSSEndpointInfoType; + } + else if(IceSSL::EndpointInfoPtr::dynamicCast(endpointInfo)) + { + type = &SSLEndpointInfoType; + } else if(Ice::OpaqueEndpointInfoPtr::dynamicCast(endpointInfo)) { type = &OpaqueEndpointInfoType; @@ -681,6 +824,7 @@ IcePy::createEndpointInfo(const Ice::EndpointInfoPtr& endpointInfo) } else { + std::cout << "CREATE" << std::endl; type = &EndpointInfoType; } diff --git a/python/python/Ice.py b/python/python/Ice.py index b8c9f0a8721..2ef4dbfcd47 100644 --- a/python/python/Ice.py +++ b/python/python/Ice.py @@ -471,6 +471,9 @@ WSEndpointInfo = IcePy.WSEndpointInfo del OpaqueEndpointInfo OpaqueEndpointInfo = IcePy.OpaqueEndpointInfo +SSLEndpointInfo = IcePy.SSLEndpointInfo +WSSEndpointInfo = IcePy.WSSEndpointInfo + # # Replace ConnectionInfo with our implementation. # @@ -485,6 +488,9 @@ UDPConnectionInfo = IcePy.UDPConnectionInfo del WSConnectionInfo WSConnectionInfo = IcePy.WSConnectionInfo +SSLConnectionInfo = IcePy.SSLConnectionInfo +WSSConnectionInfo = IcePy.WSSConnectionInfo + class ThreadNotification(object): '''Base class for thread notification callbacks. A subclass must define the start and stop methods.''' diff --git a/python/test/Ice/info/AllTests.py b/python/test/Ice/info/AllTests.py index 5dd6dbb5c69..35b21233b34 100644 --- a/python/test/Ice/info/AllTests.py +++ b/python/test/Ice/info/AllTests.py @@ -36,9 +36,9 @@ def allTests(communicator): (ipEndpoint.type() == Ice.WSEndpointType and not ipEndpoint.secure()) or # WS (ipEndpoint.type() == Ice.WSSEndpointType and ipEndpoint.secure())) # WS test((ipEndpoint.type() == Ice.TCPEndpointType and isinstance(ipEndpoint, Ice.TCPEndpointInfo)) or - (ipEndpoint.type() == Ice.SSLEndpointType) or + (ipEndpoint.type() == Ice.SSLEndpointType and isinstance(ipEndpoint, Ice.SSLEndpointInfo)) or (ipEndpoint.type() == Ice.WSEndpointType and isinstance(ipEndpoint, Ice.WSEndpointInfo)) or - (ipEndpoint.type() == Ice.WSSEndpointType)) + (ipEndpoint.type() == Ice.WSSEndpointType and isinstance(ipEndpoint, Ice.WSSEndpointInfo))) udpEndpoint = endps[1].getInfo() test(isinstance(udpEndpoint, Ice.UDPEndpointInfo)) @@ -153,8 +153,9 @@ def allTests(communicator): test(ctx["remotePort"] == str(info.localPort)) test(ctx["localPort"] == str(info.remotePort)) - if(base.ice_getConnection().type() == "ws"): - test(isinstance(info, Ice.WSConnectionInfo)) + if(base.ice_getConnection().type() == "ws" or base.ice_getConnection().type() == "wss"): + test((base.ice_getConnection().type() == "ws" and isinstance(info, Ice.WSConnectionInfo)) or + (base.ice_getConnection().type() == "wss" and isinstance(info, Ice.WSSConnectionInfo))) test(info.headers["Upgrade"] == "websocket") test(info.headers["Connection"] == "Upgrade") diff --git a/python/test/Ice/info/TestI.py b/python/test/Ice/info/TestI.py index c0b266a7ba4..863ac7ffdc9 100644 --- a/python/test/Ice/info/TestI.py +++ b/python/test/Ice/info/TestI.py @@ -62,7 +62,7 @@ class MyDerivedClassI(Test.TestIntf): ctx["remoteAddress"] = info.remoteAddress ctx["remotePort"] = str(info.remotePort) - if isinstance(info, Ice.WSConnectionInfo): + if isinstance(info, Ice.WSConnectionInfo) or isinstance(info, Ice.WSSConnectionInfo): for key, value in info.headers.items(): ctx["ws." + key] = value |