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 "chrome/common/net/x509_certificate_model.h" | 5 #include "chrome/common/net/x509_certificate_model.h" |
6 | 6 |
7 #include <openssl/bio.h> | 7 #include <openssl/bio.h> |
8 #include <openssl/obj_mac.h> | 8 #include <openssl/obj_mac.h> |
9 #include <openssl/sha.h> | 9 #include <openssl/sha.h> |
10 #include <openssl/x509v3.h> | 10 #include <openssl/x509v3.h> |
(...skipping 27 matching lines...) Expand all Loading... | |
38 return std::string(); | 38 return std::string(); |
39 | 39 |
40 scoped_ptr<unsigned char[]> buf(new unsigned char[len]); | 40 scoped_ptr<unsigned char[]> buf(new unsigned char[len]); |
41 unsigned char* bufp = buf.get(); | 41 unsigned char* bufp = buf.get(); |
42 | 42 |
43 len = i2d_ASN1_TYPE(data, &bufp); | 43 len = i2d_ASN1_TYPE(data, &bufp); |
44 | 44 |
45 return ProcessRawBytes(buf.get(), len); | 45 return ProcessRawBytes(buf.get(), len); |
46 } | 46 } |
47 | 47 |
48 std::string ProcessRawBignum(BIGNUM* n) { | |
49 int len = BN_num_bytes(n); | |
50 scoped_ptr<unsigned char[]> buf(new unsigned char[len]); | |
51 BN_bn2bin(n, buf.get()); | |
Ryan Sleevi
2014/07/07 19:53:42
nit: A bit of a code-smell to ignore a result. Tho
mattm
2014/07/07 21:32:55
Done.
| |
52 return ProcessRawBytes(buf.get(), len); | |
53 } | |
54 | |
48 std::string Asn1StringToUTF8(ASN1_STRING* asn1_string) { | 55 std::string Asn1StringToUTF8(ASN1_STRING* asn1_string) { |
49 std::string rv; | 56 std::string rv; |
50 unsigned char* buf = NULL; | 57 unsigned char* buf = NULL; |
51 int len = ASN1_STRING_to_UTF8(&buf, asn1_string); | 58 int len = ASN1_STRING_to_UTF8(&buf, asn1_string); |
52 if (len < 0) | 59 if (len < 0) |
53 return rv; | 60 return rv; |
54 rv = std::string(reinterpret_cast<const char*>(buf), len); | 61 rv = std::string(reinterpret_cast<const char*>(buf), len); |
55 OPENSSL_free(buf); | 62 OPENSSL_free(buf); |
56 return rv; | 63 return rv; |
57 } | 64 } |
(...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1177 X509_get_X509_PUBKEY(cert_handle)->algor->algorithm); | 1184 X509_get_X509_PUBKEY(cert_handle)->algor->algorithm); |
1178 } | 1185 } |
1179 | 1186 |
1180 std::string ProcessSecAlgorithmSignatureWrap( | 1187 std::string ProcessSecAlgorithmSignatureWrap( |
1181 net::X509Certificate::OSCertHandle cert_handle) { | 1188 net::X509Certificate::OSCertHandle cert_handle) { |
1182 return Asn1ObjectToString(cert_handle->sig_alg->algorithm); | 1189 return Asn1ObjectToString(cert_handle->sig_alg->algorithm); |
1183 } | 1190 } |
1184 | 1191 |
1185 std::string ProcessSubjectPublicKeyInfo( | 1192 std::string ProcessSubjectPublicKeyInfo( |
1186 net::X509Certificate::OSCertHandle cert_handle) { | 1193 net::X509Certificate::OSCertHandle cert_handle) { |
1187 // TODO(bulach): implement me. | 1194 std::string rv; |
1188 return ""; | 1195 crypto::ScopedOpenSSL<EVP_PKEY, EVP_PKEY_free> public_key( |
1196 X509_get_pubkey(cert_handle)); | |
1197 if (!public_key.get()) | |
1198 return rv; | |
1199 switch (EVP_PKEY_type(public_key.get()->type)) { | |
1200 case EVP_PKEY_RSA: { | |
1201 crypto::ScopedOpenSSL<RSA, RSA_free> rsa_key( | |
1202 EVP_PKEY_get1_RSA(public_key.get())); | |
1203 if (!rsa_key.get()) | |
1204 return rv; | |
1205 rv = l10n_util::GetStringFUTF8( | |
1206 IDS_CERT_RSA_PUBLIC_KEY_DUMP_FORMAT, | |
1207 base::UintToString16(BN_num_bits(rsa_key.get()->n)), | |
1208 base::UTF8ToUTF16(ProcessRawBignum(rsa_key.get()->n)), | |
1209 base::UintToString16(BN_num_bits(rsa_key.get()->e)), | |
1210 base::UTF8ToUTF16(ProcessRawBignum(rsa_key.get()->e))); | |
1211 return rv; | |
1212 } | |
1213 default: | |
1214 rv = ProcessRawAsn1String(X509_get_X509_PUBKEY(cert_handle)->public_key); | |
1215 return rv; | |
1216 } | |
1189 } | 1217 } |
1190 | 1218 |
1191 std::string ProcessRawBitsSignatureWrap( | 1219 std::string ProcessRawBitsSignatureWrap( |
1192 net::X509Certificate::OSCertHandle cert_handle) { | 1220 net::X509Certificate::OSCertHandle cert_handle) { |
1193 // TODO(bulach): implement me. | 1221 // TODO(bulach): implement me. |
1194 return ""; | 1222 return ""; |
1195 } | 1223 } |
1196 | 1224 |
1197 } // namespace x509_certificate_model | 1225 } // namespace x509_certificate_model |
OLD | NEW |