cert_policy.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233
  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
  3. // found in the LICENSE file.
  4. #include "ios/web/public/security/cert_policy.h"
  5. #include "net/cert/x509_certificate.h"
  6. namespace web {
  7. CertPolicy::CertPolicy() {}
  8. CertPolicy::~CertPolicy() {}
  9. // We consider a given |cert| to be a match to a saved allowed cert if the
  10. // |error| is an exact match to or subset of the errors in the saved CertStatus.
  11. CertPolicy::Judgment CertPolicy::Check(net::X509Certificate* cert,
  12. net::CertStatus error) const {
  13. auto allowed_iter = allowed_.find(cert->CalculateChainFingerprint256());
  14. if ((allowed_iter != allowed_.end()) && (allowed_iter->second & error) &&
  15. !(~(allowed_iter->second & error) ^ ~error)) {
  16. return ALLOWED;
  17. }
  18. return UNKNOWN; // We don't have a policy for this cert.
  19. }
  20. void CertPolicy::Allow(net::X509Certificate* cert, net::CertStatus error) {
  21. // If this same cert had already been saved with a different error status,
  22. // this will replace it with the new error status.
  23. allowed_[cert->CalculateChainFingerprint256()] = error;
  24. }
  25. } // namespace web