39 lines
2.1 KiB
Go
39 lines
2.1 KiB
Go
package model
|
||
|
||
import (
|
||
"time"
|
||
)
|
||
|
||
// Passkey 用户凭证密钥模型
|
||
type Passkey struct {
|
||
ID int64 `json:"id" gorm:"column:id;primaryKey;autoIncrement"`
|
||
UserID int64 `json:"user_id" gorm:"column:user_id;index"`
|
||
CredentialID string `json:"credential_id" gorm:"column:credential_id;index"` // 凭证ID,用于识别特定的passkey
|
||
PublicKey string `json:"public_key" gorm:"column:public_key"` // 公钥,用于验证签名
|
||
AttestationType string `json:"attestation_type" gorm:"column:attestation_type"` // 证明类型
|
||
AAGUID string `json:"aaguid" gorm:"column:aaguid"` // 认证器标识符
|
||
SignCount uint32 `json:"sign_count" gorm:"column:sign_count"` // 签名计数器,用于防止重放攻击
|
||
Name string `json:"name" gorm:"column:name"` // 凭证名称,用于用户识别不同的设备
|
||
DeviceType string `json:"device_type" gorm:"column:device_type"` // 设备类型
|
||
BackupEligible bool `json:"backup_eligible" gorm:"column:backup_eligible"` // 是否可备份
|
||
BackupState bool `json:"backup_state" gorm:"backup_state"` // 备份状态
|
||
Transport string `json:"transport" gorm:"column:transport"` // 传输方式 (如usb、nfc、ble等)
|
||
LastUsedAt int64 `json:"last_used_at" gorm:"column:last_used_at;autoUpdateTime"` // 最后使用时间
|
||
CreatedAt int64 `json:"created_at,omitempty" gorm:"column:created_at;autoCreateTime"`
|
||
UpdatedAt int64 `json:"updated_at,omitempty" gorm:"column:updated_at;autoUpdateTime"`
|
||
|
||
// 关联用户模型(不存入数据库)
|
||
User User `json:"-" gorm:"foreignKey:UserID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
|
||
}
|
||
|
||
// 创建表结构
|
||
func (Passkey) TableName() string {
|
||
return "passkeys"
|
||
}
|
||
|
||
// UpdateSignCount 更新签名计数器和最后使用时间
|
||
func (p *Passkey) UpdateSignCount(count uint32) {
|
||
p.SignCount = count
|
||
p.LastUsedAt = time.Now().Unix()
|
||
}
|