Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/rsa_private_key.h" | 5 #include "crypto/rsa_private_key.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 key.KeyHeader.Format = CSSM_KEYBLOB_RAW_FORMAT_PKCS8; | 64 key.KeyHeader.Format = CSSM_KEYBLOB_RAW_FORMAT_PKCS8; |
| 65 key.KeyHeader.HeaderVersion = CSSM_KEYHEADER_VERSION; | 65 key.KeyHeader.HeaderVersion = CSSM_KEYHEADER_VERSION; |
| 66 key.KeyHeader.BlobType = CSSM_KEYBLOB_RAW; | 66 key.KeyHeader.BlobType = CSSM_KEYBLOB_RAW; |
| 67 key.KeyHeader.AlgorithmId = CSSM_ALGID_RSA; | 67 key.KeyHeader.AlgorithmId = CSSM_ALGID_RSA; |
| 68 key.KeyHeader.KeyClass = CSSM_KEYCLASS_PRIVATE_KEY; | 68 key.KeyHeader.KeyClass = CSSM_KEYCLASS_PRIVATE_KEY; |
| 69 key.KeyHeader.KeyAttr = CSSM_KEYATTR_EXTRACTABLE; | 69 key.KeyHeader.KeyAttr = CSSM_KEYATTR_EXTRACTABLE; |
| 70 key.KeyHeader.KeyUsage = CSSM_KEYUSE_ANY; | 70 key.KeyHeader.KeyUsage = CSSM_KEYUSE_ANY; |
| 71 | 71 |
| 72 CSSM_KEY_SIZE key_size; | 72 CSSM_KEY_SIZE key_size; |
| 73 CSSM_RETURN crtn; | 73 CSSM_RETURN crtn; |
| 74 crtn = CSSM_QueryKeySizeInBits(GetSharedCSPHandle(), NULL, &key, &key_size); | 74 crtn = CSSM_QueryKeySizeInBits(GetSharedCSPHandle(), 0, &key, &key_size); |
|
Mark Mentovai
2012/03/27 21:09:59
CSSM_INVALID_HANDLE and again on line 136.
| |
| 75 if (crtn) { | 75 if (crtn) { |
| 76 NOTREACHED() << "CSSM_QueryKeySizeInBits failed: " << crtn; | 76 NOTREACHED() << "CSSM_QueryKeySizeInBits failed: " << crtn; |
| 77 return NULL; | 77 return NULL; |
| 78 } | 78 } |
| 79 key.KeyHeader.LogicalKeySizeInBits = key_size.LogicalKeySizeInBits; | 79 key.KeyHeader.LogicalKeySizeInBits = key_size.LogicalKeySizeInBits; |
| 80 | 80 |
| 81 // Perform a NULL unwrap operation on the key so that result's key_ | 81 // Perform a NULL unwrap operation on the key so that result's key_ |
| 82 // instance variable points to a key that can be released via CSSM_FreeKey(). | 82 // instance variable points to a key that can be released via CSSM_FreeKey(). |
| 83 CSSM_ACCESS_CREDENTIALS creds; | 83 CSSM_ACCESS_CREDENTIALS creds; |
| 84 memset(&creds, 0, sizeof(CSSM_ACCESS_CREDENTIALS)); | 84 memset(&creds, 0, sizeof(CSSM_ACCESS_CREDENTIALS)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 memcpy(public_key->KeyData.Data, &public_key_data.front(), size); | 126 memcpy(public_key->KeyData.Data, &public_key_data.front(), size); |
| 127 public_key->KeyData.Length = size; | 127 public_key->KeyData.Length = size; |
| 128 public_key->KeyHeader.Format = CSSM_KEYBLOB_RAW_FORMAT_PKCS1; | 128 public_key->KeyHeader.Format = CSSM_KEYBLOB_RAW_FORMAT_PKCS1; |
| 129 public_key->KeyHeader.HeaderVersion = CSSM_KEYHEADER_VERSION; | 129 public_key->KeyHeader.HeaderVersion = CSSM_KEYHEADER_VERSION; |
| 130 public_key->KeyHeader.BlobType = CSSM_KEYBLOB_RAW; | 130 public_key->KeyHeader.BlobType = CSSM_KEYBLOB_RAW; |
| 131 public_key->KeyHeader.AlgorithmId = CSSM_ALGID_RSA; | 131 public_key->KeyHeader.AlgorithmId = CSSM_ALGID_RSA; |
| 132 public_key->KeyHeader.KeyClass = CSSM_KEYCLASS_PUBLIC_KEY; | 132 public_key->KeyHeader.KeyClass = CSSM_KEYCLASS_PUBLIC_KEY; |
| 133 public_key->KeyHeader.KeyAttr = CSSM_KEYATTR_EXTRACTABLE; | 133 public_key->KeyHeader.KeyAttr = CSSM_KEYATTR_EXTRACTABLE; |
| 134 public_key->KeyHeader.KeyUsage = CSSM_KEYUSE_ANY; | 134 public_key->KeyHeader.KeyUsage = CSSM_KEYUSE_ANY; |
| 135 | 135 |
| 136 crtn = CSSM_QueryKeySizeInBits(GetSharedCSPHandle(), NULL, public_key, | 136 crtn = CSSM_QueryKeySizeInBits(GetSharedCSPHandle(), 0, public_key, |
| 137 &key_size); | 137 &key_size); |
| 138 if (crtn) { | 138 if (crtn) { |
| 139 DLOG(ERROR) << "CSSM_QueryKeySizeInBits failed " << crtn; | 139 DLOG(ERROR) << "CSSM_QueryKeySizeInBits failed " << crtn; |
| 140 return NULL; | 140 return NULL; |
| 141 } | 141 } |
| 142 public_key->KeyHeader.LogicalKeySizeInBits = key_size.LogicalKeySizeInBits; | 142 public_key->KeyHeader.LogicalKeySizeInBits = key_size.LogicalKeySizeInBits; |
| 143 | 143 |
| 144 return result.release(); | 144 return result.release(); |
| 145 } | 145 } |
| 146 | 146 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) const { | 194 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) const { |
| 195 PrivateKeyInfoCodec private_key_info(true); | 195 PrivateKeyInfoCodec private_key_info(true); |
| 196 std::vector<uint8> private_key_data; | 196 std::vector<uint8> private_key_data; |
| 197 private_key_data.assign(key_.KeyData.Data, | 197 private_key_data.assign(key_.KeyData.Data, |
| 198 key_.KeyData.Data + key_.KeyData.Length); | 198 key_.KeyData.Data + key_.KeyData.Length); |
| 199 return (private_key_info.Import(private_key_data) && | 199 return (private_key_info.Import(private_key_data) && |
| 200 private_key_info.ExportPublicKeyInfo(output)); | 200 private_key_info.ExportPublicKeyInfo(output)); |
| 201 } | 201 } |
| 202 | 202 |
| 203 } // namespace crypto | 203 } // namespace crypto |
| OLD | NEW |