Skip to content

Commit

Permalink
feat: accept transports information (#8)
Browse files Browse the repository at this point in the history
Allows presenting the result from AuthenticatorAttestationResponse.getTransports() to the library. Not supported by all browsers.

See https://developer.mozilla.org/en-US/docs/Web/API/AuthenticatorAttestationResponse/getTransports.
  • Loading branch information
james-d-elliott committed Dec 13, 2021
1 parent 9c370fd commit 738efed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 12 additions & 2 deletions protocol/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ type ParsedPublicKeyCredential struct {
type CredentialCreationResponse struct {
PublicKeyCredential
AttestationResponse AuthenticatorAttestationResponse `json:"response"`
Transport []string `json:"transports,omitempty"`
}

type ParsedCredentialCreationData struct {
ParsedPublicKeyCredential
Response ParsedAttestationResponse
Raw CredentialCreationResponse
Response ParsedAttestationResponse
Raw CredentialCreationResponse
Transport []AuthenticatorTransport `json:"transports,omitempty"`
}

func ParseCredentialCreationResponse(response *http.Request) (*ParsedCredentialCreationData, error) {
Expand Down Expand Up @@ -88,6 +90,14 @@ func ParseCredentialCreationResponseBody(body io.Reader) (*ParsedCredentialCreat
pcc.ID, pcc.RawID, pcc.Type, pcc.ClientExtensionResults = ccr.ID, ccr.RawID, ccr.Type, ccr.ClientExtensionResults
pcc.Raw = ccr

for _, t := range ccr.Transport {
transport := AuthenticatorTransport(t)
switch transport {
case USB, BLE, NFC, Internal:
pcc.Transport = append(pcc.Transport, transport)
}
}

parsedAttestationResponse, err := ccr.AttestationResponse.Parse()
if err != nil {
return nil, ErrParsingData.WithDetails("Error parsing attestation response")
Expand Down
3 changes: 3 additions & 0 deletions webauthn/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type Credential struct {
PublicKey []byte
// The attestation format used (if any) by the authenticator when creating the credential.
AttestationType string
// The transport types the authenticator supports.
Transport []protocol.AuthenticatorTransport
// The Authenticator information for a given certificate
Authenticator Authenticator
}
Expand All @@ -25,6 +27,7 @@ func MakeNewCredential(c *protocol.ParsedCredentialCreationData) (*Credential, e
ID: c.Response.AttestationObject.AuthData.AttData.CredentialID,
PublicKey: c.Response.AttestationObject.AuthData.AttData.CredentialPublicKey,
AttestationType: c.Response.AttestationObject.Format,
Transport: c.Transport,
Authenticator: Authenticator{
AAGUID: c.Response.AttestationObject.AuthData.AttData.AAGUID,
SignCount: c.Response.AttestationObject.AuthData.Counter,
Expand Down

0 comments on commit 738efed

Please sign in to comment.