From ed43ef971229b6021f2fcef576c17e62dfcec9f8 Mon Sep 17 00:00:00 2001 From: nissim Date: Sun, 24 Feb 2019 14:26:53 +0000 Subject: [PATCH 1/3] vapid_import_private_key - add the atual functionality --- tool/vapid.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tool/vapid.c b/tool/vapid.c index 19261b4..581cbf1 100644 --- a/tool/vapid.c +++ b/tool/vapid.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -263,8 +264,25 @@ vapid_build_token(EC_KEY* key, const char* aud, size_t audLen, uint32_t exp, } static EC_KEY* -vapid_import_private_key(const char* b64PrivKey) { - return NULL; +vapid_import_private_key(const char* b64PrivKeyPemFormat) { + size_t pv_key_len = strlen(b64PrivKey); + BIO *mem = BIO_new(BIO_s_mem()); + if ((size_t)BIO_write(mem, b64PrivKey, pv_key_len) != pv_key_len) { + return NULL; + } + + EC_KEY *EC_KEY_ptr = PEM_read_bio_ECPrivateKey(mem , NULL, NULL, NULL); + BIO_free_all(mem); + if(EC_KEY_ptr == NULL) + { + return NULL; + } + + if(EC_KEY_check_key(EC_KEY_ptr) == 0) + { + return NULL; + } + return EC_KEY_ptr; } static EC_KEY* From 17fc8573e7d459956d6257c644cf961b1d79a717 Mon Sep 17 00:00:00 2001 From: nissim Date: Sun, 24 Feb 2019 14:30:08 +0000 Subject: [PATCH 2/3] vapid_import_private_key - add the atual functionality --- tool/vapid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tool/vapid.c b/tool/vapid.c index 581cbf1..7ff7514 100644 --- a/tool/vapid.c +++ b/tool/vapid.c @@ -265,9 +265,9 @@ vapid_build_token(EC_KEY* key, const char* aud, size_t audLen, uint32_t exp, static EC_KEY* vapid_import_private_key(const char* b64PrivKeyPemFormat) { - size_t pv_key_len = strlen(b64PrivKey); + size_t pv_key_len = strlen(b64PrivKeyPemFormat); BIO *mem = BIO_new(BIO_s_mem()); - if ((size_t)BIO_write(mem, b64PrivKey, pv_key_len) != pv_key_len) { + if ((size_t)BIO_write(mem, b64PrivKeyPemFormat, pv_key_len) != pv_key_len) { return NULL; } From 3a165272bb1f408dc7858ccce2ec1fbb5fbc3922 Mon Sep 17 00:00:00 2001 From: nissim Date: Sun, 24 Feb 2019 14:32:04 +0000 Subject: [PATCH 3/3] vapid_import_private_key - add the atual functionality --- tool/vapid.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tool/vapid.c b/tool/vapid.c index 7ff7514..975e1a1 100644 --- a/tool/vapid.c +++ b/tool/vapid.c @@ -273,13 +273,12 @@ vapid_import_private_key(const char* b64PrivKeyPemFormat) { EC_KEY *EC_KEY_ptr = PEM_read_bio_ECPrivateKey(mem , NULL, NULL, NULL); BIO_free_all(mem); - if(EC_KEY_ptr == NULL) - { + if(EC_KEY_ptr == NULL) { + BIO_free_all(mem); return NULL; } - if(EC_KEY_check_key(EC_KEY_ptr) == 0) - { + if(EC_KEY_check_key(EC_KEY_ptr) == 0) { return NULL; } return EC_KEY_ptr;