Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: chrome/browser/chromeos/platform_keys/platform_keys_nss.cc

Issue 331173002: enterprise.platformKeys: Respect the 'hash' argument of generateKey. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/chromeos/platform_keys/platform_keys.h" 5 #include "chrome/browser/chromeos/platform_keys/platform_keys.h"
6 6
7 #include <cryptohi.h> 7 #include <cryptohi.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 const unsigned int modulus_length_; 145 const unsigned int modulus_length_;
146 146
147 private: 147 private:
148 // Must be called on origin thread, use CallBack() therefore. 148 // Must be called on origin thread, use CallBack() therefore.
149 GenerateKeyCallback callback_; 149 GenerateKeyCallback callback_;
150 }; 150 };
151 151
152 class SignState : public NSSOperationState { 152 class SignState : public NSSOperationState {
153 public: 153 public:
154 SignState(const std::string& public_key, 154 SignState(const std::string& public_key,
155 HashAlgorithm hash_algorithm,
155 const std::string& data, 156 const std::string& data,
156 const SignCallback& callback); 157 const SignCallback& callback);
157 virtual ~SignState() {} 158 virtual ~SignState() {}
158 159
159 virtual void OnError(const tracked_objects::Location& from, 160 virtual void OnError(const tracked_objects::Location& from,
160 const std::string& error_message) OVERRIDE { 161 const std::string& error_message) OVERRIDE {
161 CallBack(from, std::string() /* no signature */, error_message); 162 CallBack(from, std::string() /* no signature */, error_message);
162 } 163 }
163 164
164 void CallBack(const tracked_objects::Location& from, 165 void CallBack(const tracked_objects::Location& from,
165 const std::string& signature, 166 const std::string& signature,
166 const std::string& error_message) { 167 const std::string& error_message) {
167 origin_task_runner_->PostTask( 168 origin_task_runner_->PostTask(
168 from, base::Bind(callback_, signature, error_message)); 169 from, base::Bind(callback_, signature, error_message));
169 } 170 }
170 171
171 const std::string public_key_; 172 const std::string public_key_;
173 HashAlgorithm hash_algorithm_;
172 const std::string data_; 174 const std::string data_;
173 175
174 private: 176 private:
175 // Must be called on origin thread, use CallBack() therefore. 177 // Must be called on origin thread, use CallBack() therefore.
176 SignCallback callback_; 178 SignCallback callback_;
177 }; 179 };
178 180
179 class GetCertificatesState : public NSSOperationState { 181 class GetCertificatesState : public NSSOperationState {
180 public: 182 public:
181 explicit GetCertificatesState(const GetCertificatesCallback& callback); 183 explicit GetCertificatesState(const GetCertificatesCallback& callback);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 : origin_task_runner_(base::ThreadTaskRunnerHandle::Get()) { 254 : origin_task_runner_(base::ThreadTaskRunnerHandle::Get()) {
253 } 255 }
254 256
255 GenerateRSAKeyState::GenerateRSAKeyState(unsigned int modulus_length, 257 GenerateRSAKeyState::GenerateRSAKeyState(unsigned int modulus_length,
256 const GenerateKeyCallback& callback) 258 const GenerateKeyCallback& callback)
257 : modulus_length_(modulus_length), 259 : modulus_length_(modulus_length),
258 callback_(callback) { 260 callback_(callback) {
259 } 261 }
260 262
261 SignState::SignState(const std::string& public_key, 263 SignState::SignState(const std::string& public_key,
264 HashAlgorithm hash_algorithm,
262 const std::string& data, 265 const std::string& data,
263 const SignCallback& callback) 266 const SignCallback& callback)
264 : public_key_(public_key), data_(data), callback_(callback) { 267 : public_key_(public_key),
268 hash_algorithm_(hash_algorithm),
269 data_(data),
270 callback_(callback) {
265 } 271 }
266 272
267 GetCertificatesState::GetCertificatesState( 273 GetCertificatesState::GetCertificatesState(
268 const GetCertificatesCallback& callback) 274 const GetCertificatesCallback& callback)
269 : callback_(callback) { 275 : callback_(callback) {
270 } 276 }
271 277
272 ImportCertificateState::ImportCertificateState( 278 ImportCertificateState::ImportCertificateState(
273 scoped_refptr<net::X509Certificate> certificate, 279 scoped_refptr<net::X509Certificate> certificate,
274 const ImportCertificateCallback& callback) 280 const ImportCertificateCallback& callback)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 public_key_uint8, public_key_uint8 + state->public_key_.size()); 332 public_key_uint8, public_key_uint8 + state->public_key_.size());
327 333
328 // TODO(pneubeck): This searches all slots. Change to look only at |slot_|. 334 // TODO(pneubeck): This searches all slots. Change to look only at |slot_|.
329 scoped_ptr<crypto::RSAPrivateKey> rsa_key( 335 scoped_ptr<crypto::RSAPrivateKey> rsa_key(
330 crypto::RSAPrivateKey::FindFromPublicKeyInfo(public_key_vector)); 336 crypto::RSAPrivateKey::FindFromPublicKeyInfo(public_key_vector));
331 if (!rsa_key || rsa_key->key()->pkcs11Slot != state->slot_) { 337 if (!rsa_key || rsa_key->key()->pkcs11Slot != state->slot_) {
332 state->OnError(FROM_HERE, kErrorKeyNotFound); 338 state->OnError(FROM_HERE, kErrorKeyNotFound);
333 return; 339 return;
334 } 340 }
335 341
342 SECOidTag sign_alg_tag = SEC_OID_UNKNOWN;
343 switch (state->hash_algorithm_) {
344 case HASH_ALGORITHM_SHA1:
345 sign_alg_tag = SEC_OID_PKCS1_SHA1_WITH_RSA_ENCRYPTION;
346 break;
347 case HASH_ALGORITHM_SHA256:
348 sign_alg_tag = SEC_OID_PKCS1_SHA256_WITH_RSA_ENCRYPTION;
349 break;
350 case HASH_ALGORITHM_SHA384:
351 sign_alg_tag = SEC_OID_PKCS1_SHA384_WITH_RSA_ENCRYPTION;
352 break;
353 case HASH_ALGORITHM_SHA512:
354 sign_alg_tag = SEC_OID_PKCS1_SHA512_WITH_RSA_ENCRYPTION;
355 break;
356 }
357
336 SECItem sign_result = {siBuffer, NULL, 0}; 358 SECItem sign_result = {siBuffer, NULL, 0};
337 if (SEC_SignData(&sign_result, 359 if (SEC_SignData(&sign_result,
338 reinterpret_cast<const unsigned char*>(state->data_.data()), 360 reinterpret_cast<const unsigned char*>(state->data_.data()),
339 state->data_.size(), 361 state->data_.size(),
340 rsa_key->key(), 362 rsa_key->key(),
341 SEC_OID_PKCS1_SHA1_WITH_RSA_ENCRYPTION) != SECSuccess) { 363 sign_alg_tag) != SECSuccess) {
342 LOG(ERROR) << "Couldn't sign."; 364 LOG(ERROR) << "Couldn't sign.";
343 state->OnError(FROM_HERE, kErrorInternal); 365 state->OnError(FROM_HERE, kErrorInternal);
344 return; 366 return;
345 } 367 }
346 368
347 std::string signature(reinterpret_cast<const char*>(sign_result.data), 369 std::string signature(reinterpret_cast<const char*>(sign_result.data),
348 sign_result.len); 370 sign_result.len);
349 state->CallBack(FROM_HERE, signature, std::string() /* no error */); 371 state->CallBack(FROM_HERE, signature, std::string() /* no error */);
350 } 372 }
351 373
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 // Get the pointer to |state| before base::Passed releases |state|. 508 // Get the pointer to |state| before base::Passed releases |state|.
487 NSSOperationState* state_ptr = state.get(); 509 NSSOperationState* state_ptr = state.get();
488 GetCertDatabase(token_id, 510 GetCertDatabase(token_id,
489 base::Bind(&GenerateRSAKeyWithDB, base::Passed(&state)), 511 base::Bind(&GenerateRSAKeyWithDB, base::Passed(&state)),
490 browser_context, 512 browser_context,
491 state_ptr); 513 state_ptr);
492 } 514 }
493 515
494 void Sign(const std::string& token_id, 516 void Sign(const std::string& token_id,
495 const std::string& public_key, 517 const std::string& public_key,
518 HashAlgorithm hash_algorithm,
496 const std::string& data, 519 const std::string& data,
497 const SignCallback& callback, 520 const SignCallback& callback,
498 BrowserContext* browser_context) { 521 BrowserContext* browser_context) {
499 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 522 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
500 scoped_ptr<SignState> state(new SignState(public_key, data, callback)); 523 scoped_ptr<SignState> state(
524 new SignState(public_key, hash_algorithm, data, callback));
501 // Get the pointer to |state| before base::Passed releases |state|. 525 // Get the pointer to |state| before base::Passed releases |state|.
502 NSSOperationState* state_ptr = state.get(); 526 NSSOperationState* state_ptr = state.get();
503 527
504 // The NSSCertDatabase object is not required. But in case it's not available 528 // The NSSCertDatabase object is not required. But in case it's not available
505 // we would get more informative error messages and we can double check that 529 // we would get more informative error messages and we can double check that
506 // we use a key of the correct token. 530 // we use a key of the correct token.
507 GetCertDatabase(token_id, 531 GetCertDatabase(token_id,
508 base::Bind(&RSASignWithDB, base::Passed(&state)), 532 base::Bind(&RSASignWithDB, base::Passed(&state)),
509 browser_context, 533 browser_context,
510 state_ptr); 534 state_ptr);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 // we would get more informative error messages. 580 // we would get more informative error messages.
557 GetCertDatabase(token_id, 581 GetCertDatabase(token_id,
558 base::Bind(&RemoveCertificateWithDB, base::Passed(&state)), 582 base::Bind(&RemoveCertificateWithDB, base::Passed(&state)),
559 browser_context, 583 browser_context,
560 state_ptr); 584 state_ptr);
561 } 585 }
562 586
563 } // namespace platform_keys 587 } // namespace platform_keys
564 588
565 } // namespace chromeos 589 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698