| 793 | } |
| 794 | |
| 795 | bool TLSPolicy::verify_peer(bool preverified, X509_STORE_CTX* store_ctx) { |
| 796 | bool rc = false; |
| 797 | std::set<std::string> verify_failure_reasons; |
| 798 | bool verify_success; |
| 799 | std::string verify_failure_reason; |
| 800 | |
| 801 | // If certificate verification is disabled, there's nothing more to do. |
| 802 | if (std::any_of(rules.begin(), rules.end(), [](const Rule& r) { return !r.verify_cert; })) { |
| 803 | return true; |
| 804 | } |
| 805 | |
| 806 | if (!preverified) { |
| 807 | TraceEvent(SevWarn, "TLSPolicyFailure") |
| 808 | .suppressFor(1.0) |
| 809 | .detail("Reason", "preverification failed") |
| 810 | .detail("VerifyError", X509_verify_cert_error_string(X509_STORE_CTX_get_error(store_ctx))); |
| 811 | return false; |
| 812 | } |
| 813 | |
| 814 | if (!rules.size()) { |
| 815 | return true; |
| 816 | } |
| 817 | |
| 818 | // Any matching rule is sufficient. |
| 819 | for (auto& verify_rule : rules) { |
| 820 | std::tie(verify_success, verify_failure_reason) = check_verify(&verify_rule, store_ctx, is_client); |
| 821 | if (verify_success) { |
| 822 | rc = true; |
| 823 | break; |
| 824 | } else { |
| 825 | if (verify_failure_reason.length() > 0) |
| 826 | verify_failure_reasons.insert(verify_failure_reason); |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | if (!rc) { |
| 831 | // log the various failure reasons |
| 832 | for (std::string reason : verify_failure_reasons) { |
| 833 | TraceEvent(SevWarn, "TLSPolicyFailure").suppressFor(1.0).detail("Reason", reason); |
| 834 | } |
| 835 | } |
| 836 | return rc; |
| 837 | } |
no test coverage detected