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

Side by Side Diff: net/base/keygen_handler.h

Issue 843005: Adds support for the <keygen> element to Windows, matching support present on... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Fixing remaining issues Created 10 years, 8 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
« no previous file with comments | « net/base/cert_database_win.cc ('k') | net/base/keygen_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #ifndef NET_BASE_KEYGEN_HANDLER_H_ 5 #ifndef NET_BASE_KEYGEN_HANDLER_H_
6 #define NET_BASE_KEYGEN_HANDLER_H_ 6 #define NET_BASE_KEYGEN_HANDLER_H_
7 7
8 #include <map>
8 #include <string> 9 #include <string>
9 10
11 #include "base/lock.h"
12 #include "base/singleton.h"
13
10 namespace net { 14 namespace net {
11 15
12 // This class handles keypair generation for generating client 16 // This class handles keypair generation for generating client
13 // certificates via the <keygen> tag. 17 // certificates via the <keygen> tag.
14 // <http://dev.w3.org/html5/spec/Overview.html#the-keygen-element> 18 // <http://dev.w3.org/html5/spec/Overview.html#the-keygen-element>
15 // <https://developer.mozilla.org/En/HTML/HTML_Extensions/KEYGEN_Tag> 19 // <https://developer.mozilla.org/En/HTML/HTML_Extensions/KEYGEN_Tag>
16 20
17 class KeygenHandler { 21 class KeygenHandler {
18 public: 22 public:
23 // This class stores the relative location for a given private key. It does
24 // not store the private key, or a handle to the private key, on the basis
25 // that the key may be located on a smart card or device which may not be
26 // present at the time of retrieval.
27 class KeyLocation {
28 public:
29 #if defined(OS_WIN)
30 std::wstring container_name;
31 std::wstring provider_name;
32 #elif defined(OS_MACOSX)
33 std::string keychain_path;
34 #elif defined(USE_NSS)
35 std::string slot_name;
36 #endif
37
38 // Only used by unit tests
39 bool Equals(const KeyLocation& location) const;
40 };
41
42 // This class stores information about the keys the KeygenHandler has
43 // generated, so that the private keys can be properly associated with any
44 // certificates that might be sent to the client based on those keys.
45 class Cache {
46 public:
47 static Cache* GetInstance();
48 void Insert(const std::string& public_key_info,
49 const KeyLocation& location);
50
51 // True if the |public_key_info| was located and the location stored into
52 // |*location|
53 bool Find(const std::string& public_key_info, KeyLocation* location);
54
55 private:
56 typedef std::map<std::string, KeyLocation> KeyLocationMap;
57
58 // Obtain an instance of the KeyCache by using GetInstance()
59 Cache() { }
60 friend struct DefaultSingletonTraits<Cache>;
61
62 Lock lock_;
63
64 // The key cache. You must obtain |lock_| before using |cache_|
65 KeyLocationMap cache_;
66
67 DISALLOW_COPY_AND_ASSIGN(Cache);
68 };
69
19 // Creates a handler that will generate a key with the given key size 70 // Creates a handler that will generate a key with the given key size
20 // and incorporate the |challenge| into the Netscape SPKAC structure. 71 // and incorporate the |challenge| into the Netscape SPKAC structure.
21 inline KeygenHandler(int key_size_in_bits, const std::string& challenge); 72 inline KeygenHandler(int key_size_in_bits, const std::string& challenge);
22 73
23 // Actually generates the key-pair and the cert request (SPKAC), and returns 74 // Actually generates the key-pair and the cert request (SPKAC), and returns
24 // a base64-encoded string suitable for use as the form value of <keygen>. 75 // a base64-encoded string suitable for use as the form value of <keygen>.
25 std::string GenKeyAndSignChallenge(); 76 std::string GenKeyAndSignChallenge();
26 77
27 // Exposed only for unit tests. 78 // Exposed only for unit tests.
28 void set_stores_key(bool store) { stores_key_ = store;} 79 void set_stores_key(bool store) { stores_key_ = store;}
29 80
30 private: 81 private:
31 int key_size_in_bits_; // key size in bits (usually 2048) 82 int key_size_in_bits_; // key size in bits (usually 2048)
32 std::string challenge_; // challenge string sent by server 83 std::string challenge_; // challenge string sent by server
33 bool stores_key_; // should the generated key-pair be stored persistently? 84 bool stores_key_; // should the generated key-pair be stored persistently?
34 }; 85 };
35 86
36 KeygenHandler::KeygenHandler(int key_size_in_bits, 87 KeygenHandler::KeygenHandler(int key_size_in_bits,
37 const std::string& challenge) 88 const std::string& challenge)
38 : key_size_in_bits_(key_size_in_bits), 89 : key_size_in_bits_(key_size_in_bits),
39 challenge_(challenge), 90 challenge_(challenge),
40 stores_key_(true) { 91 stores_key_(true) {
41 } 92 }
42 93
43 } // namespace net 94 } // namespace net
44 95
45 #endif // NET_BASE_KEYGEN_HANDLER_H_ 96 #endif // NET_BASE_KEYGEN_HANDLER_H_
OLDNEW
« no previous file with comments | « net/base/cert_database_win.cc ('k') | net/base/keygen_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698