Skip to content

Commit 0bbfb3c

Browse files
authored
Merge pull request #60 from silinternational/develop
Release v2.1.1 - Cleanup IAM policy, update webauthn Go library
2 parents 7b8e066 + a291459 commit 0bbfb3c

File tree

8 files changed

+62
-1175
lines changed

8 files changed

+62
-1175
lines changed

fixtures_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package mfa
33
import (
44
"github.com/aws/aws-sdk-go/aws"
55
"github.com/aws/aws-sdk-go/service/dynamodb"
6-
"github.com/duo-labs/webauthn/webauthn"
6+
"github.com/go-webauthn/webauthn/webauthn"
77
)
88

99
type baseTestConfig struct {
@@ -14,7 +14,6 @@ type baseTestConfig struct {
1414
}
1515

1616
func getDBConfig(ms *MfaSuite) baseTestConfig {
17-
1817
awsConfig := testAwsConfig()
1918
envCfg := testEnvConfig(awsConfig)
2019
localStorage, err := NewStorage(&awsConfig)
@@ -24,6 +23,7 @@ func getDBConfig(ms *MfaSuite) baseTestConfig {
2423
RPDisplayName: "TestRPName", // Display Name for your site
2524
RPID: "111.11.11.11", // Generally the FQDN for your site
2625
Debug: true,
26+
RPOrigins: []string{testRpOrigin},
2727
})
2828

2929
ms.NoError(err, "failed creating new webAuthnClient for test")

go.mod

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,29 @@ go 1.18
55
require (
66
github.com/aws/aws-lambda-go v1.37.0
77
github.com/aws/aws-sdk-go v1.44.201
8-
github.com/duo-labs/webauthn v0.0.0-20221205164246-ebaf9b74c6ec
98
github.com/fxamacker/cbor/v2 v2.4.0
9+
github.com/go-webauthn/webauthn v0.8.6
1010
github.com/gorilla/mux v1.8.0
1111
github.com/kelseyhightower/envconfig v1.4.0
1212
github.com/pkg/errors v0.9.1
1313
github.com/satori/go.uuid v1.2.0
14-
github.com/stretchr/testify v1.8.1
15-
golang.org/x/crypto v0.6.0
14+
github.com/stretchr/testify v1.8.4
15+
golang.org/x/crypto v0.11.0
1616
)
1717

1818
require (
19-
github.com/cloudflare/cfssl v1.6.3 // indirect
2019
github.com/davecgh/go-spew v1.1.1 // indirect
21-
github.com/golang-jwt/jwt/v4 v4.4.3 // indirect
22-
github.com/google/certificate-transparency-go v1.1.4 // indirect
20+
github.com/go-webauthn/x v0.1.4 // indirect
21+
github.com/golang-jwt/jwt/v5 v5.0.0 // indirect
22+
github.com/google/go-tpm v0.9.0 // indirect
2323
github.com/google/uuid v1.3.0 // indirect
2424
github.com/jmespath/go-jmespath v0.4.0 // indirect
25+
github.com/kr/text v0.2.0 // indirect
2526
github.com/mitchellh/mapstructure v1.5.0 // indirect
2627
github.com/pmezard/go-difflib v1.0.0 // indirect
2728
github.com/x448/float16 v0.8.4 // indirect
29+
golang.org/x/sys v0.10.0 // indirect
2830
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
31+
gopkg.in/yaml.v2 v2.4.0 // indirect
2932
gopkg.in/yaml.v3 v3.0.1 // indirect
3033
)

go.sum

Lines changed: 14 additions & 1126 deletions
Large diffs are not rendered by default.

terraform/lambda-role-policy.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
"dynamodb:GetItem"
3636
],
3737
"Resource": [
38-
"arn:aws:dynamodb:*:${aws_account}:table/${api_key_table}",
39-
"arn:aws:dynamodb:*:${aws_account}:table/${api_key_table}_global"
38+
"arn:aws:dynamodb:*:${aws_account}:table/${api_key_table}"
4039
],
4140
"Effect": "Allow"
4241
},
@@ -51,8 +50,7 @@
5150
"dynamodb:DeleteItem"
5251
],
5352
"Resource": [
54-
"arn:aws:dynamodb:*:${aws_account}:table/${webauthn_table}",
55-
"arn:aws:dynamodb:*:${aws_account}:table/${webauthn_table}_global"
53+
"arn:aws:dynamodb:*:${aws_account}:table/${webauthn_table}"
5654
],
5755
"Effect": "Allow"
5856
}

