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 | 6 |
7 #include <nss.h> | 7 #include <nss.h> |
8 #include <pk11pub.h> | 8 #include <pk11pub.h> |
9 #include <plarena.h> | 9 #include <plarena.h> |
10 #include <prerror.h> | 10 #include <prerror.h> |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 } else { | 82 } else { |
83 result = base::StringPrintf("NSS error code: %d", PR_GetError()); | 83 result = base::StringPrintf("NSS error code: %d", PR_GetError()); |
84 } | 84 } |
85 return result; | 85 return result; |
86 } | 86 } |
87 | 87 |
88 #if defined(USE_NSS_CERTS) | 88 #if defined(USE_NSS_CERTS) |
89 #if !defined(OS_CHROMEOS) | 89 #if !defined(OS_CHROMEOS) |
90 base::FilePath GetDefaultConfigDirectory() { | 90 base::FilePath GetDefaultConfigDirectory() { |
91 base::FilePath dir; | 91 base::FilePath dir; |
92 PathService::Get(base::DIR_HOME, &dir); | 92 |
93 if (dir.empty()) { | 93 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
94 LOG(ERROR) << "Failed to get home directory."; | 94 static const char kUseCacheEnvVar[] = "NSS_DEFAULT_DB_DIR"; |
95 return dir; | 95 std::string default_db_file; |
| 96 if (env->GetVar(kUseCacheEnvVar, &default_db_file) && |
| 97 default_db_file.length() > 0) { |
| 98 dir = base::FilePath(default_db_file); |
| 99 } else { |
| 100 PathService::Get(base::DIR_HOME, &dir); |
| 101 if (dir.empty()) { |
| 102 LOG(ERROR) << "Failed to get home directory."; |
| 103 return dir; |
| 104 } |
| 105 dir = dir.AppendASCII(".pki").AppendASCII("nssdb"); |
96 } | 106 } |
97 dir = dir.AppendASCII(".pki").AppendASCII("nssdb"); | 107 |
98 if (!base::CreateDirectory(dir)) { | 108 if (!base::CreateDirectory(dir)) { |
99 LOG(ERROR) << "Failed to create " << dir.value() << " directory."; | 109 LOG(ERROR) << "Failed to create " << dir.value() << " directory."; |
100 dir.clear(); | 110 dir.clear(); |
101 } | 111 } |
102 DVLOG(2) << "DefaultConfigDirectory: " << dir.value(); | 112 DVLOG(2) << "DefaultConfigDirectory: " << dir.value(); |
103 return dir; | 113 return dir; |
104 } | 114 } |
105 #endif // !defined(IS_CHROMEOS) | 115 #endif // !defined(IS_CHROMEOS) |
106 | 116 |
107 // On non-Chrome OS platforms, return the default config directory. On Chrome OS | 117 // On non-Chrome OS platforms, return the default config directory. On Chrome OS |
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1022 return time.ToInternalValue() - base::Time::UnixEpoch().ToInternalValue(); | 1032 return time.ToInternalValue() - base::Time::UnixEpoch().ToInternalValue(); |
1023 } | 1033 } |
1024 | 1034 |
1025 #if !defined(OS_CHROMEOS) | 1035 #if !defined(OS_CHROMEOS) |
1026 PK11SlotInfo* GetPersistentNSSKeySlot() { | 1036 PK11SlotInfo* GetPersistentNSSKeySlot() { |
1027 return g_nss_singleton.Get().GetPersistentNSSKeySlot(); | 1037 return g_nss_singleton.Get().GetPersistentNSSKeySlot(); |
1028 } | 1038 } |
1029 #endif | 1039 #endif |
1030 | 1040 |
1031 } // namespace crypto | 1041 } // namespace crypto |
OLD | NEW |