-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vapid_import_private_key - add the atual functionality #40
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #40 +/- ##
=======================================
Coverage 86.56% 86.56%
=======================================
Files 14 14
Lines 1407 1407
=======================================
Hits 1218 1218
Misses 189 189 Continue to review full report at Codecov.
|
here is my approach
|
If you have the same usecase as me (generating VAPID tokens for different push services using the same key), then you probably want a function that sets both the private and public keys, not just the private. static EC_KEY*
vapid_import_public_and_private_from_private_key(const char* privateKeyB64Url) {
if (!privateKeyB64Url) { return NULL; }
size_t rawPrivKeyLen = ece_base64url_decode(privateKeyB64Url,
strlen(privateKeyB64Url),
ECE_BASE64URL_REJECT_PADDING,
NULL,
0);
if (!rawPrivKeyLen) { return NULL; }
uint8_t* rawPrivKey = malloc(rawPrivKeyLen);
if (!rawPrivKey) { return NULL; }
if (ece_base64url_decode(privateKeyB64Url, strlen(privateKeyB64Url), ECE_BASE64URL_REJECT_PADDING,
rawPrivKey, rawPrivKeyLen) != rawPrivKeyLen) {
free(rawPrivKey);
return NULL;
}
EC_KEY* key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
// Set private key
if (!key || !EC_KEY_oct2priv(key, rawPrivKey, rawPrivKeyLen)) {
EC_KEY_free(key);
free(rawPrivKey);
return NULL;
}
// Set public key
BN_CTX* ctx = BN_CTX_new();
const BIGNUM *private_key_bn = EC_KEY_get0_private_key(key);
const EC_GROUP *group = EC_KEY_get0_group(key);
EC_POINT *pubkey_point = EC_POINT_new(group);
EC_POINT_mul(group, pubkey_point, private_key_bn, NULL, NULL, ctx);
BN_CTX_free(ctx);
EC_KEY_set_public_key(key, pubkey_point);
free(rawPrivKey);
return key;
} |
current vapid_import_private_key function just return NULL.
adding import form PEM format to EC_KEY*