blob: 9e9c9c6430d51d10d7ef5ba009cce0d4c8ce4017 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# Move ~/.pki directory to ${XDG_DATA_HOME:-$HOME/.local}/share/pki on linux
# builds to follow the XDG Base Directory Specification. For details, refer to
# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
diff --git a/crypto/nss_util.cc b/crypto/nss_util.cc
index cd43cde2a5..c06e800d8e 100644
--- a/crypto/nss_util.cc
+++ b/crypto/nss_util.cc
@@ -30,6 +30,8 @@
#include "build/build_config.h"
#include "crypto/nss_crypto_module_delegate.h"
#include "crypto/nss_util_internal.h"
+#include "base/environment.h"
+#include "base/nix/xdg_util.h"
namespace crypto {
@@ -38,12 +40,25 @@ namespace {
#if !BUILDFLAG(IS_CHROMEOS)
base::FilePath GetDefaultConfigDirectory() {
base::FilePath dir;
+#if defined(OS_LINUX)
+ std::unique_ptr<base::Environment> env(base::Environment::Create());
+ dir = base::nix::GetXDGDataWriteLocation(env.get());
+#else
base::PathService::Get(base::DIR_HOME, &dir);
+#endif
if (dir.empty()) {
+#if defined(OS_LINUX)
+ LOG(ERROR) << "Failed to get $HOME or $XDG_DATA_HOME directory.";
+#else
LOG(ERROR) << "Failed to get home directory.";
+#endif
return dir;
}
+#if defined(OS_LINUX)
+ dir = dir.AppendASCII("pki").AppendASCII("nssdb");
+#else
dir = dir.AppendASCII(".pki").AppendASCII("nssdb");
+#endif
if (!base::CreateDirectory(dir)) {
LOG(ERROR) << "Failed to create " << dir.value() << " directory.";
dir.clear();
|