diff --git a/tool/vapid.c b/tool/vapid.c index 19261b4..975e1a1 100644 --- a/tool/vapid.c +++ b/tool/vapid.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -263,8 +264,24 @@ 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(b64PrivKeyPemFormat); + BIO *mem = BIO_new(BIO_s_mem()); + if ((size_t)BIO_write(mem, b64PrivKeyPemFormat, 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) { + BIO_free_all(mem); + return NULL; + } + + if(EC_KEY_check_key(EC_KEY_ptr) == 0) { + return NULL; + } + return EC_KEY_ptr; } static EC_KEY*