fix style

This commit is contained in:
Günter Obiltschnig
2018-03-05 19:54:01 +01:00
parent a2322be390
commit 38c9328db6
2 changed files with 111 additions and 111 deletions

View File

@@ -51,9 +51,9 @@ Context::Context(Usage usage, const Params& params):
Context::Context(
Usage usage,
const std::string& privateKeyFile,
const std::string& privateKeyFile,
const std::string& certificateFile,
const std::string& caLocation,
const std::string& caLocation,
VerificationMode verificationMode,
int verificationDepth,
bool loadDefaultCAs,
@@ -77,7 +77,7 @@ Context::Context(
Context::Context(
Usage usage,
const std::string& caLocation,
const std::string& caLocation,
VerificationMode verificationMode,
int verificationDepth,
bool loadDefaultCAs,
@@ -114,7 +114,7 @@ Context::~Context()
void Context::init(const Params& params)
{
Poco::Crypto::OpenSSLInitializer::initialize();
createSSLContext();
try
@@ -173,7 +173,7 @@ void Context::init(const Params& params)
SSL_CTX_set_verify_depth(_pSSLContext, params.verificationDepth);
SSL_CTX_set_mode(_pSSLContext, SSL_MODE_AUTO_RETRY);
SSL_CTX_set_session_cache_mode(_pSSLContext, SSL_SESS_CACHE_OFF);
initDH(params.dhParamsFile);
initECDH(params.ecdhCurve);
}
@@ -185,25 +185,6 @@ void Context::init(const Params& params)
}
void Context::addCertificateAuthority(const Crypto::X509Certificate &certificate)
{
if (X509_STORE* store = SSL_CTX_get_cert_store(_pSSLContext))
{
int errCode = X509_STORE_add_cert(store, const_cast<X509*>(certificate.certificate()));
if (errCode != 1)
{
std::string msg = Utility::getLastError();
throw SSLContextException("Cannot add certificate authority for Context", msg);
}
}
else
{
std::string msg = Utility::getLastError();
throw SSLContextException("Cannot add certificate authority for Context", msg);
}
}
void Context::useCertificate(const Poco::Crypto::X509Certificate& certificate)
{
int errCode = SSL_CTX_use_certificate(_pSSLContext, const_cast<X509*>(certificate.certificate()));
@@ -214,7 +195,7 @@ void Context::useCertificate(const Poco::Crypto::X509Certificate& certificate)
}
}
void Context::addChainCertificate(const Poco::Crypto::X509Certificate& certificate)
{
int errCode = SSL_CTX_add_extra_chain_cert(_pSSLContext, certificate.certificate());
@@ -225,7 +206,26 @@ void Context::addChainCertificate(const Poco::Crypto::X509Certificate& certifica
}
}
void Context::addCertificateAuthority(const Crypto::X509Certificate &certificate)
{
if (X509_STORE* store = SSL_CTX_get_cert_store(_pSSLContext))
{
int errCode = X509_STORE_add_cert(store, const_cast<X509*>(certificate.certificate()));
if (errCode != 1)
{
std::string msg = Utility::getLastError();
throw SSLContextException("Cannot add certificate authority to Context", msg);
}
}
else
{
std::string msg = Utility::getLastError();
throw SSLContextException("Cannot add certificate authority to Context", msg);
}
}
void Context::usePrivateKey(const Poco::Crypto::RSAKey& key)
{
int errCode = SSL_CTX_use_RSAPrivateKey(_pSSLContext, key.impl()->getRSA());
@@ -262,7 +262,7 @@ void Context::enableSessionCache(bool flag, const std::string& sessionIdContext)
{
SSL_CTX_set_session_cache_mode(_pSSLContext, SSL_SESS_CACHE_OFF);
}
unsigned length = static_cast<unsigned>(sessionIdContext.length());
if (length > SSL_MAX_SSL_SESSION_ID_LENGTH) length = SSL_MAX_SSL_SESSION_ID_LENGTH;
int rc = SSL_CTX_set_session_id_context(_pSSLContext, reinterpret_cast<const unsigned char*>(sessionIdContext.data()), length);
@@ -279,15 +279,15 @@ bool Context::sessionCacheEnabled() const
void Context::setSessionCacheSize(std::size_t size)
{
poco_assert (isForServerUse());
SSL_CTX_sess_set_cache_size(_pSSLContext, static_cast<long>(size));
}
std::size_t Context::getSessionCacheSize() const
{
poco_assert (isForServerUse());
return static_cast<std::size_t>(SSL_CTX_sess_get_cache_size(_pSSLContext));
}
@@ -308,7 +308,7 @@ long Context::getSessionTimeout() const
}
void Context::flushSessionCache()
void Context::flushSessionCache()
{
poco_assert (isForServerUse());
@@ -430,7 +430,7 @@ void Context::createSSLContext()
throw Poco::InvalidArgumentException("Invalid or unsupported usage");
}
}
if (!_pSSLContext)
if (!_pSSLContext)
{
unsigned long err = ERR_get_error();
throw SSLException("Cannot create SSL_CTX object", ERR_error_string(err, 0));
@@ -456,7 +456,7 @@ void Context::initDH(const std::string& dhParamsFile)
// -----END DH PARAMETERS-----
//
static const unsigned char dh1024_p[] =
static const unsigned char dh1024_p[] =
{
0xB1,0x0B,0x8F,0x96,0xA0,0x80,0xE0,0x1D,0xDE,0x92,0xDE,0x5E,
0xAE,0x5D,0x54,0xEC,0x52,0xC9,0x9F,0xBC,0xFB,0x06,0xA3,0xC6,
@@ -471,7 +471,7 @@ void Context::initDH(const std::string& dhParamsFile)
0xDF,0x1F,0xB2,0xBC,0x2E,0x4A,0x43,0x71,
};
static const unsigned char dh1024_g[] =
static const unsigned char dh1024_g[] =
{
0xA4,0xD1,0xCB,0xD5,0xC3,0xFD,0x34,0x12,0x67,0x65,0xA4,0x42,
0xEF,0xB9,0x99,0x05,0xF8,0x10,0x4D,0xD2,0x58,0xAC,0x50,0x7F,
@@ -487,26 +487,26 @@ void Context::initDH(const std::string& dhParamsFile)
};
DH* dh = 0;
if (!dhParamsFile.empty())
if (!dhParamsFile.empty())
{
BIO* bio = BIO_new_file(dhParamsFile.c_str(), "r");
if (!bio)
if (!bio)
{
std::string msg = Utility::getLastError();
throw SSLContextException(std::string("Error opening Diffie-Hellman parameters file ") + dhParamsFile, msg);
}
dh = PEM_read_bio_DHparams(bio, 0, 0, 0);
BIO_free(bio);
if (!dh)
if (!dh)
{
std::string msg = Utility::getLastError();
throw SSLContextException(std::string("Error reading Diffie-Hellman parameters from file ") + dhParamsFile, msg);
}
}
else
}
else
{
dh = DH_new();
if (!dh)
if (!dh)
{
std::string msg = Utility::getLastError();
throw SSLContextException("Error creating Diffie-Hellman parameters", msg);
@@ -525,7 +525,7 @@ void Context::initDH(const std::string& dhParamsFile)
dh->p = BN_bin2bn(dh1024_p, sizeof(dh1024_p), 0);
dh->g = BN_bin2bn(dh1024_g, sizeof(dh1024_g), 0);
dh->length = 160;
if ((!dh->p) || (!dh->g))
if ((!dh->p) || (!dh->g))
{
DH_free(dh);
throw SSLContextException("Error creating Diffie-Hellman parameters");
@@ -541,27 +541,27 @@ void Context::initDH(const std::string& dhParamsFile)
#endif
}
void Context::initECDH(const std::string& curve)
{
#if OPENSSL_VERSION_NUMBER >= 0x0090800fL
#ifndef OPENSSL_NO_ECDH
int nid = 0;
if (!curve.empty())
if (!curve.empty())
{
nid = OBJ_sn2nid(curve.c_str());
}
else
}
else
{
nid = OBJ_sn2nid("prime256v1");
}
if (nid == 0)
if (nid == 0)
{
throw SSLContextException("Unknown ECDH curve name", curve);
}
EC_KEY* ecdh = EC_KEY_new_by_curve_name(nid);
if (!ecdh)
if (!ecdh)
{
throw SSLContextException("Cannot create ECDH curve");
}