New issue
Advanced search Search tips

Issue 673058 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: May 2017
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 3
Type: Bug



Sign in to add a comment

Unit test platform SSLPrivateKey implementations

Project Member Reported by davidben@chromium.org, Dec 10 2016

Issue description

We should unit test these as best we can. After https://codereview.chromium.org/2567523003/ lands, we should have sample keys for all the key types we support, and the Android code will be a bit less of a mess.

I'm thinking abstract some of that out and then we figure out how to create an in-memory OS key for each platform, as best we can. We probably won't be able to do 100% coverage (for that, we should get some client auth servers on badssl.com or wherever and ask test folks to test it manually), but try to get it as good as we can.

For instance, if we tease apart the logic to search for keys that match certs from the SSLPrivateKey implementation, we could unit test the latter without having to deal with the former.
 
Hrm. For testing ECDSA keys on NSS, I bet the part where NSS refuses to import un"encrypted" EC keys will be a problem. Maybe we could generate and check in empty-password-encrypted versions of them to get a SECKEYPrivateKey out of it.
Keychain is still platform-wide side-effects

For CryptoAPI, I'm not sure there's benefits to this - if we created our own KSP, we're no longer testing CryptoAPI - we're testing the SPI, and that's OS-stable.
I'm interested in having unit tests for whether our translation between SSLPrivateKey and the OS APIs is correct. If the OS APIs we're calling suddenly stopped working when secretly backed by a smartcard, then, well, we're kind of out of luck.

(Ideally the OS APIs would be sufficiently stable and uniform that we primarily need to be worried about correctness north of them. This is, of course, completely false.)

But, e.g., for Android, the first couple of iterations when I tried to convert away from RSA_METHOD had mistakes. That there were unit tests I could adapt saved me a ton of error-prone and time-consuming manual testing.
I'm not sure the claim about Keychain still having platform-wide side effects is true anymore. But I'll leave the burden of proof on me to get it working. :-)
It's still true in 10.12 that adding/removing a keychain triggers the global systemwide mutex.
Owner: davidben@chromium.org
Status: Assigned (was: Untriaged)
This seems to do the trick for Mac:
https://codereview.chromium.org/2566273008/
Project Member

Comment 7 by bugdroid1@chromium.org, Dec 14 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/ebe0803de7a569dee0c7b0ab6b4685dc749b8f29

commit ebe0803de7a569dee0c7b0ab6b4685dc749b8f29
Author: davidben <davidben@chromium.org>
Date: Wed Dec 14 02:22:07 2016

Use SecKeyCreateSignature on macOS 10.12 and later.

macOS 10.12 breaks the CSSM code for smartcards. Switch to the new APIs.
In the process, refactor the Android unit tests to be common on all
platforms and unit test this stuff. SecKeychainCreate finally works, so
we can unit test the entire path from certificate to key and compare
signatures against OpenSSL.

That second part probably bears repeating. Eight years into the project's
lifetime, we FINALLY have unit tests for this code!

BUG= 666796 , 673058 

Review-Url: https://codereview.chromium.org/2566273008
Cr-Commit-Position: refs/heads/master@{#438392}

[modify] https://crrev.com/ebe0803de7a569dee0c7b0ab6b4685dc749b8f29/net/net.gypi
[modify] https://crrev.com/ebe0803de7a569dee0c7b0ab6b4685dc749b8f29/net/ssl/ssl_platform_key.h
[modify] https://crrev.com/ebe0803de7a569dee0c7b0ab6b4685dc749b8f29/net/ssl/ssl_platform_key_android.cc
[modify] https://crrev.com/ebe0803de7a569dee0c7b0ab6b4685dc749b8f29/net/ssl/ssl_platform_key_android_unittest.cc
[modify] https://crrev.com/ebe0803de7a569dee0c7b0ab6b4685dc749b8f29/net/ssl/ssl_platform_key_chromecast.cc
[modify] https://crrev.com/ebe0803de7a569dee0c7b0ab6b4685dc749b8f29/net/ssl/ssl_platform_key_mac.cc
[add] https://crrev.com/ebe0803de7a569dee0c7b0ab6b4685dc749b8f29/net/ssl/ssl_platform_key_mac.h
[add] https://crrev.com/ebe0803de7a569dee0c7b0ab6b4685dc749b8f29/net/ssl/ssl_platform_key_mac_unittest.cc
[modify] https://crrev.com/ebe0803de7a569dee0c7b0ab6b4685dc749b8f29/net/ssl/ssl_platform_key_nss.cc
[modify] https://crrev.com/ebe0803de7a569dee0c7b0ab6b4685dc749b8f29/net/ssl/ssl_platform_key_win.cc
[add] https://crrev.com/ebe0803de7a569dee0c7b0ab6b4685dc749b8f29/net/ssl/ssl_private_key_test_util.cc
[add] https://crrev.com/ebe0803de7a569dee0c7b0ab6b4685dc749b8f29/net/ssl/ssl_private_key_test_util.h

Owner: ----
Status: Available (was: Assigned)
With that, all that's left is Windows. I'll move this back to Available since I don't know enough about those APIs.
Project Member

Comment 10 by bugdroid1@chromium.org, May 10 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/d6d1e4d17563f475169ea8564be5e581759eb8fd

commit d6d1e4d17563f475169ea8564be5e581759eb8fd
Author: davidben <davidben@chromium.org>
Date: Wed May 10 16:49:01 2017

Unit-test CAPI and CNG SSLPrivateKey implementations.

This does not cover the CryptAcquireCertificatePrivateKey call (from my
manual testing, it didn't appear that the imported keys showed up
via CryptAcquireCertificatePrivateKey at all), but it tests that we are calling
CAPI and CNG correctly for the algorithms we are trying to implement. This
will be useful when we revise the interface for RSA-PSS and add support for
it. Also, it means we actually have some test for this stuff!

BUG= 673058 

Review-Url: https://codereview.chromium.org/2865883002
Cr-Commit-Position: refs/heads/master@{#470612}

[modify] https://crrev.com/d6d1e4d17563f475169ea8564be5e581759eb8fd/net/BUILD.gn
[modify] https://crrev.com/d6d1e4d17563f475169ea8564be5e581759eb8fd/net/ssl/ssl_platform_key_win.cc
[add] https://crrev.com/d6d1e4d17563f475169ea8564be5e581759eb8fd/net/ssl/ssl_platform_key_win.h
[add] https://crrev.com/d6d1e4d17563f475169ea8564be5e581759eb8fd/net/ssl/ssl_platform_key_win_unittest.cc

Owner: davidben@chromium.org
Status: Fixed (was: Available)
FINALLY!!!!

Sign in to add a comment