OLD | NEW |
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 "net/base/keygen_handler.h" | 5 #include "net/base/keygen_handler.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <rpc.h> | 8 #include <rpc.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 return true; | 58 return true; |
59 } | 59 } |
60 | 60 |
61 // Generates a DER encoded SignedPublicKeyAndChallenge structure from the | 61 // Generates a DER encoded SignedPublicKeyAndChallenge structure from the |
62 // signing key of |prov| and the specified ASCII |challenge| string and | 62 // signing key of |prov| and the specified ASCII |challenge| string and |
63 // appends it to |output|. | 63 // appends it to |output|. |
64 // True if the encoding was successfully generated. | 64 // True if the encoding was successfully generated. |
65 bool GetSignedPublicKeyAndChallenge(HCRYPTPROV prov, | 65 bool GetSignedPublicKeyAndChallenge(HCRYPTPROV prov, |
66 const std::string& challenge, | 66 const std::string& challenge, |
67 std::string* output) { | 67 std::string* output) { |
68 std::wstring wide_challenge = base::ASCIIToWide(challenge); | 68 base::string16 challenge16 = base::ASCIIToUTF16(challenge); |
69 std::vector<BYTE> spki; | 69 std::vector<BYTE> spki; |
70 | 70 |
71 if (!GetSubjectPublicKeyInfo(prov, &spki)) | 71 if (!GetSubjectPublicKeyInfo(prov, &spki)) |
72 return false; | 72 return false; |
73 | 73 |
74 // PublicKeyAndChallenge ::= SEQUENCE { | 74 // PublicKeyAndChallenge ::= SEQUENCE { |
75 // spki SubjectPublicKeyInfo, | 75 // spki SubjectPublicKeyInfo, |
76 // challenge IA5STRING | 76 // challenge IA5STRING |
77 // } | 77 // } |
78 CERT_KEYGEN_REQUEST_INFO pkac; | 78 CERT_KEYGEN_REQUEST_INFO pkac; |
79 pkac.dwVersion = CERT_KEYGEN_REQUEST_V1; | 79 pkac.dwVersion = CERT_KEYGEN_REQUEST_V1; |
80 pkac.SubjectPublicKeyInfo = | 80 pkac.SubjectPublicKeyInfo = |
81 *reinterpret_cast<PCERT_PUBLIC_KEY_INFO>(&spki[0]); | 81 *reinterpret_cast<PCERT_PUBLIC_KEY_INFO>(&spki[0]); |
82 pkac.pwszChallengeString = const_cast<wchar_t*>(wide_challenge.c_str()); | 82 pkac.pwszChallengeString = const_cast<base::char16*>(challenge16.c_str()); |
83 | 83 |
84 CRYPT_ALGORITHM_IDENTIFIER sig_alg; | 84 CRYPT_ALGORITHM_IDENTIFIER sig_alg; |
85 memset(&sig_alg, 0, sizeof(sig_alg)); | 85 memset(&sig_alg, 0, sizeof(sig_alg)); |
86 sig_alg.pszObjId = const_cast<char*>(szOID_RSA_MD5RSA); | 86 sig_alg.pszObjId = const_cast<char*>(szOID_RSA_MD5RSA); |
87 | 87 |
88 BOOL ok; | 88 BOOL ok; |
89 DWORD size = 0; | 89 DWORD size = 0; |
90 std::vector<BYTE> signed_pkac; | 90 std::vector<BYTE> signed_pkac; |
91 ok = CryptSignAndEncodeCertificate(prov, AT_KEYEXCHANGE, X509_ASN_ENCODING, | 91 ok = CryptSignAndEncodeCertificate(prov, AT_KEYEXCHANGE, X509_ASN_ENCODING, |
92 X509_KEYGEN_REQUEST_TO_BE_SIGNED, | 92 X509_KEYGEN_REQUEST_TO_BE_SIGNED, |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 213 |
214 std::string result; | 214 std::string result; |
215 base::Base64Encode(spkac, &result); | 215 base::Base64Encode(spkac, &result); |
216 | 216 |
217 VLOG(1) << "Keygen succeeded"; | 217 VLOG(1) << "Keygen succeeded"; |
218 return result; | 218 return result; |
219 } | 219 } |
220 } | 220 } |
221 | 221 |
222 } // namespace net | 222 } // namespace net |
OLD | NEW |