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

Side by Side Diff: crypto/nss_util.cc

Issue 7756025: Changed OAuth token+secret encryption to use supplemental user key. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 months 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <plarena.h> 9 #include <plarena.h>
10 #include <prerror.h> 10 #include <prerror.h>
(...skipping 13 matching lines...) Expand all
24 #include "base/file_path.h" 24 #include "base/file_path.h"
25 #include "base/file_util.h" 25 #include "base/file_util.h"
26 #include "base/lazy_instance.h" 26 #include "base/lazy_instance.h"
27 #include "base/logging.h" 27 #include "base/logging.h"
28 #include "base/memory/scoped_ptr.h" 28 #include "base/memory/scoped_ptr.h"
29 #include "base/native_library.h" 29 #include "base/native_library.h"
30 #include "base/stringprintf.h" 30 #include "base/stringprintf.h"
31 #include "base/threading/thread_restrictions.h" 31 #include "base/threading/thread_restrictions.h"
32 #include "crypto/scoped_nss_types.h" 32 #include "crypto/scoped_nss_types.h"
33 33
34 #if defined(OS_CHROMEOS)
35 #include "crypto/symmetric_key.h"
36 #endif
37
34 // USE_NSS means we use NSS for everything crypto-related. If USE_NSS is not 38 // USE_NSS means we use NSS for everything crypto-related. If USE_NSS is not
35 // defined, such as on Mac and Windows, we use NSS for SSL only -- we don't 39 // defined, such as on Mac and Windows, we use NSS for SSL only -- we don't
36 // use NSS for crypto or certificate verification, and we don't use the NSS 40 // use NSS for crypto or certificate verification, and we don't use the NSS
37 // certificate and key databases. 41 // certificate and key databases.
38 #if defined(USE_NSS) 42 #if defined(USE_NSS)
39 #include "base/synchronization/lock.h" 43 #include "base/synchronization/lock.h"
40 #include "crypto/crypto_module_blocking_password_delegate.h" 44 #include "crypto/crypto_module_blocking_password_delegate.h"
41 #endif // defined(USE_NSS) 45 #endif // defined(USE_NSS)
42 46
43 namespace crypto { 47 namespace crypto {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 return dir; 80 return dir;
77 } 81 }
78 dir = dir.AppendASCII(".pki").AppendASCII("nssdb"); 82 dir = dir.AppendASCII(".pki").AppendASCII("nssdb");
79 if (!file_util::CreateDirectory(dir)) { 83 if (!file_util::CreateDirectory(dir)) {
80 LOG(ERROR) << "Failed to create " << dir.value() << " directory."; 84 LOG(ERROR) << "Failed to create " << dir.value() << " directory.";
81 dir.clear(); 85 dir.clear();
82 } 86 }
83 return dir; 87 return dir;
84 } 88 }
85 89
90 #if defined(OS_CHROMEOS)
91 // Supplemental user key id.
92 static unsigned char kSupplementalUserKeyId[] = {
93 0xCC, 0x13, 0x19, 0xDE, 0x75, 0x5E, 0xFE, 0xFA,
94 0x5E, 0x71, 0xD4, 0xA6, 0xFB, 0x00, 0x00, 0xCC
95 };
wtc 2011/09/06 21:35:17 Nit: on line 92, remove 'static'. You said:
zel 2011/09/06 22:33:35 Done.
96 // Supplemental user key nickname.
97 const char kSupplementalKeyNickname[] = "ChromeOS_SupplementalUserKey";
wtc 2011/09/06 21:35:17 I believe the nickname can contain spaces, so you
zel 2011/09/06 22:33:35 I have removed the nickname, I have no good use fo
98 #endif // defined(OS_CHROMEOS)
99
100
86 // On non-chromeos platforms, return the default config directory. 101 // On non-chromeos platforms, return the default config directory.
87 // On chromeos, return a read-only directory with fake root CA certs for testing 102 // On chromeos, return a read-only directory with fake root CA certs for testing
88 // (which will not exist on non-testing images). These root CA certs are used 103 // (which will not exist on non-testing images). These root CA certs are used
89 // by the local Google Accounts server mock we use when testing our login code. 104 // by the local Google Accounts server mock we use when testing our login code.
90 // If this directory is not present, NSS_Init() will fail. It is up to the 105 // If this directory is not present, NSS_Init() will fail. It is up to the
91 // caller to failover to NSS_NoDB_Init() at that point. 106 // caller to failover to NSS_NoDB_Init() at that point.
92 FilePath GetInitialConfigDirectory() { 107 FilePath GetInitialConfigDirectory() {
93 #if defined(OS_CHROMEOS) 108 #if defined(OS_CHROMEOS)
94 return FilePath(kReadOnlyCertDB); 109 return FilePath(kReadOnlyCertDB);
95 #else 110 #else
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 bool IsTPMTokenReady() { 296 bool IsTPMTokenReady() {
282 return tpm_slot_ != NULL; 297 return tpm_slot_ != NULL;
283 } 298 }
284 299
285 PK11SlotInfo* GetTPMSlot() { 300 PK11SlotInfo* GetTPMSlot() {
286 std::string token_name; 301 std::string token_name;
287 GetTPMTokenInfo(&token_name, NULL); 302 GetTPMTokenInfo(&token_name, NULL);
288 return FindSlotWithTokenName(token_name); 303 return FindSlotWithTokenName(token_name);
289 } 304 }
290 305
306 SymmetricKey* GetSupplementalUserKey() {
307 DCHECK(chromeos_user_logged_in_);
308
309 PK11SlotInfo* slot = NULL;
310 PK11SymKey *key = NULL;
311 PLArenaPool *arena = 0;
wtc 2011/09/06 21:35:17 Nit: on line 310, put '*' next to the type. On li
zel 2011/09/06 22:33:35 Done.
312 SECItem keyID;
313 CK_MECHANISM_TYPE type = CKM_AES_ECB;
Will Drewry 2011/09/06 20:20:21 Not that it really matters for this usage, but mig
zel 2011/09/06 21:02:22 crypto::Encryptor class seems to support CKM_AES_C
314
315 arena = PORT_NewArena(SEC_ASN1_DEFAULT_ARENA_SIZE);
316 if (!arena)
317 goto done;
318
319 slot = GetPublicNSSKeySlot();
320 if (!slot)
321 goto done;
322
323 if (PK11_Authenticate(slot, PR_TRUE, NULL) != SECSuccess)
324 goto done;
325
326 keyID.type = siBuffer;
327 keyID.data = kSupplementalUserKeyId;
328 keyID.len = static_cast<int>(sizeof(kSupplementalUserKeyId));
329
330 // Find/generate AES key.
331 key = PK11_FindFixedKey(slot, type, &keyID, NULL);
332 if (!key) {
333 key = PK11_TokenKeyGen(slot, type, NULL,
334 32, /* keysize in bytes*/
wtc 2011/09/06 21:35:17 Nit: use C++ style comment: // keysize in bytes
zel 2011/09/06 22:33:35 Done.
335 &keyID, PR_TRUE, NULL);
336 if (key && PK11_SetSymKeyNickname(key,
337 kSupplementalKeyNickname) != SECSuccess) {
wtc 2011/09/06 21:35:17 I think this if statement should say: if (!key
zel 2011/09/06 22:33:35 Done.
338 goto done;
Will Drewry 2011/09/06 20:20:21 How is this any different than doing nothing since
zel 2011/09/06 21:02:22 Done.
339 }
340 }
341
342 done:
343 if (arena)
344 PORT_FreeArena(arena, PR_TRUE);
345
346 if (slot)
347 PK11_FreeSlot(slot);
348
349 return key ? new SymmetricKey(key) : NULL;
350 }
291 #endif // defined(OS_CHROMEOS) 351 #endif // defined(OS_CHROMEOS)
292 352
293 353
294 bool OpenTestNSSDB(const FilePath& path, const char* description) { 354 bool OpenTestNSSDB(const FilePath& path, const char* description) {
295 test_slot_ = OpenUserDB(path, description); 355 test_slot_ = OpenUserDB(path, description);
296 return !!test_slot_; 356 return !!test_slot_;
297 } 357 }
298 358
299 void CloseTestNSSDB() { 359 void CloseTestNSSDB() {
300 if (test_slot_) { 360 if (test_slot_) {
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 } 755 }
696 756
697 bool IsTPMTokenReady() { 757 bool IsTPMTokenReady() {
698 return g_nss_singleton.Get().IsTPMTokenReady(); 758 return g_nss_singleton.Get().IsTPMTokenReady();
699 } 759 }
700 760
701 bool EnsureTPMTokenReady() { 761 bool EnsureTPMTokenReady() {
702 return g_nss_singleton.Get().EnsureTPMTokenReady(); 762 return g_nss_singleton.Get().EnsureTPMTokenReady();
703 } 763 }
704 764
765 SymmetricKey* GetSupplementalUserKey() {
766 return g_nss_singleton.Get().GetSupplementalUserKey();
767 }
705 #endif // defined(OS_CHROMEOS) 768 #endif // defined(OS_CHROMEOS)
706 769
707 // TODO(port): Implement this more simply. We can convert by subtracting an 770 // TODO(port): Implement this more simply. We can convert by subtracting an
708 // offset (the difference between NSPR's and base::Time's epochs). 771 // offset (the difference between NSPR's and base::Time's epochs).
709 base::Time PRTimeToBaseTime(PRTime prtime) { 772 base::Time PRTimeToBaseTime(PRTime prtime) {
710 PRExplodedTime prxtime; 773 PRExplodedTime prxtime;
711 PR_ExplodeTime(prtime, PR_GMTParameters, &prxtime); 774 PR_ExplodeTime(prtime, PR_GMTParameters, &prxtime);
712 775
713 base::Time::Exploded exploded; 776 base::Time::Exploded exploded;
714 exploded.year = prxtime.tm_year; 777 exploded.year = prxtime.tm_year;
(...skipping 10 matching lines...) Expand all
725 788
726 PK11SlotInfo* GetPublicNSSKeySlot() { 789 PK11SlotInfo* GetPublicNSSKeySlot() {
727 return g_nss_singleton.Get().GetPublicNSSKeySlot(); 790 return g_nss_singleton.Get().GetPublicNSSKeySlot();
728 } 791 }
729 792
730 PK11SlotInfo* GetPrivateNSSKeySlot() { 793 PK11SlotInfo* GetPrivateNSSKeySlot() {
731 return g_nss_singleton.Get().GetPrivateNSSKeySlot(); 794 return g_nss_singleton.Get().GetPrivateNSSKeySlot();
732 } 795 }
733 796
734 } // namespace crypto 797 } // namespace crypto
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698