Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: net/cert/cert_verify_proc_unittest.cc

Issue 2627523002: Refactor the assignment of CertVerifyResult::has_md2, etc. (Closed)
Patch Set: fix PrintTo() Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/cert/cert_verify_proc_openssl.cc ('k') | net/cert/cert_verify_proc_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/cert_verify_proc.h" 5 #include "net/cert/cert_verify_proc.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 1659 matching lines...) Expand 10 before | Expand all | Expand 10 after
1670 EXPECT_SHA1_LEAF = 1 << 4, 1670 EXPECT_SHA1_LEAF = 1 << 4,
1671 }; 1671 };
1672 1672
1673 struct WeakDigestTestData { 1673 struct WeakDigestTestData {
1674 const char* root_cert_filename; 1674 const char* root_cert_filename;
1675 const char* intermediate_cert_filename; 1675 const char* intermediate_cert_filename;
1676 const char* ee_cert_filename; 1676 const char* ee_cert_filename;
1677 int expected_algorithms; 1677 int expected_algorithms;
1678 }; 1678 };
1679 1679
1680 const char* StringOrDefault(const char* str, const char* default_value) {
1681 if (!str)
1682 return default_value;
1683 return str;
1684 }
1685
1680 // GTest 'magic' pretty-printer, so that if/when a test fails, it knows how 1686 // GTest 'magic' pretty-printer, so that if/when a test fails, it knows how
1681 // to output the parameter that was passed. Without this, it will simply 1687 // to output the parameter that was passed. Without this, it will simply
1682 // attempt to print out the first twenty bytes of the object, which depending 1688 // attempt to print out the first twenty bytes of the object, which depending
1683 // on platform and alignment, may result in an invalid read. 1689 // on platform and alignment, may result in an invalid read.
1684 void PrintTo(const WeakDigestTestData& data, std::ostream* os) { 1690 void PrintTo(const WeakDigestTestData& data, std::ostream* os) {
1685 *os << "root: " 1691 *os << "root: " << StringOrDefault(data.root_cert_filename, "none")
1686 << (data.root_cert_filename ? data.root_cert_filename : "none") 1692 << "; intermediate: "
1687 << "; intermediate: " << data.intermediate_cert_filename 1693 << StringOrDefault(data.intermediate_cert_filename, "none")
1688 << "; end-entity: " << data.ee_cert_filename; 1694 << "; end-entity: " << data.ee_cert_filename;
1689 } 1695 }
1690 1696
1691 class CertVerifyProcWeakDigestTest 1697 class CertVerifyProcWeakDigestTest
1692 : public CertVerifyProcTest, 1698 : public CertVerifyProcTest,
1693 public testing::WithParamInterface<WeakDigestTestData> { 1699 public testing::WithParamInterface<WeakDigestTestData> {
1694 public: 1700 public:
1695 CertVerifyProcWeakDigestTest() {} 1701 CertVerifyProcWeakDigestTest() {}
1696 virtual ~CertVerifyProcWeakDigestTest() {} 1702 virtual ~CertVerifyProcWeakDigestTest() {}
1697 }; 1703 };
1698 1704
1699 // Test that the underlying cryptographic library properly surfaces the 1705 // Test that the CertVerifyProc::Verify() properly surfaces the (weak) hashing
1700 // algorithms used in the chain. Some libraries, like NSS, don't return 1706 // algorithms used in the chain.
1701 // the failing chain on error, and thus not all tests can be run.
1702 TEST_P(CertVerifyProcWeakDigestTest, VerifyDetectsAlgorithm) { 1707 TEST_P(CertVerifyProcWeakDigestTest, VerifyDetectsAlgorithm) {
1703 WeakDigestTestData data = GetParam(); 1708 WeakDigestTestData data = GetParam();
1704 base::FilePath certs_dir = GetTestCertsDirectory(); 1709 base::FilePath certs_dir = GetTestCertsDirectory();
1705 1710
1706 ScopedTestRoot test_root; 1711 scoped_refptr<X509Certificate> intermediate_cert;
1707 if (data.root_cert_filename) { 1712 scoped_refptr<X509Certificate> root_cert;
1708 scoped_refptr<X509Certificate> root_cert = 1713
1709 ImportCertFromFile(certs_dir, data.root_cert_filename); 1714 // Build |intermediates| as the full chain (including trust anchor).
1710 ASSERT_TRUE(root_cert); 1715 X509Certificate::OSCertHandles intermediates;
1711 test_root.Reset(root_cert.get()); 1716
1717 if (data.intermediate_cert_filename) {
1718 intermediate_cert =
1719 ImportCertFromFile(certs_dir, data.intermediate_cert_filename);
1720 ASSERT_TRUE(intermediate_cert);
1721 intermediates.push_back(intermediate_cert->os_cert_handle());
1712 } 1722 }
1713 1723
1714 scoped_refptr<X509Certificate> intermediate_cert = 1724 if (data.root_cert_filename) {
1715 ImportCertFromFile(certs_dir, data.intermediate_cert_filename); 1725 root_cert = ImportCertFromFile(certs_dir, data.root_cert_filename);
1716 ASSERT_TRUE(intermediate_cert); 1726 ASSERT_TRUE(root_cert);
1727 intermediates.push_back(root_cert->os_cert_handle());
1728 }
1729
1717 scoped_refptr<X509Certificate> ee_cert = 1730 scoped_refptr<X509Certificate> ee_cert =
1718 ImportCertFromFile(certs_dir, data.ee_cert_filename); 1731 ImportCertFromFile(certs_dir, data.ee_cert_filename);
1719 ASSERT_TRUE(ee_cert); 1732 ASSERT_TRUE(ee_cert);
1720 1733
1721 X509Certificate::OSCertHandles intermediates;
1722 intermediates.push_back(intermediate_cert->os_cert_handle());
1723
1724 scoped_refptr<X509Certificate> ee_chain = 1734 scoped_refptr<X509Certificate> ee_chain =
1725 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(), 1735 X509Certificate::CreateFromHandle(ee_cert->os_cert_handle(),
1726 intermediates); 1736 intermediates);
1727 ASSERT_TRUE(ee_chain); 1737 ASSERT_TRUE(ee_chain);
1728 1738
1729 int flags = 0; 1739 int flags = 0;
1730 CertVerifyResult verify_result; 1740 CertVerifyResult verify_result;
1731 Verify(ee_chain.get(), "127.0.0.1", flags, NULL, empty_cert_list_, 1741
1732 &verify_result); 1742 // Use a mock CertVerifyProc that returns success with a verified_cert of
1743 // |ee_chain|.
1744 //
1745 // This is sufficient for the purposes of this test, as the checking for weak
1746 // hashing algorithms is done by CertVerifyProc::Verify().
1747 scoped_refptr<CertVerifyProc> proc =
1748 new MockCertVerifyProc(CertVerifyResult());
1749 proc->Verify(ee_chain.get(), "127.0.0.1", std::string(), flags, nullptr,
1750 empty_cert_list_, &verify_result);
1733 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD2), verify_result.has_md2); 1751 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD2), verify_result.has_md2);
1734 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD4), verify_result.has_md4); 1752 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD4), verify_result.has_md4);
1735 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD5), verify_result.has_md5); 1753 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_MD5), verify_result.has_md5);
1736 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_SHA1), verify_result.has_sha1); 1754 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_SHA1), verify_result.has_sha1);
1737 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_SHA1_LEAF), 1755 EXPECT_EQ(!!(data.expected_algorithms & EXPECT_SHA1_LEAF),
1738 verify_result.has_sha1_leaf); 1756 verify_result.has_sha1_leaf);
1739 } 1757 }
1740 1758
1741 // Unlike TEST/TEST_F, which are macros that expand to further macros,
1742 // INSTANTIATE_TEST_CASE_P is a macro that expands directly to code that
1743 // stringizes the arguments. As a result, macros passed as parameters (such as
1744 // prefix or test_case_name) will not be expanded by the preprocessor. To work
1745 // around this, indirect the macro for INSTANTIATE_TEST_CASE_P, so that the
1746 // pre-processor will expand macros such as MAYBE_test_name before
1747 // instantiating the test.
1748 #define WRAPPED_INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \
1749 INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator)
1750
1751 // The signature algorithm of the root CA should not matter. 1759 // The signature algorithm of the root CA should not matter.
1752 const WeakDigestTestData kVerifyRootCATestData[] = { 1760 const WeakDigestTestData kVerifyRootCATestData[] = {
1753 {"weak_digest_md5_root.pem", "weak_digest_sha1_intermediate.pem", 1761 {"weak_digest_md5_root.pem", "weak_digest_sha1_intermediate.pem",
1754 "weak_digest_sha1_ee.pem", EXPECT_SHA1 | EXPECT_SHA1_LEAF}, 1762 "weak_digest_sha1_ee.pem", EXPECT_SHA1 | EXPECT_SHA1_LEAF},
1755 #if defined(USE_OPENSSL_CERTS) || defined(OS_WIN)
1756 // MD4 is not supported by OS X / NSS
1757 {"weak_digest_md4_root.pem", "weak_digest_sha1_intermediate.pem", 1763 {"weak_digest_md4_root.pem", "weak_digest_sha1_intermediate.pem",
1758 "weak_digest_sha1_ee.pem", EXPECT_SHA1 | EXPECT_SHA1_LEAF}, 1764 "weak_digest_sha1_ee.pem", EXPECT_SHA1 | EXPECT_SHA1_LEAF},
1759 #endif
1760 {"weak_digest_md2_root.pem", "weak_digest_sha1_intermediate.pem", 1765 {"weak_digest_md2_root.pem", "weak_digest_sha1_intermediate.pem",
1761 "weak_digest_sha1_ee.pem", EXPECT_SHA1 | EXPECT_SHA1_LEAF}, 1766 "weak_digest_sha1_ee.pem", EXPECT_SHA1 | EXPECT_SHA1_LEAF},
1762 }; 1767 };
1763 INSTANTIATE_TEST_CASE_P(VerifyRoot, 1768 INSTANTIATE_TEST_CASE_P(VerifyRoot,
1764 CertVerifyProcWeakDigestTest, 1769 CertVerifyProcWeakDigestTest,
1765 testing::ValuesIn(kVerifyRootCATestData)); 1770 testing::ValuesIn(kVerifyRootCATestData));
1766 1771
1767 // The signature algorithm of intermediates should be properly detected. 1772 // The signature algorithm of intermediates should be properly detected.
1768 const WeakDigestTestData kVerifyIntermediateCATestData[] = { 1773 const WeakDigestTestData kVerifyIntermediateCATestData[] = {
1769 {"weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem", 1774 {"weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem",
1770 "weak_digest_sha1_ee.pem", EXPECT_MD5 | EXPECT_SHA1 | EXPECT_SHA1_LEAF}, 1775 "weak_digest_sha1_ee.pem", EXPECT_MD5 | EXPECT_SHA1 | EXPECT_SHA1_LEAF},
1771 #if defined(USE_OPENSSL_CERTS) || defined(OS_WIN)
1772 // MD4 is not supported by OS X / NSS
1773 {"weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem", 1776 {"weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem",
1774 "weak_digest_sha1_ee.pem", EXPECT_MD4 | EXPECT_SHA1 | EXPECT_SHA1_LEAF}, 1777 "weak_digest_sha1_ee.pem", EXPECT_MD4 | EXPECT_SHA1 | EXPECT_SHA1_LEAF},
1775 #endif
1776 {"weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem", 1778 {"weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem",
1777 "weak_digest_sha1_ee.pem", EXPECT_MD2 | EXPECT_SHA1 | EXPECT_SHA1_LEAF}, 1779 "weak_digest_sha1_ee.pem", EXPECT_MD2 | EXPECT_SHA1 | EXPECT_SHA1_LEAF},
1778 }; 1780 };
1779 // Disabled on NSS - MD4 is not supported, and MD2 and MD5 are disabled. 1781
1780 #if defined(USE_NSS_CERTS) || defined(OS_IOS) 1782 INSTANTIATE_TEST_CASE_P(VerifyIntermediate,
1781 #define MAYBE_VerifyIntermediate DISABLED_VerifyIntermediate 1783 CertVerifyProcWeakDigestTest,
1782 #else 1784 testing::ValuesIn(kVerifyIntermediateCATestData));
1783 #define MAYBE_VerifyIntermediate VerifyIntermediate
1784 #endif
1785 WRAPPED_INSTANTIATE_TEST_CASE_P(
1786 MAYBE_VerifyIntermediate,
1787 CertVerifyProcWeakDigestTest,
1788 testing::ValuesIn(kVerifyIntermediateCATestData));
1789 1785
1790 // The signature algorithm of end-entity should be properly detected. 1786 // The signature algorithm of end-entity should be properly detected.
1791 const WeakDigestTestData kVerifyEndEntityTestData[] = { 1787 const WeakDigestTestData kVerifyEndEntityTestData[] = {
1792 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", 1788 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
1793 "weak_digest_md5_ee.pem", EXPECT_MD5 | EXPECT_SHA1 }, 1789 "weak_digest_md5_ee.pem", EXPECT_MD5 | EXPECT_SHA1 },
1794 #if defined(USE_OPENSSL_CERTS) || defined(OS_WIN)
1795 // MD4 is not supported by OS X / NSS
1796 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", 1790 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
1797 "weak_digest_md4_ee.pem", EXPECT_MD4 | EXPECT_SHA1 }, 1791 "weak_digest_md4_ee.pem", EXPECT_MD4 | EXPECT_SHA1 },
1798 #endif
1799 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem", 1792 { "weak_digest_sha1_root.pem", "weak_digest_sha1_intermediate.pem",
1800 "weak_digest_md2_ee.pem", EXPECT_MD2 | EXPECT_SHA1 }, 1793 "weak_digest_md2_ee.pem", EXPECT_MD2 | EXPECT_SHA1 },
1801 }; 1794 };
1802 // Disabled on NSS - NSS caches chains/signatures in such a way that cannot
1803 // be cleared until NSS is cleanly shutdown, which is not presently supported
1804 // in Chromium.
1805 // OSX 10.12+ stops building the chain at the first weak digest.
1806 #if defined(USE_NSS_CERTS) || defined(OS_IOS) || defined(OS_MACOSX)
1807 #define MAYBE_VerifyEndEntity DISABLED_VerifyEndEntity
1808 #else
1809 #define MAYBE_VerifyEndEntity VerifyEndEntity
1810 #endif
1811 WRAPPED_INSTANTIATE_TEST_CASE_P(MAYBE_VerifyEndEntity,
1812 CertVerifyProcWeakDigestTest,
1813 testing::ValuesIn(kVerifyEndEntityTestData));
1814 1795
1815 // Incomplete chains should still report the status of the intermediate. 1796 INSTANTIATE_TEST_CASE_P(VerifyEndEntity,
1797 CertVerifyProcWeakDigestTest,
1798 testing::ValuesIn(kVerifyEndEntityTestData));
1799
1800 // Incomplete chains do not report the status of the intermediate.
1801 // Note: really each of these tests should also expect the digest algorithm of
1802 // the intermediate (included as a comment). However CertVerifyProc::Verify() is
1803 // unable to distinguish that this is an intermediate and not a trust anchor, so
1804 // this intermediate is treated like a trust anchor.
1816 const WeakDigestTestData kVerifyIncompleteIntermediateTestData[] = { 1805 const WeakDigestTestData kVerifyIncompleteIntermediateTestData[] = {
1817 {NULL, "weak_digest_md5_intermediate.pem", "weak_digest_sha1_ee.pem", 1806 {NULL, "weak_digest_md5_intermediate.pem", "weak_digest_sha1_ee.pem",
1818 EXPECT_MD5 | EXPECT_SHA1 | EXPECT_SHA1_LEAF}, 1807 /*EXPECT_MD5 |*/ EXPECT_SHA1 | EXPECT_SHA1_LEAF},
1819 #if defined(USE_OPENSSL_CERTS) || defined(OS_WIN)
1820 // MD4 is not supported by OS X / NSS
1821 {NULL, "weak_digest_md4_intermediate.pem", "weak_digest_sha1_ee.pem", 1808 {NULL, "weak_digest_md4_intermediate.pem", "weak_digest_sha1_ee.pem",
1822 EXPECT_MD4 | EXPECT_SHA1 | EXPECT_SHA1_LEAF}, 1809 /*EXPECT_MD4 |*/ EXPECT_SHA1 | EXPECT_SHA1_LEAF},
1823 #endif
1824 {NULL, "weak_digest_md2_intermediate.pem", "weak_digest_sha1_ee.pem", 1810 {NULL, "weak_digest_md2_intermediate.pem", "weak_digest_sha1_ee.pem",
1825 EXPECT_MD2 | EXPECT_SHA1 | EXPECT_SHA1_LEAF}, 1811 /*EXPECT_MD2 |*/ EXPECT_SHA1 | EXPECT_SHA1_LEAF},
1826 }; 1812 };
1827 // Disabled on NSS - libpkix does not return constructed chains on error, 1813
1828 // preventing us from detecting/inspecting the verified chain. 1814 INSTANTIATE_TEST_CASE_P(
1829 #if defined(USE_NSS_CERTS) || defined(OS_IOS)
1830 #define MAYBE_VerifyIncompleteIntermediate \
1831 DISABLED_VerifyIncompleteIntermediate
1832 #else
1833 #define MAYBE_VerifyIncompleteIntermediate VerifyIncompleteIntermediate
1834 #endif
1835 WRAPPED_INSTANTIATE_TEST_CASE_P(
1836 MAYBE_VerifyIncompleteIntermediate, 1815 MAYBE_VerifyIncompleteIntermediate,
1837 CertVerifyProcWeakDigestTest, 1816 CertVerifyProcWeakDigestTest,
1838 testing::ValuesIn(kVerifyIncompleteIntermediateTestData)); 1817 testing::ValuesIn(kVerifyIncompleteIntermediateTestData));
1839 1818
1840 // Incomplete chains should still report the status of the end-entity. 1819 // Incomplete chains should report the status of the end-entity.
1820 // Note: really each of these tests should also expect EXPECT_SHA1 (included as
1821 // a comment). However CertVerifyProc::Verify() is unable to distinguish that
1822 // this is an intermediate and not a trust anchor, so this intermediate is
1823 // treated like a trust anchor.
1841 const WeakDigestTestData kVerifyIncompleteEETestData[] = { 1824 const WeakDigestTestData kVerifyIncompleteEETestData[] = {
1842 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md5_ee.pem", 1825 {NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md5_ee.pem",
1843 EXPECT_MD5 | EXPECT_SHA1 }, 1826 /*EXPECT_SHA1 |*/ EXPECT_MD5},
1844 #if defined(USE_OPENSSL_CERTS) || defined(OS_WIN) 1827 {NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md4_ee.pem",
1845 // MD4 is not supported by OS X / NSS 1828 /*EXPECT_SHA1 |*/ EXPECT_MD4},
1846 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md4_ee.pem", 1829 {NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md2_ee.pem",
1847 EXPECT_MD4 | EXPECT_SHA1 }, 1830 /*EXPECT_SHA1 |*/ EXPECT_MD2},
1848 #endif
1849 { NULL, "weak_digest_sha1_intermediate.pem", "weak_digest_md2_ee.pem",
1850 EXPECT_MD2 | EXPECT_SHA1 },
1851 }; 1831 };
1852 // Disabled on NSS - libpkix does not return constructed chains on error, 1832
1853 // preventing us from detecting/inspecting the verified chain. 1833 INSTANTIATE_TEST_CASE_P(VerifyIncompleteEndEntity,
1854 // OSX 10.12+ stops building the chain at the first weak digest. 1834 CertVerifyProcWeakDigestTest,
1855 #if defined(USE_NSS_CERTS) || defined(OS_IOS) || defined(OS_MACOSX) 1835 testing::ValuesIn(kVerifyIncompleteEETestData));
1856 #define MAYBE_VerifyIncompleteEndEntity DISABLED_VerifyIncompleteEndEntity
1857 #else
1858 #define MAYBE_VerifyIncompleteEndEntity VerifyIncompleteEndEntity
1859 #endif
1860 WRAPPED_INSTANTIATE_TEST_CASE_P(
1861 MAYBE_VerifyIncompleteEndEntity,
1862 CertVerifyProcWeakDigestTest,
1863 testing::ValuesIn(kVerifyIncompleteEETestData));
1864 1836
1865 // Differing algorithms between the intermediate and the EE should still be 1837 // Differing algorithms between the intermediate and the EE should still be
1866 // reported. 1838 // reported.
1867 const WeakDigestTestData kVerifyMixedTestData[] = { 1839 const WeakDigestTestData kVerifyMixedTestData[] = {
1868 { "weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem", 1840 { "weak_digest_sha1_root.pem", "weak_digest_md5_intermediate.pem",
1869 "weak_digest_md2_ee.pem", EXPECT_MD2 | EXPECT_MD5 }, 1841 "weak_digest_md2_ee.pem", EXPECT_MD2 | EXPECT_MD5 },
1870 { "weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem", 1842 { "weak_digest_sha1_root.pem", "weak_digest_md2_intermediate.pem",
1871 "weak_digest_md5_ee.pem", EXPECT_MD2 | EXPECT_MD5 }, 1843 "weak_digest_md5_ee.pem", EXPECT_MD2 | EXPECT_MD5 },
1872 #if defined(USE_OPENSSL_CERTS) || defined(OS_WIN)
1873 // MD4 is not supported by OS X / NSS
1874 { "weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem", 1844 { "weak_digest_sha1_root.pem", "weak_digest_md4_intermediate.pem",
1875 "weak_digest_md2_ee.pem", EXPECT_MD2 | EXPECT_MD4 }, 1845 "weak_digest_md2_ee.pem", EXPECT_MD2 | EXPECT_MD4 },
1876 #endif
1877 }; 1846 };
1878 // NSS does not support MD4 and does not enable MD2 by default, making all 1847
1879 // permutations invalid. 1848 INSTANTIATE_TEST_CASE_P(VerifyMixed,
1880 // OSX 10.12+ stops building the chain at the first weak digest. 1849 CertVerifyProcWeakDigestTest,
1881 #if defined(USE_NSS_CERTS) || defined(OS_IOS) || defined(OS_MACOSX) 1850 testing::ValuesIn(kVerifyMixedTestData));
1882 #define MAYBE_VerifyMixed DISABLED_VerifyMixed 1851
1883 #else 1852 // The EE is a trusted certificate. Even though it uses weak hashes, these
1884 #define MAYBE_VerifyMixed VerifyMixed 1853 // should not be reported.
1885 #endif 1854 const WeakDigestTestData kVerifyTrustedEETestData[] = {
1886 WRAPPED_INSTANTIATE_TEST_CASE_P( 1855 {NULL, NULL, "weak_digest_md5_ee.pem", 0},
1887 MAYBE_VerifyMixed, 1856 {NULL, NULL, "weak_digest_md4_ee.pem", 0},
1888 CertVerifyProcWeakDigestTest, 1857 {NULL, NULL, "weak_digest_md2_ee.pem", 0},
1889 testing::ValuesIn(kVerifyMixedTestData)); 1858 {NULL, NULL, "weak_digest_sha1_ee.pem", 0},
1859 };
1860
1861 INSTANTIATE_TEST_CASE_P(VerifyTrustedEE,
1862 CertVerifyProcWeakDigestTest,
1863 testing::ValuesIn(kVerifyTrustedEETestData));
1890 1864
1891 // For the list of valid hostnames, see 1865 // For the list of valid hostnames, see
1892 // net/cert/data/ssl/certificates/subjectAltName_sanity_check.pem 1866 // net/cert/data/ssl/certificates/subjectAltName_sanity_check.pem
1893 static const struct CertVerifyProcNameData { 1867 static const struct CertVerifyProcNameData {
1894 const char* hostname; 1868 const char* hostname;
1895 bool valid; // Whether or not |hostname| matches a subjectAltName. 1869 bool valid; // Whether or not |hostname| matches a subjectAltName.
1896 } kVerifyNameData[] = { 1870 } kVerifyNameData[] = {
1897 { "127.0.0.1", false }, // Don't match the common name 1871 { "127.0.0.1", false }, // Don't match the common name
1898 { "127.0.0.2", true }, // Matches the iPAddress SAN (IPv4) 1872 { "127.0.0.2", true }, // Matches the iPAddress SAN (IPv4)
1899 { "FE80:0:0:0:0:0:0:1", true }, // Matches the iPAddress SAN (IPv6) 1873 { "FE80:0:0:0:0:0:0:1", true }, // Matches the iPAddress SAN (IPv6)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1941 &verify_result); 1915 &verify_result);
1942 if (data.valid) { 1916 if (data.valid) {
1943 EXPECT_THAT(error, IsOk()); 1917 EXPECT_THAT(error, IsOk());
1944 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID); 1918 EXPECT_FALSE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID);
1945 } else { 1919 } else {
1946 EXPECT_THAT(error, IsError(ERR_CERT_COMMON_NAME_INVALID)); 1920 EXPECT_THAT(error, IsError(ERR_CERT_COMMON_NAME_INVALID));
1947 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID); 1921 EXPECT_TRUE(verify_result.cert_status & CERT_STATUS_COMMON_NAME_INVALID);
1948 } 1922 }
1949 } 1923 }
1950 1924
1951 WRAPPED_INSTANTIATE_TEST_CASE_P( 1925 INSTANTIATE_TEST_CASE_P(VerifyName,
1952 VerifyName, 1926 CertVerifyProcNameTest,
1953 CertVerifyProcNameTest, 1927 testing::ValuesIn(kVerifyNameData));
1954 testing::ValuesIn(kVerifyNameData));
1955 1928
1956 #if defined(OS_MACOSX) && !defined(OS_IOS) 1929 #if defined(OS_MACOSX) && !defined(OS_IOS)
1957 // Test that CertVerifyProcMac reacts appropriately when Apple's certificate 1930 // Test that CertVerifyProcMac reacts appropriately when Apple's certificate
1958 // verifier rejects a certificate with a fatal error. This is a regression 1931 // verifier rejects a certificate with a fatal error. This is a regression
1959 // test for https://crbug.com/472291. 1932 // test for https://crbug.com/472291.
1960 // (Since 10.12, this causes a recoverable error instead of a fatal one.) 1933 // (Since 10.12, this causes a recoverable error instead of a fatal one.)
1961 // TODO(mattm): Try to find a different way to cause a fatal error that works 1934 // TODO(mattm): Try to find a different way to cause a fatal error that works
1962 // on 10.12. 1935 // on 10.12.
1963 TEST_F(CertVerifyProcTest, LargeKey) { 1936 TEST_F(CertVerifyProcTest, LargeKey) {
1964 // Load root_ca_cert.pem into the test root store. 1937 // Load root_ca_cert.pem into the test root store.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2075 int flags = 0; 2048 int flags = 0;
2076 CertVerifyResult verify_result; 2049 CertVerifyResult verify_result;
2077 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_, 2050 int error = Verify(cert.get(), "127.0.0.1", flags, NULL, empty_cert_list_,
2078 &verify_result); 2051 &verify_result);
2079 EXPECT_EQ(OK, error); 2052 EXPECT_EQ(OK, error);
2080 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0); 2053 histograms.ExpectTotalCount(kTLSFeatureExtensionHistogram, 0);
2081 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0); 2054 histograms.ExpectTotalCount(kTLSFeatureExtensionOCSPHistogram, 0);
2082 } 2055 }
2083 2056
2084 } // namespace net 2057 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/cert_verify_proc_openssl.cc ('k') | net/cert/cert_verify_proc_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698