Repository navigation
ssl_verify_openssl: reject too long SAN email instead of truncating it - #1144
rootvector2 wants to merge 1 commit into
Conversation
| msg(D_TLS_ERRORS, "ASN1 ERROR: string contained terminating zero"); | ||
| } | ||
| else if (strlcpy(out, buf, size) >= size) | ||
| else if (strlen(buf) >= size) |
There was a problem hiding this comment.
Nit: strlen() runs twice, once here and once in the branch above. Running it just once and storing the size would be cleaner.
There was a problem hiding this comment.
Done, strlen() is called once now and stored in len.
| msg(D_TLS_ERRORS, "ASN1 ERROR: string contained terminating zero"); | ||
| } | ||
| else if (strlcpy(out, buf, size) >= size) | ||
| else if (strlen(buf) >= size) |
There was a problem hiding this comment.
Could we match the CN path (extract_x509_field_ssl()) behavior here? There, a value to large fails, it doesn't fall back to a previous smaller value.
But here, if a previous email did fit and the current one is too large, the previous one is used.
The CN path uses the last matching field, and returns FAILURE if that field is too long.
There was a problem hiding this comment.
Makes sense. A too long entry now clears out and sets retval = false, so [short, long] fails like a too long CN does, while a later fitting entry still wins the same way the CN path takes the last matching field. Updated the test to expect FAILURE and renamed it to ssl_test_reject_too_long_san_email; test_ssl and the full ctest run pass.
extract_x509_extension() checks whether an rfc822Name fits into the username buffer with the return value of strlcpy(), but strlcpy() has already copied the truncated address into the buffer at that point. The loop only logs "string too long" and keeps retval from an earlier email entry, so a certificate with a short email address followed by one longer than TLS_USERNAME_LEN is accepted with the first 64 characters of the long address as username. Check the length before copying and fail on a too long entry, the same way extract_x509_field_ssl() fails for a too long CN instead of falling back to an earlier, shorter value. Signed-off-by: Naveed Khan <dxbnaveed.k@gmail.com>
9b727a0 to
a39df5c
Compare
extract_x509_extension()checks whether an rfc822Name fits intooutwith the return value ofstrlcpy(), but by thenstrlcpy()has already written the truncated address. If an earlier SAN email already setretval, the function still returnsSUCCESS, so with--x509-username-field ext:subjectAltNamea cert carryingshort@example.comfollowed by a 66 character address gets the first 64 characters of the long one as its username, which then becomes the common name used for ccd, iroutes and--verify-x509-name. Found while reviewingextract_x509_extension()after thestrlcpy()conversion in 670cc97; the newtest_sslcase gets the truncated address back on master.Check the length before copying and fail on a too long entry, the same way
extract_x509_field_ssl()fails for a too long CN instead of falling back to an earlier, shorter value. Abusing this needs a CA that signs several requester-chosen email addresses into one cert, so I'd treat it as hardening; the check belongs in the extractor becauseverify_cert()only ever sees the final string.The commit carries a
Signed-off-by, so it can go to gerrit as is.