@@ -2737,8 +2737,7 @@ static ParsePublicKeyResult TryParsePublicKey(
2737
2737
2738
2738
static ParsePublicKeyResult ParsePublicKeyPEM (EVPKeyPointer* pkey,
2739
2739
const char * key_pem,
2740
- int key_pem_len,
2741
- bool allow_certificate) {
2740
+ int key_pem_len) {
2742
2741
BIOPointer bp (BIO_new_mem_buf (const_cast <char *>(key_pem), key_pem_len));
2743
2742
if (!bp)
2744
2743
return ParsePublicKeyResult::kParsePublicFailed ;
@@ -2759,8 +2758,7 @@ static ParsePublicKeyResult ParsePublicKeyPEM(EVPKeyPointer* pkey,
2759
2758
[](const unsigned char ** p, long l) { // NOLINT(runtime/int)
2760
2759
return d2i_PublicKey (EVP_PKEY_RSA, nullptr , p, l);
2761
2760
});
2762
- if (ret != ParsePublicKeyResult::kParsePublicNotRecognized ||
2763
- !allow_certificate)
2761
+ if (ret != ParsePublicKeyResult::kParsePublicNotRecognized )
2764
2762
return ret;
2765
2763
2766
2764
// X.509 fallback.
@@ -2775,11 +2773,10 @@ static ParsePublicKeyResult ParsePublicKeyPEM(EVPKeyPointer* pkey,
2775
2773
static bool ParsePublicKey (EVPKeyPointer* pkey,
2776
2774
const PublicKeyEncodingConfig& config,
2777
2775
const char * key,
2778
- size_t key_len,
2779
- bool allow_certificate) {
2776
+ size_t key_len) {
2780
2777
if (config.format_ == kKeyFormatPEM ) {
2781
2778
ParsePublicKeyResult r =
2782
- ParsePublicKeyPEM (pkey, key, key_len, allow_certificate );
2779
+ ParsePublicKeyPEM (pkey, key, key_len);
2783
2780
return r == ParsePublicKeyResult::kParsePublicOk ;
2784
2781
} else {
2785
2782
CHECK_EQ (config.format_ , kKeyFormatDER );
@@ -3029,15 +3026,14 @@ static PublicKeyEncodingConfig GetPublicKeyEncodingFromJs(
3029
3026
static ManagedEVPPKey GetPublicKeyFromJs (
3030
3027
const FunctionCallbackInfo<Value>& args,
3031
3028
unsigned int * offset,
3032
- bool allow_key_object,
3033
- bool allow_certificate) {
3029
+ bool allow_key_object) {
3034
3030
if (args[*offset]->IsString () || Buffer::HasInstance (args[*offset])) {
3035
3031
Environment* env = Environment::GetCurrent (args);
3036
3032
ByteSource key = ByteSource::FromStringOrBuffer (env, args[(*offset)++]);
3037
3033
PublicKeyEncodingConfig config =
3038
3034
GetPublicKeyEncodingFromJs (args, offset, kKeyContextInput );
3039
3035
EVPKeyPointer pkey;
3040
- ParsePublicKey (&pkey, config, key.get (), key.size (), allow_certificate );
3036
+ ParsePublicKey (&pkey, config, key.get (), key.size ());
3041
3037
if (!pkey)
3042
3038
ThrowCryptoError (env, ERR_get_error (), " Failed to read public key" );
3043
3039
return ManagedEVPPKey (pkey.release ());
@@ -3158,8 +3154,7 @@ static bool IsRSAPrivateKey(const unsigned char* data, size_t size) {
3158
3154
static ManagedEVPPKey GetPublicOrPrivateKeyFromJs (
3159
3155
const FunctionCallbackInfo<Value>& args,
3160
3156
unsigned int * offset,
3161
- bool allow_key_object,
3162
- bool allow_certificate) {
3157
+ bool allow_key_object) {
3163
3158
if (args[*offset]->IsString () || Buffer::HasInstance (args[*offset])) {
3164
3159
Environment* env = Environment::GetCurrent (args);
3165
3160
ByteSource data = ByteSource::FromStringOrBuffer (env, args[(*offset)++]);
@@ -3173,8 +3168,7 @@ static ManagedEVPPKey GetPublicOrPrivateKeyFromJs(
3173
3168
// For PEM, we can easily determine whether it is a public or private key
3174
3169
// by looking for the respective PEM tags.
3175
3170
ParsePublicKeyResult ret = ParsePublicKeyPEM (&pkey, data.get (),
3176
- data.size (),
3177
- allow_certificate);
3171
+ data.size ());
3178
3172
if (ret == ParsePublicKeyResult::kParsePublicNotRecognized ) {
3179
3173
pkey = ParsePrivateKey (config, data.get (), data.size ());
3180
3174
}
@@ -3199,8 +3193,7 @@ static ManagedEVPPKey GetPublicOrPrivateKeyFromJs(
3199
3193
}
3200
3194
3201
3195
if (is_public) {
3202
- ParsePublicKey (&pkey, config, data.get (), data.size (),
3203
- allow_certificate);
3196
+ ParsePublicKey (&pkey, config, data.get (), data.size ());
3204
3197
} else {
3205
3198
pkey = ParsePrivateKey (config, data.get (), data.size ());
3206
3199
}
@@ -3413,7 +3406,7 @@ void KeyObject::Init(const FunctionCallbackInfo<Value>& args) {
3413
3406
CHECK_EQ (args.Length (), 3 );
3414
3407
3415
3408
offset = 0 ;
3416
- pkey = GetPublicKeyFromJs (args, &offset, false , false );
3409
+ pkey = GetPublicKeyFromJs (args, &offset, false );
3417
3410
if (!pkey)
3418
3411
return ;
3419
3412
key->InitPublic (pkey);
@@ -4695,7 +4688,7 @@ void Verify::VerifyFinal(const FunctionCallbackInfo<Value>& args) {
4695
4688
ASSIGN_OR_RETURN_UNWRAP (&verify, args.Holder ());
4696
4689
4697
4690
unsigned int offset = 0 ;
4698
- ManagedEVPPKey pkey = GetPublicKeyFromJs (args, &offset, true , true );
4691
+ ManagedEVPPKey pkey = GetPublicKeyFromJs (args, &offset, true );
4699
4692
4700
4693
char * hbuf = Buffer::Data (args[offset]);
4701
4694
ssize_t hlen = Buffer::Length (args[offset]);
@@ -4751,7 +4744,7 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
4751
4744
Environment* env = Environment::GetCurrent (args);
4752
4745
4753
4746
unsigned int offset = 0 ;
4754
- ManagedEVPPKey pkey = GetPublicOrPrivateKeyFromJs (args, &offset, true , true );
4747
+ ManagedEVPPKey pkey = GetPublicOrPrivateKeyFromJs (args, &offset, true );
4755
4748
if (!pkey)
4756
4749
return ;
4757
4750
0 commit comments