00001
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "KjSslObject.h"
00035
00036 KjSslObject::KjSslObject()
00037 {
00038 m_pCtx = NULL;
00039 SSL_load_error_strings();
00040 SSL_library_init();
00041 m_pCtx=SSL_CTX_new(SSLv3_method());
00042 SSL_CTX_set_options(m_pCtx, SSL_OP_ALL);
00043 }
00044
00045 KjSslObject::~KjSslObject()
00046 {
00047 }
00048
00051 void KjSslObject::CheckErrors(const string &_str)
00052 {
00053 int i;
00054 cerr << _str << ':' << endl;
00055 while((i=ERR_get_error()))
00056 {
00057 char strErr[1024];
00058 ERR_error_string_n(i,strErr,sizeof(strErr));
00059 cerr<< "\tError " << i << ": " << strErr << endl;
00060 }
00061 }
00062
00067 void KjSslObject::CheckSslErrors(const SSL *_pSsl, const int _iRet, const string &_str)
00068 {
00069 int iErr = SSL_get_error(_pSsl, _iRet);
00070 switch (iErr)
00071 {
00072 case SSL_ERROR_NONE:
00073 cout << "No Error:: " << _str << " -- The TLS/SSL I/O operation completed." << endl;
00074 break;
00075 case SSL_ERROR_ZERO_RETURN:
00076 cerr << "Error:: " << _str << " -- The TLS/SSL connection has been closed." << endl;
00077 break;
00078 case SSL_ERROR_WANT_READ:
00079 cerr << "Error:: " << _str << " -- The operation READ did not complete" << endl;
00080 break;
00081 case SSL_ERROR_WANT_WRITE:
00082 cerr << "Error:: " << _str << " -- The operation WRITE did not complete" << endl;
00083 break;
00084 case SSL_ERROR_WANT_CONNECT:
00085 cerr << "Error:: " << _str << " -- The operation CONNECT did not complete" << endl;
00086 break;
00087 case SSL_ERROR_WANT_X509_LOOKUP:
00088 cerr << "Error:: " << _str << " -- The operation X509_LOOKUP did not complete" << endl;
00089 break;
00090 case SSL_ERROR_SYSCALL:
00091 cerr << "Error:: " << _str << " -- Some I/O error occurred." << endl;
00092 break;
00093 case SSL_ERROR_SSL:
00094 cerr << "Error:: " << _str << " -- A failure in the SSL library occurred, usually a protocol error." << endl;
00095 break;
00096 default:
00097 break;
00098 }
00099 }