mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-13 20:37:30 +01:00
fixed GH #510: Incorrect RSAKey construction from istream
This commit is contained in:
@@ -86,7 +86,9 @@ RSAKeyImpl::RSAKeyImpl(
|
|||||||
RSA* pubKey = PEM_read_bio_RSAPublicKey(bio, &_pRSA, 0, 0);
|
RSA* pubKey = PEM_read_bio_RSAPublicKey(bio, &_pRSA, 0, 0);
|
||||||
if (!pubKey)
|
if (!pubKey)
|
||||||
{
|
{
|
||||||
int rc = BIO_seek(bio, 0);
|
int rc = BIO_reset(bio);
|
||||||
|
// BIO_reset() normally returns 1 for success and 0 or -1 for failure.
|
||||||
|
// File BIOs are an exception, they return 0 for success and -1 for failure.
|
||||||
if (rc != 0) throw Poco::FileException("Failed to load public key", publicKeyFile);
|
if (rc != 0) throw Poco::FileException("Failed to load public key", publicKeyFile);
|
||||||
pubKey = PEM_read_bio_RSA_PUBKEY(bio, &_pRSA, 0, 0);
|
pubKey = PEM_read_bio_RSA_PUBKEY(bio, &_pRSA, 0, 0);
|
||||||
}
|
}
|
||||||
@@ -147,8 +149,10 @@ RSAKeyImpl::RSAKeyImpl(std::istream* pPublicKeyStream, std::istream* pPrivateKey
|
|||||||
RSA* publicKey = PEM_read_bio_RSAPublicKey(bio, &_pRSA, 0, 0);
|
RSA* publicKey = PEM_read_bio_RSAPublicKey(bio, &_pRSA, 0, 0);
|
||||||
if (!publicKey)
|
if (!publicKey)
|
||||||
{
|
{
|
||||||
int rc = BIO_seek(bio, 0);
|
int rc = BIO_reset(bio);
|
||||||
if (rc != 0) throw Poco::FileException("Failed to load public key");
|
// BIO_reset() normally returns 1 for success and 0 or -1 for failure.
|
||||||
|
// File BIOs are an exception, they return 0 for success and -1 for failure.
|
||||||
|
if (rc != 1) throw Poco::FileException("Failed to load public key");
|
||||||
publicKey = PEM_read_bio_RSA_PUBKEY(bio, &_pRSA, 0, 0);
|
publicKey = PEM_read_bio_RSA_PUBKEY(bio, &_pRSA, 0, 0);
|
||||||
}
|
}
|
||||||
BIO_free(bio);
|
BIO_free(bio);
|
||||||
|
|||||||
Reference in New Issue
Block a user