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