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

Side by Side Diff: crypto/nss_util.cc

Issue 18121007: *WIP* Store NSS slots per profile. Move keygen to chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: certdb: handle GetCertTrust and IsUntrusted, failed attempt to handle SetCertTrust Created 7 years, 1 month 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
« no previous file with comments | « crypto/nss_util.h ('k') | crypto/nss_util_internal.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_util.h" 5 #include "crypto/nss_util.h"
6 #include "crypto/nss_util_internal.h" 6 #include "crypto/nss_util_internal.h"
7 7
8 #include <nss.h> 8 #include <nss.h>
9 #include <pk11pub.h> 9 #include <pk11pub.h>
10 #include <plarena.h> 10 #include <plarena.h>
11 #include <prerror.h> 11 #include <prerror.h>
12 #include <prinit.h> 12 #include <prinit.h>
13 #include <prtime.h> 13 #include <prtime.h>
14 #include <secmod.h> 14 #include <secmod.h>
15 15
16 #if defined(OS_LINUX) 16 #if defined(OS_LINUX)
17 #include <linux/nfs_fs.h> 17 #include <linux/nfs_fs.h>
18 #include <sys/vfs.h> 18 #include <sys/vfs.h>
19 #elif defined(OS_OPENBSD) 19 #elif defined(OS_OPENBSD)
20 #include <sys/mount.h> 20 #include <sys/mount.h>
21 #include <sys/param.h> 21 #include <sys/param.h>
22 #endif 22 #endif
23 23
24 #include <map>
24 #include <vector> 25 #include <vector>
25 26
27 #include "base/callback.h"
26 #include "base/debug/alias.h" 28 #include "base/debug/alias.h"
27 #include "base/environment.h" 29 #include "base/environment.h"
28 #include "base/file_util.h" 30 #include "base/file_util.h"
29 #include "base/files/file_path.h" 31 #include "base/files/file_path.h"
30 #include "base/files/scoped_temp_dir.h" 32 #include "base/files/scoped_temp_dir.h"
31 #include "base/lazy_instance.h" 33 #include "base/lazy_instance.h"
32 #include "base/logging.h" 34 #include "base/logging.h"
33 #include "base/memory/scoped_ptr.h" 35 #include "base/memory/scoped_ptr.h"
34 #include "base/metrics/histogram.h" 36 #include "base/metrics/histogram.h"
35 #include "base/native_library.h" 37 #include "base/native_library.h"
38 #include "base/stl_util.h"
36 #include "base/strings/stringprintf.h" 39 #include "base/strings/stringprintf.h"
37 #include "base/threading/thread_restrictions.h" 40 #include "base/threading/thread_restrictions.h"
38 #include "build/build_config.h" 41 #include "build/build_config.h"
39 42
40 // USE_NSS means we use NSS for everything crypto-related. If USE_NSS is not 43 // USE_NSS means we use NSS for everything crypto-related. If USE_NSS is not
41 // defined, such as on Mac and Windows, we use NSS for SSL only -- we don't 44 // defined, such as on Mac and Windows, we use NSS for SSL only -- we don't
42 // use NSS for crypto or certificate verification, and we don't use the NSS 45 // use NSS for crypto or certificate verification, and we don't use the NSS
43 // certificate and key databases. 46 // certificate and key databases.
44 #if defined(USE_NSS) 47 #if defined(USE_NSS)
45 #include "base/synchronization/lock.h" 48 #include "base/synchronization/lock.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 base::FilePath dir = file_util::GetHomeDir(); 82 base::FilePath dir = file_util::GetHomeDir();
80 if (dir.empty()) { 83 if (dir.empty()) {
81 LOG(ERROR) << "Failed to get home directory."; 84 LOG(ERROR) << "Failed to get home directory.";
82 return dir; 85 return dir;
83 } 86 }
84 dir = dir.AppendASCII(".pki").AppendASCII("nssdb"); 87 dir = dir.AppendASCII(".pki").AppendASCII("nssdb");
85 if (!file_util::CreateDirectory(dir)) { 88 if (!file_util::CreateDirectory(dir)) {
86 LOG(ERROR) << "Failed to create " << dir.value() << " directory."; 89 LOG(ERROR) << "Failed to create " << dir.value() << " directory.";
87 dir.clear(); 90 dir.clear();
88 } 91 }
92 VLOG(1) << "DefaultConfigDirectory: " << dir.value();
89 return dir; 93 return dir;
90 } 94 }
91 95
92 // On non-Chrome OS platforms, return the default config directory. On Chrome OS 96 // On non-Chrome OS platforms, return the default config directory. On Chrome OS
93 // test images, return a read-only directory with fake root CA certs (which are 97 // test images, return a read-only directory with fake root CA certs (which are
94 // used by the local Google Accounts server mock we use when testing our login 98 // used by the local Google Accounts server mock we use when testing our login
95 // code). On Chrome OS non-test images (where the read-only directory doesn't 99 // code). On Chrome OS non-test images (where the read-only directory doesn't
96 // exist), return an empty path. 100 // exist), return an empty path.
97 base::FilePath GetInitialConfigDirectory() { 101 base::FilePath GetInitialConfigDirectory() {
98 #if defined(OS_CHROMEOS) 102 #if defined(OS_CHROMEOS)
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 void CrashOnNSSInitFailure() { 210 void CrashOnNSSInitFailure() {
207 int nss_error = PR_GetError(); 211 int nss_error = PR_GetError();
208 int os_error = PR_GetOSError(); 212 int os_error = PR_GetOSError();
209 base::debug::Alias(&nss_error); 213 base::debug::Alias(&nss_error);
210 base::debug::Alias(&os_error); 214 base::debug::Alias(&os_error);
211 LOG(ERROR) << "Error initializing NSS without a persistent database: " 215 LOG(ERROR) << "Error initializing NSS without a persistent database: "
212 << GetNSSErrorMessage(); 216 << GetNSSErrorMessage();
213 LOG(FATAL) << "nss_error=" << nss_error << ", os_error=" << os_error; 217 LOG(FATAL) << "nss_error=" << nss_error << ", os_error=" << os_error;
214 } 218 }
215 219
220 #if defined(OS_CHROMEOS)
221 class ChromeOSUserData {
222 public:
223 ChromeOSUserData(ScopedPK11Slot public_slot, bool is_primary_user)
224 : public_slot_(public_slot.Pass()), is_primary_user_(is_primary_user) {}
225 ~ChromeOSUserData() {
226 // Don't close when NSS is < 3.15.1, because it would require an additional
227 // sleep for 1 second after closing the database, due to
228 // http://bugzil.la/875601.
229 if (NSS_VersionCheck("3.15.1")) {
230 if (public_slot_ && !is_primary_user_) {
231 SECStatus status = SECMOD_CloseUserDB(public_slot_.get());
232 if (status != SECSuccess)
233 PLOG(ERROR) << "SECMOD_CloseUserDB failed: " << PORT_GetError();
234 }
235 }
236 }
237
238 ScopedPK11Slot GetPublicSlot() {
239 return ScopedPK11Slot(public_slot_ ? PK11_ReferenceSlot(public_slot_.get())
240 : NULL);
241 }
242
243 ScopedPK11Slot GetPrivateSlot() {
244 return ScopedPK11Slot(
245 private_slot_ ? PK11_ReferenceSlot(private_slot_.get()) : NULL);
246 }
247
248 void OnPrivateSlotReady(
249 const base::Callback<void(ScopedPK11Slot)>& callback) {
250 if (private_slot_)
251 callback.Run(GetPrivateSlot());
252 else
253 tpm_ready_callback_list_.push_back(callback);
254 }
255
256 void SetPrivateSlot(ScopedPK11Slot private_slot) {
257 DCHECK(!private_slot_);
258 private_slot_ = private_slot.Pass();
259
260 for (SlotReadyCallbackList::iterator i = tpm_ready_callback_list_.begin();
261 i != tpm_ready_callback_list_.end();
262 ++i) {
263 (*i).Run(GetPrivateSlot());
264 }
265 tpm_ready_callback_list_.clear();
266 }
267
268 private:
269 ScopedPK11Slot public_slot_;
270 ScopedPK11Slot private_slot_;
271 bool is_primary_user_;
272
273 typedef std::vector<base::Callback<void(ScopedPK11Slot)> >
274 SlotReadyCallbackList;
275 SlotReadyCallbackList tpm_ready_callback_list_;
276 };
277 #endif // defined(OS_CHROMEOS)
278
216 class NSSInitSingleton { 279 class NSSInitSingleton {
217 public: 280 public:
218 #if defined(OS_CHROMEOS) 281 #if defined(OS_CHROMEOS)
219 void OpenPersistentNSSDB() { 282 void OpenPersistentNSSDB() {
220 if (!chromeos_user_logged_in_) { 283 if (!chromeos_user_logged_in_) {
221 // GetDefaultConfigDirectory causes us to do blocking IO on UI thread. 284 // GetDefaultConfigDirectory causes us to do blocking IO on UI thread.
222 // Temporarily allow it until we fix http://crbug.com/70119 285 // Temporarily allow it until we fix http://crbug.com/70119
223 base::ThreadRestrictions::ScopedAllowIO allow_io; 286 base::ThreadRestrictions::ScopedAllowIO allow_io;
224 chromeos_user_logged_in_ = true; 287 chromeos_user_logged_in_ = true;
225 288
226 // This creates another DB slot in NSS that is read/write, unlike 289 // This creates another DB slot in NSS that is read/write, unlike
227 // the fake root CA cert DB and the "default" crypto key 290 // the fake root CA cert DB and the "default" crypto key
228 // provider, which are still read-only (because we initialized 291 // provider, which are still read-only (because we initialized
229 // NSS before we had a cryptohome mounted). 292 // NSS before we had a cryptohome mounted).
230 software_slot_ = OpenUserDB(GetDefaultConfigDirectory(), 293 software_slot_ = OpenUserDB(GetDefaultConfigDirectory(),
231 kNSSDatabaseName); 294 kNSSDatabaseName);
232 } 295 }
233 } 296 }
234 297
298 PK11SlotInfo* OpenPersistentNSSDBForPath(const base::FilePath& path) {
299 VLOG(1) << __func__ << " " << path.value();
300 // We do NSS file io on the IO thread.
301 base::ThreadRestrictions::ScopedAllowIO allow_io;
302
303 base::FilePath nssdb_path = path.AppendASCII(".pki").AppendASCII("nssdb");
304 if (!file_util::CreateDirectory(nssdb_path)) {
305 LOG(ERROR) << "Failed to create " << nssdb_path.value() << " directory.";
306 return NULL;
307 }
308 return OpenUserDB(nssdb_path, kNSSDatabaseName);
309 }
310
235 void EnableTPMTokenForNSS() { 311 void EnableTPMTokenForNSS() {
236 // If this gets set, then we'll use the TPM for certs with 312 // If this gets set, then we'll use the TPM for certs with
237 // private keys, otherwise we'll fall back to the software 313 // private keys, otherwise we'll fall back to the software
238 // implementation. 314 // implementation.
239 tpm_token_enabled_for_nss_ = true; 315 tpm_token_enabled_for_nss_ = true;
240 } 316 }
241 317
318 bool IsTPMTokenEnabledForNSS() {
319 return tpm_token_enabled_for_nss_;
320 }
321
242 bool InitializeTPMToken(const std::string& token_name, 322 bool InitializeTPMToken(const std::string& token_name,
243 int token_slot_id, 323 int token_slot_id,
244 const std::string& user_pin) { 324 const std::string& user_pin) {
245 // If EnableTPMTokenForNSS hasn't been called, return false. 325 // If EnableTPMTokenForNSS hasn't been called, return false.
246 if (!tpm_token_enabled_for_nss_) 326 if (!tpm_token_enabled_for_nss_)
247 return false; 327 return false;
248 328
249 // If everything is already initialized, then return true. 329 // If everything is already initialized, then return true.
250 if (chaps_module_ && tpm_slot_) 330 if (chaps_module_ && tpm_slot_)
251 return true; 331 return true;
(...skipping 16 matching lines...) Expand all
268 if (!chaps_module_ && test_slot_) { 348 if (!chaps_module_ && test_slot_) {
269 // chromeos_unittests try to test the TPM initialization process. If we 349 // chromeos_unittests try to test the TPM initialization process. If we
270 // have a test DB open, pretend that it is the TPM slot. 350 // have a test DB open, pretend that it is the TPM slot.
271 tpm_slot_ = PK11_ReferenceSlot(test_slot_); 351 tpm_slot_ = PK11_ReferenceSlot(test_slot_);
272 return true; 352 return true;
273 } 353 }
274 } 354 }
275 if (chaps_module_){ 355 if (chaps_module_){
276 tpm_slot_ = GetTPMSlotForId(token_slot_id); 356 tpm_slot_ = GetTPMSlotForId(token_slot_id);
277 357
358 if (tpm_slot_) {
359 for (TPMReadyCallbackList::iterator i =
360 tpm_ready_callback_list_.begin();
361 i != tpm_ready_callback_list_.end();
362 ++i) {
363 (*i).Run();
364 }
365 tpm_ready_callback_list_.clear();
366 }
367
278 return tpm_slot_ != NULL; 368 return tpm_slot_ != NULL;
279 } 369 }
280 return false; 370 return false;
281 } 371 }
282 372
283 void GetTPMTokenInfo(std::string* token_name, std::string* user_pin) { 373 void GetTPMTokenInfo(std::string* token_name, std::string* user_pin) {
284 if (!tpm_token_enabled_for_nss_) { 374 if (!tpm_token_enabled_for_nss_) {
285 LOG(ERROR) << "GetTPMTokenInfo called before TPM Token is ready."; 375 LOG(ERROR) << "GetTPMTokenInfo called before TPM Token is ready.";
286 return; 376 return;
287 } 377 }
288 if (token_name) 378 if (token_name)
289 *token_name = tpm_token_name_; 379 *token_name = tpm_token_name_;
290 if (user_pin) 380 if (user_pin)
291 *user_pin = tpm_user_pin_; 381 *user_pin = tpm_user_pin_;
292 } 382 }
293 383
294 bool IsTPMTokenReady() { 384 bool IsTPMTokenReady() {
295 return tpm_slot_ != NULL; 385 return tpm_slot_ != NULL;
296 } 386 }
297 387
388 void OnTPMReady(const base::Closure& callback) {
389 if (IsTPMTokenReady())
390 callback.Run();
391 else
392 tpm_ready_callback_list_.push_back(callback);
393 }
394
298 // Note that CK_SLOT_ID is an unsigned long, but cryptohome gives us the slot 395 // Note that CK_SLOT_ID is an unsigned long, but cryptohome gives us the slot
299 // id as an int. This should be safe since this is only used with chaps, which 396 // id as an int. This should be safe since this is only used with chaps, which
300 // we also control. 397 // we also control.
301 PK11SlotInfo* GetTPMSlotForId(CK_SLOT_ID slot_id) { 398 PK11SlotInfo* GetTPMSlotForId(CK_SLOT_ID slot_id) {
302 if (!chaps_module_) 399 if (!chaps_module_)
303 return NULL; 400 return NULL;
304 401
305 VLOG(1) << "Poking chaps module."; 402 VLOG(1) << "Poking chaps module.";
306 SECStatus rv = SECMOD_UpdateSlotList(chaps_module_); 403 SECStatus rv = SECMOD_UpdateSlotList(chaps_module_);
307 if (rv != SECSuccess) 404 if (rv != SECSuccess)
308 PLOG(ERROR) << "SECMOD_UpdateSlotList failed: " << PORT_GetError(); 405 PLOG(ERROR) << "SECMOD_UpdateSlotList failed: " << PORT_GetError();
309 406
310 PK11SlotInfo* slot = SECMOD_LookupSlot(chaps_module_->moduleID, slot_id); 407 PK11SlotInfo* slot = SECMOD_LookupSlot(chaps_module_->moduleID, slot_id);
311 if (!slot) 408 if (!slot)
312 LOG(ERROR) << "TPM slot " << slot_id << " not found."; 409 LOG(ERROR) << "TPM slot " << slot_id << " not found.";
313 return slot; 410 return slot;
314 } 411 }
412
413 bool InitializeNSSForChromeOSUser(
414 const std::string& email,
415 const std::string& username_hash,
416 bool is_primary_user,
417 const base::FilePath& path) {
418 if (chromeos_user_map_.find(username_hash) != chromeos_user_map_.end()) {
419 // This user already exists in our mapping.
420 VLOG(1) << username_hash << " already initialized.";
421 return false;
422 }
423 ScopedPK11Slot public_slot;
424 if (is_primary_user) {
425 VLOG(1) << "Primary user, using GetPublicNSSKeySlot()";
426 public_slot.reset(GetPublicNSSKeySlot());
427 } else {
428 VLOG(1) << "Opening NSS DB";
429 public_slot.reset(OpenPersistentNSSDBForPath(path));
430 }
431 chromeos_user_map_[username_hash] =
432 new ChromeOSUserData(public_slot.Pass(), is_primary_user);
433 return true;
434 }
435
436 void InitializeTPMForChromeOSUser(const std::string& username_hash,
437 CK_SLOT_ID slot_id) {
438 DCHECK(chromeos_user_map_.find(username_hash) != chromeos_user_map_.end());
439 chromeos_user_map_[username_hash]
440 ->SetPrivateSlot(ScopedPK11Slot(GetTPMSlotForId(slot_id)));
441 }
442
443 void InitializePrivateSoftwareSlotForChromeOSUser(
444 const std::string& username_hash) {
445 LOG(WARNING) << "using software private slot for " << username_hash;
446 DCHECK(chromeos_user_map_.find(username_hash) != chromeos_user_map_.end());
447 chromeos_user_map_[username_hash]->SetPrivateSlot(
448 chromeos_user_map_[username_hash]->GetPublicSlot());
449 }
450
451 ScopedPK11Slot GetPublicSlotForChromeOSUser(
452 const std::string& username_hash) {
453 if (test_slot_) {
454 VLOG(1) << "returning test_slot_ for " << username_hash;
455 return ScopedPK11Slot(PK11_ReferenceSlot(test_slot_));
456 }
457
458 if (chromeos_user_map_.find(username_hash) == chromeos_user_map_.end()) {
459 LOG(ERROR) << username_hash << " not initialized.";
460 return ScopedPK11Slot();
461 }
462 return chromeos_user_map_[username_hash]->GetPublicSlot();
463 }
464
465 void OnPrivateSlotReadyForChromeOSUser(
466 const std::string& username_hash,
467 const base::Callback<void(ScopedPK11Slot)>& callback) {
468 if (test_slot_) {
469 VLOG(1) << "returning test_slot_ for " << username_hash;
470 callback.Run(ScopedPK11Slot(PK11_ReferenceSlot(test_slot_)));
471 return;
472 }
473
474 if (chromeos_user_map_.find(username_hash) == chromeos_user_map_.end()) {
475 LOG(ERROR) << username_hash << " not initialized.";
476 callback.Run(ScopedPK11Slot());
477 return;
478 }
479 chromeos_user_map_[username_hash]->OnPrivateSlotReady(callback);
480 }
315 #endif // defined(OS_CHROMEOS) 481 #endif // defined(OS_CHROMEOS)
316 482
317 483
318 bool OpenTestNSSDB() { 484 bool OpenTestNSSDB() {
319 if (test_slot_) 485 if (test_slot_)
320 return true; 486 return true;
321 if (!g_test_nss_db_dir.Get().CreateUniqueTempDir()) 487 if (!g_test_nss_db_dir.Get().CreateUniqueTempDir())
322 return false; 488 return false;
323 test_slot_ = OpenUserDB(g_test_nss_db_dir.Get().path(), kTestTPMTokenName); 489 test_slot_ = OpenUserDB(g_test_nss_db_dir.Get().path(), kTestTPMTokenName);
324 return !!test_slot_; 490 return !!test_slot_;
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 base::TimeTicks::Now() - start_time, 652 base::TimeTicks::Now() - start_time,
487 base::TimeDelta::FromMilliseconds(10), 653 base::TimeDelta::FromMilliseconds(10),
488 base::TimeDelta::FromHours(1), 654 base::TimeDelta::FromHours(1),
489 50); 655 50);
490 } 656 }
491 657
492 // NOTE(willchan): We don't actually execute this code since we leak NSS to 658 // NOTE(willchan): We don't actually execute this code since we leak NSS to
493 // prevent non-joinable threads from using NSS after it's already been shut 659 // prevent non-joinable threads from using NSS after it's already been shut
494 // down. 660 // down.
495 ~NSSInitSingleton() { 661 ~NSSInitSingleton() {
662 #if defined(OS_CHROMEOS)
663 STLDeleteValues(&chromeos_user_map_);
664 #endif
496 if (tpm_slot_) { 665 if (tpm_slot_) {
497 PK11_FreeSlot(tpm_slot_); 666 PK11_FreeSlot(tpm_slot_);
498 tpm_slot_ = NULL; 667 tpm_slot_ = NULL;
499 } 668 }
500 if (software_slot_) { 669 if (software_slot_) {
501 SECMOD_CloseUserDB(software_slot_); 670 SECMOD_CloseUserDB(software_slot_);
502 PK11_FreeSlot(software_slot_); 671 PK11_FreeSlot(software_slot_);
503 software_slot_ = NULL; 672 software_slot_ = NULL;
504 } 673 }
505 CloseTestNSSDB(); 674 CloseTestNSSDB();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 } 749 }
581 return db_slot; 750 return db_slot;
582 } 751 }
583 752
584 // If this is set to true NSS is forced to be initialized without a DB. 753 // If this is set to true NSS is forced to be initialized without a DB.
585 static bool force_nodb_init_; 754 static bool force_nodb_init_;
586 755
587 bool tpm_token_enabled_for_nss_; 756 bool tpm_token_enabled_for_nss_;
588 std::string tpm_token_name_; 757 std::string tpm_token_name_;
589 std::string tpm_user_pin_; 758 std::string tpm_user_pin_;
759 typedef std::vector<base::Closure> TPMReadyCallbackList;
760 TPMReadyCallbackList tpm_ready_callback_list_;
590 SECMODModule* chaps_module_; 761 SECMODModule* chaps_module_;
591 PK11SlotInfo* software_slot_; 762 PK11SlotInfo* software_slot_;
592 PK11SlotInfo* test_slot_; 763 PK11SlotInfo* test_slot_;
593 PK11SlotInfo* tpm_slot_; 764 PK11SlotInfo* tpm_slot_;
594 SECMODModule* root_; 765 SECMODModule* root_;
595 bool chromeos_user_logged_in_; 766 bool chromeos_user_logged_in_;
767 #if defined(OS_CHROMEOS)
768 typedef std::map<std::string, ChromeOSUserData*> ChromeOSUserMap;
769 ChromeOSUserMap chromeos_user_map_;
770 #endif
596 #if defined(USE_NSS) 771 #if defined(USE_NSS)
597 // TODO(davidben): When https://bugzilla.mozilla.org/show_bug.cgi?id=564011 772 // TODO(davidben): When https://bugzilla.mozilla.org/show_bug.cgi?id=564011
598 // is fixed, we will no longer need the lock. 773 // is fixed, we will no longer need the lock.
599 base::Lock write_lock_; 774 base::Lock write_lock_;
600 #endif // defined(USE_NSS) 775 #endif // defined(USE_NSS)
601 }; 776 };
602 777
603 // static 778 // static
604 bool NSSInitSingleton::force_nodb_init_ = false; 779 bool NSSInitSingleton::force_nodb_init_ = false;
605 780
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 922
748 #if defined(OS_CHROMEOS) 923 #if defined(OS_CHROMEOS)
749 void OpenPersistentNSSDB() { 924 void OpenPersistentNSSDB() {
750 g_nss_singleton.Get().OpenPersistentNSSDB(); 925 g_nss_singleton.Get().OpenPersistentNSSDB();
751 } 926 }
752 927
753 void EnableTPMTokenForNSS() { 928 void EnableTPMTokenForNSS() {
754 g_nss_singleton.Get().EnableTPMTokenForNSS(); 929 g_nss_singleton.Get().EnableTPMTokenForNSS();
755 } 930 }
756 931
932 bool IsTPMTokenEnabledForNSS() {
933 return g_nss_singleton.Get().IsTPMTokenEnabledForNSS();
934 }
935
757 void GetTPMTokenInfo(std::string* token_name, std::string* user_pin) { 936 void GetTPMTokenInfo(std::string* token_name, std::string* user_pin) {
758 g_nss_singleton.Get().GetTPMTokenInfo(token_name, user_pin); 937 g_nss_singleton.Get().GetTPMTokenInfo(token_name, user_pin);
759 } 938 }
760 939
761 bool IsTPMTokenReady() { 940 bool IsTPMTokenReady() {
762 return g_nss_singleton.Get().IsTPMTokenReady(); 941 return g_nss_singleton.Get().IsTPMTokenReady();
763 } 942 }
764 943
944 void OnTPMReady(const base::Closure& callback) {
945 g_nss_singleton.Get().OnTPMReady(callback);
946 }
947
765 bool InitializeTPMToken(const std::string& token_name, 948 bool InitializeTPMToken(const std::string& token_name,
766 int token_slot_id, 949 int token_slot_id,
767 const std::string& user_pin) { 950 const std::string& user_pin) {
768 return g_nss_singleton.Get().InitializeTPMToken( 951 return g_nss_singleton.Get().InitializeTPMToken(
769 token_name, token_slot_id, user_pin); 952 token_name, token_slot_id, user_pin);
770 } 953 }
954
955 bool InitializeNSSForChromeOSUser(
956 const std::string& email,
957 const std::string& username_hash,
958 bool is_primary_user,
959 const base::FilePath& path) {
960 return g_nss_singleton.Get().InitializeNSSForChromeOSUser(
961 email, username_hash, is_primary_user, path);
962 }
963 void InitializeTPMForChromeOSUser(
964 const std::string& username_hash,
965 CK_SLOT_ID slot_id) {
966 g_nss_singleton.Get().InitializeTPMForChromeOSUser(username_hash, slot_id);
967 }
968 void InitializePrivateSoftwareSlotForChromeOSUser(
969 const std::string& username_hash) {
970 g_nss_singleton.Get().InitializePrivateSoftwareSlotForChromeOSUser(
971 username_hash);
972 }
973 ScopedPK11Slot GetPublicSlotForChromeOSUser(const std::string& username_hash) {
974 return g_nss_singleton.Get().GetPublicSlotForChromeOSUser(username_hash);
975 }
976 void OnPrivateSlotReadyForChromeOSUser(
977 const std::string& username_hash,
978 const base::Callback<void(ScopedPK11Slot)>& callback) {
979 g_nss_singleton.Get().OnPrivateSlotReadyForChromeOSUser(username_hash,
980 callback);
981 }
771 #endif // defined(OS_CHROMEOS) 982 #endif // defined(OS_CHROMEOS)
772 983
773 base::Time PRTimeToBaseTime(PRTime prtime) { 984 base::Time PRTimeToBaseTime(PRTime prtime) {
774 return base::Time::FromInternalValue( 985 return base::Time::FromInternalValue(
775 prtime + base::Time::UnixEpoch().ToInternalValue()); 986 prtime + base::Time::UnixEpoch().ToInternalValue());
776 } 987 }
777 988
778 PRTime BaseTimeToPRTime(base::Time time) { 989 PRTime BaseTimeToPRTime(base::Time time) {
779 return time.ToInternalValue() - base::Time::UnixEpoch().ToInternalValue(); 990 return time.ToInternalValue() - base::Time::UnixEpoch().ToInternalValue();
780 } 991 }
781 992
782 PK11SlotInfo* GetPublicNSSKeySlot() { 993 PK11SlotInfo* GetPublicNSSKeySlot() {
783 return g_nss_singleton.Get().GetPublicNSSKeySlot(); 994 return g_nss_singleton.Get().GetPublicNSSKeySlot();
784 } 995 }
785 996
786 PK11SlotInfo* GetPrivateNSSKeySlot() { 997 PK11SlotInfo* GetPrivateNSSKeySlot() {
787 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); 998 return g_nss_singleton.Get().GetPrivateNSSKeySlot();
788 } 999 }
789 1000
790 } // namespace crypto 1001 } // namespace crypto
OLDNEW
« no previous file with comments | « crypto/nss_util.h ('k') | crypto/nss_util_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698