Commit 5204e97
authored
Fix cleartext leak in signatures of UTF-8 encoded messages (#244)
When signing UTF-8 encoded messages containing multi-byte characters
(like German umlauts ö, ü, ä), the signature could be incorrectly
sized (e.g., 90 bytes instead of 64 bytes). This occurred because
Ruby's string slicing [0, n] operates on characters (not bytes) when
the string has UTF-8 encoding.
The issue affected both signing and verification:
1. SigningKey#sign: The line `sign_attached(message)[0, signature_bytes]`
would slice the first 64 characters instead of the first 64 bytes,
resulting in signatures larger than 64 bytes when the combined
signature+message buffer inherited UTF-8 encoding from the message.
2. VerifyKey#verify: The concatenation `signature + message` would fail
with an encoding compatibility error when trying to combine an
ASCII-8BIT signature with a UTF-8 message.
Fix: Force messages to binary encoding (ASCII-8BIT) before passing them
to the underlying libsodium functions. This ensures:
- String slicing operates on bytes, not characters
- Signatures are always exactly 64 bytes
- No encoding compatibility errors during verification
Added test case with German umlauts to prevent regression.1 parent 4d50984 commit 5204e97
3 files changed
Lines changed: 16 additions & 2 deletions
File tree
- lib/rbnacl/signatures/ed25519
- spec/rbnacl/signatures/ed25519
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
81 | 85 | | |
82 | 86 | | |
83 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
55 | 58 | | |
56 | 59 | | |
57 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
21 | 28 | | |
22 | 29 | | |
23 | 30 | | |
| |||
0 commit comments