Skip to content

Commit

Permalink
fix(protocol): previous unmarshal functionality broken (#180)
Browse files Browse the repository at this point in the history
This fixes an CBOR unmarshalling issue that was caused without properly reading the upgrade notes for a dependency upgrade. We added a note to ensure we investigate the specific use case for the new unmarshal method later.
  • Loading branch information
james-d-elliott authored Nov 18, 2023
1 parent c3b982f commit 68d2368
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 3 additions & 5 deletions protocol/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,14 @@ func (a *AuthenticatorData) unmarshalAttestedData(rawAuthData []byte) (err error
}

// Unmarshall the credential's Public Key into CBOR encoding.
func unmarshalCredentialPublicKey(keyBytes []byte) ([]byte, error) {
func unmarshalCredentialPublicKey(keyBytes []byte) (rawBytes []byte, err error) {
var m interface{}

err := webauthncbor.Unmarshal(keyBytes, &m)
if err != nil {
if err = webauthncbor.Unmarshal(keyBytes, &m); err != nil {
return nil, err
}

rawBytes, err := webauthncbor.Marshal(m)
if err != nil {
if rawBytes, err = webauthncbor.Marshal(m); err != nil {
return nil, err
}

Expand Down
5 changes: 4 additions & 1 deletion protocol/webauthncbor/webauthncbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ var ctap2CBOREncMode, _ = cbor.CTAP2EncOptions().EncMode()
// following the CTAP2 canonical CBOR encoding form.
// (https://fidoalliance.org/specs/fido-v2.0-ps-20190130/fido-client-to-authenticator-protocol-v2.0-ps-20190130.html#message-encoding)
func Unmarshal(data []byte, v interface{}) error {
return ctap2CBORDecMode.Unmarshal(data, v)
// TODO (james-d-elliott): investigate the specific use case for Unmarshal vs UnmarshalFirst to determine the edge cases where this may be useful.
_, err := ctap2CBORDecMode.UnmarshalFirst(data, v)

return err
}

// Marshal encodes the value pointed to by v
Expand Down
1 change: 1 addition & 0 deletions protocol/webauthncose/webauthncose.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ func HasherFromCOSEAlg(coseAlg COSEAlgorithmIdentifier) func() hash.Hash {
// ParsePublicKey figures out what kind of COSE material was provided and create the data for the new key.
func ParsePublicKey(keyBytes []byte) (interface{}, error) {
pk := PublicKeyData{}
// TODO (james-d-elliott): investigate the ignored errors.
webauthncbor.Unmarshal(keyBytes, &pk)

switch COSEKeyType(pk.KeyType) {
Expand Down

0 comments on commit 68d2368

Please sign in to comment.