Skip to content

Commit c78016b

Browse files
committed
Implement GetRemoteCertificate for DTLSTransport in wasm
1 parent d08789b commit c78016b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

dtlstransport_js.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,31 @@ func (r *DTLSTransport) ICETransport() *ICETransport {
3434
underlying: underlying,
3535
}
3636
}
37+
38+
func (t *DTLSTransport) GetRemoteCertificate() []byte {
39+
if t.underlying.IsNull() || t.underlying.IsUndefined() {
40+
return nil
41+
}
42+
43+
// Firefox does not support getRemoteCertificates: https://bugzilla.mozilla.org/show_bug.cgi?id=1805446
44+
jsGet := t.underlying.Get("getRemoteCertificates")
45+
if jsGet.IsUndefined() || jsGet.IsNull() {
46+
return nil
47+
}
48+
49+
jsCerts := t.underlying.Call("getRemoteCertificates")
50+
if jsCerts.Length() == 0 {
51+
return nil
52+
}
53+
54+
buf := jsCerts.Index(0)
55+
u8 := js.Global().Get("Uint8Array").New(buf)
56+
57+
if u8.Length() == 0 {
58+
return nil
59+
}
60+
61+
cert := make([]byte, u8.Length())
62+
js.CopyBytesToGo(cert, u8)
63+
return cert
64+
}

0 commit comments

Comments
 (0)