-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Implement GetRemoteCertificate
for DTLSTransport
in wasm
#3119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3119 +/- ##
==========================================
- Coverage 78.67% 78.45% -0.22%
==========================================
Files 91 91
Lines 11407 11428 +21
==========================================
- Hits 8974 8966 -8
- Misses 1945 1972 +27
- Partials 488 490 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@talentlessguy that sounds good to me! However you think is best to test it. The WASM stuff can be frustrating. So w/e works I am in support of :) |
This demo in JavaScript works: function bufferToHex(buffer) {
const byteArray = new Uint8Array(buffer)
return Array.from(byteArray)
.map((b) => b.toString(16).padStart(2, '0'))
.join('')
.toUpperCase()
}
async function run() {
const pcConfig = {
iceServers: [{ urls: 'stun:stun.l.google.com:19302' }],
}
const localPC = new RTCPeerConnection(pcConfig)
const remotePC = new RTCPeerConnection(pcConfig)
const stream = await navigator.mediaDevices.getUserMedia({ audio: true })
const [track] = stream.getAudioTracks()
localPC.addTrack(track, stream)
localPC.onicecandidate = (e) => {
if (e.candidate) remotePC.addIceCandidate(e.candidate)
}
remotePC.onicecandidate = (e) => {
if (e.candidate) localPC.addIceCandidate(e.candidate)
}
localPC.onconnectionstatechange = () => {
console.log('Connection state changed:', localPC.connectionState)
if (localPC.connectionState === 'connected') {
const [sender] = localPC.getSenders()
if (sender?.transport instanceof RTCDtlsTransport) {
const dtlsTransport = sender.transport
const certs = dtlsTransport.getRemoteCertificates()
if (certs.length > 0) {
console.log(`Got ${certs.length} remote certificate(s):`) // Got 1 remote certificate
certs.forEach((cert, i) => {
console.log(`Certificate ${i + 1}:\n${bufferToHex(cert)}`) // DER raw cert
})
} else {
console.warn('No remote certificates returned.')
}
} else {
console.warn('DTLS transport not available.')
}
}
}
const offer = await localPC.createOffer()
await localPC.setLocalDescription(offer)
await remotePC.setRemoteDescription(offer)
const answer = await remotePC.createAnswer()
await remotePC.setLocalDescription(answer)
await localPC.setRemoteDescription(answer)
}
run().catch(console.error) Outputs a DER certificate I'll try to write tests based on this demo. I'm also not sure if pion/webrtc implements |
|
I haven't tested it personally yet. I will try to recreate the demo using Go+WASM soon-ish to make sure it works exactly the same, and then write tests that will mock Web APIs |
Description
Implements basic support for
GetRemoteCertificate
usinggetRemoteCertificates
I'm not sure how to write tests for it, do I mock JS globals?
Reference issue
Partially addresses libp2p/go-libp2p#3277