openssl: Add generic RSA public key encoding
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
#ifndef OPENSSL_NO_RSA
|
#ifndef OPENSSL_NO_RSA
|
||||||
|
|
||||||
#include "openssl_rsa_public_key.h"
|
#include "openssl_rsa_public_key.h"
|
||||||
|
#include "openssl_util.h"
|
||||||
|
|
||||||
#include <utils/debug.h>
|
#include <utils/debug.h>
|
||||||
|
|
||||||
@@ -248,6 +249,7 @@ METHOD(public_key_t, get_encoding, bool,
|
|||||||
private_openssl_rsa_public_key_t *this, cred_encoding_type_t type,
|
private_openssl_rsa_public_key_t *this, cred_encoding_type_t type,
|
||||||
chunk_t *encoding)
|
chunk_t *encoding)
|
||||||
{
|
{
|
||||||
|
bool success = FALSE;
|
||||||
u_char *p;
|
u_char *p;
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
@@ -255,11 +257,10 @@ METHOD(public_key_t, get_encoding, bool,
|
|||||||
case PUBKEY_SPKI_ASN1_DER:
|
case PUBKEY_SPKI_ASN1_DER:
|
||||||
case PUBKEY_PEM:
|
case PUBKEY_PEM:
|
||||||
{
|
{
|
||||||
bool success = TRUE;
|
|
||||||
|
|
||||||
*encoding = chunk_alloc(i2d_RSA_PUBKEY(this->rsa, NULL));
|
*encoding = chunk_alloc(i2d_RSA_PUBKEY(this->rsa, NULL));
|
||||||
p = encoding->ptr;
|
p = encoding->ptr;
|
||||||
i2d_RSA_PUBKEY(this->rsa, &p);
|
i2d_RSA_PUBKEY(this->rsa, &p);
|
||||||
|
success = TRUE;
|
||||||
|
|
||||||
if (type == PUBKEY_PEM)
|
if (type == PUBKEY_PEM)
|
||||||
{
|
{
|
||||||
@@ -280,7 +281,20 @@ METHOD(public_key_t, get_encoding, bool,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return FALSE;
|
{
|
||||||
|
chunk_t n = chunk_empty, e = chunk_empty;
|
||||||
|
|
||||||
|
if (openssl_bn2chunk(this->rsa->n, &n) &&
|
||||||
|
openssl_bn2chunk(this->rsa->e, &e))
|
||||||
|
{
|
||||||
|
success = lib->encoding->encode(lib->encoding, type, NULL,
|
||||||
|
encoding, CRED_PART_RSA_MODULUS, n,
|
||||||
|
CRED_PART_RSA_PUB_EXP, e, CRED_PART_END);
|
||||||
|
}
|
||||||
|
chunk_free(&n);
|
||||||
|
chunk_free(&e);
|
||||||
|
return success;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user