@@ -2710,8 +2710,7 @@ static ParsePublicKeyResult TryParsePublicKey(
2710
2710
2711
2711
static ParsePublicKeyResult ParsePublicKeyPEM (EVPKeyPointer* pkey,
2712
2712
const char * key_pem,
2713
- int key_pem_len,
2714
- bool allow_certificate) {
2713
+ int key_pem_len) {
2715
2714
BIOPointer bp (BIO_new_mem_buf (const_cast <char *>(key_pem), key_pem_len));
2716
2715
if (!bp)
2717
2716
return ParsePublicKeyResult::kParsePublicFailed ;
@@ -2732,8 +2731,7 @@ static ParsePublicKeyResult ParsePublicKeyPEM(EVPKeyPointer* pkey,
2732
2731
[](const unsigned char ** p, long l) { // NOLINT(runtime/int)
2733
2732
return d2i_PublicKey (EVP_PKEY_RSA, nullptr , p, l);
2734
2733
});
2735
- if (ret != ParsePublicKeyResult::kParsePublicNotRecognized ||
2736
- !allow_certificate)
2734
+ if (ret != ParsePublicKeyResult::kParsePublicNotRecognized )
2737
2735
return ret;
2738
2736
2739
2737
// X.509 fallback.
@@ -2748,11 +2746,10 @@ static ParsePublicKeyResult ParsePublicKeyPEM(EVPKeyPointer* pkey,
2748
2746
static bool ParsePublicKey (EVPKeyPointer* pkey,
2749
2747
const PublicKeyEncodingConfig& config,
2750
2748
const char * key,
2751
- size_t key_len,
2752
- bool allow_certificate) {
2749
+ size_t key_len) {
2753
2750
if (config.format_ == kKeyFormatPEM ) {
2754
2751
ParsePublicKeyResult r =
2755
- ParsePublicKeyPEM (pkey, key, key_len, allow_certificate );
2752
+ ParsePublicKeyPEM (pkey, key, key_len);
2756
2753
return r == ParsePublicKeyResult::kParsePublicOk ;
2757
2754
} else {
2758
2755
CHECK_EQ (config.format_ , kKeyFormatDER );
@@ -3002,15 +2999,14 @@ static PublicKeyEncodingConfig GetPublicKeyEncodingFromJs(
3002
2999
static ManagedEVPPKey GetPublicKeyFromJs (
3003
3000
const FunctionCallbackInfo<Value>& args,
3004
3001
unsigned int * offset,
3005
- bool allow_key_object,
3006
- bool allow_certificate) {
3002
+ bool allow_key_object) {
3007
3003
if (args[*offset]->IsString () || Buffer::HasInstance (args[*offset])) {
3008
3004
Environment* env = Environment::GetCurrent (args);
3009
3005
ByteSource key = ByteSource::FromStringOrBuffer (env, args[(*offset)++]);
3010
3006
PublicKeyEncodingConfig config =
3011
3007
GetPublicKeyEncodingFromJs (args, offset, kKeyContextInput );
3012
3008
EVPKeyPointer pkey;
3013
- ParsePublicKey (&pkey, config, key.get (), key.size (), allow_certificate );
3009
+ ParsePublicKey (&pkey, config, key.get (), key.size ());
3014
3010
if (!pkey)
3015
3011
ThrowCryptoError (env, ERR_get_error (), " Failed to read public key" );
3016
3012
return ManagedEVPPKey (pkey.release ());
@@ -3131,8 +3127,7 @@ static bool IsRSAPrivateKey(const unsigned char* data, size_t size) {
3131
3127
static ManagedEVPPKey GetPublicOrPrivateKeyFromJs (
3132
3128
const FunctionCallbackInfo<Value>& args,
3133
3129
unsigned int * offset,
3134
- bool allow_key_object,
3135
- bool allow_certificate) {
3130
+ bool allow_key_object) {
3136
3131
if (args[*offset]->IsString () || Buffer::HasInstance (args[*offset])) {
3137
3132
Environment* env = Environment::GetCurrent (args);
3138
3133
ByteSource data = ByteSource::FromStringOrBuffer (env, args[(*offset)++]);
@@ -3146,8 +3141,7 @@ static ManagedEVPPKey GetPublicOrPrivateKeyFromJs(
3146
3141
// For PEM, we can easily determine whether it is a public or private key
3147
3142
// by looking for the respective PEM tags.
3148
3143
ParsePublicKeyResult ret = ParsePublicKeyPEM (&pkey, data.get (),
3149
- data.size (),
3150
- allow_certificate);
3144
+ data.size ());
3151
3145
if (ret == ParsePublicKeyResult::kParsePublicNotRecognized ) {
3152
3146
pkey = ParsePrivateKey (config, data.get (), data.size ());
3153
3147
}
@@ -3172,8 +3166,7 @@ static ManagedEVPPKey GetPublicOrPrivateKeyFromJs(
3172
3166
}
3173
3167
3174
3168
if (is_public) {
3175
- ParsePublicKey (&pkey, config, data.get (), data.size (),
3176
- allow_certificate);
3169
+ ParsePublicKey (&pkey, config, data.get (), data.size ());
3177
3170
} else {
3178
3171
pkey = ParsePrivateKey (config, data.get (), data.size ());
3179
3172
}
@@ -3386,7 +3379,7 @@ void KeyObject::Init(const FunctionCallbackInfo<Value>& args) {
3386
3379
CHECK_EQ (args.Length (), 3 );
3387
3380
3388
3381
offset = 0 ;
3389
- pkey = GetPublicKeyFromJs (args, &offset, false , false );
3382
+ pkey = GetPublicKeyFromJs (args, &offset, false );
3390
3383
if (!pkey)
3391
3384
return ;
3392
3385
key->InitPublic (pkey);
@@ -4668,7 +4661,7 @@ void Verify::VerifyFinal(const FunctionCallbackInfo<Value>& args) {
4668
4661
ASSIGN_OR_RETURN_UNWRAP (&verify, args.Holder ());
4669
4662
4670
4663
unsigned int offset = 0 ;
4671
- ManagedEVPPKey pkey = GetPublicKeyFromJs (args, &offset, true , true );
4664
+ ManagedEVPPKey pkey = GetPublicKeyFromJs (args, &offset, true );
4672
4665
4673
4666
char * hbuf = Buffer::Data (args[offset]);
4674
4667
ssize_t hlen = Buffer::Length (args[offset]);
@@ -4724,7 +4717,7 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
4724
4717
Environment* env = Environment::GetCurrent (args);
4725
4718
4726
4719
unsigned int offset = 0 ;
4727
- ManagedEVPPKey pkey = GetPublicOrPrivateKeyFromJs (args, &offset, true , true );
4720
+ ManagedEVPPKey pkey = GetPublicOrPrivateKeyFromJs (args, &offset, true );
4728
4721
if (!pkey)
4729
4722
return ;
4730
4723
0 commit comments