blob: cfa26dd4338f60d76c4ba6073a34781e95eca6da [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:261/*
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Steve Anton10542f22019-01-11 17:11:0011#ifndef RTC_BASE_SSL_FINGERPRINT_H_
12#define RTC_BASE_SSL_FINGERPRINT_H_
henrike@webrtc.orgf0488722014-05-13 18:00:2613
Yves Gerey988cc082018-10-23 10:03:0114#include <stddef.h>
15#include <stdint.h>
Ali Tofigh7fa90572022-03-17 14:47:4916
Henrik Kjellanderec78f1c2017-06-29 05:52:5017#include <string>
henrike@webrtc.orgf0488722014-05-13 18:00:2618
Ali Tofigh7fa90572022-03-17 14:47:4919#include "absl/strings/string_view.h"
Steve Anton10542f22019-01-11 17:11:0020#include "rtc_base/copy_on_write_buffer.h"
Mirko Bonadei35214fc2019-09-23 12:54:2821#include "rtc_base/system/rtc_export.h"
Henrik Kjellanderec78f1c2017-06-29 05:52:5022
23namespace rtc {
24
Yves Gerey988cc082018-10-23 10:03:0125class RTCCertificate;
Henrik Kjellanderec78f1c2017-06-29 05:52:5026class SSLCertificate;
Yves Gerey988cc082018-10-23 10:03:0127class SSLIdentity;
Henrik Kjellanderec78f1c2017-06-29 05:52:5028
Mirko Bonadei35214fc2019-09-23 12:54:2829struct RTC_EXPORT SSLFingerprint {
Steve Anton4905edb2018-10-16 02:27:4430 // TODO(steveanton): Remove once downstream projects have moved off of this.
Ali Tofigh7fa90572022-03-17 14:47:4931 static SSLFingerprint* Create(absl::string_view algorithm,
Mirko Bonadei6932fb22018-10-15 14:18:0332 const rtc::SSLIdentity* identity);
Steve Anton4905edb2018-10-16 02:27:4433 // TODO(steveanton): Rename to Create once projects have migrated.
34 static std::unique_ptr<SSLFingerprint> CreateUnique(
Ali Tofigh7fa90572022-03-17 14:47:4935 absl::string_view algorithm,
Steve Anton4905edb2018-10-16 02:27:4436 const rtc::SSLIdentity& identity);
Henrik Kjellanderec78f1c2017-06-29 05:52:5037
Steve Anton4905edb2018-10-16 02:27:4438 static std::unique_ptr<SSLFingerprint> Create(
Ali Tofigh7fa90572022-03-17 14:47:4939 absl::string_view algorithm,
Steve Anton4905edb2018-10-16 02:27:4440 const rtc::SSLCertificate& cert);
Henrik Kjellanderec78f1c2017-06-29 05:52:5041
Steve Anton4905edb2018-10-16 02:27:4442 // TODO(steveanton): Remove once downstream projects have moved off of this.
Ali Tofigh7fa90572022-03-17 14:47:4943 static SSLFingerprint* CreateFromRfc4572(absl::string_view algorithm,
44 absl::string_view fingerprint);
Steve Anton4905edb2018-10-16 02:27:4445 // TODO(steveanton): Rename to CreateFromRfc4572 once projects have migrated.
46 static std::unique_ptr<SSLFingerprint> CreateUniqueFromRfc4572(
Ali Tofigh7fa90572022-03-17 14:47:4947 absl::string_view algorithm,
48 absl::string_view fingerprint);
Henrik Kjellanderec78f1c2017-06-29 05:52:5049
50 // Creates a fingerprint from a certificate, using the same digest algorithm
51 // as the certificate's signature.
Steve Anton4905edb2018-10-16 02:27:4452 static std::unique_ptr<SSLFingerprint> CreateFromCertificate(
53 const RTCCertificate& cert);
Henrik Kjellanderec78f1c2017-06-29 05:52:5054
Ali Tofigh7fa90572022-03-17 14:47:4955 SSLFingerprint(absl::string_view algorithm,
Steve Anton4905edb2018-10-16 02:27:4456 ArrayView<const uint8_t> digest_view);
57 // TODO(steveanton): Remove once downstream projects have moved off of this.
Ali Tofigh7fa90572022-03-17 14:47:4958 SSLFingerprint(absl::string_view algorithm,
Henrik Kjellanderec78f1c2017-06-29 05:52:5059 const uint8_t* digest_in,
60 size_t digest_len);
61
Byoungchan Lee917dcba2021-05-11 13:27:1062 SSLFingerprint(const SSLFingerprint& from) = default;
63 SSLFingerprint& operator=(const SSLFingerprint& from) = default;
Henrik Kjellanderec78f1c2017-06-29 05:52:5064
65 bool operator==(const SSLFingerprint& other) const;
66
67 std::string GetRfc4572Fingerprint() const;
68
69 std::string ToString() const;
70
71 std::string algorithm;
72 rtc::CopyOnWriteBuffer digest;
73};
74
75} // namespace rtc
henrike@webrtc.orgf0488722014-05-13 18:00:2676
Steve Anton10542f22019-01-11 17:11:0077#endif // RTC_BASE_SSL_FINGERPRINT_H_