Repository navigation
Generate ice_lite credentials with RAND_bytes() instead of random() - #195
Merged
Merged
Conversation
ice_lite_data_ctor() builds the local ICE ufrag and pwd with generate_random_string(), which takes each character from random() % 64. random() is seeded once per process from a 32-bit value and is an additive lagged generator (r[i] = r[i-3] + r[i-31]), so the low bits of its output are fully predictable from earlier output. The local pwd is the only key for MESSAGE-INTEGRITY on incoming binding requests, and a check that passes makes the module force-latch the stream to its source. A caller who sends "A" with long ufrag/pwd gets local credentials of the same length back in their own answer, which is enough random() % 64 output to recover the generator's low bits and compute the ufrag/pwd of the sessions created after it, regardless of how many random() calls the port table makes in between. RFC 8445 5.3 asks for at least 24 bits of randomness in the ufrag and 128 bits in the pwd. Move the helper into the module, its only user, and draw the bytes from RAND_bytes(). The module is only built with libcrypto, and dtls_gw uses RAND_bytes() the same way. Fail the allocation if RAND_bytes() fails.
sobomax
force-pushed
the
ice-lite-csprng-creds
branch
2 times, most recently
from
November 26, 2026 23:46
b784199 to
072c870
Compare
Replace the charset[] table lookup in ice_random_string() with a branch-light arithmetic mapping of 6 random bits onto 64 distinct ice-chars (+, /, A-Z, a-z, 0-9), see RFC 8445 section 15.1.
sobomax
force-pushed
the
ice-lite-csprng-creds
branch
from
November 27, 2026 00:31
072c870 to
fc2ff9c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ice_lite takes its local ufrag/pwd from
random() % 64, which can be predicted from credentials the module hands out to other callers:random()is seeded once per process from 32 bits, and glibc's generator isr[i] = r[i-3] + r[i-31]. Each character exposes bits 1..6 of an output, and bit 0 is a 31-bit linear sequence whose carries show up in those bits.Athe local credentials get the same length as the remote ones, so a caller who offers a 256-char ufrag and pwd gets 512 consecutive outputs back in their own answer. That is enough to solve for bit 0 and compute the ufrag/pwd of the nextS/Aexactly, however manyrandom()calls the port table makes in between.S-first flow,rufragisn't checked untilAarrives. RFC 8445 5.3 asks for at least 24 bits of randomness in the ufrag and 128 bits in the pwd. Right now the whole process has at most 32.The bytes now come from
RAND_bytes(), and the helper has moved into the module, which is its only user. ice_lite is only built with libcrypto, and dtls_gw already callsRAND_bytes(). With a 64-entry charset the 24-char pwd carries 144 bits.Repro: a bit-exact model of glibc
srandom()/random()(it matchessrand(1)→ 1804289383, 846930886, 1681692777) with a random seed, a random number of discarded outputs, an attackerAwith 256+256 chars, then 0..15 unrelated calls and a victimS. From the attacker's 512 characters it predicts the victim's 4-char ufrag and 24-char pwd on every run, out of 16 candidates for the unknown gap. FedRAND_bytes-style output, the same solver finds no consistent state. I compiled and exercised the new helper standalone with clang-Wall -Wextra -Werror, but couldn't build the full tree or run the test suite on this machine.