Skip to content

Conversation

@anhu
Copy link
Member

@anhu anhu commented Mar 28, 2025

Fixes #8597

@anhu
Copy link
Member Author

anhu commented Mar 28, 2025

jenkins retest this please
(Java crashed.)

@anhu anhu changed the title Validate asn date based on string length Validate asn date based on position of Z Mar 28, 2025
@anhu
Copy link
Member Author

anhu commented Mar 28, 2025

Jenkins retest this please

@anhu
Copy link
Member Author

anhu commented Mar 29, 2025

jenkins retest this please

@anhu anhu requested review from wolfSSL-Bot and removed request for wolfSSL-Bot March 29, 2025 06:14
Copy link
Contributor

@JacobBarthelmeh JacobBarthelmeh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a test case

@JacobBarthelmeh JacobBarthelmeh assigned anhu and unassigned wolfSSL-Bot Mar 31, 2025
@anhu anhu requested a review from JacobBarthelmeh April 4, 2025 14:47
@anhu anhu assigned JacobBarthelmeh and unassigned anhu Apr 4, 2025
@anhu anhu requested a review from SparkiDev April 4, 2025 14:49
Copy link
Contributor

@JacobBarthelmeh JacobBarthelmeh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a test case

SparkiDev
SparkiDev previously approved these changes Apr 8, 2025
@anhu
Copy link
Member Author

anhu commented Apr 22, 2025

It will always eventually succeed. Need to redesign this part so we actually record whether it was generalized or utc.

        if (GetTimeString(crl->crlList->lastDate, ASN_UTC_TIME,
            tmp, MAX_WIDTH) != WOLFSSL_SUCCESS) {
            if (GetTimeString(crl->crlList->lastDate, ASN_GENERALIZED_TIME,
            tmp, MAX_WIDTH) != WOLFSSL_SUCCESS) {
                WOLFSSL_MSG("Error getting last update date");
                return WOLFSSL_FAILURE;
            }
        }

@anhu anhu force-pushed the check_date_fmt branch from 7542802 to b98bf85 Compare May 12, 2025 15:43
@anhu
Copy link
Member Author

anhu commented May 12, 2025

Please do not merge. I would like to squash this once it is approved.

@anhu anhu requested review from JacobBarthelmeh and SparkiDev May 12, 2025 19:54
@anhu anhu assigned wolfSSL-Bot and unassigned anhu and wolfSSL-Bot May 12, 2025
@anhu
Copy link
Member Author

anhu commented May 12, 2025

Jenkins retest this please

* built into macro values. */
if (format == ASN_UTC_TIME) {
/* UTCTime format requires YYMMDDHHMMSSZ. */
if (date[i + ASN_UTC_TIME_SIZE - 2] != 'Z') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any guard to prevent an out-of-bounds read here, which would result in undefined behavior.

GetTimeString() is passed a len arg, but does not pass it on to ExtractDate(), and does not do any bounds checking of its own before passing date to ExtractDate().

Note that the unsafe logic can be reached from public API wolfSSL_ASN1_TIME_to_string(), also with no relevant bounds protection, so this is really not OK on that basis alone.

Bottom line, a refactor is needed to pass the len to ExtractDate() and use it for bounds checking.

Also note that the existing calls in ExtractDate() to btoi() and GetTime() are unsafe if date is not null-terminated. It is never safe to handle a non-null-terminated string without having and honoring an explicit length, but worse, there is no way to use btoi() and GetTime() safely on non-null-terminated strings.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@douzzer ,

Not sure how we can resolve this. Note the following:

int wc_ValidateDate(const byte* date, byte format, int dateType)
...
    if (!ExtractDate(date, format, &certTime, &i)) {
        WOLFSSL_MSG("Error extracting the date");
        return 0;
    }

No len is passed in to wc_ValidateDate(). It is a wolfcrypt local function, but it is macrofied to XVALIDATE_DATE . I think in order to get the level of safety you are looking for we need a major refactor which would fall way out of the scope of this PR.

I suggest your proposal be done in another PR. Let me know your thoughts.

@douzzer douzzer assigned anhu and douzzer and unassigned wolfSSL-Bot May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:wolfSSL accepts the incorrect GeneralizedTime value.

5 participants