OLD | NEW |
---|---|
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 #include <stdlib.h> | |
wtc
2013/11/21 21:03:44
This header isn't necessary.
agl
2013/11/22 16:22:35
Done.
| |
15 | 16 |
16 #if defined(OS_LINUX) | 17 #if defined(OS_LINUX) |
17 #include <linux/nfs_fs.h> | 18 #include <linux/nfs_fs.h> |
18 #include <sys/vfs.h> | 19 #include <sys/vfs.h> |
19 #elif defined(OS_OPENBSD) | 20 #elif defined(OS_OPENBSD) |
20 #include <sys/mount.h> | 21 #include <sys/mount.h> |
21 #include <sys/param.h> | 22 #include <sys/param.h> |
22 #endif | 23 #endif |
23 | 24 |
24 #include <vector> | 25 #include <vector> |
25 | 26 |
27 #include "base/cpu.h" | |
26 #include "base/debug/alias.h" | 28 #include "base/debug/alias.h" |
27 #include "base/debug/stack_trace.h" | 29 #include "base/debug/stack_trace.h" |
28 #include "base/environment.h" | 30 #include "base/environment.h" |
31 #include "base/environment.h" | |
wtc
2013/11/21 21:03:44
Delete this line (a duplicate).
agl
2013/11/22 16:22:35
Done.
| |
29 #include "base/file_util.h" | 32 #include "base/file_util.h" |
30 #include "base/files/file_path.h" | 33 #include "base/files/file_path.h" |
31 #include "base/files/scoped_temp_dir.h" | 34 #include "base/files/scoped_temp_dir.h" |
32 #include "base/lazy_instance.h" | 35 #include "base/lazy_instance.h" |
33 #include "base/logging.h" | 36 #include "base/logging.h" |
34 #include "base/memory/scoped_ptr.h" | 37 #include "base/memory/scoped_ptr.h" |
35 #include "base/metrics/histogram.h" | 38 #include "base/metrics/histogram.h" |
36 #include "base/native_library.h" | 39 #include "base/native_library.h" |
37 #include "base/strings/stringprintf.h" | 40 #include "base/strings/stringprintf.h" |
38 #include "base/threading/thread_checker.h" | 41 #include "base/threading/thread_checker.h" |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 test_slot_(NULL), | 411 test_slot_(NULL), |
409 tpm_slot_(NULL), | 412 tpm_slot_(NULL), |
410 root_(NULL), | 413 root_(NULL), |
411 chromeos_user_logged_in_(false) { | 414 chromeos_user_logged_in_(false) { |
412 base::TimeTicks start_time = base::TimeTicks::Now(); | 415 base::TimeTicks start_time = base::TimeTicks::Now(); |
413 | 416 |
414 // It's safe to construct on any thread, since LazyInstance will prevent any | 417 // It's safe to construct on any thread, since LazyInstance will prevent any |
415 // other threads from accessing until the constructor is done. | 418 // other threads from accessing until the constructor is done. |
416 thread_checker_.DetachFromThread(); | 419 thread_checker_.DetachFromThread(); |
417 | 420 |
421 DisableAESNIIfNeeded(); | |
422 | |
418 EnsureNSPRInit(); | 423 EnsureNSPRInit(); |
419 | 424 |
420 // We *must* have NSS >= 3.14.3. | 425 // We *must* have NSS >= 3.14.3. |
421 COMPILE_ASSERT( | 426 COMPILE_ASSERT( |
422 (NSS_VMAJOR == 3 && NSS_VMINOR == 14 && NSS_VPATCH >= 3) || | 427 (NSS_VMAJOR == 3 && NSS_VMINOR == 14 && NSS_VPATCH >= 3) || |
423 (NSS_VMAJOR == 3 && NSS_VMINOR > 14) || | 428 (NSS_VMAJOR == 3 && NSS_VMINOR > 14) || |
424 (NSS_VMAJOR > 3), | 429 (NSS_VMAJOR > 3), |
425 nss_version_check_failed); | 430 nss_version_check_failed); |
426 // Also check the run-time NSS version. | 431 // Also check the run-time NSS version. |
427 // NSS_VersionCheck is a >= check, not strict equality. | 432 // NSS_VersionCheck is a >= check, not strict equality. |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
600 if (PK11_NeedUserInit(db_slot)) | 605 if (PK11_NeedUserInit(db_slot)) |
601 PK11_InitPin(db_slot, NULL, NULL); | 606 PK11_InitPin(db_slot, NULL, NULL); |
602 } | 607 } |
603 else { | 608 else { |
604 LOG(ERROR) << "Error opening persistent database (" << modspec | 609 LOG(ERROR) << "Error opening persistent database (" << modspec |
605 << "): " << GetNSSErrorMessage(); | 610 << "): " << GetNSSErrorMessage(); |
606 } | 611 } |
607 return db_slot; | 612 return db_slot; |
608 } | 613 } |
609 | 614 |
615 static void DisableAESNIIfNeeded() { | |
616 base::CPU cpu; | |
617 | |
618 if (cpu.has_avx_hardware() && !cpu.has_avx()) { | |
619 // Some versions of NSS have a bug that causes AVX instructions to be | |
620 // used without testing whether XSAVE is enabled by the operating system. | |
621 // In order to work around this, we disable AES-NI in NSS when we find | |
622 // that |has_avx()| is false (which includes the XSAVE test). | |
wtc
2013/11/21 21:03:44
Add the NSS bug number or URL here so we will know
agl
2013/11/22 16:22:35
Done.
| |
623 base::Environment::Create()->SetVar("NSS_DISABLE_HW_AES", "1"); | |
wtc
2013/11/21 21:03:44
We can also consider just turning off the AES-GCM
| |
624 } | |
625 } | |
626 | |
610 // If this is set to true NSS is forced to be initialized without a DB. | 627 // If this is set to true NSS is forced to be initialized without a DB. |
611 static bool force_nodb_init_; | 628 static bool force_nodb_init_; |
612 | 629 |
613 bool tpm_token_enabled_for_nss_; | 630 bool tpm_token_enabled_for_nss_; |
614 std::string tpm_token_name_; | 631 std::string tpm_token_name_; |
615 std::string tpm_user_pin_; | 632 std::string tpm_user_pin_; |
616 SECMODModule* chaps_module_; | 633 SECMODModule* chaps_module_; |
617 PK11SlotInfo* software_slot_; | 634 PK11SlotInfo* software_slot_; |
618 PK11SlotInfo* test_slot_; | 635 PK11SlotInfo* test_slot_; |
619 PK11SlotInfo* tpm_slot_; | 636 PK11SlotInfo* tpm_slot_; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
809 | 826 |
810 PK11SlotInfo* GetPublicNSSKeySlot() { | 827 PK11SlotInfo* GetPublicNSSKeySlot() { |
811 return g_nss_singleton.Get().GetPublicNSSKeySlot(); | 828 return g_nss_singleton.Get().GetPublicNSSKeySlot(); |
812 } | 829 } |
813 | 830 |
814 PK11SlotInfo* GetPrivateNSSKeySlot() { | 831 PK11SlotInfo* GetPrivateNSSKeySlot() { |
815 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); | 832 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); |
816 } | 833 } |
817 | 834 |
818 } // namespace crypto | 835 } // namespace crypto |
OLD | NEW |