henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 1 | /* |
| 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 Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #ifndef RTC_BASE_SSL_FINGERPRINT_H_ |
| 12 | #define RTC_BASE_SSL_FINGERPRINT_H_ |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 13 | |
Yves Gerey | 988cc08 | 2018-10-23 10:03:01 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | #include <stdint.h> |
Ali Tofigh | 7fa9057 | 2022-03-17 14:47:49 | [diff] [blame] | 16 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 17 | #include <string> |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 18 | |
Ali Tofigh | 7fa9057 | 2022-03-17 14:47:49 | [diff] [blame] | 19 | #include "absl/strings/string_view.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 20 | #include "rtc_base/copy_on_write_buffer.h" |
Mirko Bonadei | 35214fc | 2019-09-23 12:54:28 | [diff] [blame] | 21 | #include "rtc_base/system/rtc_export.h" |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 22 | |
| 23 | namespace rtc { |
| 24 | |
Yves Gerey | 988cc08 | 2018-10-23 10:03:01 | [diff] [blame] | 25 | class RTCCertificate; |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 26 | class SSLCertificate; |
Yves Gerey | 988cc08 | 2018-10-23 10:03:01 | [diff] [blame] | 27 | class SSLIdentity; |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 28 | |
Mirko Bonadei | 35214fc | 2019-09-23 12:54:28 | [diff] [blame] | 29 | struct RTC_EXPORT SSLFingerprint { |
Steve Anton | 4905edb | 2018-10-16 02:27:44 | [diff] [blame] | 30 | // TODO(steveanton): Remove once downstream projects have moved off of this. |
Ali Tofigh | 7fa9057 | 2022-03-17 14:47:49 | [diff] [blame] | 31 | static SSLFingerprint* Create(absl::string_view algorithm, |
Mirko Bonadei | 6932fb2 | 2018-10-15 14:18:03 | [diff] [blame] | 32 | const rtc::SSLIdentity* identity); |
Steve Anton | 4905edb | 2018-10-16 02:27:44 | [diff] [blame] | 33 | // TODO(steveanton): Rename to Create once projects have migrated. |
| 34 | static std::unique_ptr<SSLFingerprint> CreateUnique( |
Ali Tofigh | 7fa9057 | 2022-03-17 14:47:49 | [diff] [blame] | 35 | absl::string_view algorithm, |
Steve Anton | 4905edb | 2018-10-16 02:27:44 | [diff] [blame] | 36 | const rtc::SSLIdentity& identity); |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 37 | |
Steve Anton | 4905edb | 2018-10-16 02:27:44 | [diff] [blame] | 38 | static std::unique_ptr<SSLFingerprint> Create( |
Ali Tofigh | 7fa9057 | 2022-03-17 14:47:49 | [diff] [blame] | 39 | absl::string_view algorithm, |
Steve Anton | 4905edb | 2018-10-16 02:27:44 | [diff] [blame] | 40 | const rtc::SSLCertificate& cert); |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 41 | |
Steve Anton | 4905edb | 2018-10-16 02:27:44 | [diff] [blame] | 42 | // TODO(steveanton): Remove once downstream projects have moved off of this. |
Ali Tofigh | 7fa9057 | 2022-03-17 14:47:49 | [diff] [blame] | 43 | static SSLFingerprint* CreateFromRfc4572(absl::string_view algorithm, |
| 44 | absl::string_view fingerprint); |
Steve Anton | 4905edb | 2018-10-16 02:27:44 | [diff] [blame] | 45 | // TODO(steveanton): Rename to CreateFromRfc4572 once projects have migrated. |
| 46 | static std::unique_ptr<SSLFingerprint> CreateUniqueFromRfc4572( |
Ali Tofigh | 7fa9057 | 2022-03-17 14:47:49 | [diff] [blame] | 47 | absl::string_view algorithm, |
| 48 | absl::string_view fingerprint); |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 49 | |
| 50 | // Creates a fingerprint from a certificate, using the same digest algorithm |
| 51 | // as the certificate's signature. |
Steve Anton | 4905edb | 2018-10-16 02:27:44 | [diff] [blame] | 52 | static std::unique_ptr<SSLFingerprint> CreateFromCertificate( |
| 53 | const RTCCertificate& cert); |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 54 | |
Ali Tofigh | 7fa9057 | 2022-03-17 14:47:49 | [diff] [blame] | 55 | SSLFingerprint(absl::string_view algorithm, |
Steve Anton | 4905edb | 2018-10-16 02:27:44 | [diff] [blame] | 56 | ArrayView<const uint8_t> digest_view); |
| 57 | // TODO(steveanton): Remove once downstream projects have moved off of this. |
Ali Tofigh | 7fa9057 | 2022-03-17 14:47:49 | [diff] [blame] | 58 | SSLFingerprint(absl::string_view algorithm, |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 59 | const uint8_t* digest_in, |
| 60 | size_t digest_len); |
| 61 | |
Byoungchan Lee | 917dcba | 2021-05-11 13:27:10 | [diff] [blame] | 62 | SSLFingerprint(const SSLFingerprint& from) = default; |
| 63 | SSLFingerprint& operator=(const SSLFingerprint& from) = default; |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 64 | |
| 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.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 76 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 77 | #endif // RTC_BASE_SSL_FINGERPRINT_H_ |