blob: 6e06bc6426e1d042626f0ab5431a67c6b87b4d1a [file] [log] [blame]
Benjamin Wright8c27cca2018-10-25 10:16:44 -07001/*
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 */
Patrik Höglundbd6ffaf2018-11-16 14:55:16 +010010
Benjamin Wright8c27cca2018-10-25 10:16:44 -070011package org.webrtc;
12
13/**
14 * CryptoOptions defines advanced cryptographic settings for native WebRTC.
15 * These settings must be passed into RTCConfiguration. WebRTC is secur by
16 * default and you should not need to set any of these options unless you are
17 * specifically looking for an additional crypto feature such as AES_GCM
18 * support. This class is the Java binding of native api/crypto/cryptooptions.h
19 */
20public final class CryptoOptions {
21 /**
22 * SRTP Related Peer Connection Options.
23 */
24 public final class Srtp {
25 /**
26 * Enable GCM crypto suites from RFC 7714 for SRTP. GCM will only be used
27 * if both sides enable it
28 */
29 private final boolean enableGcmCryptoSuites;
30 /**
31 * If set to true, the (potentially insecure) crypto cipher
Mirko Bonadei7750d802021-07-26 17:27:42 +020032 * kSrtpAes128CmSha1_32 will be included in the list of supported ciphers
Benjamin Wright8c27cca2018-10-25 10:16:44 -070033 * during negotiation. It will only be used if both peers support it and no
34 * other ciphers get preferred.
35 */
36 private final boolean enableAes128Sha1_32CryptoCipher;
37 /**
38 * If set to true, encrypted RTP header extensions as defined in RFC 6904
39 * will be negotiated. They will only be used if both peers support them.
40 */
41 private final boolean enableEncryptedRtpHeaderExtensions;
42
43 private Srtp(boolean enableGcmCryptoSuites, boolean enableAes128Sha1_32CryptoCipher,
44 boolean enableEncryptedRtpHeaderExtensions) {
45 this.enableGcmCryptoSuites = enableGcmCryptoSuites;
46 this.enableAes128Sha1_32CryptoCipher = enableAes128Sha1_32CryptoCipher;
47 this.enableEncryptedRtpHeaderExtensions = enableEncryptedRtpHeaderExtensions;
48 }
49
50 @CalledByNative("Srtp")
51 public boolean getEnableGcmCryptoSuites() {
52 return enableGcmCryptoSuites;
53 }
54
55 @CalledByNative("Srtp")
56 public boolean getEnableAes128Sha1_32CryptoCipher() {
57 return enableAes128Sha1_32CryptoCipher;
58 }
59
60 @CalledByNative("Srtp")
61 public boolean getEnableEncryptedRtpHeaderExtensions() {
62 return enableEncryptedRtpHeaderExtensions;
63 }
64 }
65
66 /**
67 * Options to be used when the FrameEncryptor / FrameDecryptor APIs are used.
68 */
69 public final class SFrame {
70 /**
71 * If set all RtpSenders must have an FrameEncryptor attached to them before
72 * they are allowed to send packets. All RtpReceivers must have a
73 * FrameDecryptor attached to them before they are able to receive packets.
74 */
75 private final boolean requireFrameEncryption;
76
77 private SFrame(boolean requireFrameEncryption) {
78 this.requireFrameEncryption = requireFrameEncryption;
79 }
80
81 @CalledByNative("SFrame")
82 public boolean getRequireFrameEncryption() {
83 return requireFrameEncryption;
84 }
85 }
86
87 private final Srtp srtp;
88 private final SFrame sframe;
89
90 private CryptoOptions(boolean enableGcmCryptoSuites, boolean enableAes128Sha1_32CryptoCipher,
91 boolean enableEncryptedRtpHeaderExtensions, boolean requireFrameEncryption) {
92 this.srtp = new Srtp(
93 enableGcmCryptoSuites, enableAes128Sha1_32CryptoCipher, enableEncryptedRtpHeaderExtensions);
94 this.sframe = new SFrame(requireFrameEncryption);
95 }
96
97 public static Builder builder() {
98 return new Builder();
99 }
100
101 @CalledByNative
102 public Srtp getSrtp() {
103 return srtp;
104 }
105
106 @CalledByNative
107 public SFrame getSFrame() {
108 return sframe;
109 }
110
111 public static class Builder {
Patrik Höglundbd6ffaf2018-11-16 14:55:16 +0100112 private boolean enableGcmCryptoSuites;
113 private boolean enableAes128Sha1_32CryptoCipher;
114 private boolean enableEncryptedRtpHeaderExtensions;
115 private boolean requireFrameEncryption;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700116
117 private Builder() {}
118
119 public Builder setEnableGcmCryptoSuites(boolean enableGcmCryptoSuites) {
120 this.enableGcmCryptoSuites = enableGcmCryptoSuites;
121 return this;
122 }
123
124 public Builder setEnableAes128Sha1_32CryptoCipher(boolean enableAes128Sha1_32CryptoCipher) {
125 this.enableAes128Sha1_32CryptoCipher = enableAes128Sha1_32CryptoCipher;
126 return this;
127 }
128
129 public Builder setEnableEncryptedRtpHeaderExtensions(
130 boolean enableEncryptedRtpHeaderExtensions) {
131 this.enableEncryptedRtpHeaderExtensions = enableEncryptedRtpHeaderExtensions;
132 return this;
133 }
134
135 public Builder setRequireFrameEncryption(boolean requireFrameEncryption) {
136 this.requireFrameEncryption = requireFrameEncryption;
137 return this;
138 }
139
140 public CryptoOptions createCryptoOptions() {
141 return new CryptoOptions(enableGcmCryptoSuites, enableAes128Sha1_32CryptoCipher,
142 enableEncryptedRtpHeaderExtensions, requireFrameEncryption);
143 }
144 }
145}