Commit 236a41d
constanze
fix(pem): use CRYPTO_memcmp and cpp_jwt's base64 instead of hand-rolled ones
Review feedback on #2401.
constantTimeEquals hand-rolled the XOR-accumulate compare; BoringSSL ships
CRYPTO_memcmp for exactly this, so call it. Length is still compared first —
the signature length follows from the algorithm, not the secret, so an early
exit there leaks nothing about the key.
base64UrlDecode hand-rolled the URL-safe alphabet translation on top of
absl::Base64Unescape; cpp_jwt's base64_uri_decode does the same job and is the
one part of that library that needs no BIO, so it links against our BoringSSL.
It is lenient where ours was strict — a non-alphabet byte yields a partial
decode instead of an error — which changes no behaviour here: the HMAC over
header.payload is verified BEFORE the payload is decoded, and a truncated
decode then fails to parse as JSON. NonBase64UrlCharInPayload_Unauthenticated
pins that so it cannot regress behind either decoder.
Reworded the cpp_jwt rationale comment. BIO_f_base64 IS declared in BoringSSL's
public bio.h; it is the implementation in decrepit/bio/base64_bio.c that
@boringssl//:crypto does not build. Verified by linking a probe that calls
jwt::decode(..., verify(true)): 'ld.lld: error: undefined symbol:
BIO_f_base64'. Signing works today (shared/manager/manager.cc) because
HMACSign<>::sign takes the header-only base64 path and never touches a BIO.
Verified with --config=x86_64_sysroot:
default 35 tests, 35 passed
--//…:direct_query=false 3 tests, 3 passed1 parent eeff121 commit 236a41d
3 files changed
Lines changed: 40 additions & 33 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
42 | | - | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
85 | 92 | | |
86 | 93 | | |
87 | 94 | | |
| |||
100 | 107 | | |
101 | 108 | | |
102 | 109 | | |
103 | | - | |
104 | | - | |
105 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
106 | 114 | | |
107 | 115 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
| 116 | + | |
113 | 117 | | |
114 | 118 | | |
115 | | - | |
116 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
117 | 122 | | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
| 123 | + | |
| 124 | + | |
136 | 125 | | |
137 | 126 | | |
138 | 127 | | |
| |||
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
446 | 446 | | |
447 | 447 | | |
448 | 448 | | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
449 | 466 | | |
450 | 467 | | |
451 | 468 | | |
| |||
0 commit comments