diff options
author | Mark Spruiell <mes@zeroc.com> | 2006-04-25 18:25:05 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2006-04-25 18:25:05 +0000 |
commit | 8399fc0295b7c1e00de0c57604d355ea20887d2c (patch) | |
tree | 9b581d27da5a6ff0a9e187b972db4c0b69f7a209 /cpp/src/IceSSL/Util.cpp | |
parent | adding generated directory (diff) | |
download | ice-8399fc0295b7c1e00de0c57604d355ea20887d2c.tar.bz2 ice-8399fc0295b7c1e00de0c57604d355ea20887d2c.tar.xz ice-8399fc0295b7c1e00de0c57604d355ea20887d2c.zip |
minor cleanup in IceSSL
Diffstat (limited to 'cpp/src/IceSSL/Util.cpp')
-rw-r--r-- | cpp/src/IceSSL/Util.cpp | 78 |
1 files changed, 66 insertions, 12 deletions
diff --git a/cpp/src/IceSSL/Util.cpp b/cpp/src/IceSSL/Util.cpp index ba21216e997..09909f9d5d9 100644 --- a/cpp/src/IceSSL/Util.cpp +++ b/cpp/src/IceSSL/Util.cpp @@ -8,7 +8,7 @@ // ********************************************************************** #include <Util.h> -#include <Ice/LocalException.h>
+#include <Ice/LocalException.h> #include <Ice/Network.h> #ifdef _WIN32 @@ -21,6 +21,8 @@ # include <sys/stat.h> #endif +#include <openssl/err.h> + #include <IceUtil/DisableWarnings.h> using namespace std; @@ -394,8 +396,8 @@ IceSSL::checkPath(string& path, const string& defaultDir, bool dir) { // // Check if file exists. If not, try prepending the default - // directory and check again. If the file is found, the - // string argument is modified and true is returned. Otherwise + // directory and check again. If the path exists, the string + // argument is modified and true is returned. Otherwise // false is returned. // #ifdef _WIN32 @@ -436,14 +438,12 @@ IceSSL::populateConnectionInfo(SSL* ssl, SOCKET fd) assert(ssl != 0); // - // On the client side SSL_get_peer_cert_chain returns the - // entire chain of certs. On the server side the peer - // certificate must be obtained seperately. + // On the client side, SSL_get_peer_cert_chain returns the entire chain of certs. + // On the server side, the peer certificate must be obtained separately. // - // Since we have no clear idea whether the connection is server or - // client side the peer certificate is obtained seperately, and - // compared against the first certificate in the chain. If they - // are not the same, it is added to the chain. + // Since we have no clear idea whether the connection is server or client side, + // the peer certificate is obtained separately and compared against the first + // certificate in the chain. If they are not the same, it is added to the chain. // X509* cert = SSL_get_peer_certificate(ssl); STACK_OF(X509)* chain = SSL_get_peer_cert_chain(ssl); @@ -462,8 +462,7 @@ IceSSL::populateConnectionInfo(SSL* ssl, SOCKET fd) { X509* cert = sk_X509_value(chain, i); // - // This has to duplicate the certificate since the stack - // comes straight from the SSL connection. + // Duplicate the certificate since the stack comes straight from the SSL connection. // info.certs.push_back(new Certificate(X509_dup(cert))); } @@ -478,3 +477,58 @@ IceSSL::populateConnectionInfo(SSL* ssl, SOCKET fd) return info; } + +string +IceSSL::getSslErrors(bool verbose) +{ + ostringstream ostr; + + const char* file; + const char* data; + int line; + int flags; + unsigned long err; + int count = 0; + while((err = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) + { + if(count > 0) + { + ostr << endl; + } + + if(verbose) + { + if(count > 0) + { + ostr << endl; + } + + char buf[200]; + ERR_error_string_n(err, buf, sizeof(buf)); + + ostr << "error # = " << err << endl; + ostr << "message = " << buf << endl; + ostr << "location = " << file << ", " << line; + if(flags & ERR_TXT_STRING) + { + ostr << endl; + ostr << "data = " << data; + } + } + else + { + const char* reason = ERR_reason_error_string(err); + ostr << (reason == NULL ? "unknown reason" : reason); + if(flags & ERR_TXT_STRING) + { + ostr << ": " << data; + } + } + + ++count; + } + + ERR_clear_error(); + + return ostr.str(); +} |