diff options
author | Martin Willi <martin@strongswan.org> | 2009-08-27 09:58:38 +0200 |
---|---|---|
committer | Martin Willi <martin@strongswan.org> | 2009-08-27 09:58:38 +0200 |
commit | b12c6d163d179ad238fe920eb9f1746b96f51166 (patch) | |
tree | 417f9955630d710b543ce5289e308e0bb08a8a39 /src/libstrongswan/plugins/openssl/openssl_util.c | |
parent | 2ee8cd04bdeac33c893c9b20c82e465e03b5a769 (diff) | |
download | strongswan-b12c6d163d179ad238fe920eb9f1746b96f51166.tar.bz2 strongswan-b12c6d163d179ad238fe920eb9f1746b96f51166.tar.xz |
do openssl fingerprinting/encoding directly, openssl provides all functions
Diffstat (limited to 'src/libstrongswan/plugins/openssl/openssl_util.c')
-rw-r--r-- | src/libstrongswan/plugins/openssl/openssl_util.c | 124 |
1 files changed, 0 insertions, 124 deletions
diff --git a/src/libstrongswan/plugins/openssl/openssl_util.c b/src/libstrongswan/plugins/openssl/openssl_util.c index 60b4e74e0..5caae4bdd 100644 --- a/src/libstrongswan/plugins/openssl/openssl_util.c +++ b/src/libstrongswan/plugins/openssl/openssl_util.c @@ -124,127 +124,3 @@ bool openssl_bn_split(chunk_t chunk, BIGNUM *a, BIGNUM *b) return TRUE; } -/** - * wrap publicKey in subjectPublicKeyInfo - */ -static chunk_t build_info(chunk_t key) -{ - X509_PUBKEY *pubkey; - chunk_t enc; - u_char *p; - - pubkey = X509_PUBKEY_new(); - ASN1_OBJECT_free(pubkey->algor->algorithm); - pubkey->algor->algorithm = OBJ_nid2obj(NID_rsaEncryption); - - if (pubkey->algor->parameter == NULL || - pubkey->algor->parameter->type != V_ASN1_NULL) - { - ASN1_TYPE_free(pubkey->algor->parameter); - pubkey->algor->parameter = ASN1_TYPE_new(); - pubkey->algor->parameter->type = V_ASN1_NULL; - } - M_ASN1_BIT_STRING_set(pubkey->public_key, key.ptr, key.len); - - enc = chunk_alloc(i2d_X509_PUBKEY(pubkey, NULL)); - p = enc.ptr; - i2d_X509_PUBKEY(pubkey, &p); - X509_PUBKEY_free(pubkey); - - return enc; -} - -/** - * Build fingerprints of a private/public RSA key. - */ -static bool build_fingerprint(chunk_t key, key_encoding_type_t type, - chunk_t *fingerprint) -{ - hasher_t *hasher; - - hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA1); - if (!hasher) - { - DBG1("SHA1 hash algorithm not supported, fingerprinting failed"); - return FALSE; - } - if (type == KEY_ID_PUBKEY_INFO_SHA1) - { - chunk_t enc; - - enc = build_info(key); - hasher->allocate_hash(hasher, enc, fingerprint); - chunk_free(&enc); - } - else - { - hasher->allocate_hash(hasher, key, fingerprint); - } - hasher->destroy(hasher); - return TRUE; -} - -/** - * See header. - */ -bool openssl_encode(key_encoding_type_t type, chunk_t *encoding, va_list args) -{ - chunk_t key; - - switch (type) - { - case KEY_PUB_ASN1_DER: - /* this encoding is currently not supported for ECDSA keys */ - if (key_encoding_args(args, KEY_PART_RSA_PUB_ASN1_DER, &key, - KEY_PART_END)) - { - *encoding = chunk_clone(key); - return TRUE; - } - return FALSE; - case KEY_PUB_SPKI_ASN1_DER: - /* key encoding, wrapped in a subjectPublicKeyInfo field */ - if (key_encoding_args(args, KEY_PART_RSA_PUB_ASN1_DER, &key, - KEY_PART_END)) - { - *encoding = build_info(key); - return TRUE; - } - else if (key_encoding_args(args, KEY_PART_ECDSA_PUB_ASN1_DER, &key, - KEY_PART_END)) - { - /* ECDSA keys are already wrapped in the publickeyInfo field, - * they are incomplete without */ - *encoding = chunk_clone(key); - return TRUE; - } - return FALSE; - case KEY_PRIV_ASN1_DER: - if (key_encoding_args(args, KEY_PART_RSA_PRIV_ASN1_DER, &key, - KEY_PART_END) || - key_encoding_args(args, KEY_PART_ECDSA_PRIV_ASN1_DER, &key, - KEY_PART_END)) - { - *encoding = chunk_clone(key); - return TRUE; - } - return FALSE; - case KEY_ID_PUBKEY_SHA1: - case KEY_ID_PUBKEY_INFO_SHA1: - if (key_encoding_args(args, KEY_PART_RSA_PUB_ASN1_DER, &key, - KEY_PART_END)) - { - return build_fingerprint(key, type, encoding); - } - else if (key_encoding_args(args, KEY_PART_ECDSA_PUB_ASN1_DER, &key, - KEY_PART_END)) - { - /* for ECDSA the two keyids are currently the same */ - return build_fingerprint(key, KEY_ID_PUBKEY_SHA1, encoding); - } - return FALSE; - default: - return FALSE; - } -} - |