| 738 | } |
| 739 | |
| 740 | std::tuple<bool, std::string> check_verify(const TLSPolicy::Rule* verify, X509_STORE_CTX* store_ctx, bool is_client) { |
| 741 | X509_NAME *subject, *issuer; |
| 742 | bool rc = false; |
| 743 | X509* cert = nullptr; |
| 744 | // if returning false, give a reason string |
| 745 | std::string reason = ""; |
| 746 | |
| 747 | // Check subject criteria. |
| 748 | cert = sk_X509_value(X509_STORE_CTX_get0_chain(store_ctx), 0); |
| 749 | if ((subject = X509_get_subject_name(cert)) == nullptr) { |
| 750 | reason = "Cert subject error"; |
| 751 | goto err; |
| 752 | } |
| 753 | for (auto& pair : verify->subject_criteria) { |
| 754 | if (!match_criteria( |
| 755 | cert, subject, pair.first, pair.second.criteria, pair.second.match_type, pair.second.location)) { |
| 756 | reason = "Cert subject match failure"; |
| 757 | goto err; |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | // Check issuer criteria. |
| 762 | if ((issuer = X509_get_issuer_name(cert)) == nullptr) { |
| 763 | reason = "Cert issuer error"; |
| 764 | goto err; |
| 765 | } |
| 766 | for (auto& pair : verify->issuer_criteria) { |
| 767 | if (!match_criteria( |
| 768 | cert, issuer, pair.first, pair.second.criteria, pair.second.match_type, pair.second.location)) { |
| 769 | reason = "Cert issuer match failure"; |
| 770 | goto err; |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | // Check root criteria - this is the subject of the final certificate in the stack. |
| 775 | cert = sk_X509_value(X509_STORE_CTX_get0_chain(store_ctx), sk_X509_num(X509_STORE_CTX_get0_chain(store_ctx)) - 1); |
| 776 | if ((subject = X509_get_subject_name(cert)) == nullptr) { |
| 777 | reason = "Root subject error"; |
| 778 | goto err; |
| 779 | } |
| 780 | for (auto& pair : verify->root_criteria) { |
| 781 | if (!match_criteria( |
| 782 | cert, subject, pair.first, pair.second.criteria, pair.second.match_type, pair.second.location)) { |
| 783 | reason = "Root subject match failure"; |
| 784 | goto err; |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | // If we got this far, everything checked out... |
| 789 | rc = true; |
| 790 | |
| 791 | err: |
| 792 | return std::make_tuple(rc, reason); |
| 793 | } |
| 794 | |
| 795 | bool TLSPolicy::verify_peer(bool preverified, X509_STORE_CTX* store_ctx) { |
| 796 | bool rc = false; |
no test coverage detected