-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
WebAuthn CredentialID field needs to be increased in size #20530
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
Merged
6543
merged 15 commits into
go-gitea:main
from
zeripath:fix-20457-increase-webauthn-credential-field
Jul 30, 2022
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
835cf4c
WebAuthn CredentialID field needs to be increased in size
zeripath 8b0716b
Merge remote-tracking branch 'origin/main' into fix-20457-increase-we…
zeripath 46fced8
Move to use webauthnCredential CredentialID as bytes
zeripath 919d517
fix test
zeripath 248b5ce
i hate our linter
zeripath 72cd759
of course MSSQL has to be difficult
zeripath 25388aa
i hate our linter
zeripath 3eb1d13
and change the lookup function
zeripath da04731
and change the lookup function
zeripath 9f15fed
separate the out the droptablecolumns into another migration
zeripath 0e675c9
Update models/migrations/v223.go
zeripath 7926dac
Update webauthn.go
zeripath 197c197
nit
6543 ebfa23a
Merge branch 'main' into fix-20457-increase-webauthn-credential-field
6543 550160c
Merge branch 'main' into fix-20457-increase-webauthn-credential-field
6543 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...igrations/fixtures/Test_storeWebauthnCredentialIDAsBytes/expected_webauthn_credential.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
- | ||
id: 1 | ||
credential_id: "TVHE44TOH7DF7V48SEAIT3EMMJ7TGBOQ289E5AQB34S98LFCUFJ7U2NAVI8RJG6K2F4TC8AQ8KBNO7AGEOQOL9NE43GR63HTEHJSLOG=" | ||
- | ||
id: 2 | ||
credential_id: "051CLMMKB62S6M9M2A4H54K7MMCQALFJ36G4TGB2S9A47APLTILU6C6744CEBG4EKCGV357N21BSLH8JD33GQMFAR6DQ70S76P34J6FR=" | ||
- | ||
id: 4 | ||
credential_id: "APU4B1NDTEVTEM60V4T0FRL7SRJMO9KIE2AKFQ8JDGTQ7VHFI41FDEFTDLBVQEAE4ER49QV2GTGVFDNBO31BPOA3OQN6879OT6MTU3G=" |
31 changes: 31 additions & 0 deletions
31
models/migrations/fixtures/Test_storeWebauthnCredentialIDAsBytes/webauthn_credential.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
- | ||
id: 1 | ||
lower_name: "u2fkey-correctly-migrated" | ||
name: "u2fkey-correctly-migrated" | ||
user_id: 1 | ||
credential_id: "TVHE44TOH7DF7V48SEAIT3EMMJ7TGBOQ289E5AQB34S98LFCUFJ7U2NAVI8RJG6K2F4TC8AQ8KBNO7AGEOQOL9NE43GR63HTEHJSLOG=" | ||
public_key: 0x040d0967a2cad045011631187576492a0beb5b377954b4f694c5afc8bdf25270f87f09a9ab6ce9c282f447ba71b2f2bae2105b32b847e0704f310f48644e3eddf2 | ||
attestation_type: 'fido-u2f' | ||
sign_count: 1 | ||
clone_warning: false | ||
- | ||
id: 2 | ||
lower_name: "non-u2f-key" | ||
name: "non-u2f-key" | ||
user_id: 1 | ||
credential_id: "051CLMMKB62S6M9M2A4H54K7MMCQALFJ36G4TGB2S9A47APLTILU6C6744CEBG4EKCGV357N21BSLH8JD33GQMFAR6DQ70S76P34J6FR" | ||
public_key: 0x040d0967a2cad045011631187576492a0beb5b377954b4f694c5afc8bdf25270f87f09a9ab6ce9c282f447ba71b2f2bae2105b32b847e0704f310f48644e3eddf2 | ||
attestation_type: 'none' | ||
sign_count: 1 | ||
clone_warning: false | ||
- | ||
id: 4 | ||
lower_name: "packed-key" | ||
name: "packed-key" | ||
user_id: 1 | ||
credential_id: "APU4B1NDTEVTEM60V4T0FRL7SRJMO9KIE2AKFQ8JDGTQ7VHFI41FDEFTDLBVQEAE4ER49QV2GTGVFDNBO31BPOA3OQN6879OT6MTU3G=" | ||
public_key: 0x040d0967a2cad045011631187576492a0beb5b377954b4f694c5afc8bdf25270f87f09a9ab6ce9c282f447ba71b2f2bae2105b32b847e0704f310f48644e3eddf2 | ||
attestation_type: 'fido-u2f' | ||
sign_count: 1 | ||
clone_warning: false | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package migrations | ||
|
||
import ( | ||
"encoding/base32" | ||
"fmt" | ||
|
||
"code.gitea.io/gitea/modules/timeutil" | ||
|
||
"xorm.io/xorm" | ||
) | ||
|
||
func storeWebauthnCredentialIDAsBytes(x *xorm.Engine) error { | ||
// Create webauthnCredential table | ||
type webauthnCredential struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
Name string | ||
LowerName string `xorm:"unique(s)"` | ||
UserID int64 `xorm:"INDEX unique(s)"` | ||
CredentialID string `xorm:"INDEX VARCHAR(410)"` | ||
CredentialIDBytes []byte `xorm:"INDEX VARBINARY(1024)"` // CredentialID is at most 1023 bytes as per spec released 20 July 2022 | ||
PublicKey []byte | ||
AttestationType string | ||
AAGUID []byte | ||
SignCount uint32 `xorm:"BIGINT"` | ||
CloneWarning bool | ||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` | ||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` | ||
} | ||
if err := x.Sync2(&webauthnCredential{}); err != nil { | ||
return err | ||
} | ||
|
||
var start int | ||
creds := make([]*webauthnCredential, 0, 50) | ||
for { | ||
err := x.Select("id, credential_id").OrderBy("id").Limit(50, start).Find(&creds) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = func() error { | ||
sess := x.NewSession() | ||
defer sess.Close() | ||
if err := sess.Begin(); err != nil { | ||
return fmt.Errorf("unable to allow start session. Error: %w", err) | ||
} | ||
for _, cred := range creds { | ||
cred.CredentialIDBytes, err = base32.HexEncoding.DecodeString(cred.CredentialID) | ||
if err != nil { | ||
return fmt.Errorf("unable to parse credential id %s for credential[%d]: %w", cred.CredentialID, cred.ID, err) | ||
} | ||
count, err := sess.ID(cred.ID).Cols("credential_id_bytes").Update(cred) | ||
if count != 1 || err != nil { | ||
return fmt.Errorf("unable to update credential id bytes for credential[%d]: %d,%w", cred.ID, count, err) | ||
} | ||
} | ||
return sess.Commit() | ||
}() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(creds) < 50 { | ||
break | ||
} | ||
start += 50 | ||
creds = creds[:0] | ||
} | ||
|
||
// Drop the old credential ID | ||
sess := x.NewSession() | ||
defer sess.Close() | ||
|
||
if err := dropTableColumns(sess, "webauthn_credential", "credential_id"); err != nil { | ||
return fmt.Errorf("unable to drop old credentialID column: %w", err) | ||
} | ||
return sess.Commit() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package migrations | ||
|
||
import ( | ||
"encoding/base32" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_storeWebauthnCredentialIDAsBytes(t *testing.T) { | ||
// Create webauthnCredential table | ||
type WebauthnCredential struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
Name string | ||
LowerName string `xorm:"unique(s)"` | ||
UserID int64 `xorm:"INDEX unique(s)"` | ||
CredentialID string `xorm:"INDEX VARCHAR(410)"` | ||
PublicKey []byte | ||
AttestationType string | ||
AAGUID []byte | ||
SignCount uint32 `xorm:"BIGINT"` | ||
CloneWarning bool | ||
} | ||
|
||
type ExpectedWebauthnCredential struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
CredentialID string // CredentialID is at most 1023 bytes as per spec released 20 July 2022 | ||
} | ||
|
||
type ConvertedWebauthnCredential struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
CredentialIDBytes []byte `xorm:"INDEX VARBINARY(1024)"` // CredentialID is at most 1023 bytes as per spec released 20 July 2022 | ||
} | ||
|
||
// Prepare and load the testing database | ||
x, deferable := prepareTestEnv(t, 0, new(WebauthnCredential), new(ExpectedWebauthnCredential)) | ||
if x == nil || t.Failed() { | ||
defer deferable() | ||
return | ||
} | ||
defer deferable() | ||
6543 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if err := storeWebauthnCredentialIDAsBytes(x); err != nil { | ||
assert.NoError(t, err) | ||
return | ||
} | ||
|
||
expected := []ExpectedWebauthnCredential{} | ||
if err := x.Table("expected_webauthn_credential").Asc("id").Find(&expected); !assert.NoError(t, err) { | ||
return | ||
} | ||
|
||
got := []ConvertedWebauthnCredential{} | ||
if err := x.Table("webauthn_credential").Select("id, credential_id_bytes").Asc("id").Find(&got); !assert.NoError(t, err) { | ||
return | ||
} | ||
|
||
for i, e := range expected { | ||
credIDBytes, _ := base32.HexEncoding.DecodeString(e.CredentialID) | ||
assert.Equal(t, credIDBytes, got[i].CredentialIDBytes) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.