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 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1127 | 1127 |
1128 std::string HashCertSHA1(net::X509Certificate::OSCertHandle cert_handle) { | 1128 std::string HashCertSHA1(net::X509Certificate::OSCertHandle cert_handle) { |
1129 unsigned char sha1_data[SHA_DIGEST_LENGTH] = {0}; | 1129 unsigned char sha1_data[SHA_DIGEST_LENGTH] = {0}; |
1130 unsigned int sha1_size = sizeof(sha1_data); | 1130 unsigned int sha1_size = sizeof(sha1_data); |
1131 int ret = X509_digest(cert_handle, EVP_sha1(), sha1_data, &sha1_size); | 1131 int ret = X509_digest(cert_handle, EVP_sha1(), sha1_data, &sha1_size); |
1132 DCHECK(ret); | 1132 DCHECK(ret); |
1133 DCHECK_EQ(sha1_size, sizeof(sha1_data)); | 1133 DCHECK_EQ(sha1_size, sizeof(sha1_data)); |
1134 return ProcessRawBytes(sha1_data, sha1_size); | 1134 return ProcessRawBytes(sha1_data, sha1_size); |
1135 } | 1135 } |
1136 | 1136 |
1137 void GetCertChainFromCert(net::X509Certificate::OSCertHandle cert_handle, | |
1138 net::X509Certificate::OSCertHandles* cert_handles) { | |
1139 // TODO(bulach): how to get the chain out of a certificate? | |
1140 cert_handles->push_back(net::X509Certificate::DupOSCertHandle(cert_handle)); | |
1141 } | |
1142 | |
1143 void DestroyCertChain(net::X509Certificate::OSCertHandles* cert_handles) { | |
1144 for (net::X509Certificate::OSCertHandles::iterator i = cert_handles->begin(); | |
1145 i != cert_handles->end(); ++i) | |
1146 X509_free(*i); | |
1147 cert_handles->clear(); | |
1148 } | |
1149 | |
1150 std::string GetCMSString(const net::X509Certificate::OSCertHandles& cert_chain, | 1137 std::string GetCMSString(const net::X509Certificate::OSCertHandles& cert_chain, |
1151 size_t start, size_t end) { | 1138 size_t start, size_t end) { |
1152 std::string rv; | 1139 std::string rv; |
1153 crypto::ScopedOpenSSL<PKCS7, PKCS7_free> p7(PKCS7_new()); | 1140 crypto::ScopedOpenSSL<PKCS7, PKCS7_free> p7(PKCS7_new()); |
1154 if (!p7.get()) | 1141 if (!p7.get()) |
1155 return rv; | 1142 return rv; |
1156 if (!PKCS7_set_type(p7.get(), NID_pkcs7_signed)) | 1143 if (!PKCS7_set_type(p7.get(), NID_pkcs7_signed)) |
1157 return rv; | 1144 return rv; |
1158 | 1145 |
1159 for (size_t i = start; i < end; ++i) { | 1146 for (size_t i = start; i < end; ++i) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 return rv; | 1202 return rv; |
1216 } | 1203 } |
1217 } | 1204 } |
1218 | 1205 |
1219 std::string ProcessRawBitsSignatureWrap( | 1206 std::string ProcessRawBitsSignatureWrap( |
1220 net::X509Certificate::OSCertHandle cert_handle) { | 1207 net::X509Certificate::OSCertHandle cert_handle) { |
1221 return ProcessRawAsn1String(cert_handle->signature); | 1208 return ProcessRawAsn1String(cert_handle->signature); |
1222 } | 1209 } |
1223 | 1210 |
1224 } // namespace x509_certificate_model | 1211 } // namespace x509_certificate_model |
OLD | NEW |