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

Release 2.2.0 -- return key_handle_hash from login #64

Merged
merged 4 commits into from
Oct 17, 2023
Merged
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
10 changes: 8 additions & 2 deletions webauthn.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ type finishRegistrationResponse struct {
KeyHandleHash string `json:"key_handle_hash"`
}

type finishLoginResponse struct {
CredentialID string `json:"credentialId"` // DEPRECATED, use KeyHandleHash instead
KeyHandleHash string `json:"key_handle_hash"`
}

func BeginRegistration(w http.ResponseWriter, r *http.Request) {
user, err := getUserFromContext(r)
if err != nil {
Expand Down Expand Up @@ -120,8 +125,9 @@ func FinishLogin(w http.ResponseWriter, r *http.Request) {
return
}

resp := map[string]string{
"credentialId": string(credential.ID),
resp := finishLoginResponse{
CredentialID: string(credential.ID),
KeyHandleHash: hashAndEncodeKeyHandle(credential.ID),
}

jsonResponse(w, resp, http.StatusOK)
Expand Down
4 changes: 4 additions & 0 deletions webauthn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,11 @@ func (ms *MfaSuite) Test_FinishLogin() {
// Give user two different credentials to see them come through
const credID1 = "11345678-1234-1234-1234-123456789012"
credIDEncoded1 := base64.StdEncoding.EncodeToString([]byte(credID1))
khh1 := hashAndEncodeKeyHandle([]byte(credID1))

const credID2 = "22345678-1234-1234-1234-123456789012"
credIDEncoded2 := base64.StdEncoding.EncodeToString([]byte(credID2))
khh2 := hashAndEncodeKeyHandle([]byte(credID2))

const challenge = "W8GzFU8pGjhoRbWrLDlamAfq_y4S1CZG1VuoeRLARrE"

Expand Down Expand Up @@ -688,13 +690,15 @@ func (ms *MfaSuite) Test_FinishLogin() {
httpReq: reqWithBody1,
wantBodyContains: []string{
`"credentialId":"` + credID1 + `"`,
`"key_handle_hash":"` + khh1 + `"`,
},
},
{
name: "with second credential",
httpReq: reqWithBody2,
wantBodyContains: []string{
`"credentialId":"` + credID2 + `"`,
`"key_handle_hash":"` + khh2 + `"`,
},
},
}
Expand Down