Skip to content
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

Allow authentication caller to provide raw hashed challenge #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,20 @@ func authenticateRequest(req *AuthenticateRequest) ([]byte, []byte, error) {
return nil, nil, fmt.Errorf("Error marshaling clientData to json: %s", err)
}

var challengeHash []byte
if req.RawChallenge {
challengeHash, err = websafeDecode(req.Challenge)
if err != nil {
return []byte{}, []byte{}, fmt.Errorf("base64 challenge: %s", err)
}
} else {
challengeHash = sha256(clientJson)
}

// Pack into byte array
// https://fidoalliance.org/specs/fido-u2f-v1.0-nfc-bt-amendment-20150514/fido-u2f-raw-message-formats.html#authentication-request-message---u2f_authenticate
request := butil.Concat(
sha256(clientJson),
challengeHash,
sha256([]byte(req.AppId)),
[]byte{byte(len(keyHandle))},
keyHandle,
Expand Down
4 changes: 4 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ type AuthenticateRequest struct {
// Optional boolean (defaults to false) to use WebAuthn authentication with U2f
// devices
WebAuthn bool

// Optional boolean (defaults to false) that indicates the Challenge string is a raw
// base64 websafe SHA256 hash that should be used directly as the authentication challenge
RawChallenge bool
}

// A response from an Authenticate operation.
Expand Down