u2fsimulator/u2fsimulator.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import (
1616
"strings"
1717
"time"
1818

19-
"github.com/duo-labs/webauthn/protocol"
20-
"github.com/duo-labs/webauthn/protocol/webauthncbor"
21-
"github.com/duo-labs/webauthn/protocol/webauthncose"
19+
"github.com/go-webauthn/webauthn/protocol"
20+
"github.com/go-webauthn/webauthn/protocol/webauthncbor"
21+
"github.com/go-webauthn/webauthn/protocol/webauthncose"
2222
)
2323

2424
const (
@@ -120,7 +120,7 @@ func getPrivateKey() *ecdsa.PrivateKey {
120120
}
121121

122122
// GetAuthDataAndPrivateKey return the authentication data as a string and as a byte slice
123-
// and also returns the private key
123+
// and also returns the private key
124124
func GetAuthDataAndPrivateKey(rpID, keyHandle string) (authDataStr string, authData []byte, privateKey *ecdsa.PrivateKey) {
125125
// Add in the RP ID Hash (32 bytes)
126126
RPIDHash := sha256.Sum256([]byte(rpID))
@@ -197,7 +197,6 @@ func getCertBytes(privateKey *ecdsa.PrivateKey, serialNumber *big.Int, certReade
197197
// GetASN1Signature signs a hash (which should be the result of hashing a larger message)
198198
// using the private key.
199199
func GetASN1Signature(notRandom io.Reader, privateKey *ecdsa.PrivateKey, sha256Digest []byte) (DsaSignature, []byte) {
200-
201200
r, s, err := ecdsa.Sign(notRandom, privateKey, sha256Digest[:])
202201
if err != nil {
203202
panic("error generating signature: " + err.Error())
@@ -214,11 +213,9 @@ func GetASN1Signature(notRandom io.Reader, privateKey *ecdsa.PrivateKey, sha256D
214213
}
215214

216215
// getSignatureForAttObject starts with byte(0) and appends the sha256 sum of the rpOrigin and of the clientData
217-
// and then appends the keyHandle and an elliptic Marshalled version of the public key
218-
// It does a sha256 sum of that and creates a dsa signature of it with the private key and without using any
219-
// randomizing
216+
// and then appends the keyHandle and an elliptic Marshalled version of the public key. It does a sha256 sum of
217+
// that and creates a dsa signature of it with the private key and without using any randomizing.
220218
func getSignatureForAttObject(notRandom io.Reader, clientData []byte, keyHandle string, privateKey *ecdsa.PrivateKey, rpOrigin string) []byte {
221-
222219
appParam := sha256.Sum256([]byte(rpOrigin))
223220
challenge := sha256.Sum256(clientData)
224221

@@ -284,17 +281,22 @@ type U2fRegistrationResponse struct {
284281
}
285282

286283
// U2fRegistration is intended to assist with automated testing by
287-
// returning to an api server something similar to what a client
288-
// would return following a registration ceremony with a U2F key
284+
// returning to an api server something similar to what a client
285+
// would return following a registration ceremony with a U2F key
286+
//
289287
// It expects a POST call with the following elements in the body/form
288+
//
290289
// "challenge"
291290
// "keyHandle" (optional)
292-
// (Although the api server wouldn't normally deal with a challenge and keyHandle,
293-
// including them here allows for more predictability with the test results.)
291+
//
292+
// (Although the api server wouldn't normally deal with a challenge and keyHandle,
293+
// including them here allows for more predictability with the test results.)
294+
//
294295
// It also expects the following headers to be set on the request
296+
//
295297
// "x-mfa-RPID"
296-
// "x-mfa-RPOrigin"
297-
// "x-mfa-UserUUID"
298+
// "x-mfa-RPOrigin"
299+
// "x-mfa-UserUUID"
298300
func U2fRegistration(w http.ResponseWriter, r *http.Request) {
299301
reqBody, err := io.ReadAll(r.Body)
300302
if err != nil {

user.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010
"log"
1111
"net/http"
1212

13-
cbor "github.com/fxamacker/cbor/v2"
13+
"github.com/fxamacker/cbor/v2"
1414
"github.com/pkg/errors"
1515

16-
"github.com/duo-labs/webauthn/protocol"
17-
"github.com/duo-labs/webauthn/protocol/webauthncose"
18-
"github.com/duo-labs/webauthn/webauthn"
16+
"github.com/go-webauthn/webauthn/protocol"
17+
"github.com/go-webauthn/webauthn/protocol/webauthncose"
18+
"github.com/go-webauthn/webauthn/webauthn"
1919
)
2020

2121
const (
@@ -133,12 +133,10 @@ func (u *DynamoUser) saveNewCredential(credential webauthn.Credential) error {
133133
return u.encryptAndStoreCredentials()
134134
}
135135

136-
// DeleteCredential expects a hashed-encoded credential id.
137-
// It finds a matching credential for that user and saves the user
138-
// without that credential included.
139-
// Alternatively, if the given credential id indicates that a legacy U2F key should be removed
140-
// (e.g. by matching the string "u2f")
141-
// then that user is saved with all of its legacy u2f fields blanked out.
136+
// DeleteCredential expects a hashed-encoded credential id. It finds a matching credential for that user and saves the
137+
// user without that credential included. Alternatively, if the given credential id indicates that a legacy U2F key
138+
// should be removed (e.g. by matching the string "u2f") then that user is saved with all of its legacy u2f fields
139+
// blanked out.
142140
func (u *DynamoUser) DeleteCredential(credIDHash string) (int, error) {
143141
// load to be sure working with the latest data
144142
err := u.Load()
@@ -371,7 +369,7 @@ func (u *DynamoUser) FinishLogin(r *http.Request) (*webauthn.Credential, error)
371369
}
372370

373371
// there is an issue with URLEncodeBase64.UnmarshalJSON and null values
374-
// see https://github.com/duo-labs/webauthn/issues/69
372+
// see https://github.com/go-webauthn/webauthn/issues/69
375373
// null byte sequence is []byte{158,233,101}
376374
if isNullByteSlice(parsedResponse.Response.UserHandle) {
377375
parsedResponse.Response.UserHandle = nil

webauthn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"net/http"
1111
"strings"
1212

13-
"github.com/duo-labs/webauthn/protocol"
14-
"github.com/duo-labs/webauthn/webauthn"
13+
"github.com/go-webauthn/webauthn/protocol"
14+
"github.com/go-webauthn/webauthn/webauthn"
1515
"github.com/gorilla/mux"
1616
uuid "github.com/satori/go.uuid"
1717
)

webauthn_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515

1616
"github.com/aws/aws-sdk-go/aws"
1717
"github.com/aws/aws-sdk-go/service/dynamodb"
18-
"github.com/duo-labs/webauthn/protocol"
19-
"github.com/duo-labs/webauthn/webauthn"
18+
"github.com/go-webauthn/webauthn/protocol"
19+
"github.com/go-webauthn/webauthn/webauthn"
2020
"github.com/gorilla/mux"
2121
"github.com/stretchr/testify/require"
2222

@@ -35,7 +35,7 @@ const (
3535
testRpId = "dKbqkhPJnC90siSSsyDPQCYqlMGpUKA5fyklC2CEHvA"
3636

3737
AssertionTypeFido = "fido-u2f"
38-
testRpOrigin = "localhost"
38+
testRpOrigin = "https://example.com"
3939
)
4040

4141
func getTestAssertionResponse(credID, authData, clientData, attestationObject string) []byte {
@@ -52,7 +52,6 @@ func getTestAssertionResponse(credID, authData, clientData, attestationObject st
5252
}
5353

5454
func getTestAssertionRequest(credID1, authData1, clientData1, attestObject1 string, user *DynamoUser) *http.Request {
55-
5655
assertResp := getTestAssertionResponse(credID1, authData1, clientData1, attestObject1)
5756

5857
body := ioutil.NopCloser(bytes.NewReader(assertResp))
@@ -138,6 +137,7 @@ func (ms *MfaSuite) Test_BeginRegistration() {
138137
RPDisplayName: "TestRPName", // Display Name for your site
139138
RPID: "111.11.11.11", // Generally the FQDN for your site
140139
Debug: true,
140+
RPOrigins: []string{testRpOrigin},
141141
})
142142

143143
ms.NoError(err, "failed creating new webAuthnClient for test")
@@ -429,6 +429,7 @@ func (ms *MfaSuite) Test_BeginLogin() {
429429
RPDisplayName: "TestRPName", // Display Name for your site
430430
RPID: "111.11.11.11", // Generally the FQDN for your site
431431
Debug: true,
432+
RPOrigins: []string{testRpOrigin},
432433
})
433434

434435
ms.NoError(err, "failed creating new webAuthnClient for test")
@@ -629,7 +630,7 @@ func (ms *MfaSuite) Test_FinishLogin() {
629630

630631
signature1 := GenerateAuthenticationSig(authDataBytes1, cdBytes, privateKey1)
631632

632-
var assertionResponse1 = `{
633+
assertionResponse1 := `{
633634
"id":"` + credIDEncoded1 + `",
634635
"rawId":"` + credIDEncoded1 + `",
635636
"type":"public-key",
@@ -651,7 +652,7 @@ func (ms *MfaSuite) Test_FinishLogin() {
651652

652653
signature2 := GenerateAuthenticationSig(authDataBytes2, cdBytes, privateKey1)
653654

654-
var assertionResponse2 = `{
655+
assertionResponse2 := `{
655656
"id":"` + credIDEncoded2 + `",
656657
"rawId":"` + credIDEncoded2 + `",
657658
"type":"public-key",
@@ -768,7 +769,6 @@ func Test_GetPublicKeyAsBytes(t *testing.T) {
768769
want := []byte{4, 6, 214, 26, 66, 24, 173, 50, 249, 174, 188, 167, 158, 81, 153, 174, 135, 222, 147, 153, 116, 209, 27, 16, 127, 233, 183, 236, 149, 105, 147, 84, 94, 138, 214, 31, 142, 253, 63, 17, 232, 200, 228, 33, 96, 172, 95, 227, 235, 203, 196, 73, 134, 227, 177, 108, 60, 40, 190, 118, 9, 6, 237, 18, 103}
769770

770771
assert.Equal(want, got, "incorrect public Key")
771-
772772
}
773773

774774
func Router() *mux.Router {
@@ -802,7 +802,6 @@ func testAuthnMiddleware(next http.Handler) http.Handler {
802802
}
803803

804804
func (ms *MfaSuite) Test_DeleteCredential() {
805-
806805
baseConfigs := getDBConfig(ms)
807806

808807
users := getTestWebauthnUsers(ms, baseConfigs)
@@ -876,7 +875,6 @@ func (ms *MfaSuite) Test_DeleteCredential() {
876875
}
877876
for _, tt := range tests {
878877
ms.T().Run(tt.name, func(t *testing.T) {
879-
880878
request, _ := http.NewRequest("DELETE", fmt.Sprintf("/webauthn/credential/%s", tt.credID), nil)
881879

882880
request.Header.Set("x-mfa-apikey", tt.user.ApiKeyValue)

0 commit comments

Comments
 (0)