| OLD | NEW | 
|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "crypto/nss_key_util.h" | 5 #include "crypto/nss_key_util.h" | 
| 6 | 6 | 
| 7 #include <keyhi.h> | 7 #include <keyhi.h> | 
| 8 #include <pk11pub.h> | 8 #include <pk11pub.h> | 
| 9 #include <stdint.h> | 9 #include <stdint.h> | 
| 10 | 10 | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
| 39   ASSERT_TRUE(GenerateRSAKeyPairNSS(internal_slot(), kKeySizeBits, | 39   ASSERT_TRUE(GenerateRSAKeyPairNSS(internal_slot(), kKeySizeBits, | 
| 40                                     false /* not permanent */, &public_key, | 40                                     false /* not permanent */, &public_key, | 
| 41                                     &private_key)); | 41                                     &private_key)); | 
| 42 | 42 | 
| 43   EXPECT_EQ(rsaKey, SECKEY_GetPublicKeyType(public_key.get())); | 43   EXPECT_EQ(rsaKey, SECKEY_GetPublicKeyType(public_key.get())); | 
| 44   EXPECT_EQ(rsaKey, SECKEY_GetPrivateKeyType(private_key.get())); | 44   EXPECT_EQ(rsaKey, SECKEY_GetPrivateKeyType(private_key.get())); | 
| 45   EXPECT_EQ((kKeySizeBits + 7) / 8, | 45   EXPECT_EQ((kKeySizeBits + 7) / 8, | 
| 46             PK11_GetPrivateModulusLen(private_key.get())); | 46             PK11_GetPrivateModulusLen(private_key.get())); | 
| 47 } | 47 } | 
| 48 | 48 | 
| 49 #if defined(USE_NSS_CERTS) |  | 
| 50 TEST_F(NSSKeyUtilTest, FindNSSKeyFromPublicKeyInfo) { | 49 TEST_F(NSSKeyUtilTest, FindNSSKeyFromPublicKeyInfo) { | 
| 51   // Create an NSS keypair, which will put the keys in the user's NSSDB. | 50   // Create an NSS keypair, which will put the keys in the user's NSSDB. | 
| 52   ScopedSECKEYPublicKey public_key; | 51   ScopedSECKEYPublicKey public_key; | 
| 53   ScopedSECKEYPrivateKey private_key; | 52   ScopedSECKEYPrivateKey private_key; | 
| 54   ASSERT_TRUE(GenerateRSAKeyPairNSS(internal_slot(), 512, | 53   ASSERT_TRUE(GenerateRSAKeyPairNSS(internal_slot(), 512, | 
| 55                                     false /* not permanent */, &public_key, | 54                                     false /* not permanent */, &public_key, | 
| 56                                     &private_key)); | 55                                     &private_key)); | 
| 57 | 56 | 
| 58   ScopedSECItem item(SECKEY_EncodeDERSubjectPublicKeyInfo(public_key.get())); | 57   ScopedSECItem item(SECKEY_EncodeDERSubjectPublicKeyInfo(public_key.get())); | 
| 59   ASSERT_TRUE(item); | 58   ASSERT_TRUE(item); | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 76   ScopedSECItem item(SECKEY_EncodeDERSubjectPublicKeyInfo(public_key.get())); | 75   ScopedSECItem item(SECKEY_EncodeDERSubjectPublicKeyInfo(public_key.get())); | 
| 77   ASSERT_TRUE(item); | 76   ASSERT_TRUE(item); | 
| 78   std::vector<uint8_t> public_key_der(item->data, item->data + item->len); | 77   std::vector<uint8_t> public_key_der(item->data, item->data + item->len); | 
| 79 | 78 | 
| 80   // Remove the keys from the DB, and make sure we can't find them again. | 79   // Remove the keys from the DB, and make sure we can't find them again. | 
| 81   PK11_DestroyTokenObject(private_key->pkcs11Slot, private_key->pkcs11ID); | 80   PK11_DestroyTokenObject(private_key->pkcs11Slot, private_key->pkcs11ID); | 
| 82   PK11_DestroyTokenObject(public_key->pkcs11Slot, public_key->pkcs11ID); | 81   PK11_DestroyTokenObject(public_key->pkcs11Slot, public_key->pkcs11ID); | 
| 83 | 82 | 
| 84   EXPECT_FALSE(FindNSSKeyFromPublicKeyInfo(public_key_der)); | 83   EXPECT_FALSE(FindNSSKeyFromPublicKeyInfo(public_key_der)); | 
| 85 } | 84 } | 
| 86 #endif  // defined(USE_NSS_CERTS) |  | 
| 87 | 85 | 
| 88 }  // namespace crypto | 86 }  // namespace crypto | 
| OLD | NEW | 
|---|