| 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( |
| 75 GetSharedCSPHandle(), CSSM_INVALID_HANDLE, &key, &key_size); |
| 75 if (crtn) { | 76 if (crtn) { |
| 76 NOTREACHED() << "CSSM_QueryKeySizeInBits failed: " << crtn; | 77 NOTREACHED() << "CSSM_QueryKeySizeInBits failed: " << crtn; |
| 77 return NULL; | 78 return NULL; |
| 78 } | 79 } |
| 79 key.KeyHeader.LogicalKeySizeInBits = key_size.LogicalKeySizeInBits; | 80 key.KeyHeader.LogicalKeySizeInBits = key_size.LogicalKeySizeInBits; |
| 80 | 81 |
| 81 // Perform a NULL unwrap operation on the key so that result's key_ | 82 // 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(). | 83 // instance variable points to a key that can be released via CSSM_FreeKey(). |
| 83 CSSM_ACCESS_CREDENTIALS creds; | 84 CSSM_ACCESS_CREDENTIALS creds; |
| 84 memset(&creds, 0, sizeof(CSSM_ACCESS_CREDENTIALS)); | 85 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); | 127 memcpy(public_key->KeyData.Data, &public_key_data.front(), size); |
| 127 public_key->KeyData.Length = size; | 128 public_key->KeyData.Length = size; |
| 128 public_key->KeyHeader.Format = CSSM_KEYBLOB_RAW_FORMAT_PKCS1; | 129 public_key->KeyHeader.Format = CSSM_KEYBLOB_RAW_FORMAT_PKCS1; |
| 129 public_key->KeyHeader.HeaderVersion = CSSM_KEYHEADER_VERSION; | 130 public_key->KeyHeader.HeaderVersion = CSSM_KEYHEADER_VERSION; |
| 130 public_key->KeyHeader.BlobType = CSSM_KEYBLOB_RAW; | 131 public_key->KeyHeader.BlobType = CSSM_KEYBLOB_RAW; |
| 131 public_key->KeyHeader.AlgorithmId = CSSM_ALGID_RSA; | 132 public_key->KeyHeader.AlgorithmId = CSSM_ALGID_RSA; |
| 132 public_key->KeyHeader.KeyClass = CSSM_KEYCLASS_PUBLIC_KEY; | 133 public_key->KeyHeader.KeyClass = CSSM_KEYCLASS_PUBLIC_KEY; |
| 133 public_key->KeyHeader.KeyAttr = CSSM_KEYATTR_EXTRACTABLE; | 134 public_key->KeyHeader.KeyAttr = CSSM_KEYATTR_EXTRACTABLE; |
| 134 public_key->KeyHeader.KeyUsage = CSSM_KEYUSE_ANY; | 135 public_key->KeyHeader.KeyUsage = CSSM_KEYUSE_ANY; |
| 135 | 136 |
| 136 crtn = CSSM_QueryKeySizeInBits(GetSharedCSPHandle(), NULL, public_key, | 137 crtn = CSSM_QueryKeySizeInBits( |
| 137 &key_size); | 138 GetSharedCSPHandle(), CSSM_INVALID_HANDLE, public_key, &key_size); |
| 138 if (crtn) { | 139 if (crtn) { |
| 139 DLOG(ERROR) << "CSSM_QueryKeySizeInBits failed " << crtn; | 140 DLOG(ERROR) << "CSSM_QueryKeySizeInBits failed " << crtn; |
| 140 return NULL; | 141 return NULL; |
| 141 } | 142 } |
| 142 public_key->KeyHeader.LogicalKeySizeInBits = key_size.LogicalKeySizeInBits; | 143 public_key->KeyHeader.LogicalKeySizeInBits = key_size.LogicalKeySizeInBits; |
| 143 | 144 |
| 144 return result.release(); | 145 return result.release(); |
| 145 } | 146 } |
| 146 | 147 |
| 147 // static | 148 // static |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) const { | 195 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) const { |
| 195 PrivateKeyInfoCodec private_key_info(true); | 196 PrivateKeyInfoCodec private_key_info(true); |
| 196 std::vector<uint8> private_key_data; | 197 std::vector<uint8> private_key_data; |
| 197 private_key_data.assign(key_.KeyData.Data, | 198 private_key_data.assign(key_.KeyData.Data, |
| 198 key_.KeyData.Data + key_.KeyData.Length); | 199 key_.KeyData.Data + key_.KeyData.Length); |
| 199 return (private_key_info.Import(private_key_data) && | 200 return (private_key_info.Import(private_key_data) && |
| 200 private_key_info.ExportPublicKeyInfo(output)); | 201 private_key_info.ExportPublicKeyInfo(output)); |
| 201 } | 202 } |
| 202 | 203 |
| 203 } // namespace crypto | 204 } // namespace crypto |
| OLD | NEW |