cert_verify_result.cc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright (c) 2011 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 "net/cert/cert_verify_result.h"
  5. #include <tuple>
  6. #include "base/values.h"
  7. #include "net/base/net_errors.h"
  8. #include "net/cert/ct_policy_status.h"
  9. #include "net/cert/ct_signed_certificate_timestamp_log_param.h"
  10. #include "net/cert/x509_certificate.h"
  11. #include "net/cert/x509_certificate_net_log_param.h"
  12. namespace net {
  13. CertVerifyResult::CertVerifyResult() {
  14. Reset();
  15. }
  16. CertVerifyResult::CertVerifyResult(const CertVerifyResult& other) {
  17. *this = other;
  18. }
  19. CertVerifyResult::~CertVerifyResult() = default;
  20. CertVerifyResult& CertVerifyResult::operator=(const CertVerifyResult& other) {
  21. verified_cert = other.verified_cert;
  22. cert_status = other.cert_status;
  23. has_sha1 = other.has_sha1;
  24. has_sha1_leaf = other.has_sha1_leaf;
  25. is_issued_by_known_root = other.is_issued_by_known_root;
  26. is_issued_by_additional_trust_anchor =
  27. other.is_issued_by_additional_trust_anchor;
  28. public_key_hashes = other.public_key_hashes;
  29. ocsp_result = other.ocsp_result;
  30. scts = other.scts;
  31. policy_compliance = other.policy_compliance;
  32. ClearAllUserData();
  33. CloneDataFrom(other);
  34. return *this;
  35. }
  36. void CertVerifyResult::Reset() {
  37. verified_cert = nullptr;
  38. cert_status = 0;
  39. has_sha1 = false;
  40. has_sha1_leaf = false;
  41. is_issued_by_known_root = false;
  42. is_issued_by_additional_trust_anchor = false;
  43. public_key_hashes.clear();
  44. ocsp_result = OCSPVerifyResult();
  45. scts.clear();
  46. policy_compliance =
  47. ct::CTPolicyCompliance::CT_POLICY_COMPLIANCE_DETAILS_NOT_AVAILABLE;
  48. ClearAllUserData();
  49. }
  50. base::Value CertVerifyResult::NetLogParams(int net_error) const {
  51. base::Value::Dict dict;
  52. DCHECK_NE(ERR_IO_PENDING, net_error);
  53. if (net_error < 0)
  54. dict.Set("net_error", net_error);
  55. dict.Set("is_issued_by_known_root", is_issued_by_known_root);
  56. if (is_issued_by_additional_trust_anchor) {
  57. dict.Set("is_issued_by_additional_trust_anchor", true);
  58. }
  59. dict.Set("cert_status", static_cast<int>(cert_status));
  60. // TODO(mattm): This double-wrapping of the certificate list is weird. Remove
  61. // this (probably requires updates to netlog-viewer).
  62. base::Value::Dict certificate_dict;
  63. certificate_dict.Set("certificates",
  64. net::NetLogX509CertificateList(verified_cert.get()));
  65. dict.Set("verified_cert", std::move(certificate_dict));
  66. base::Value::List hashes;
  67. for (const auto& public_key_hash : public_key_hashes)
  68. hashes.Append(public_key_hash.ToString());
  69. dict.Set("public_key_hashes", std::move(hashes));
  70. dict.Set("scts", net::NetLogSignedCertificateTimestampParams(&scts));
  71. return base::Value(std::move(dict));
  72. }
  73. } // namespace net