diff options
author | Anthony Neal <aneal@zeroc.com> | 2002-03-27 23:21:12 +0000 |
---|---|---|
committer | Anthony Neal <aneal@zeroc.com> | 2002-03-27 23:21:12 +0000 |
commit | 47c14153acda0a14ef83accaa93453177fb60571 (patch) | |
tree | 2600428b56bc8b86925e55e55fe6ec1dfeb0dc22 /cpp/src/Ice/SystemOpenSSL.cpp | |
parent | comments (diff) | |
download | ice-47c14153acda0a14ef83accaa93453177fb60571.tar.bz2 ice-47c14153acda0a14ef83accaa93453177fb60571.tar.xz ice-47c14153acda0a14ef83accaa93453177fb60571.zip |
Cleaned up some stuff.
Diffstat (limited to 'cpp/src/Ice/SystemOpenSSL.cpp')
-rw-r--r-- | cpp/src/Ice/SystemOpenSSL.cpp | 163 |
1 files changed, 68 insertions, 95 deletions
diff --git a/cpp/src/Ice/SystemOpenSSL.cpp b/cpp/src/Ice/SystemOpenSSL.cpp index 321ceb68360..6250b087593 100644 --- a/cpp/src/Ice/SystemOpenSSL.cpp +++ b/cpp/src/Ice/SystemOpenSSL.cpp @@ -23,7 +23,7 @@ // #include <IceUtil/Config.h> #include <IceUtil/Mutex.h> -#include <IceUtil/RecMutex.h>
+#include <IceUtil/RecMutex.h> #include <Ice/SslConnectionOpenSSL.h> #include <Ice/SystemOpenSSL.h> #include <Ice/SslException.h> @@ -31,9 +31,9 @@ #include <Ice/OpenSSLJanitors.h> #include <Ice/TraceLevels.h> #include <Ice/Logger.h> -
-#include <Ice/RSAPrivateKey.h>
-#include <Ice/DHParams.h>
+ +#include <Ice/RSAPrivateKey.h> +#include <Ice/DHParams.h> #include <openssl/e_os.h> #include <openssl/rand.h> @@ -51,8 +51,8 @@ using IceSSL::SystemInternalPtr; IceSSL::ConnectionPtr IceSSL::OpenSSL::System::createConnection(ContextType connectionType, int socket) { - IceUtil::RecMutex::Lock sync(_configMutex);
-
+ IceUtil::RecMutex::Lock sync(_configMutex); + if (connectionType == ClientServer) { UnsupportedContextException unsupportedException(__FILE__, __LINE__); @@ -82,37 +82,11 @@ IceSSL::OpenSSL::System::createConnection(ContextType connectionType, int socket return connection; } -void -IceSSL::OpenSSL::System::shutdown() -{
-/* - // Free our temporary RSA keys. - RSAMap::iterator iRSA = _tempRSAKeys.begin(); - RSAMap::iterator eRSA = _tempRSAKeys.end(); - - while (iRSA != eRSA) - { - RSA_free((*iRSA).second); - iRSA++; - }
- - // Free our temporary DH params. - DHMap::iterator iDH = _tempDHKeys.begin(); - DHMap::iterator eDH = _tempDHKeys.end(); - - while (iDH != eDH) - { - DH_free((*iDH).second); - iDH++; - } -*/
-} - bool IceSSL::OpenSSL::System::isConfigured(ContextType contextType) { - IceUtil::RecMutex::Lock sync(_configMutex);
-
+ IceUtil::RecMutex::Lock sync(_configMutex); + bool retCode = false; switch (contextType) @@ -142,8 +116,8 @@ IceSSL::OpenSSL::System::isConfigured(ContextType contextType) void IceSSL::OpenSSL::System::configure(ContextType contextType) { - IceUtil::RecMutex::Lock sync(_configMutex);
-
+ IceUtil::RecMutex::Lock sync(_configMutex); + switch (contextType) { case Client : @@ -170,7 +144,7 @@ IceSSL::OpenSSL::System::configure(ContextType contextType) string serverCertPath = _properties->getProperty("Ice.SSL.Server.CertPath"); // Short cut, so that we only have to load the file once. - if ((clientConfigFile == serverConfigFile) && (clientCertPath == serverCertPath))
+ if ((clientConfigFile == serverConfigFile) && (clientCertPath == serverCertPath)) { loadConfig(ClientServer, clientConfigFile, clientCertPath); } @@ -182,7 +156,7 @@ IceSSL::OpenSSL::System::configure(ContextType contextType) break; } } -}
+} void IceSSL::OpenSSL::System::loadConfig(ContextType contextType, @@ -230,7 +204,7 @@ IceSSL::OpenSSL::System::loadConfig(ContextType contextType, // Actually parse the file now. sslConfig.process(); -
+ if ((contextType == Client || contextType == ClientServer)) { GeneralConfig clientGeneral; @@ -245,7 +219,7 @@ IceSSL::OpenSSL::System::loadConfig(ContextType contextType, _clientContext.configure(clientGeneral, clientCertAuth, clientBaseCerts); } } -
+ if ((contextType == Server || contextType == ClientServer)) { GeneralConfig serverGeneral; @@ -335,11 +309,11 @@ IceSSL::OpenSSL::System::getRSAKey(int isExport, int keyLength) rsa_tmp = rsaCert; } else - {
- if (rsaCert != 0)
+ { + if (rsaCert != 0) { RSA_free(rsaCert); - rsaCert = 0;
+ rsaCert = 0; } } } @@ -402,9 +376,9 @@ void IceSSL::OpenSSL::System::setCertificateVerifier(ContextType contextType, const IceSSL::CertificateVerifierPtr& verifier) { - IceUtil::RecMutex::Lock sync(_configMutex);
-
- IceSSL::OpenSSL::CertificateVerifierPtr castVerifier;
+ IceUtil::RecMutex::Lock sync(_configMutex); + + IceSSL::OpenSSL::CertificateVerifierPtr castVerifier; castVerifier = IceSSL::OpenSSL::CertificateVerifierPtr::dynamicCast(verifier); if (!castVerifier.get()) @@ -427,8 +401,8 @@ IceSSL::OpenSSL::System::setCertificateVerifier(ContextType contextType, void IceSSL::OpenSSL::System::addTrustedCertificateBase64(ContextType contextType, const string& certString) { - IceUtil::RecMutex::Lock sync(_configMutex);
-
+ IceUtil::RecMutex::Lock sync(_configMutex); + if (contextType == Client || contextType == ClientServer) { _clientContext.addTrustedCertificateBase64(certString); @@ -440,29 +414,29 @@ IceSSL::OpenSSL::System::addTrustedCertificateBase64(ContextType contextType, co } } -void
-IceSSL::OpenSSL::System::addTrustedCertificate(ContextType contextType, const Ice::ByteSeq& certSeq)
-{
- IceUtil::RecMutex::Lock sync(_configMutex);
-
- if (contextType == Client || contextType == ClientServer)
- {
- _clientContext.addTrustedCertificate(certSeq);
- }
-
- if (contextType == Server || contextType == ClientServer)
- {
- _serverContext.addTrustedCertificate(certSeq);
- }
-}
-
+void +IceSSL::OpenSSL::System::addTrustedCertificate(ContextType contextType, const Ice::ByteSeq& certSeq) +{ + IceUtil::RecMutex::Lock sync(_configMutex); + + if (contextType == Client || contextType == ClientServer) + { + _clientContext.addTrustedCertificate(certSeq); + } + + if (contextType == Server || contextType == ClientServer) + { + _serverContext.addTrustedCertificate(certSeq); + } +} + void IceSSL::OpenSSL::System::setRSAKeysBase64(ContextType contextType, const std::string& privateKey, const std::string& publicKey) { - IceUtil::RecMutex::Lock sync(_configMutex);
-
+ IceUtil::RecMutex::Lock sync(_configMutex); + if (contextType == Client || contextType == ClientServer) { _clientContext.setRSAKeysBase64(privateKey, publicKey); @@ -479,8 +453,8 @@ IceSSL::OpenSSL::System::setRSAKeys(ContextType contextType, const ::Ice::ByteSeq& privateKey, const ::Ice::ByteSeq& publicKey) { - IceUtil::RecMutex::Lock sync(_configMutex);
-
+ IceUtil::RecMutex::Lock sync(_configMutex); + if (contextType == Client || contextType == ClientServer) { _clientContext.setRSAKeys(privateKey, publicKey); @@ -510,7 +484,6 @@ IceSSL::OpenSSL::System::System(const IceInternal::InstancePtr& instance) : IceSSL::OpenSSL::System::~System() { - shutdown(); } // @@ -524,13 +497,13 @@ IceSSL::OpenSSL::System::seedRand() RAND_screen(); #endif - char buffer[1024];
+ char buffer[1024]; const char* file = RAND_file_name(buffer, sizeof(buffer)); -
- if (file == 0)
- {
- return 0;
- }
+ + if (file == 0) + { + return 0; + } return RAND_load_file(file, -1); } @@ -539,11 +512,11 @@ long IceSSL::OpenSSL::System::loadRandFiles(const string& names) { if (!names.empty()) - {
- return 0;
+ { + return 0; } -
- long tot = 0;
+ + long tot = 0; int egd; // Make a modifiable copy of the string. @@ -588,27 +561,27 @@ void IceSSL::OpenSSL::System::initRandSystem(const string& randBytesFiles) { if (_randSeeded) - {
- return;
- }
-
- long randBytesLoaded = seedRand();
- - if (!randBytesFiles.empty())
- {
- randBytesLoaded += loadRandFiles(randBytesFiles);
- }
-
+ { + return; + } + + long randBytesLoaded = seedRand(); + + if (!randBytesFiles.empty()) + { + randBytesLoaded += loadRandFiles(randBytesFiles); + } + if (!randBytesLoaded && !RAND_status() && (_traceLevels->security >= IceSSL::SECURITY_WARNINGS)) - {
- // In this case, there are two options open to us - specify a random data file using the
- // RANDFILE environment variable, or specify additional random data files in the
+ { + // In this case, there are two options open to us - specify a random data file using the + // RANDFILE environment variable, or specify additional random data files in the // SSL configuration file. _logger->trace(_traceLevels->securityCat, "WRN There is a lack of random data, consider specifying additional random data files."); } -
- _randSeeded = (randBytesLoaded > 0 ? 1 : 0);
+ + _randSeeded = (randBytesLoaded > 0 ? 1 : 0); } void |