OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/cert/x509_certificate.h" | 5 #include "net/cert/x509_certificate.h" |
6 | 6 |
7 #include <CommonCrypto/CommonDigest.h> | 7 #include <CommonCrypto/CommonDigest.h> |
8 #include <Security/Security.h> | 8 #include <Security/Security.h> |
9 | 9 |
10 #include <cert.h> | 10 #include <cert.h> |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 if (!cert_data) | 177 if (!cert_data) |
178 return sha1; | 178 return sha1; |
179 DCHECK(CFDataGetBytePtr(cert_data)); | 179 DCHECK(CFDataGetBytePtr(cert_data)); |
180 DCHECK_NE(0, CFDataGetLength(cert_data)); | 180 DCHECK_NE(0, CFDataGetLength(cert_data)); |
181 CC_SHA1(CFDataGetBytePtr(cert_data), CFDataGetLength(cert_data), sha1.data); | 181 CC_SHA1(CFDataGetBytePtr(cert_data), CFDataGetLength(cert_data), sha1.data); |
182 | 182 |
183 return sha1; | 183 return sha1; |
184 } | 184 } |
185 | 185 |
186 // static | 186 // static |
| 187 SHA256HashValue X509Certificate::CalculateFingerprint256(OSCertHandle cert) { |
| 188 SHA256HashValue sha256; |
| 189 memset(sha256.data, 0, sizeof(sha256.data)); |
| 190 |
| 191 ScopedCFTypeRef<CFDataRef> cert_data(SecCertificateCopyData(cert)); |
| 192 if (!cert_data) |
| 193 return sha256; |
| 194 DCHECK(CFDataGetBytePtr(cert_data)); |
| 195 DCHECK_NE(0, CFDataGetLength(cert_data)); |
| 196 CC_SHA256( |
| 197 CFDataGetBytePtr(cert_data), CFDataGetLength(cert_data), sha256.data); |
| 198 |
| 199 return sha256; |
| 200 } |
| 201 |
| 202 // static |
187 SHA1HashValue X509Certificate::CalculateCAFingerprint( | 203 SHA1HashValue X509Certificate::CalculateCAFingerprint( |
188 const OSCertHandles& intermediates) { | 204 const OSCertHandles& intermediates) { |
189 SHA1HashValue sha1; | 205 SHA1HashValue sha1; |
190 memset(sha1.data, 0, sizeof(sha1.data)); | 206 memset(sha1.data, 0, sizeof(sha1.data)); |
191 | 207 |
192 // The CC_SHA(3cc) man page says all CC_SHA1_xxx routines return 1, so | 208 // The CC_SHA(3cc) man page says all CC_SHA1_xxx routines return 1, so |
193 // we don't check their return values. | 209 // we don't check their return values. |
194 CC_SHA1_CTX sha1_ctx; | 210 CC_SHA1_CTX sha1_ctx; |
195 CC_SHA1_Init(&sha1_ctx); | 211 CC_SHA1_Init(&sha1_ctx); |
196 for (size_t i = 0; i < intermediates.size(); ++i) { | 212 for (size_t i = 0; i < intermediates.size(); ++i) { |
(...skipping 29 matching lines...) Expand all Loading... |
226 | 242 |
227 // static | 243 // static |
228 void X509Certificate::GetPublicKeyInfo(OSCertHandle cert_handle, | 244 void X509Certificate::GetPublicKeyInfo(OSCertHandle cert_handle, |
229 size_t* size_bits, | 245 size_t* size_bits, |
230 PublicKeyType* type) { | 246 PublicKeyType* type) { |
231 x509_util_ios::NSSCertificate nss_cert(cert_handle); | 247 x509_util_ios::NSSCertificate nss_cert(cert_handle); |
232 x509_util::GetPublicKeyInfo(nss_cert.cert_handle(), size_bits, type); | 248 x509_util::GetPublicKeyInfo(nss_cert.cert_handle(), size_bits, type); |
233 } | 249 } |
234 | 250 |
235 } // namespace net | 251 } // namespace net |
OLD | NEW |