| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "googleurl/src/gurl.h" |
| 12 |
| 11 namespace net { | 13 namespace net { |
| 12 | 14 |
| 13 // This class handles keypair generation for generating client | 15 // This class handles keypair generation for generating client |
| 14 // certificates via the <keygen> tag. | 16 // certificates via the <keygen> tag. |
| 15 // <http://dev.w3.org/html5/spec/Overview.html#the-keygen-element> | 17 // <http://dev.w3.org/html5/spec/Overview.html#the-keygen-element> |
| 16 // <https://developer.mozilla.org/En/HTML/HTML_Extensions/KEYGEN_Tag> | 18 // <https://developer.mozilla.org/En/HTML/HTML_Extensions/KEYGEN_Tag> |
| 17 | 19 |
| 18 class KeygenHandler { | 20 class KeygenHandler { |
| 19 public: | 21 public: |
| 20 // Creates a handler that will generate a key with the given key size | 22 // Creates a handler that will generate a key with the given key size and |
| 21 // and incorporate the |challenge| into the Netscape SPKAC structure. | 23 // incorporate the |challenge| into the Netscape SPKAC structure. The request |
| 22 inline KeygenHandler(int key_size_in_bits, const std::string& challenge); | 24 // for the key originated from |url|. |
| 25 inline KeygenHandler(int key_size_in_bits, |
| 26 const std::string& challenge, |
| 27 const GURL& url); |
| 23 | 28 |
| 24 // Actually generates the key-pair and the cert request (SPKAC), and returns | 29 // Actually generates the key-pair and the cert request (SPKAC), and returns |
| 25 // a base64-encoded string suitable for use as the form value of <keygen>. | 30 // a base64-encoded string suitable for use as the form value of <keygen>. |
| 26 std::string GenKeyAndSignChallenge(); | 31 std::string GenKeyAndSignChallenge(); |
| 27 | 32 |
| 28 // Exposed only for unit tests. | 33 // Exposed only for unit tests. |
| 29 void set_stores_key(bool store) { stores_key_ = store;} | 34 void set_stores_key(bool store) { stores_key_ = store;} |
| 30 | 35 |
| 31 private: | 36 private: |
| 32 int key_size_in_bits_; // key size in bits (usually 2048) | 37 int key_size_in_bits_; // key size in bits (usually 2048) |
| 33 std::string challenge_; // challenge string sent by server | 38 std::string challenge_; // challenge string sent by server |
| 39 GURL url_; // the URL that requested the key |
| 34 bool stores_key_; // should the generated key-pair be stored persistently? | 40 bool stores_key_; // should the generated key-pair be stored persistently? |
| 35 }; | 41 }; |
| 36 | 42 |
| 37 KeygenHandler::KeygenHandler(int key_size_in_bits, | 43 KeygenHandler::KeygenHandler(int key_size_in_bits, |
| 38 const std::string& challenge) | 44 const std::string& challenge, |
| 45 const GURL& url) |
| 39 : key_size_in_bits_(key_size_in_bits), | 46 : key_size_in_bits_(key_size_in_bits), |
| 40 challenge_(challenge), | 47 challenge_(challenge), |
| 48 url_(url), |
| 41 stores_key_(true) { | 49 stores_key_(true) { |
| 42 } | 50 } |
| 43 | 51 |
| 44 } // namespace net | 52 } // namespace net |
| 45 | 53 |
| 46 #endif // NET_BASE_KEYGEN_HANDLER_H_ | 54 #endif // NET_BASE_KEYGEN_HANDLER_H_ |
| OLD | NEW |