1 parent
586f2bca19
commit
7114e9ed4a
13 files changed
+587
-10
No files matched your search
@@ -0,0 +1,14 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// recoveryRequestContext 保留请求的取消信号;兼容无 HTTP 请求的内部调用。
|
||||
func recoveryRequestContext(req *http.Request) context.Context {
|
||||
if req == nil {
|
||||
return context.Background()
|
||||
}
|
||||
return req.Context()
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.pcux.cn/xuans/Smail/db"
|
||||
"git.pcux.cn/xuans/Smail/dto/response"
|
||||
"git.pcux.cn/xuans/Smail/internal/passwordtest"
|
||||
"git.pcux.cn/xuans/Smail/models"
|
||||
"git.pcux.cn/xuans/Smail/services/access"
|
||||
"git.pcux.cn/xuans/Smail/services/credentials"
|
||||
appcontext "git.pcux.cn/xuans/Smail/utils/context"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func TestRecoveryGenerationHandlersForwardRequestCancellation(t *testing.T) {
|
||||
engine, err := xorm.NewEngine("sqlite", filepath.Join(t.TempDir(), "cancel.db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
oldDB, oldSecurity := db.Instance, securityRuntime
|
||||
t.Cleanup(func() { db.Instance = oldDB; securityRuntime = oldSecurity; _ = engine.Close() })
|
||||
if err := engine.Sync2(&models.User{}, &models.RecoveryCode{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
user := models.User{Account: "cancel-user", Role: string(access.RoleUser)}
|
||||
if _, err := engine.Insert(&user); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := engine.Insert(&models.RecoveryCode{UserID: user.ID, CodeHash: "original-hash", CodeVersion: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
service, err := credentials.NewService(engine)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
db.Instance = engine
|
||||
ConfigureSecurityRuntime(nil, nil, nil, service)
|
||||
actor := &appcontext.Context{UserID: user.ID, Role: access.RoleSuperAdmin, RecentAuth: true, RecoveryCodeConfigured: true}
|
||||
for _, item := range []struct {
|
||||
name string
|
||||
handler func(*appcontext.Context, http.ResponseWriter, *http.Request)
|
||||
}{{"self", GenerateRecoveryCodes}, {"managed", GenerateManagedRecoveryCodes}} {
|
||||
t.Run(item.name, func(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
request := httptest.NewRequest(http.MethodPost, "/api/security", strings.NewReader(`{"user_id":`+strconv.Itoa(user.ID)+`,"count":10}`)).WithContext(ctx)
|
||||
recorder := httptest.NewRecorder()
|
||||
item.handler(actor, recorder, request)
|
||||
var result response.Response
|
||||
if err := json.Unmarshal(recorder.Body.Bytes(), &result); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.ErrorNo == 0 {
|
||||
t.Fatal("已取消的请求返回了成功")
|
||||
}
|
||||
var rows []models.RecoveryCode
|
||||
if err := engine.Find(&rows); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(rows) != 1 || rows[0].CodeHash != "original-hash" || rows[0].UsedAt != nil {
|
||||
t.Fatal("已取消请求轮换了恢复码")
|
||||
}
|
||||
})
|
||||
}
|
||||
// 资源繁忙必须返回可重试状态,不能把它当作凭据错误。
|
||||
release := passwordtest.Hold(t)
|
||||
defer release()
|
||||
request := httptest.NewRequest(http.MethodPost, "/api/security", strings.NewReader(`{"user_id":`+strconv.Itoa(user.ID)+`,"count":10}`))
|
||||
recorder := httptest.NewRecorder()
|
||||
GenerateManagedRecoveryCodes(actor, recorder, request)
|
||||
if recorder.Code != http.StatusServiceUnavailable || recorder.Header().Get("Retry-After") != "1" || !strings.Contains(recorder.Body.String(), "AUTH_BUSY") {
|
||||
t.Fatal("管理恢复码入口没有传递可重试繁忙状态")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecoveryRequestContextPreservesDeadline(t *testing.T) {
|
||||
if recoveryRequestContext(nil).Err() != nil {
|
||||
t.Fatal("无请求的兼容上下文不可用")
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
request := httptest.NewRequest(http.MethodPost, "/", nil).WithContext(ctx)
|
||||
if recoveryRequestContext(request) != ctx {
|
||||
t.Fatal("HTTP 上下文被替换")
|
||||
}
|
||||
}
|
||||
@@ -321,7 +321,7 @@ func GenerateRecoveryCodes(ctx *context.Context, w http.ResponseWriter, req *htt
|
||||
writeSecurityError(w, response.ServerError, "安全凭据服务不可用")
|
||||
return
|
||||
}
|
||||
codes, err := service.GenerateRecoveryCodes(ctx.UserID, input.Count)
|
||||
codes, err := service.GenerateRecoveryCodesContext(recoveryRequestContext(req), ctx.UserID, input.Count)
|
||||
if err != nil {
|
||||
if writePasswordBusy(w, err) {
|
||||
return
|
||||
|
||||
@@ -109,8 +109,11 @@ func GenerateManagedRecoveryCodes(ctx *context.Context, w http.ResponseWriter, r
|
||||
writeSecurityError(w, response.ServerError, "安全凭据服务不可用")
|
||||
return
|
||||
}
|
||||
codes, err := service.GenerateRecoveryCodes(target.ID, input.Count)
|
||||
codes, err := service.GenerateRecoveryCodesContext(recoveryRequestContext(req), target.ID, input.Count)
|
||||
if err != nil {
|
||||
if writePasswordBusy(w, err) {
|
||||
return
|
||||
}
|
||||
log.WithContext(ctx).WithError(err).Error("generate managed recovery codes failed")
|
||||
writeSecurityError(w, response.ParamsError, "安全码生成失败")
|
||||
return
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package credentials
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// contextMutex 保留凭据写入的互斥顺序,同时允许等待中的请求及时取消。
|
||||
// 零值可用,初始化后不得复制。
|
||||
type contextMutex struct {
|
||||
once sync.Once
|
||||
slot chan struct{}
|
||||
}
|
||||
|
||||
func (m *contextMutex) LockContext(ctx context.Context) error {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
m.once.Do(func() { m.slot = make(chan struct{}, 1) })
|
||||
select {
|
||||
case m.slot <- struct{}{}:
|
||||
if err := ctx.Err(); err != nil {
|
||||
m.Unlock()
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
}
|
||||
|
||||
func (m *contextMutex) Lock() {
|
||||
_ = m.LockContext(context.Background())
|
||||
}
|
||||
|
||||
func (m *contextMutex) Unlock() {
|
||||
select {
|
||||
case <-m.slot:
|
||||
default:
|
||||
panic("unlock of unlocked credential mutex")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package credentials
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestContextMutexKeepsMutualExclusion(t *testing.T) {
|
||||
var mutex contextMutex
|
||||
var group sync.WaitGroup
|
||||
count := 0
|
||||
for i := 0; i < 12; i++ {
|
||||
group.Add(1)
|
||||
go func() {
|
||||
defer group.Done()
|
||||
for j := 0; j < 100; j++ {
|
||||
mutex.Lock()
|
||||
count++
|
||||
mutex.Unlock()
|
||||
}
|
||||
}()
|
||||
}
|
||||
group.Wait()
|
||||
if count != 1200 {
|
||||
t.Fatal("并发写入失去互斥保护")
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextMutexCancellationDoesNotLoseLock(t *testing.T) {
|
||||
var mutex contextMutex
|
||||
cancelled, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
if !errors.Is(mutex.LockContext(cancelled), context.Canceled) {
|
||||
t.Fatal("已取消请求获取了锁")
|
||||
}
|
||||
mutex.Lock()
|
||||
ctx, cancelWait := context.WithTimeout(context.Background(), 10*time.Millisecond)
|
||||
defer cancelWait()
|
||||
if !errors.Is(mutex.LockContext(ctx), context.DeadlineExceeded) {
|
||||
t.Fatal("等待锁未响应截止时间")
|
||||
}
|
||||
mutex.Unlock()
|
||||
if err := mutex.LockContext(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mutex.Unlock()
|
||||
}
|
||||
|
||||
func TestContextMutexInvalidUnlockPanics(t *testing.T) {
|
||||
defer func() {
|
||||
if recover() == nil {
|
||||
t.Fatal("未持有锁的解锁没有报错")
|
||||
}
|
||||
}()
|
||||
var mutex contextMutex
|
||||
mutex.Unlock()
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package credentials
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.pcux.cn/xuans/Smail/models"
|
||||
"git.pcux.cn/xuans/Smail/utils/password"
|
||||
"xorm.io/xorm/contexts"
|
||||
)
|
||||
|
||||
func seedRecoveryCode(t *testing.T, s *Service) {
|
||||
t.Helper()
|
||||
if _, err := s.engine.Insert(&models.RecoveryCode{UserID: 1, CodeHash: "preserved-hash", CodeVersion: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func assertRecoveryCodePreserved(t *testing.T, s *Service) {
|
||||
t.Helper()
|
||||
var rows []models.RecoveryCode
|
||||
if err := s.engine.Find(&rows); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(rows) != 1 || rows[0].CodeHash != "preserved-hash" || rows[0].UsedAt != nil {
|
||||
t.Fatal("取消或失败后旧恢复码发生变化")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecoveryGenerationAlreadyCancelledDoesNotHash(t *testing.T) {
|
||||
s := newFixture(t)
|
||||
seedRecoveryCode(t, s)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
codes, err := s.generateRecoveryCodes(ctx, 1, 10, func(string) (string, error) {
|
||||
t.Fatal("取消后不应执行密码计算")
|
||||
return "", nil
|
||||
})
|
||||
if codes != nil || !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("取消结果错误:%v", err)
|
||||
}
|
||||
assertRecoveryCodePreserved(t, s)
|
||||
}
|
||||
|
||||
func TestRecoveryGenerationCancelledBetweenHashesPreservesOldCodes(t *testing.T) {
|
||||
for _, cancelAt := range []int{1, 5, 10} {
|
||||
t.Run(time.Duration(cancelAt).String(), func(t *testing.T) {
|
||||
s := newFixture(t)
|
||||
seedRecoveryCode(t, s)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
calls := 0
|
||||
codes, err := s.generateRecoveryCodes(ctx, 1, 10, func(string) (string, error) {
|
||||
calls++
|
||||
if calls == cancelAt {
|
||||
cancel()
|
||||
}
|
||||
return "test-hash", nil
|
||||
})
|
||||
if codes != nil || !errors.Is(err, context.Canceled) || calls != cancelAt {
|
||||
t.Fatalf("取消未停止后续计算:调用=%d,错误=%v", calls, err)
|
||||
}
|
||||
assertRecoveryCodePreserved(t, s)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecoveryGenerationCancelsWhileWaitingForCredentialLock(t *testing.T) {
|
||||
s := newFixture(t)
|
||||
seedRecoveryCode(t, s)
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
|
||||
defer cancel()
|
||||
started := time.Now()
|
||||
codes, err := s.generateRecoveryCodes(ctx, 1, 10, func(string) (string, error) { return "test-hash", nil })
|
||||
if codes != nil || !errors.Is(err, context.DeadlineExceeded) || time.Since(started) > time.Second {
|
||||
t.Fatalf("等待凭据锁时未及时取消:%v", err)
|
||||
}
|
||||
assertRecoveryCodePreserved(t, s)
|
||||
}
|
||||
|
||||
func TestRecoveryGenerationCancelsWhileWaitingForDatabase(t *testing.T) {
|
||||
s := newFixture(t)
|
||||
seedRecoveryCode(t, s)
|
||||
s.engine.SetMaxOpenConns(1)
|
||||
conn, err := s.engine.DB().DB.Conn(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
|
||||
defer cancel()
|
||||
codes, err := s.generateRecoveryCodes(ctx, 1, 10, func(string) (string, error) { return "test-hash", nil })
|
||||
_ = conn.Close()
|
||||
if codes != nil || !errors.Is(err, context.DeadlineExceeded) {
|
||||
t.Fatalf("数据库等待未取消:%v", err)
|
||||
}
|
||||
assertRecoveryCodePreserved(t, s)
|
||||
}
|
||||
|
||||
type recoveryCancelHook struct {
|
||||
cancel context.CancelFunc
|
||||
index int
|
||||
seen int
|
||||
}
|
||||
|
||||
func (h *recoveryCancelHook) BeforeProcess(c *contexts.ContextHook) (context.Context, error) {
|
||||
return c.Ctx, nil
|
||||
}
|
||||
|
||||
func (h *recoveryCancelHook) AfterProcess(c *contexts.ContextHook) error {
|
||||
if strings.HasPrefix(c.SQL, "INSERT") {
|
||||
h.seen++
|
||||
if h.seen == h.index {
|
||||
h.cancel()
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestRecoveryGenerationCancellationRollsBackRevocationAndInserts(t *testing.T) {
|
||||
for _, cancelAt := range []int{1, 10} {
|
||||
t.Run(time.Duration(cancelAt).String(), func(t *testing.T) {
|
||||
s := newFixture(t)
|
||||
seedRecoveryCode(t, s)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
hook := &recoveryCancelHook{cancel: cancel, index: cancelAt}
|
||||
s.engine.AddHook(hook)
|
||||
codes, err := s.generateRecoveryCodes(ctx, 1, 10, func(string) (string, error) { return "test-hash", nil })
|
||||
if codes != nil || err == nil || hook.seen != cancelAt {
|
||||
t.Fatalf("事务取消失败:%v", err)
|
||||
}
|
||||
assertRecoveryCodePreserved(t, s)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecoveryGenerationHashFailurePreservesOldCodes(t *testing.T) {
|
||||
s := newFixture(t)
|
||||
seedRecoveryCode(t, s)
|
||||
calls := 0
|
||||
codes, err := s.generateRecoveryCodes(context.Background(), 1, 10, func(string) (string, error) {
|
||||
calls++
|
||||
if calls == 3 {
|
||||
return "", password.ErrBusy
|
||||
}
|
||||
return "test-hash", nil
|
||||
})
|
||||
if codes != nil || !errors.Is(err, password.ErrBusy) || calls != 3 {
|
||||
t.Fatalf("计算失败未保留状态:%v", err)
|
||||
}
|
||||
assertRecoveryCodePreserved(t, s)
|
||||
}
|
||||
|
||||
func TestRecoveryGenerationContextKeepsTenStrongHashes(t *testing.T) {
|
||||
s := newFixture(t)
|
||||
codes, err := s.GenerateRecoveryCodesContext(context.Background(), 1, 10)
|
||||
if err != nil || len(codes) != 10 {
|
||||
t.Fatalf("十枚恢复码生成失败:%v", err)
|
||||
}
|
||||
var rows []models.RecoveryCode
|
||||
if err := s.engine.Find(&rows); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(rows) != 10 {
|
||||
t.Fatal("恢复码数量不一致")
|
||||
}
|
||||
seen := make(map[string]bool)
|
||||
for i, row := range rows {
|
||||
if !strings.HasPrefix(row.CodeHash, "$argon2id$v=19$m=65536,t=3,p=1$") || row.UsedAt != nil || row.CodeVersion != 1 || seen[codes[i]] {
|
||||
t.Fatal("密码参数、版本或随机性发生变化")
|
||||
}
|
||||
seen[codes[i]] = true
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,17 @@
|
||||
package credentials
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/base32"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.pcux.cn/xuans/Smail/models"
|
||||
"git.pcux.cn/xuans/Smail/utils/password"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"golang.org/x/text/unicode/norm"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
@@ -34,7 +35,7 @@ const (
|
||||
// Service 统一管理密保问题和离线恢复码。
|
||||
type Service struct {
|
||||
engine *xorm.Engine
|
||||
mu sync.Mutex
|
||||
mu contextMutex
|
||||
now func() time.Time
|
||||
vaultRoot string
|
||||
}
|
||||
@@ -140,6 +141,16 @@ func (s *Service) VerifySecurityQuestion(userID int, answer string) (bool, error
|
||||
|
||||
// GenerateRecoveryCodes 撤销旧码并生成一组只返回一次的离线恢复码。
|
||||
func (s *Service) GenerateRecoveryCodes(userID int, count int) ([]string, error) {
|
||||
return s.GenerateRecoveryCodesContext(context.Background(), userID, count)
|
||||
}
|
||||
|
||||
// GenerateRecoveryCodesContext 在请求取消时停止后续计算,并回滚尚未提交的恢复码轮换。
|
||||
// 单次 Argon2id 计算不可中断,因此每次计算前后检查取消,不降低原有密码强度。
|
||||
func (s *Service) GenerateRecoveryCodesContext(ctx context.Context, userID int, count int) ([]string, error) {
|
||||
return s.generateRecoveryCodes(ctx, userID, count, password.Hash)
|
||||
}
|
||||
|
||||
func (s *Service) generateRecoveryCodes(ctx context.Context, userID int, count int, hashSecret func(string) (string, error)) (codes []string, resultErr error) {
|
||||
if s == nil || s.engine == nil {
|
||||
return nil, ErrUnavailable
|
||||
}
|
||||
@@ -152,45 +163,73 @@ func (s *Service) GenerateRecoveryCodes(userID int, count int) ([]string, error)
|
||||
if count < minCodeCount || count > maxCodeCount {
|
||||
return nil, fmt.Errorf("recovery code count must be between %d and %d", minCodeCount, maxCodeCount)
|
||||
}
|
||||
codes := make([]string, 0, count)
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
started := time.Now()
|
||||
phase := "hash"
|
||||
log.WithFields(log.Fields{"action": "生成离线恢复码", "phase": phase, "count": count}).Info("开始处理离线恢复码")
|
||||
defer func() {
|
||||
log.WithFields(log.Fields{"action": "生成离线恢复码", "phase": phase, "count": count,
|
||||
"elapsed_ms": time.Since(started).Milliseconds(), "success": resultErr == nil,
|
||||
"cancelled": ctx.Err() != nil}).Info("离线恢复码处理结束")
|
||||
}()
|
||||
codes = make([]string, 0, count)
|
||||
items := make([]models.RecoveryCode, 0, count)
|
||||
for i := 0; i < count; i++ {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
plain, err := newRecoveryCode()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hash, err := password.Hash(plain)
|
||||
hash, err := hashSecret(plain)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("hash recovery code: %w", err)
|
||||
}
|
||||
codes = append(codes, plain)
|
||||
items = append(items, models.RecoveryCode{UserID: userID, CodeHash: hash, CodeVersion: 1})
|
||||
}
|
||||
|
||||
s.mu.Lock()
|
||||
phase = "lock"
|
||||
log.WithFields(log.Fields{"action": "生成离线恢复码", "phase": phase, "count": count,
|
||||
"hash_ms": time.Since(started).Milliseconds()}).Info("恢复码密码计算结束")
|
||||
if err := s.mu.LockContext(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer s.mu.Unlock()
|
||||
phase = "transaction"
|
||||
session := s.engine.NewSession()
|
||||
if session == nil {
|
||||
return nil, ErrUnavailable
|
||||
}
|
||||
defer session.Close()
|
||||
session.Context(ctx)
|
||||
if err := session.Begin(); err != nil {
|
||||
return nil, fmt.Errorf("begin recovery code transaction: %w", err)
|
||||
}
|
||||
defer session.Rollback()
|
||||
now := s.now()
|
||||
if _, err := session.Where("user_id = ? AND used_at IS NULL", userID).Cols("used_at").Update(&models.RecoveryCode{UsedAt: &now}); err != nil {
|
||||
_ = session.Rollback()
|
||||
return nil, fmt.Errorf("revoke old recovery codes: %w", err)
|
||||
}
|
||||
for i := range items {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := session.Insert(&items[i]); err != nil {
|
||||
_ = session.Rollback()
|
||||
return nil, fmt.Errorf("store recovery code: %w", err)
|
||||
}
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := session.Commit(); err != nil {
|
||||
return nil, fmt.Errorf("commit recovery codes: %w", err)
|
||||
}
|
||||
phase = "complete"
|
||||
return codes, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user