-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfidoAuthenticationResponse.go
77 lines (61 loc) · 2.3 KB
/
fidoAuthenticationResponse.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package k6fido
import (
"crypto/sha256"
"encoding/base64"
"encoding/json"
"fmt"
)
type FidoAuthenticationResponseBuilder interface {
Build(aaid string, overriddenSignature string, signatureSignData string,
privKey string, pubKey string) (*SendUafResponse, error)
}
type FidoAuthenticationResponse struct {
facetId string
returnUafRequest ReturnUafRequest
isKeyRotationSupported bool
username string
}
func (b *FidoAuthenticationResponse) Build(aaid string, overriddenSignature string, signatureSignData string,
privKey string, pubKey string, keyId string) (*SendUafResponse, error) {
var regRequestEntries []RegRequestEntry
err := json.Unmarshal([]byte(b.returnUafRequest.UafRequest), ®RequestEntries)
if err != nil {
return nil, fmt.Errorf("Error unmarshalling uafRequest: %v", err)
}
regRequestEntry := regRequestEntries[0]
finalChallengeParams := FinalChallengeParams{
AppID: regRequestEntry.Header.AppID,
Challenge: regRequestEntry.Challenge,
FacetID: b.facetId,
}
base64FcByte, _ := json.Marshal(finalChallengeParams)
base64FcString := base64.URLEncoding.EncodeToString(base64FcByte)
finalChallengeParamsHash := sha256.Sum256([]byte(base64FcString))
fidoAuthenticationSignedAssertions, err := NewFidoAuthenticationSignedAssertions(aaid, pubKey, privKey, overriddenSignature, signatureSignData, finalChallengeParamsHash[:], keyId)
if err != nil {
return nil, fmt.Errorf("Failed to build authentication assertions: %v", err)
}
assertions := []AuthenticatorSignAssertion{*fidoAuthenticationSignedAssertions}
regResponseEntry := FidoResponseEntry{
Header: regRequestEntry.Header,
Assertions: assertions,
Base64FcParams: base64FcString,
}
regResponseEntries := []FidoResponseEntry{regResponseEntry}
responseJson, err := json.Marshal(regResponseEntries)
if err != nil {
return nil, fmt.Errorf("Error marshalling registration response entries: %v", err)
}
context := make(map[string]interface{})
context["username"] = b.username
contextJson, err := json.Marshal(context)
if err != nil {
return nil, fmt.Errorf("Error marshalling context: %v", err)
}
contextString := string(contextJson)
sendUafResponse := &SendUafResponse{
UafResponse: string(responseJson),
Context: contextString,
}
return sendUafResponse, nil
}