Skip to content

Commit

Permalink
Merge pull request #64 from silinternational/develop
Browse files Browse the repository at this point in the history
Release 2.2.0 -- return key_handle_hash from login
  • Loading branch information
briskt authored Oct 17, 2023
2 parents a5d9b36 + f7ff0ba commit d94260f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
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

0 comments on commit d94260f

Please sign in to comment.