Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion webrtc-jni/src/main/cpp/src/JNI_RTCDtlsTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ JNIEXPORT jobject JNICALL Java_dev_onvoid_webrtc_RTCDtlsTransport_getRemoteCerti
auto info = transport->Information();
auto certChain = info.remote_ssl_certificates();

size_t count = certChain->GetSize();
// There is no chain before the handshake has received one.
size_t count = certChain != nullptr ? certChain->GetSize() : 0;

jni::JavaArrayList certificates(env, count);

Expand Down
3 changes: 2 additions & 1 deletion webrtc/src/main/java/dev/onvoid/webrtc/RTCDtlsTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public class RTCDtlsTransport extends NativeObject {

/**
* Returns the certificate chain in use by the remote side, with each
* certificate encoded in PEM format.
* certificate encoded in PEM format. The list is empty until the DTLS
* handshake has received the certificates of the remote side.
*
* @return The certificate chain in use by the remote side.
*/
Expand Down
39 changes: 39 additions & 0 deletions webrtc/src/test/java/dev/onvoid/webrtc/RTCDtlsTransportTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -127,6 +129,43 @@ public void onError(String error) { }
"The replaced observer must not receive further events");
}

@Test
void remoteCertificates() {
List<RTCCertificatePEM> certificates = transport.getRemoteCertificates();

assertFalse(certificates.isEmpty());

for (RTCCertificatePEM certificate : certificates) {
assertTrue(certificate.getCertificate().startsWith("-----BEGIN CERTIFICATE-----"));
}
}

@Test
void remoteCertificatesBeforeHandshake() throws Exception {
TestPeerConnection offerer = new TestPeerConnection(factory);

try {
AudioTrackSource audioSource = factory.createAudioSource(new AudioOptions());
AudioTrack audioTrack = factory.createAudioTrack("audioTrack", audioSource);
RTCRtpSender audioSender = offerer.getPeerConnection()
.addTrack(audioTrack, Collections.singletonList("stream1"));

// Setting the local description creates the transport, which has
// no remote certificates before the handshake. Reading them used
// to crash the VM.
offerer.createOffer();

RTCDtlsTransport dtlsTransport = audioSender.getTransport();
assertNotNull(dtlsTransport);
assertEquals(RTCDtlsTransportState.NEW, dtlsTransport.getState());

assertTrue(dtlsTransport.getRemoteCertificates().isEmpty());
}
finally {
offerer.close();
}
}

@Test
void observerCanUseRtpSender() throws Exception {
// WebRTC reports DTLS states on the network thread, which is also the
Expand Down
Loading