[email protected] | 557737f7 | 2013-12-06 22:24:07 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #include "chrome/browser/net/nss_context.h" | ||||
6 | |||||
7 | #include "content/public/browser/browser_thread.h" | ||||
8 | #include "crypto/nss_util_internal.h" | ||||
[email protected] | 057ad5f | 2013-12-20 19:00:57 | [diff] [blame] | 9 | #include "net/cert/nss_cert_database.h" |
[email protected] | 557737f7 | 2013-12-06 22:24:07 | [diff] [blame] | 10 | |
[email protected] | 30bb2810 | 2014-07-25 10:09:52 | [diff] [blame] | 11 | namespace { |
12 | net::NSSCertDatabase* g_nss_cert_database = NULL; | ||||
13 | } // namespace | ||||
14 | |||||
[email protected] | 557737f7 | 2013-12-06 22:24:07 | [diff] [blame] | 15 | crypto::ScopedPK11Slot GetPublicNSSKeySlotForResourceContext( |
16 | content::ResourceContext* context) { | ||||
anujk.sharma | 2e02ce16 | 2015-04-29 23:10:02 | [diff] [blame] | 17 | DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
[email protected] | 49631886 | 2014-07-13 07:19:00 | [diff] [blame] | 18 | return crypto::ScopedPK11Slot(crypto::GetPersistentNSSKeySlot()); |
[email protected] | 557737f7 | 2013-12-06 22:24:07 | [diff] [blame] | 19 | } |
20 | |||||
21 | crypto::ScopedPK11Slot GetPrivateNSSKeySlotForResourceContext( | ||||
22 | content::ResourceContext* context, | ||||
23 | const base::Callback<void(crypto::ScopedPK11Slot)>& callback) { | ||||
anujk.sharma | 2e02ce16 | 2015-04-29 23:10:02 | [diff] [blame] | 24 | DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
[email protected] | 49631886 | 2014-07-13 07:19:00 | [diff] [blame] | 25 | return crypto::ScopedPK11Slot(crypto::GetPersistentNSSKeySlot()); |
[email protected] | 557737f7 | 2013-12-06 22:24:07 | [diff] [blame] | 26 | } |
[email protected] | 057ad5f | 2013-12-20 19:00:57 | [diff] [blame] | 27 | |
28 | net::NSSCertDatabase* GetNSSCertDatabaseForResourceContext( | ||||
29 | content::ResourceContext* context, | ||||
30 | const base::Callback<void(net::NSSCertDatabase*)>& callback) { | ||||
[email protected] | 30bb2810 | 2014-07-25 10:09:52 | [diff] [blame] | 31 | // This initialization is not thread safe. This CHECK ensures that this code |
32 | // is only run on a single thread. | ||||
33 | CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | ||||
34 | if (!g_nss_cert_database) { | ||||
35 | // Linux has only a single persistent slot compared to ChromeOS's separate | ||||
36 | // public and private slot. | ||||
37 | // Redirect any slot usage to this persistent slot on Linux. | ||||
38 | g_nss_cert_database = new net::NSSCertDatabase( | ||||
39 | crypto::ScopedPK11Slot( | ||||
40 | crypto::GetPersistentNSSKeySlot()) /* public slot */, | ||||
41 | crypto::ScopedPK11Slot( | ||||
42 | crypto::GetPersistentNSSKeySlot()) /* private slot */); | ||||
43 | } | ||||
44 | return g_nss_cert_database; | ||||
[email protected] | 057ad5f | 2013-12-20 19:00:57 | [diff] [blame] | 45 | } |