From f6b8e0eae4374f339487a33e3e4fe5462d5816e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sat, 25 Nov 2017 10:16:00 +0100 Subject: New upstream version 2.0.0 --- ccast/axTLS/asn1.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) mode change 100644 => 100755 ccast/axTLS/asn1.c (limited to 'ccast/axTLS/asn1.c') diff --git a/ccast/axTLS/asn1.c b/ccast/axTLS/asn1.c old mode 100644 new mode 100755 index b082275..b5e678e --- a/ccast/axTLS/asn1.c +++ b/ccast/axTLS/asn1.c @@ -200,6 +200,40 @@ int asn1_get_private_key(const uint8_t *buf, int len, RSA_CTX **rsa_ctx) return X509_OK; } +/** + * Read the modulus and public exponent of an RSA certificate. + */ +int asn1_get_public_key(const uint8_t *cert, int *offset, RSA_CTX **rsa_ctx) +{ + int ret = X509_NOT_OK, mod_len, pub_len; + uint8_t *modulus = NULL, *pub_exp = NULL; + int len; + + /* Hmm. Not checking that the two ints are within the squence ... */ + if ((len = asn1_next_obj(cert, offset, ASN1_SEQUENCE)) < 0) + goto end_pub_key; + + if ((mod_len = asn1_get_int(cert, offset, &modulus)) <= 0) { + ret = X509_INVALID_PUB_KEY; + goto end_pub_key; + } + if ((pub_len = asn1_get_int(cert, offset, &pub_exp)) <= 0) { + free(modulus); + ret = X509_INVALID_PUB_KEY; + goto end_pub_key; + } + + RSA_pub_key_new(rsa_ctx, modulus, mod_len, pub_exp, pub_len); + + free(modulus); + free(pub_exp); + + ret = X509_OK; + +end_pub_key: + return ret; +} + /** * Get the time of a certificate. Ignore hours/minutes/seconds. */ -- cgit v1.2.3