Skip to content

Commit

Permalink
Set EVP private key on SSL context (#2259)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjoe authored and aleks-f committed Jun 3, 2018
1 parent 5665230 commit 490a8ca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions NetSSL_OpenSSL/include/Poco/Net/Context.h
Expand Up @@ -21,6 +21,7 @@
#include "Poco/Net/NetSSL.h"
#include "Poco/Net/SocketDefs.h"
#include "Poco/Crypto/X509Certificate.h"
#include "Poco/Crypto/EVPPKey.h"
#include "Poco/Crypto/RSAKey.h"
#include "Poco/RefCountedObject.h"
#include "Poco/AutoPtr.h"
Expand Down Expand Up @@ -236,6 +237,16 @@ class NetSSL_API Context: public Poco::RefCountedObject
/// must have been setup with the SSLManager, or the SSLManager's PrivateKeyPassphraseRequired
/// event must be handled.

void usePrivateKey(const Poco::Crypto::EVPPKey &pkey);
/// Sets the private key to be used by the Context.
///
/// Note that useCertificate() must always be called before
/// usePrivateKey().
///
/// Note: If the private key is protected by a passphrase, a PrivateKeyPassphraseHandler
/// must have been setup with the SSLManager, or the SSLManager's PrivateKeyPassphraseRequired
/// event must be handled.

SSL_CTX* sslContext() const;
/// Returns the underlying OpenSSL SSL Context object.

Expand Down
11 changes: 11 additions & 0 deletions NetSSL_OpenSSL/src/Context.cpp
Expand Up @@ -237,6 +237,17 @@ void Context::usePrivateKey(const Poco::Crypto::RSAKey& key)
}


void Context::usePrivateKey(const Poco::Crypto::EVPPKey& pkey)
{
int errCode = SSL_CTX_use_PrivateKey(_pSSLContext, const_cast<EVP_PKEY*>(static_cast<const EVP_PKEY*>(pkey)));
if (errCode != 1)
{
std::string msg = Utility::getLastError();
throw SSLContextException("Cannot set private key for Context", msg);
}
}


void Context::enableSessionCache(bool flag)
{
if (flag)
Expand Down

0 comments on commit 490a8ca

Please sign in to comment.