Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions dtlstransport_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,31 @@
underlying: underlying,
}
}

func (t *DTLSTransport) GetRemoteCertificate() []byte {
if t.underlying.IsNull() || t.underlying.IsUndefined() {
return nil
}

Check warning on line 41 in dtlstransport_js.go

View check run for this annotation

Codecov / codecov/patch

dtlstransport_js.go#L38-L41

Added lines #L38 - L41 were not covered by tests

// Firefox does not support getRemoteCertificates: https://bugzilla.mozilla.org/show_bug.cgi?id=1805446
jsGet := t.underlying.Get("getRemoteCertificates")
if jsGet.IsUndefined() || jsGet.IsNull() {
return nil
}

Check warning on line 47 in dtlstransport_js.go

View check run for this annotation

Codecov / codecov/patch

dtlstransport_js.go#L44-L47

Added lines #L44 - L47 were not covered by tests

jsCerts := t.underlying.Call("getRemoteCertificates")
if jsCerts.Length() == 0 {
return nil
}

Check warning on line 52 in dtlstransport_js.go

View check run for this annotation

Codecov / codecov/patch

dtlstransport_js.go#L49-L52

Added lines #L49 - L52 were not covered by tests

buf := jsCerts.Index(0)
u8 := js.Global().Get("Uint8Array").New(buf)

if u8.Length() == 0 {
return nil
}

Check warning on line 59 in dtlstransport_js.go

View check run for this annotation

Codecov / codecov/patch

dtlstransport_js.go#L54-L59

Added lines #L54 - L59 were not covered by tests

cert := make([]byte, u8.Length())
js.CopyBytesToGo(cert, u8)
return cert

Check warning on line 63 in dtlstransport_js.go

View check run for this annotation

Codecov / codecov/patch

dtlstransport_js.go#L61-L63

Added lines #L61 - L63 were not covered by tests
}
Loading