Commit 8d9853e
authored
Make ssl/crypto report the failures it was swallowing (#92)
The package had two conventions and no rule. RandBytes and Pbkdf2Sha256 checked
what OpenSSL returned and raised. Digest and HmacSha256 checked nothing and
handed back whatever was in the output buffer.
HmacSha256 returned thirty-two zero bytes when HMAC failed. That is not a
degenerate hash, it is a code an attacker can send: a verifier comparing a
computed code against one it was given accepts when the computation failed.
HMAC returns NULL when the key and the message pointers are both null, and an
empty Array[U8] has a null pointer, so the code was already reachable with
ordinary input. HmacSha256(empty, empty) returned zeros. Empty keys and empty
messages are well defined, so both now get a pointer to bytes HMAC will not
read, and a NULL return raises.
Digest.final returned its @pony_alloc output buffer without looking at what
EVP_DigestFinal_ex made of it. @pony_alloc does not zero, so a failed finalise
handed back whatever this actor freed last, as a hash. It raises now, and the
buffer is dropped.
EVP_MD_CTX_new returns NULL when it cannot allocate and EVP_DigestInit_ex
dereferences it. The constructors are partial and raise there, at the one point
that knows whether OpenSSL gave us a context. Deferring it would let someone
build an actor around a Digest that is doomed to raise on every final().
Six lengths were narrowed to a C int with no check. A length in [2^31, 2^32)
narrows negative and OpenSSL rejects it. A length past 2^32 narrows to a small
positive one: RandBytes(2^32 + 5) allocated four gigabytes, filled five bytes,
was told it succeeded, and returned the lot. Each length is checked against what
an int holds, before anything is allocated.
Digest's constructors, Digest.final and HmacSha256 are partial now. append was
already partial, so a streaming digest was always written inside a try.
Closes #85
Closes #86
Closes #881 parent 11f7bac commit 8d9853e
9 files changed
Lines changed: 395 additions & 169 deletions
File tree
- .release-notes
- examples/digest-example
- ssl/crypto
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
| |||
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
| 29 | + | |
26 | 30 | | |
27 | 31 | | |
28 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
0 commit comments