Commit 3414577
Add verifyContext to CertificateIdentityVerifier
Summary:
This diff adds a new `verifyContext()` method to the `CertificateIdentityVerifier` interface that is called during OpenSSL's certificate verification callback for each certificate in the chain. This allows implementers to inspect and verify the entire certificate chain by accessing the `X509_STORE_CTX` directly.
**Key Changes:**
- Added virtual `verifyContext(bool preverifyOk, X509_STORE_CTX& ctx)` method to `CertificateIdentityVerifier` with a default pass-through implementation
- `verifyContext()` is called **for each certificate in the chain** (root → intermediate(s) → leaf) during the SSL handshake
- Modified `AsyncSSLSocket::sslVerifyCallback()` to call `verifyContext()` after `handshakeVer()` and before `verifyLeaf()`
- `verifyContext()` updates the verification state without short-circuiting - unlike `handshakeVer()`, it allows processing to continue even when changing the result
- If `verifyContext()` returns `false`, verification fails and `verifyLeaf()` will NOT be called
- If `verifyContext()` returns `true`, verification succeeds and `verifyLeaf()` may be called for the leaf certificate at depth 0
- Updated `MockCertificateIdentityVerifier` to include `MOCK_METHOD` for the new method
- Updated existing tests to mock `verifyContext()` calls and verify proper call ordering
- Comprehensively updated documentation to accurately describe the verification flow and `verifyContext()` behavior
**Why This Change:**
This provides more flexibility for custom certificate verification by allowing access to the full certificate chain context. Some verification scenarios require:
- Inspecting the entire chain (not just the leaf certificate)
- Accessing OpenSSL's `X509_STORE_CTX` for advanced validation
- Performing verification at different chain depths
- Overriding OpenSSL's verification decisions (can rescue failed OpenSSL verifications or fail successful ones)
- Short-circuiting verification early based on chain-level policies
The method is marked `noexcept` and allows the verification flow to continue, enabling `verifyLeaf()` to be called for additional leaf certificate validation even when `verifyContext()` changes the result.
**Verification Flow:**
1. OpenSSL performs internal certificate chain validation
2. HandshakeCB's `handshakeVer()` is invoked (if registered)
- Short-circuits if it changes the result
3. CertificateIdentityVerifier's `verifyContext()` is invoked (if registered)
- Called once for each cert in chain
- Updates verification state without short-circuiting
- Can override OpenSSL's decision in either direction
4. CertificateIdentityVerifier's `verifyLeaf()` is invoked (if registered)
- Called only for leaf certificate at depth 0
- Only if all previous steps succeeded (preverifyOk is true)
Reviewed By: yfeldblum
Differential Revision: D87812821
fbshipit-source-id: a1ba21bb643c497c9da67f6e7deda75a05d8da0c1 parent 8c3e1ad commit 3414577
File tree
5 files changed
+232
-20
lines changed- third-party/folly/src/folly/io/async
- test
5 files changed
+232
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1996 | 1996 | | |
1997 | 1997 | | |
1998 | 1998 | | |
1999 | | - | |
| 1999 | + | |
2000 | 2000 | | |
2001 | 2001 | | |
2002 | 2002 | | |
2003 | 2003 | | |
2004 | 2004 | | |
2005 | | - | |
| 2005 | + | |
2006 | 2006 | | |
2007 | 2007 | | |
2008 | 2008 | | |
2009 | 2009 | | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
2010 | 2020 | | |
2011 | | - | |
| 2021 | + | |
| 2022 | + | |
2012 | 2023 | | |
2013 | 2024 | | |
2014 | 2025 | | |
2015 | | - | |
2016 | | - | |
| 2026 | + | |
| 2027 | + | |
| 2028 | + | |
2017 | 2029 | | |
2018 | 2030 | | |
2019 | 2031 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
205 | 207 | | |
206 | 208 | | |
207 | 209 | | |
| |||
Lines changed: 59 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
| 19 | + | |
| 20 | + | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
31 | 40 | | |
32 | 41 | | |
33 | 42 | | |
| |||
39 | 48 | | |
40 | 49 | | |
41 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
42 | 95 | | |
43 | 96 | | |
44 | 97 | | |
| |||
Lines changed: 144 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1485 | 1485 | | |
1486 | 1486 | | |
1487 | 1487 | | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
1488 | 1493 | | |
1489 | 1494 | | |
1490 | 1495 | | |
1491 | 1496 | | |
1492 | 1497 | | |
1493 | 1498 | | |
| 1499 | + | |
1494 | 1500 | | |
1495 | 1501 | | |
1496 | 1502 | | |
| |||
1542 | 1548 | | |
1543 | 1549 | | |
1544 | 1550 | | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
1545 | 1557 | | |
1546 | 1558 | | |
1547 | 1559 | | |
1548 | 1560 | | |
1549 | 1561 | | |
| 1562 | + | |
1550 | 1563 | | |
1551 | 1564 | | |
1552 | 1565 | | |
| |||
1562 | 1575 | | |
1563 | 1576 | | |
1564 | 1577 | | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
1565 | 1691 | | |
1566 | 1692 | | |
1567 | 1693 | | |
| |||
1583 | 1709 | | |
1584 | 1710 | | |
1585 | 1711 | | |
1586 | | - | |
| 1712 | + | |
1587 | 1713 | | |
1588 | 1714 | | |
| 1715 | + | |
1589 | 1716 | | |
1590 | 1717 | | |
1591 | 1718 | | |
| |||
1622 | 1749 | | |
1623 | 1750 | | |
1624 | 1751 | | |
1625 | | - | |
| 1752 | + | |
1626 | 1753 | | |
1627 | 1754 | | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
1628 | 1758 | | |
1629 | 1759 | | |
1630 | 1760 | | |
| |||
1645 | 1775 | | |
1646 | 1776 | | |
1647 | 1777 | | |
1648 | | - | |
| 1778 | + | |
1649 | 1779 | | |
1650 | 1780 | | |
1651 | 1781 | | |
1652 | 1782 | | |
1653 | 1783 | | |
1654 | 1784 | | |
1655 | | - | |
| 1785 | + | |
1656 | 1786 | | |
1657 | 1787 | | |
1658 | 1788 | | |
| |||
1695 | 1825 | | |
1696 | 1826 | | |
1697 | 1827 | | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
1698 | 1832 | | |
1699 | 1833 | | |
1700 | 1834 | | |
1701 | 1835 | | |
| 1836 | + | |
1702 | 1837 | | |
1703 | 1838 | | |
1704 | 1839 | | |
1705 | 1840 | | |
1706 | 1841 | | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
1707 | 1846 | | |
1708 | 1847 | | |
1709 | 1848 | | |
1710 | 1849 | | |
| 1850 | + | |
1711 | 1851 | | |
1712 | 1852 | | |
1713 | 1853 | | |
| |||
Lines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
495 | 495 | | |
496 | 496 | | |
497 | 497 | | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
498 | 503 | | |
499 | 504 | | |
500 | 505 | | |
501 | 506 | | |
502 | | - | |
| 507 | + | |
503 | 508 | | |
504 | 509 | | |
505 | 510 | | |
| |||
0 commit comments