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 11 #ifndef RTC_BASE_SSL_FINGERPRINT_H_ 12 #define RTC_BASE_SSL_FINGERPRINT_H_ 13 14 #include <stddef.h> 15 #include <stdint.h> 16 17 #include <string> 18 19 #include "absl/strings/string_view.h" 20 #include "rtc_base/copy_on_write_buffer.h" 21 #include "rtc_base/system/rtc_export.h" 22 23 namespace rtc { 24 25 class RTCCertificate; 26 class SSLCertificate; 27 class SSLIdentity; 28 29 struct RTC_EXPORT SSLFingerprint { 30 // TODO(steveanton): Remove once downstream projects have moved off of this. 31 static SSLFingerprint* Create(absl::string_view algorithm, 32 const rtc::SSLIdentity* identity); 33 // TODO(steveanton): Rename to Create once projects have migrated. 34 static std::unique_ptr<SSLFingerprint> CreateUnique( 35 absl::string_view algorithm, 36 const rtc::SSLIdentity& identity); 37 38 static std::unique_ptr<SSLFingerprint> Create( 39 absl::string_view algorithm, 40 const rtc::SSLCertificate& cert); 41 42 // TODO(steveanton): Remove once downstream projects have moved off of this. 43 static SSLFingerprint* CreateFromRfc4572(absl::string_view algorithm, 44 absl::string_view fingerprint); 45 // TODO(steveanton): Rename to CreateFromRfc4572 once projects have migrated. 46 static std::unique_ptr<SSLFingerprint> CreateUniqueFromRfc4572( 47 absl::string_view algorithm, 48 absl::string_view fingerprint); 49 50 // Creates a fingerprint from a certificate, using the same digest algorithm 51 // as the certificate's signature. 52 static std::unique_ptr<SSLFingerprint> CreateFromCertificate( 53 const RTCCertificate& cert); 54 55 SSLFingerprint(absl::string_view algorithm, 56 ArrayView<const uint8_t> digest_view); 57 // TODO(steveanton): Remove once downstream projects have moved off of this. 58 SSLFingerprint(absl::string_view algorithm, 59 const uint8_t* digest_in, 60 size_t digest_len); 61 62 SSLFingerprint(const SSLFingerprint& from) = default; 63 SSLFingerprint& operator=(const SSLFingerprint& from) = default; 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 76 77 #endif // RTC_BASE_SSL_FINGERPRINT_H_ 78