| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 const std::string& algorithm, const rtc::SSLIdentity* identity) { | 23 const std::string& algorithm, const rtc::SSLIdentity* identity) { |
| 24 if (!identity) { | 24 if (!identity) { |
| 25 return NULL; | 25 return NULL; |
| 26 } | 26 } |
| 27 | 27 |
| 28 return Create(algorithm, &(identity->certificate())); | 28 return Create(algorithm, &(identity->certificate())); |
| 29 } | 29 } |
| 30 | 30 |
| 31 SSLFingerprint* SSLFingerprint::Create( | 31 SSLFingerprint* SSLFingerprint::Create( |
| 32 const std::string& algorithm, const rtc::SSLCertificate* cert) { | 32 const std::string& algorithm, const rtc::SSLCertificate* cert) { |
| 33 uint8 digest_val[64]; | 33 uint8_t digest_val[64]; |
| 34 size_t digest_len; | 34 size_t digest_len; |
| 35 bool ret = cert->ComputeDigest( | 35 bool ret = cert->ComputeDigest( |
| 36 algorithm, digest_val, sizeof(digest_val), &digest_len); | 36 algorithm, digest_val, sizeof(digest_val), &digest_len); |
| 37 if (!ret) { | 37 if (!ret) { |
| 38 return NULL; | 38 return NULL; |
| 39 } | 39 } |
| 40 | 40 |
| 41 return new SSLFingerprint(algorithm, digest_val, digest_len); | 41 return new SSLFingerprint(algorithm, digest_val, digest_len); |
| 42 } | 42 } |
| 43 | 43 |
| 44 SSLFingerprint* SSLFingerprint::CreateFromRfc4572( | 44 SSLFingerprint* SSLFingerprint::CreateFromRfc4572( |
| 45 const std::string& algorithm, const std::string& fingerprint) { | 45 const std::string& algorithm, const std::string& fingerprint) { |
| 46 if (algorithm.empty() || !rtc::IsFips180DigestAlgorithm(algorithm)) | 46 if (algorithm.empty() || !rtc::IsFips180DigestAlgorithm(algorithm)) |
| 47 return NULL; | 47 return NULL; |
| 48 | 48 |
| 49 if (fingerprint.empty()) | 49 if (fingerprint.empty()) |
| 50 return NULL; | 50 return NULL; |
| 51 | 51 |
| 52 size_t value_len; | 52 size_t value_len; |
| 53 char value[rtc::MessageDigest::kMaxSize]; | 53 char value[rtc::MessageDigest::kMaxSize]; |
| 54 value_len = rtc::hex_decode_with_delimiter(value, sizeof(value), | 54 value_len = rtc::hex_decode_with_delimiter(value, sizeof(value), |
| 55 fingerprint.c_str(), | 55 fingerprint.c_str(), |
| 56 fingerprint.length(), | 56 fingerprint.length(), |
| 57 ':'); | 57 ':'); |
| 58 if (!value_len) | 58 if (!value_len) |
| 59 return NULL; | 59 return NULL; |
| 60 | 60 |
| 61 return new SSLFingerprint(algorithm, | 61 return new SSLFingerprint(algorithm, reinterpret_cast<uint8_t*>(value), |
| 62 reinterpret_cast<uint8*>(value), | |
| 63 value_len); | 62 value_len); |
| 64 } | 63 } |
| 65 | 64 |
| 66 SSLFingerprint::SSLFingerprint( | 65 SSLFingerprint::SSLFingerprint(const std::string& algorithm, |
| 67 const std::string& algorithm, const uint8* digest_in, size_t digest_len) | 66 const uint8_t* digest_in, |
| 67 size_t digest_len) |
| 68 : algorithm(algorithm) { | 68 : algorithm(algorithm) { |
| 69 digest.SetData(digest_in, digest_len); | 69 digest.SetData(digest_in, digest_len); |
| 70 } | 70 } |
| 71 | 71 |
| 72 SSLFingerprint::SSLFingerprint(const SSLFingerprint& from) | 72 SSLFingerprint::SSLFingerprint(const SSLFingerprint& from) |
| 73 : algorithm(from.algorithm), digest(from.digest) {} | 73 : algorithm(from.algorithm), digest(from.digest) {} |
| 74 | 74 |
| 75 bool SSLFingerprint::operator==(const SSLFingerprint& other) const { | 75 bool SSLFingerprint::operator==(const SSLFingerprint& other) const { |
| 76 return algorithm == other.algorithm && | 76 return algorithm == other.algorithm && |
| 77 digest == other.digest; | 77 digest == other.digest; |
| 78 } | 78 } |
| 79 | 79 |
| 80 std::string SSLFingerprint::GetRfc4572Fingerprint() const { | 80 std::string SSLFingerprint::GetRfc4572Fingerprint() const { |
| 81 std::string fingerprint = | 81 std::string fingerprint = |
| 82 rtc::hex_encode_with_delimiter(digest.data<char>(), digest.size(), ':'); | 82 rtc::hex_encode_with_delimiter(digest.data<char>(), digest.size(), ':'); |
| 83 std::transform(fingerprint.begin(), fingerprint.end(), | 83 std::transform(fingerprint.begin(), fingerprint.end(), |
| 84 fingerprint.begin(), ::toupper); | 84 fingerprint.begin(), ::toupper); |
| 85 return fingerprint; | 85 return fingerprint; |
| 86 } | 86 } |
| 87 | 87 |
| 88 std::string SSLFingerprint::ToString() { | 88 std::string SSLFingerprint::ToString() { |
| 89 std::string fp_str = algorithm; | 89 std::string fp_str = algorithm; |
| 90 fp_str.append(" "); | 90 fp_str.append(" "); |
| 91 fp_str.append(GetRfc4572Fingerprint()); | 91 fp_str.append(GetRfc4572Fingerprint()); |
| 92 return fp_str; | 92 return fp_str; |
| 93 } | 93 } |
| 94 | 94 |
| 95 } // namespace rtc | 95 } // namespace rtc |
| OLD | NEW |