-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathassertion.go
73 lines (60 loc) · 2.4 KB
/
assertion.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
package appvalidate
import (
"encoding/json"
"time"
"github.com/tidepool-org/platform/structure"
appAssert "github.com/bas-d/appattest/assertion"
appUtils "github.com/bas-d/appattest/utils"
)
// AssertionVerify is the expected request body used by clients to complete
// the assertion process. Assertion can only be done after attestation is
// completed. The Assertion should be the base64 encoding of the binary CBOR
// data returned from the iOS APIs.
type AssertionVerify struct {
UserID string `json:"-"`
KeyID string `json:"keyId"`
ClientData AssertionClientData `json:"clientData"`
Assertion string `json:"assertion"`
}
// AssertionUpdate contains the assertion fields to update in an AppValidation
// to pass to a repository.
type AssertionUpdate struct {
Challenge string `bson:"assertionChallenge,omitempty"`
VerifiedTime time.Time `bson:"assertionVerifiedTime,omitempty"`
AssertionCounter uint32 `bson:"assertionCounter,omitempty"`
}
type AssertionResponse struct {
Data any `json:"data"`
}
type AssertionClientData struct {
Challenge string `json:"challenge"`
Partner string `json:"partner"` // Which partner are we requesting a secret from
PartnerData json.RawMessage `json:"partnerData"` // Data to send to partner - This is a RawMessage because it is partner specific. The validation of this is delayed until later.
}
func NewAssertionVerify(userID string) *AssertionVerify {
return &AssertionVerify{
UserID: userID,
}
}
func (av *AssertionVerify) Validate(v structure.Validator) {
v.String("assertion", &av.Assertion).NotEmpty().Matches(base64Chars)
v.String("clientData.challenge", &av.ClientData.Challenge).NotEmpty()
v.String("clientData.partner", &av.ClientData.Partner).OneOf(partners...)
v.String("userId", &av.UserID).NotEmpty()
v.String("keyId", &av.KeyID).NotEmpty()
}
func transformAssertion(av *AssertionVerify) (*appAssert.AuthenticatorAssertionResponse, error) {
clientDataRaw, err := json.Marshal(av.ClientData)
if err != nil {
return nil, err
}
var assertion appUtils.URLEncodedBase64
assertionRaw := b64StdEncodingToURLEncoding(av.Assertion)
if err := assertion.UnmarshalJSON([]byte(assertionRaw)); err != nil {
return nil, err
}
return &appAssert.AuthenticatorAssertionResponse{
RawClientData: appUtils.URLEncodedBase64(clientDataRaw),
Assertion: assertion,
}, nil
}