Closed Bug 1653641 Opened 6 years ago Closed 6 years ago

Audit DTLS async certificate verification

Categories

(NSS :: Libraries, task, P1)

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: kjacobs, Assigned: kjacobs)

Details

(Keywords: sec-audit)

Attachments

(1 file)

ekr pointed out two issues in our DTLS code:

  1. The comment at [1] doesn't jive with that the code actually does. We want to re-send an ACK, not another Finished.

  2. The comment at [2] indicates that async authCertificate callbacks are not properly handled in DTLS. To block it, we'd need to fail if IS_DTLS ~here. However, we have a few tests that actually do test DTLS with an async callback. We need to audit the code and add tests as necessary to be sure this actually works.

Marking as security just in case the audit uncovers any issues.

[1] https://searchfox.org/nss/source/lib/ssl/dtls13con.c#416,422
[2] https://searchfox.org/nss/source/lib/ssl/dtlscon.c#273

A few points.

  1. It looks like the code translates SECWouldBlock to SECSuccess here:
    https://searchfox.org/nss/source/lib/ssl/ssl3con.c#11242

  2. A little bit of stepoing through these tests in the debugger suggests they behave correctly, though perhaps some more checks are required.

  3. We might consider changing
    https://searchfox.org/nss/source/lib/ssl/dtlscon.c#488

to rv != SECSuccess. I changed that locally and the tests seem OK

NIing MT in case he has thoughts.

Flags: needinfo?(mt)

I couldn't see anything that would indicate that async validation didn't work. The logic we rely upon - at least as far as I could see - is not DTLS-specific.

We don't support async validation for client certificates, which is different. That would require some changes, but I suspect that they wouldn't be that intrusive even. But that's a separate bug.

I did find a few things in my investigation:

  • this looks suspect. It should probably be goto loser.

  • ssl3_AlwaysFail doesn't always fail. It fails just once. It should probably reset restartTarget.

  • this should probably be moved to ssl3_FinishHandshake, noting that it requires the recv buf lock open.

None of that suggests anything is wrong with our code for certificate validation.

Flags: needinfo?(mt)

I think you are right about the goto loser thing.

With that said, as far as I can tell all that happens either way is that we bubble the error up the stack and the handshake fails, so it doesn't matter if we clear the buffer (which we do for other handshake message encoding errors because we goto loser). I think what's going on here is we have harmonized error handling for the "I don't want this message yet" and the "this message is busted" cases, and one requires looping and one does not. As far as I can all all of these returns should be goto loser just for consistency.

Kevin, can you please verify.

I don't see any cases where the return SECFailure is problematic, but yes, it should be goto loser to be safe and consistent.

The gtest coverage for async here is actually pretty complete: I only found one test that could be easily parameterized and the important cases already cover both variants. We obviously don't have the same level of application testing, but I think we can safely say that NSS does support this.

Edit: ssl3_AlwaysFail should indeed be reset each time, but there's no problem since fatalAlertSent gets set the first time it's assigned. That is checked in ssl3_GatherCompleteHandshake

I'll attach a patch addressing the tweaks.

There's a r+ patch which didn't land and no activity in this bug for 2 weeks.
:kjacobs, could you have a look please?
For more information, please visit auto_nag documentation.

Flags: needinfo?(kjacobs.bugzilla)
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Flags: needinfo?(kjacobs.bugzilla)
Resolution: --- → FIXED
Target Milestone: --- → 3.57
Group: crypto-core-security → core-security-release
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: