diff options
author | Tobias Brunner <tobias@strongswan.org> | 2013-08-14 18:23:00 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2013-09-13 15:23:49 +0200 |
commit | 3b939e20a96984584a941da452513220ef0c38af (patch) | |
tree | c542de5cebeca40df66b4c440becfdc4e194f29b | |
parent | b5cc7053c83285181b0ee7ea0f13bed3431d9fd0 (diff) | |
download | strongswan-3b939e20a96984584a941da452513220ef0c38af.tar.bz2 strongswan-3b939e20a96984584a941da452513220ef0c38af.tar.xz |
openssl: Add generic RSA public key encoding
-rw-r--r-- | src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c b/src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c index 48beedef6..f0c172629 100644 --- a/src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c +++ b/src/libstrongswan/plugins/openssl/openssl_rsa_public_key.c @@ -19,6 +19,7 @@ #ifndef OPENSSL_NO_RSA #include "openssl_rsa_public_key.h" +#include "openssl_util.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, chunk_t *encoding) { + bool success = FALSE; u_char *p; switch (type) @@ -255,11 +257,10 @@ METHOD(public_key_t, get_encoding, bool, case PUBKEY_SPKI_ASN1_DER: case PUBKEY_PEM: { - bool success = TRUE; - *encoding = chunk_alloc(i2d_RSA_PUBKEY(this->rsa, NULL)); p = encoding->ptr; i2d_RSA_PUBKEY(this->rsa, &p); + success = TRUE; if (type == PUBKEY_PEM) { @@ -280,7 +281,20 @@ METHOD(public_key_t, get_encoding, bool, return TRUE; } 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; + } } } |