| 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 <cert.h> | 5 #include <cert.h> |
| 6 #include <cryptohi.h> | 6 #include <cryptohi.h> |
| 7 #include <keyhi.h> | 7 #include <keyhi.h> |
| 8 #include <nss.h> | 8 #include <nss.h> |
| 9 #include <pk11pub.h> | 9 #include <pk11pub.h> |
| 10 #include <prtime.h> | 10 #include <prtime.h> |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 } | 256 } |
| 257 | 257 |
| 258 // static | 258 // static |
| 259 void X509Certificate::GetPublicKeyInfo(OSCertHandle cert_handle, | 259 void X509Certificate::GetPublicKeyInfo(OSCertHandle cert_handle, |
| 260 size_t* size_bits, | 260 size_t* size_bits, |
| 261 PublicKeyType* type) { | 261 PublicKeyType* type) { |
| 262 x509_util::GetPublicKeyInfo(cert_handle, size_bits, type); | 262 x509_util::GetPublicKeyInfo(cert_handle, size_bits, type); |
| 263 } | 263 } |
| 264 | 264 |
| 265 // static | 265 // static |
| 266 X509Certificate::SignatureHashAlgorithm |
| 267 X509Certificate::GetSignatureHashAlgorithm(OSCertHandle cert_handle) { |
| 268 SECAlgorithmID& signature = cert_handle->signature; |
| 269 SECOidTag oid_tag = SECOID_FindOIDTag(&signature.algorithm); |
| 270 switch (oid_tag) { |
| 271 case SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION: |
| 272 return kSignatureHashAlgorithmMd5; |
| 273 case SEC_OID_PKCS1_MD2_WITH_RSA_ENCRYPTION: |
| 274 return kSignatureHashAlgorithmMd2; |
| 275 case SEC_OID_PKCS1_MD4_WITH_RSA_ENCRYPTION: |
| 276 return kSignatureHashAlgorithmMd4; |
| 277 case SEC_OID_PKCS1_SHA1_WITH_RSA_ENCRYPTION: |
| 278 case SEC_OID_ISO_SHA1_WITH_RSA_SIGNATURE: |
| 279 case SEC_OID_ANSIX9_DSA_SIGNATURE_WITH_SHA1_DIGEST: |
| 280 case SEC_OID_ANSIX962_ECDSA_SHA1_SIGNATURE: |
| 281 return kSignatureHashAlgorithmSha1; |
| 282 default: |
| 283 return kSignatureHashAlgorithmOther; |
| 284 } |
| 285 } |
| 286 |
| 287 // static |
| 266 bool X509Certificate::IsSelfSigned(OSCertHandle cert_handle) { | 288 bool X509Certificate::IsSelfSigned(OSCertHandle cert_handle) { |
| 267 crypto::ScopedSECKEYPublicKey public_key(CERT_ExtractPublicKey(cert_handle)); | 289 crypto::ScopedSECKEYPublicKey public_key(CERT_ExtractPublicKey(cert_handle)); |
| 268 if (!public_key.get()) | 290 if (!public_key.get()) |
| 269 return false; | 291 return false; |
| 270 if (SECSuccess != CERT_VerifySignedDataWithPublicKey( | 292 if (SECSuccess != CERT_VerifySignedDataWithPublicKey( |
| 271 &cert_handle->signatureWrap, public_key.get(), NULL)) { | 293 &cert_handle->signatureWrap, public_key.get(), NULL)) { |
| 272 return false; | 294 return false; |
| 273 } | 295 } |
| 274 return CERT_CompareName(&cert_handle->subject, &cert_handle->issuer) == | 296 return CERT_CompareName(&cert_handle->subject, &cert_handle->issuer) == |
| 275 SECEqual; | 297 SECEqual; |
| 276 } | 298 } |
| 277 | 299 |
| 278 } // namespace net | 300 } // namespace net |
| OLD | NEW |