| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/sha256_legacy_support_win.h" | |
| 6 | |
| 7 #include <windows.h> | |
| 8 #include <wincrypt.h> | |
| 9 | |
| 10 #include <cert.h> | 5 #include <cert.h> |
| 11 #include <keyhi.h> | 6 #include <keyhi.h> |
| 12 #include <secoid.h> | 7 #include <secoid.h> |
| 13 | 8 |
| 14 #include "base/lazy_instance.h" | |
| 15 #include "base/logging.h" | 9 #include "base/logging.h" |
| 16 #include "base/strings/string_piece.h" | |
| 17 #include "base/win/windows_version.h" | |
| 18 #include "crypto/scoped_nss_types.h" | 10 #include "crypto/scoped_nss_types.h" |
| 11 #include "net/cert/sha256_legacy_support_win.h" |
| 19 | 12 |
| 20 namespace net { | 13 namespace net { |
| 21 | 14 |
| 22 namespace sha256_interception { | 15 namespace sha256_interception { |
| 23 | 16 |
| 24 namespace { | |
| 25 | |
| 26 bool IsSupportedSubjectType(DWORD subject_type) { | |
| 27 switch (subject_type) { | |
| 28 case CRYPT_VERIFY_CERT_SIGN_SUBJECT_BLOB: | |
| 29 case CRYPT_VERIFY_CERT_SIGN_SUBJECT_CERT: | |
| 30 case CRYPT_VERIFY_CERT_SIGN_SUBJECT_CRL: | |
| 31 return true; | |
| 32 } | |
| 33 return false; | |
| 34 } | |
| 35 | |
| 36 bool IsSupportedIssuerType(DWORD issuer_type) { | |
| 37 switch (issuer_type) { | |
| 38 case CRYPT_VERIFY_CERT_SIGN_ISSUER_PUBKEY: | |
| 39 case CRYPT_VERIFY_CERT_SIGN_ISSUER_CERT: | |
| 40 case CRYPT_VERIFY_CERT_SIGN_ISSUER_CHAIN: | |
| 41 return true; | |
| 42 } | |
| 43 return false; | |
| 44 } | |
| 45 | |
| 46 base::StringPiece GetSubjectSignature(DWORD subject_type, | |
| 47 void* subject_data) { | |
| 48 switch (subject_type) { | |
| 49 case CRYPT_VERIFY_CERT_SIGN_SUBJECT_BLOB: { | |
| 50 CRYPT_DATA_BLOB* data_blob = | |
| 51 reinterpret_cast<CRYPT_DATA_BLOB*>(subject_data); | |
| 52 return base::StringPiece(reinterpret_cast<char*>(data_blob->pbData), | |
| 53 data_blob->cbData); | |
| 54 } | |
| 55 case CRYPT_VERIFY_CERT_SIGN_SUBJECT_CERT: { | |
| 56 PCCERT_CONTEXT subject_cert = | |
| 57 reinterpret_cast<PCCERT_CONTEXT>(subject_data); | |
| 58 return base::StringPiece( | |
| 59 reinterpret_cast<char*>(subject_cert->pbCertEncoded), | |
| 60 subject_cert->cbCertEncoded); | |
| 61 } | |
| 62 case CRYPT_VERIFY_CERT_SIGN_SUBJECT_CRL: { | |
| 63 PCCRL_CONTEXT subject_crl = | |
| 64 reinterpret_cast<PCCRL_CONTEXT>(subject_data); | |
| 65 return base::StringPiece( | |
| 66 reinterpret_cast<char*>(subject_crl->pbCrlEncoded), | |
| 67 subject_crl->cbCrlEncoded); | |
| 68 } | |
| 69 } | |
| 70 return base::StringPiece(); | |
| 71 } | |
| 72 | |
| 73 PCERT_PUBLIC_KEY_INFO GetIssuerPublicKey(DWORD issuer_type, | |
| 74 void* issuer_data) { | |
| 75 switch (issuer_type) { | |
| 76 case CRYPT_VERIFY_CERT_SIGN_ISSUER_PUBKEY: | |
| 77 return reinterpret_cast<PCERT_PUBLIC_KEY_INFO>(issuer_data); | |
| 78 case CRYPT_VERIFY_CERT_SIGN_ISSUER_CERT: { | |
| 79 PCCERT_CONTEXT cert = reinterpret_cast<PCCERT_CONTEXT>(issuer_data); | |
| 80 return &cert->pCertInfo->SubjectPublicKeyInfo; | |
| 81 } | |
| 82 case CRYPT_VERIFY_CERT_SIGN_ISSUER_CHAIN: { | |
| 83 PCCERT_CHAIN_CONTEXT chain = | |
| 84 reinterpret_cast<PCCERT_CHAIN_CONTEXT>(issuer_data); | |
| 85 PCCERT_CONTEXT cert = chain->rgpChain[0]->rgpElement[0]->pCertContext; | |
| 86 return &cert->pCertInfo->SubjectPublicKeyInfo; | |
| 87 } | |
| 88 } | |
| 89 return NULL; | |
| 90 } | |
| 91 | |
| 92 } // namespace | |
| 93 | |
| 94 BOOL CryptVerifyCertificateSignatureExHook( | 17 BOOL CryptVerifyCertificateSignatureExHook( |
| 95 CryptVerifyCertificateSignatureExFunc original_func, | 18 CryptVerifyCertificateSignatureExFunc original_func, |
| 96 HCRYPTPROV_LEGACY provider, | 19 HCRYPTPROV_LEGACY provider, |
| 97 DWORD encoding_type, | 20 DWORD encoding_type, |
| 98 DWORD subject_type, | 21 DWORD subject_type, |
| 99 void* subject_data, | 22 void* subject_data, |
| 100 DWORD issuer_type, | 23 DWORD issuer_type, |
| 101 void* issuer_data, | 24 void* issuer_data, |
| 102 DWORD flags, | 25 DWORD flags, |
| 103 void* extra) { | 26 void* extra) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 if (rv != SECSuccess) { | 109 if (rv != SECSuccess) { |
| 187 SetLastError(static_cast<DWORD>(NTE_BAD_SIGNATURE)); | 110 SetLastError(static_cast<DWORD>(NTE_BAD_SIGNATURE)); |
| 188 return FALSE; | 111 return FALSE; |
| 189 } | 112 } |
| 190 return TRUE; | 113 return TRUE; |
| 191 } | 114 } |
| 192 | 115 |
| 193 } // namespace sha256_interception | 116 } // namespace sha256_interception |
| 194 | 117 |
| 195 } // namespace net | 118 } // namespace net |
| OLD | NEW |