mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 13:58:51 +02:00
use DER format for generated keys in RSAKeypairGenerator
This commit is contained in:
parent
5f67194564
commit
69402e275c
2 changed files with 20 additions and 19 deletions
|
@ -64,7 +64,6 @@
|
||||||
#include <ParticlesScriptingInterface.h>
|
#include <ParticlesScriptingInterface.h>
|
||||||
#include <PerfStat.h>
|
#include <PerfStat.h>
|
||||||
#include <ResourceCache.h>
|
#include <ResourceCache.h>
|
||||||
#include <RSAKeypairGenerator.h>
|
|
||||||
#include <UserActivityLogger.h>
|
#include <UserActivityLogger.h>
|
||||||
#include <UUID.h>
|
#include <UUID.h>
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
#include <openssl/rsa.h>
|
#include <openssl/rsa.h>
|
||||||
#include <openssl/pem.h>
|
#include <openssl/x509.h>
|
||||||
|
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
|
|
||||||
|
@ -44,24 +44,28 @@ void RSAKeypairGenerator::generateKeypair() {
|
||||||
BN_free(exponent);
|
BN_free(exponent);
|
||||||
|
|
||||||
// grab the public key and private key from the file
|
// grab the public key and private key from the file
|
||||||
BIO *privateKeyBIO = BIO_new(BIO_s_mem());
|
unsigned char* publicKeyDER = NULL;
|
||||||
int privateWrite = PEM_write_bio_RSAPrivateKey(privateKeyBIO, keyPair, NULL, NULL, 0, NULL, NULL);
|
int publicKeyLength = i2d_RSA_PUBKEY(keyPair, &publicKeyDER);
|
||||||
|
|
||||||
BIO *publicKeyBIO = BIO_new(BIO_s_mem());
|
unsigned char* privateKeyDER = NULL;
|
||||||
int publicWrite = PEM_write_bio_RSAPublicKey(publicKeyBIO, keyPair);
|
int privateKeyLength = i2d_RSAPrivateKey(keyPair, &privateKeyDER);
|
||||||
|
|
||||||
if (privateWrite == 0 || publicWrite == 0) {
|
if (publicKeyLength <= 0 || privateKeyLength <= 0) {
|
||||||
// we had a error grabbing either the private or public key from the RSA
|
qDebug() << "Error getting DER public or private key from RSA struct -" << ERR_get_error();
|
||||||
|
|
||||||
// bubble up our error
|
|
||||||
emit errorGeneratingKeypair();
|
emit errorGeneratingKeypair();
|
||||||
|
|
||||||
// cleanup the RSA struct
|
// cleanup the RSA struct
|
||||||
RSA_free(keyPair);
|
RSA_free(keyPair);
|
||||||
|
|
||||||
// cleanup the BIOs
|
// cleanup the public and private key DER data, if required
|
||||||
BIO_free(privateKeyBIO);
|
if (publicKeyLength > 0) {
|
||||||
BIO_free(publicKeyBIO);
|
delete publicKeyDER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (privateKeyLength > 0) {
|
||||||
|
delete privateKeyDER;
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -70,14 +74,12 @@ void RSAKeypairGenerator::generateKeypair() {
|
||||||
// we can cleanup the RSA struct before we continue on
|
// we can cleanup the RSA struct before we continue on
|
||||||
RSA_free(keyPair);
|
RSA_free(keyPair);
|
||||||
|
|
||||||
char* publicKeyData;
|
QByteArray publicKeyArray(reinterpret_cast<char*>(publicKeyDER), publicKeyLength);
|
||||||
int publicKeyLength = BIO_get_mem_data(publicKeyBIO, &publicKeyData);
|
QByteArray privateKeyArray(reinterpret_cast<char*>(privateKeyDER), privateKeyLength);
|
||||||
|
|
||||||
char* privateKeyData;
|
// cleanup the publicKeyDER and publicKeyDER data
|
||||||
int privateKeyLength = BIO_get_mem_data(privateKeyBIO, &privateKeyData);
|
delete publicKeyDER;
|
||||||
|
delete privateKeyDER;
|
||||||
QByteArray publicKeyArray(publicKeyData, publicKeyLength);
|
|
||||||
QByteArray privateKeyArray(privateKeyData, privateKeyLength);
|
|
||||||
|
|
||||||
emit generatedKeypair(publicKeyArray, privateKeyArray);
|
emit generatedKeypair(publicKeyArray, privateKeyArray);
|
||||||
}
|
}
|
Loading…
Reference in a new issue