summaryrefslogtreecommitdiff
path: root/cpp/src/IceSSL/OpenSSLPluginI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/IceSSL/OpenSSLPluginI.cpp')
-rw-r--r--cpp/src/IceSSL/OpenSSLPluginI.cpp130
1 files changed, 130 insertions, 0 deletions
diff --git a/cpp/src/IceSSL/OpenSSLPluginI.cpp b/cpp/src/IceSSL/OpenSSLPluginI.cpp
new file mode 100644
index 00000000000..7328dfbf41d
--- /dev/null
+++ b/cpp/src/IceSSL/OpenSSLPluginI.cpp
@@ -0,0 +1,130 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2017 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 <IceSSL/PluginI.h>
+#include <IceSSL/OpenSSL.h>
+#include <IceSSL/OpenSSLEngine.h>
+
+#include <Ice/Initialize.h>
+
+using namespace std;
+
+namespace
+{
+
+class PluginI : public IceSSL::PluginI,
+ public IceSSL::OpenSSL::Plugin
+{
+public:
+
+ PluginI(const Ice::CommunicatorPtr&);
+
+ virtual string getEngineName() const;
+ virtual Ice::Long getEngineVersion() const;
+ virtual IceSSL::CertificatePtr create(x509_st*) const;
+ virtual IceSSL::CertificatePtr load(const std::string&) const;
+ virtual IceSSL::CertificatePtr decode(const std::string&) const;
+ virtual void setContext(SSL_CTX*);
+ virtual SSL_CTX* getContext();
+};
+
+} // anonymous namespace end
+
+//
+// Plugin implementation.
+//
+PluginI::PluginI(const Ice::CommunicatorPtr& com) :
+ IceSSL::PluginI(com, new IceSSL::OpenSSL::SSLEngine(com))
+{
+}
+
+string
+PluginI::getEngineName() const
+{
+ ostringstream os;
+ os << "OpenSSLEngine@" << SSLeay_version(SSLEAY_VERSION);
+ return os.str();
+}
+
+Ice::Long
+PluginI::getEngineVersion() const
+{
+ return SSLeay();
+}
+
+IceSSL::CertificatePtr
+PluginI::create(x509_st* cert) const
+{
+ return IceSSL::OpenSSL::Certificate::create(cert);
+}
+
+IceSSL::CertificatePtr
+PluginI::load(const std::string& file) const
+{
+ return IceSSL::OpenSSL::Certificate::load(file);
+}
+
+IceSSL::CertificatePtr
+PluginI::decode(const std::string& encoding) const
+{
+ return IceSSL::OpenSSL::Certificate::load(encoding);
+}
+
+void
+PluginI::setContext(SSL_CTX* context)
+{
+ IceSSL::OpenSSL::SSLEngine* engine = dynamic_cast<IceSSL::OpenSSL::SSLEngine*>(_engine.get());
+ assert(engine);
+ engine->context(context);
+}
+
+SSL_CTX*
+PluginI::getContext()
+{
+ IceSSL::OpenSSL::SSLEngine* engine = dynamic_cast<IceSSL::OpenSSL::SSLEngine*>(_engine.get());
+ assert(engine);
+ return engine->context();
+}
+
+#ifdef _WIN32
+//
+// Plug-in factory function.
+//
+extern "C" ICESSL_OPENSSL_API Ice::Plugin*
+createIceSSLOpenSSL(const Ice::CommunicatorPtr& communicator, const string& /*name*/, const Ice::StringSeq& /*args*/)
+{
+ return new PluginI(communicator);
+}
+
+#else
+
+extern "C" ICESSL_API Ice::Plugin*
+createIceSSL(const Ice::CommunicatorPtr& communicator, const string& /*name*/, const Ice::StringSeq& /*args*/)
+{
+ return new PluginI(communicator);
+}
+
+//
+// The following functions are defined only when OpenSSL is the default
+// implementation. In Windows the default implementation is always
+// SChannel.
+//
+IceSSL::CertificatePtr
+IceSSL::Certificate::load(const std::string& file)
+{
+ return IceSSL::OpenSSL::Certificate::load(file);
+}
+
+IceSSL::CertificatePtr
+IceSSL::Certificate::decode(const std::string& encoding)
+{
+ return IceSSL::OpenSSL::Certificate::decode(encoding);
+}
+
+#endif