Add certificate gen/set functionality to bring Android closer to JS API
The JS API supports two operations which have never been implemented in the Android counterpart: - generate a new certificate - use this certificate when creating a new PeerConnection Both functions are illustrated in the generateCertificate example code: - https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/generateCertificate Currently, on Android, a new certificate is automatically generated for every PeerConnection with no programmatic way to set a specific certificate. A twin of this feature is already underway for iOS here: - https://webrtc-review.googlesource.com/c/src/+/87303 Work sponsored by |pipe| Bug: webrtc:9546 Change-Id: Iac221517df3ae380aef83c18c9e59b028d709a4f Reviewed-on: https://webrtc-review.googlesource.com/c/89980 Commit-Queue: Sami Kalliomäki <sakal@webrtc.org> Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> Reviewed-by: Steve Anton <steveanton@webrtc.org> Reviewed-by: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#25090}
This commit is contained in:
committed by
Commit Bot
parent
dcc023816e
commit
0213786b39
@ -385,6 +385,7 @@ public class PeerConnection {
|
||||
public IceTransportsType iceTransportsType;
|
||||
public List<IceServer> iceServers;
|
||||
public BundlePolicy bundlePolicy;
|
||||
@Nullable public RtcCertificatePem certificate;
|
||||
public RtcpMuxPolicy rtcpMuxPolicy;
|
||||
public TcpCandidatePolicy tcpCandidatePolicy;
|
||||
public CandidateNetworkPolicy candidateNetworkPolicy;
|
||||
@ -517,6 +518,12 @@ public class PeerConnection {
|
||||
return bundlePolicy;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@CalledByNative("RTCConfiguration")
|
||||
RtcCertificatePem getCertificate() {
|
||||
return certificate;
|
||||
}
|
||||
|
||||
@CalledByNative("RTCConfiguration")
|
||||
RtcpMuxPolicy getRtcpMuxPolicy() {
|
||||
return rtcpMuxPolicy;
|
||||
@ -721,6 +728,10 @@ public class PeerConnection {
|
||||
return nativeGetRemoteDescription();
|
||||
}
|
||||
|
||||
public RtcCertificatePem getCertificate() {
|
||||
return nativeGetCertificate();
|
||||
}
|
||||
|
||||
public DataChannel createDataChannel(String label, DataChannel.Init init) {
|
||||
return nativeCreateDataChannel(label, init);
|
||||
}
|
||||
@ -1107,6 +1118,7 @@ public class PeerConnection {
|
||||
private native long nativeGetNativePeerConnection();
|
||||
private native SessionDescription nativeGetLocalDescription();
|
||||
private native SessionDescription nativeGetRemoteDescription();
|
||||
private native RtcCertificatePem nativeGetCertificate();
|
||||
private native DataChannel nativeCreateDataChannel(String label, DataChannel.Init init);
|
||||
private native void nativeCreateOffer(SdpObserver observer, MediaConstraints constraints);
|
||||
private native void nativeCreateAnswer(SdpObserver observer, MediaConstraints constraints);
|
||||
|
||||
73
sdk/android/api/org/webrtc/RtcCertificatePem.java
Normal file
73
sdk/android/api/org/webrtc/RtcCertificatePem.java
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
package org.webrtc;
|
||||
|
||||
/**
|
||||
* Easily storable/serializable version of a native C++ RTCCertificatePEM.
|
||||
*/
|
||||
public class RtcCertificatePem {
|
||||
/** PEM string representation of the private key. */
|
||||
public final String privateKey;
|
||||
/** PEM string representation of the certificate. */
|
||||
public final String certificate;
|
||||
/** Default expiration time of 30 days. */
|
||||
private static final long DEFAULT_EXPIRY = 60 * 60 * 24 * 30;
|
||||
|
||||
/** Instantiate an RtcCertificatePem object from stored strings. */
|
||||
@CalledByNative
|
||||
public RtcCertificatePem(String privateKey, String certificate) {
|
||||
this.privateKey = privateKey;
|
||||
this.certificate = certificate;
|
||||
}
|
||||
|
||||
@CalledByNative
|
||||
String getPrivateKey() {
|
||||
return privateKey;
|
||||
}
|
||||
|
||||
@CalledByNative
|
||||
String getCertificate() {
|
||||
return certificate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a new RtcCertificatePem with the default settings of KeyType = ECDSA and
|
||||
* expires = 30 days.
|
||||
*/
|
||||
public static RtcCertificatePem generateCertificate() {
|
||||
return nativeGenerateCertificate(PeerConnection.KeyType.ECDSA, DEFAULT_EXPIRY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a new RtcCertificatePem with a custom KeyType and the default setting of
|
||||
* expires = 30 days.
|
||||
*/
|
||||
public static RtcCertificatePem generateCertificate(PeerConnection.KeyType keyType) {
|
||||
return nativeGenerateCertificate(keyType, DEFAULT_EXPIRY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a new RtcCertificatePem with a custom expires and the default setting of
|
||||
* KeyType = ECDSA.
|
||||
*/
|
||||
public static RtcCertificatePem generateCertificate(long expires) {
|
||||
return nativeGenerateCertificate(PeerConnection.KeyType.ECDSA, expires);
|
||||
}
|
||||
|
||||
/** Generate a new RtcCertificatePem with a custom KeyType and a custom expires. */
|
||||
public static RtcCertificatePem generateCertificate(
|
||||
PeerConnection.KeyType keyType, long expires) {
|
||||
return nativeGenerateCertificate(keyType, expires);
|
||||
}
|
||||
|
||||
private static native RtcCertificatePem nativeGenerateCertificate(
|
||||
PeerConnection.KeyType keyType, long expires);
|
||||
}
|
||||
Reference in New Issue
Block a user