You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.6 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2018 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. #include "api/crypto/crypto_options.h"
  11. #include "rtc_base/ssl_stream_adapter.h"
  12. namespace webrtc {
  13. CryptoOptions::CryptoOptions() {}
  14. CryptoOptions::CryptoOptions(const CryptoOptions& other) {
  15. srtp = other.srtp;
  16. sframe = other.sframe;
  17. }
  18. CryptoOptions::~CryptoOptions() {}
  19. // static
  20. CryptoOptions CryptoOptions::NoGcm() {
  21. CryptoOptions options;
  22. options.srtp.enable_gcm_crypto_suites = false;
  23. return options;
  24. }
  25. std::vector<int> CryptoOptions::GetSupportedDtlsSrtpCryptoSuites() const {
  26. std::vector<int> crypto_suites;
  27. if (srtp.enable_gcm_crypto_suites) {
  28. crypto_suites.push_back(rtc::SRTP_AEAD_AES_256_GCM);
  29. crypto_suites.push_back(rtc::SRTP_AEAD_AES_128_GCM);
  30. }
  31. // Note: SRTP_AES128_CM_SHA1_80 is what is required to be supported (by
  32. // draft-ietf-rtcweb-security-arch), but SRTP_AES128_CM_SHA1_32 is allowed as
  33. // well, and saves a few bytes per packet if it ends up selected.
  34. // As the cipher suite is potentially insecure, it will only be used if
  35. // enabled by both peers.
  36. if (srtp.enable_aes128_sha1_32_crypto_cipher) {
  37. crypto_suites.push_back(rtc::SRTP_AES128_CM_SHA1_32);
  38. }
  39. crypto_suites.push_back(rtc::SRTP_AES128_CM_SHA1_80);
  40. return crypto_suites;
  41. }
  42. bool CryptoOptions::operator==(const CryptoOptions& other) const {
  43. struct data_being_tested_for_equality {
  44. struct Srtp {
  45. bool enable_gcm_crypto_suites;
  46. bool enable_aes128_sha1_32_crypto_cipher;
  47. bool enable_encrypted_rtp_header_extensions;
  48. } srtp;
  49. struct SFrame {
  50. bool require_frame_encryption;
  51. } sframe;
  52. };
  53. static_assert(sizeof(data_being_tested_for_equality) == sizeof(*this),
  54. "Did you add something to CryptoOptions and forget to "
  55. "update operator==?");
  56. return srtp.enable_gcm_crypto_suites == other.srtp.enable_gcm_crypto_suites &&
  57. srtp.enable_aes128_sha1_32_crypto_cipher ==
  58. other.srtp.enable_aes128_sha1_32_crypto_cipher &&
  59. srtp.enable_encrypted_rtp_header_extensions ==
  60. other.srtp.enable_encrypted_rtp_header_extensions &&
  61. sframe.require_frame_encryption ==
  62. other.sframe.require_frame_encryption;
  63. }
  64. bool CryptoOptions::operator!=(const CryptoOptions& other) const {
  65. return !(*this == other);
  66. }
  67. } // namespace webrtc