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