Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f3477cb2
authored
Sep 30, 2025
by
Seefs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: blob type
parent
9e552663
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
13 deletions
+19
-13
model/passkey.go
+19
-13
No files found.
model/passkey.go
View file @
f3477cb2
package
model
import
(
"encoding/base64"
"encoding/json"
"errors"
"fmt"
...
...
@@ -21,10 +22,10 @@ var (
type
PasskeyCredential
struct
{
ID
int
`json:"id" gorm:"primaryKey"`
UserID
int
`json:"user_id" gorm:"uniqueIndex;not null"`
CredentialID
[]
byte
`json:"credential_id" gorm:"type:blob;uniqueIndex;not null"`
PublicKey
[]
byte
`json:"public_key" gorm:"type:blob;not null"`
CredentialID
string
`json:"credential_id" gorm:"type:varchar(512);uniqueIndex;not null"`
// base64 encoded
PublicKey
string
`json:"public_key" gorm:"type:text;not null"`
// base64 encoded
AttestationType
string
`json:"attestation_type" gorm:"type:varchar(255)"`
AAGUID
[]
byte
`json:"aaguid" gorm:"type:blob"`
AAGUID
string
`json:"aaguid" gorm:"type:varchar(512)"`
// base64 encoded
SignCount
uint32
`json:"sign_count" gorm:"default:0"`
CloneWarning
bool
`json:"clone_warning"`
UserPresent
bool
`json:"user_present"`
...
...
@@ -78,14 +79,18 @@ func (p *PasskeyCredential) ToWebAuthnCredential() webauthn.Credential {
BackupState
:
p
.
BackupState
,
}
credID
,
_
:=
base64
.
StdEncoding
.
DecodeString
(
p
.
CredentialID
)
pubKey
,
_
:=
base64
.
StdEncoding
.
DecodeString
(
p
.
PublicKey
)
aaguid
,
_
:=
base64
.
StdEncoding
.
DecodeString
(
p
.
AAGUID
)
return
webauthn
.
Credential
{
ID
:
p
.
Credential
ID
,
PublicKey
:
p
.
Public
Key
,
ID
:
cred
ID
,
PublicKey
:
p
ub
Key
,
AttestationType
:
p
.
AttestationType
,
Transport
:
p
.
TransportList
(),
Flags
:
flags
,
Authenticator
:
webauthn
.
Authenticator
{
AAGUID
:
p
.
AAGUID
,
AAGUID
:
aaguid
,
SignCount
:
p
.
SignCount
,
CloneWarning
:
p
.
CloneWarning
,
Attachment
:
protocol
.
AuthenticatorAttachment
(
p
.
Attachment
),
...
...
@@ -99,10 +104,10 @@ func NewPasskeyCredentialFromWebAuthn(userID int, credential *webauthn.Credentia
}
passkey
:=
&
PasskeyCredential
{
UserID
:
userID
,
CredentialID
:
credential
.
ID
,
PublicKey
:
credential
.
PublicKey
,
CredentialID
:
base64
.
StdEncoding
.
EncodeToString
(
credential
.
ID
)
,
PublicKey
:
base64
.
StdEncoding
.
EncodeToString
(
credential
.
PublicKey
)
,
AttestationType
:
credential
.
AttestationType
,
AAGUID
:
credential
.
Authenticator
.
AAGUID
,
AAGUID
:
base64
.
StdEncoding
.
EncodeToString
(
credential
.
Authenticator
.
AAGUID
)
,
SignCount
:
credential
.
Authenticator
.
SignCount
,
CloneWarning
:
credential
.
Authenticator
.
CloneWarning
,
UserPresent
:
credential
.
Flags
.
UserPresent
,
...
...
@@ -119,10 +124,10 @@ func (p *PasskeyCredential) ApplyValidatedCredential(credential *webauthn.Creden
if
credential
==
nil
||
p
==
nil
{
return
}
p
.
CredentialID
=
credential
.
ID
p
.
PublicKey
=
credential
.
PublicKey
p
.
CredentialID
=
base64
.
StdEncoding
.
EncodeToString
(
credential
.
ID
)
p
.
PublicKey
=
base64
.
StdEncoding
.
EncodeToString
(
credential
.
PublicKey
)
p
.
AttestationType
=
credential
.
AttestationType
p
.
AAGUID
=
credential
.
Authenticator
.
AAGUID
p
.
AAGUID
=
base64
.
StdEncoding
.
EncodeToString
(
credential
.
Authenticator
.
AAGUID
)
p
.
SignCount
=
credential
.
Authenticator
.
SignCount
p
.
CloneWarning
=
credential
.
Authenticator
.
CloneWarning
p
.
UserPresent
=
credential
.
Flags
.
UserPresent
...
...
@@ -157,8 +162,9 @@ func GetPasskeyByCredentialID(credentialID []byte) (*PasskeyCredential, error) {
return
nil
,
ErrFriendlyPasskeyNotFound
}
credIDStr
:=
base64
.
StdEncoding
.
EncodeToString
(
credentialID
)
var
credential
PasskeyCredential
if
err
:=
DB
.
Where
(
"credential_id = ?"
,
cred
entialID
)
.
First
(
&
credential
)
.
Error
;
err
!=
nil
{
if
err
:=
DB
.
Where
(
"credential_id = ?"
,
cred
IDStr
)
.
First
(
&
credential
)
.
Error
;
err
!=
nil
{
if
errors
.
Is
(
err
,
gorm
.
ErrRecordNotFound
)
{
common
.
SysLog
(
fmt
.
Sprintf
(
"GetPasskeyByCredentialID: passkey not found for credential ID length %d"
,
len
(
credentialID
)))
return
nil
,
ErrFriendlyPasskeyNotFound
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment