blob: d65d665d833c0be8f5ac44bfb8e85c3dce9c00cf [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
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 09:11:00 -080011#ifndef RTC_BASE_SSL_FINGERPRINT_H_
12#define RTC_BASE_SSL_FINGERPRINT_H_
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000013
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h>
15#include <stdint.h>
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020016#include <string>
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000017
Steve Anton10542f22019-01-11 09:11:00 -080018#include "rtc_base/copy_on_write_buffer.h"
Mirko Bonadei35214fc2019-09-23 14:54:28 +020019#include "rtc_base/system/rtc_export.h"
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020020
21namespace rtc {
22
Yves Gerey988cc082018-10-23 12:03:01 +020023class RTCCertificate;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020024class SSLCertificate;
Yves Gerey988cc082018-10-23 12:03:01 +020025class SSLIdentity;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020026
Mirko Bonadei35214fc2019-09-23 14:54:28 +020027struct RTC_EXPORT SSLFingerprint {
Steve Anton4905edb2018-10-15 19:27:44 -070028 // TODO(steveanton): Remove once downstream projects have moved off of this.
Henrik Grunell2b156262018-10-11 11:15:48 +000029 static SSLFingerprint* Create(const std::string& algorithm,
Mirko Bonadei6932fb22018-10-15 14:18:03 +000030 const rtc::SSLIdentity* identity);
Steve Anton4905edb2018-10-15 19:27:44 -070031 // 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 Kjellanderec78f1c2017-06-29 07:52:50 +020035
Steve Anton4905edb2018-10-15 19:27:44 -070036 static std::unique_ptr<SSLFingerprint> Create(
37 const std::string& algorithm,
38 const rtc::SSLCertificate& cert);
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020039
Steve Anton4905edb2018-10-15 19:27:44 -070040 // TODO(steveanton): Remove once downstream projects have moved off of this.
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020041 static SSLFingerprint* CreateFromRfc4572(const std::string& algorithm,
42 const std::string& fingerprint);
Steve Anton4905edb2018-10-15 19:27:44 -070043 // 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 Kjellanderec78f1c2017-06-29 07:52:50 +020047
48 // Creates a fingerprint from a certificate, using the same digest algorithm
49 // as the certificate's signature.
Steve Anton4905edb2018-10-15 19:27:44 -070050 static std::unique_ptr<SSLFingerprint> CreateFromCertificate(
51 const RTCCertificate& cert);
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020052
53 SSLFingerprint(const std::string& algorithm,
Steve Anton4905edb2018-10-15 19:27:44 -070054 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 Kjellanderec78f1c2017-06-29 07:52:50 +020057 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.orgf0488722014-05-13 18:00:26 +000073
Steve Anton10542f22019-01-11 09:11:00 -080074#endif // RTC_BASE_SSL_FINGERPRINT_H_