@@ -16,8 +16,15 @@ using v8::Value;
16
16
namespace crypto {
17
17
namespace SPKAC {
18
18
bool VerifySpkac (const ArrayBufferOrViewContents<char >& input) {
19
+ size_t length = input.size ();
20
+ #ifdef OPENSSL_IS_BORINGSSL
21
+ // OpenSSL uses EVP_DecodeBlock, which explicitly removes trailing characters,
22
+ // while BoringSSL uses EVP_DecodedLength and EVP_DecodeBase64, which do not.
23
+ // As such, we trim those characters here for compatibility.
24
+ length = std::string (input.data ()).find_last_not_of (" \n\r\t " ) + 1 ;
25
+ #endif
19
26
NetscapeSPKIPointer spki (
20
- NETSCAPE_SPKI_b64_decode (input.data (), input. size () ));
27
+ NETSCAPE_SPKI_b64_decode (input.data (), length ));
21
28
if (!spki)
22
29
return false ;
23
30
@@ -45,8 +52,15 @@ ByteSource ExportPublicKey(Environment* env,
45
52
BIOPointer bio (BIO_new (BIO_s_mem ()));
46
53
if (!bio) return ByteSource ();
47
54
55
+ size_t length = input.size ();
56
+ #ifdef OPENSSL_IS_BORINGSSL
57
+ // OpenSSL uses EVP_DecodeBlock, which explicitly removes trailing characters,
58
+ // while BoringSSL uses EVP_DecodedLength and EVP_DecodeBase64, which do not.
59
+ // As such, we trim those characters here for compatibility.
60
+ length = std::string (input.data ()).find_last_not_of (" \n\r\t " ) + 1 ;
61
+ #endif
48
62
NetscapeSPKIPointer spki (
49
- NETSCAPE_SPKI_b64_decode (input.data (), input. size () ));
63
+ NETSCAPE_SPKI_b64_decode (input.data (), length ));
50
64
if (!spki) return ByteSource ();
51
65
52
66
EVPKeyPointer pkey (NETSCAPE_SPKI_get_pubkey (spki.get ()));
@@ -73,8 +87,15 @@ void ExportPublicKey(const FunctionCallbackInfo<Value>& args) {
73
87
}
74
88
75
89
ByteSource ExportChallenge (const ArrayBufferOrViewContents<char >& input) {
90
+ size_t length = input.size ();
91
+ #ifdef OPENSSL_IS_BORINGSSL
92
+ // OpenSSL uses EVP_DecodeBlock, which explicitly removes trailing characters,
93
+ // while BoringSSL uses EVP_DecodedLength and EVP_DecodeBase64, which do not.
94
+ // As such, we trim those characters here for compatibility.
95
+ length = std::string (input.data ()).find_last_not_of (" \n\r\t " ) + 1 ;
96
+ #endif
76
97
NetscapeSPKIPointer sp (
77
- NETSCAPE_SPKI_b64_decode (input.data (), input. size () ));
98
+ NETSCAPE_SPKI_b64_decode (input.data (), length ));
78
99
if (!sp)
79
100
return ByteSource ();
80
101
0 commit comments