fix(protocols): 修复第三方协议授权码密码验证后解密展示并优化交互提示
Some checks are pending
Security Checks / security (push) Waiting to run
Some checks are pending
Security Checks / security (push) Waiting to run
This commit is contained in:
parent
f285b5c904
commit
fcb64a34bd
@ -164,12 +164,18 @@ func LoadSecurityContext(ctx *context.Context) {
|
|||||||
|
|
||||||
func credentialRuntime() *credentials.Service {
|
func credentialRuntime() *credentials.Service {
|
||||||
if service := currentSecurityRuntime().credentials; service != nil {
|
if service := currentSecurityRuntime().credentials; service != nil {
|
||||||
|
if service.VaultRoot() == "" && config.ROOT_PATH != "" {
|
||||||
|
service.SetVaultRoot(config.ROOT_PATH)
|
||||||
|
}
|
||||||
return service
|
return service
|
||||||
}
|
}
|
||||||
if db.Instance == nil {
|
if db.Instance == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
service, _ := credentials.NewService(db.Instance)
|
service, _ := credentials.NewService(db.Instance)
|
||||||
|
if service != nil && config.ROOT_PATH != "" {
|
||||||
|
service.SetVaultRoot(config.ROOT_PATH)
|
||||||
|
}
|
||||||
return service
|
return service
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -32,6 +32,7 @@ type ProtocolCredentialStatus struct {
|
|||||||
Protocol string `json:"protocol"`
|
Protocol string `json:"protocol"`
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
Configured bool `json:"configured"`
|
Configured bool `json:"configured"`
|
||||||
|
CanReveal bool `json:"can_reveal"`
|
||||||
CreatedAt *time.Time `json:"created_at,omitempty"`
|
CreatedAt *time.Time `json:"created_at,omitempty"`
|
||||||
UpdatedAt *time.Time `json:"updated_at,omitempty"`
|
UpdatedAt *time.Time `json:"updated_at,omitempty"`
|
||||||
LastUsedAt *time.Time `json:"last_used_at,omitempty"`
|
LastUsedAt *time.Time `json:"last_used_at,omitempty"`
|
||||||
@ -75,6 +76,7 @@ func (s *Service) ListProtocolCredentials(userID int) ([]ProtocolCredentialStatu
|
|||||||
updatedAt := item.UpdatedAt
|
updatedAt := item.UpdatedAt
|
||||||
status.Enabled = item.Enabled
|
status.Enabled = item.Enabled
|
||||||
status.Configured = item.CodeHash != "" && item.RevokedAt == nil
|
status.Configured = item.CodeHash != "" && item.RevokedAt == nil
|
||||||
|
status.CanReveal = item.CodeCiphertext != "" && item.RevokedAt == nil
|
||||||
status.CreatedAt = &createdAt
|
status.CreatedAt = &createdAt
|
||||||
status.UpdatedAt = &updatedAt
|
status.UpdatedAt = &updatedAt
|
||||||
status.LastUsedAt = item.LastUsedAt
|
status.LastUsedAt = item.LastUsedAt
|
||||||
@ -255,11 +257,12 @@ func (s *Service) RevealProtocolCodes(userID int) (map[string]string, error) {
|
|||||||
if userID <= 0 {
|
if userID <= 0 {
|
||||||
return nil, ErrInvalidUser
|
return nil, ErrInvalidUser
|
||||||
}
|
}
|
||||||
if s.vaultRoot == "" {
|
|
||||||
return make(map[string]string), nil
|
|
||||||
}
|
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
|
vaultRoot := s.vaultRoot
|
||||||
|
if vaultRoot == "" {
|
||||||
|
return make(map[string]string), nil
|
||||||
|
}
|
||||||
var items []models.ProtocolCredential
|
var items []models.ProtocolCredential
|
||||||
if err := s.engine.Where("user_id = ? AND enabled = ? AND revoked_at IS NULL", userID, true).Find(&items); err != nil {
|
if err := s.engine.Where("user_id = ? AND enabled = ? AND revoked_at IS NULL", userID, true).Find(&items); err != nil {
|
||||||
return nil, fmt.Errorf("load protocol credentials for reveal: %w", err)
|
return nil, fmt.Errorf("load protocol credentials for reveal: %w", err)
|
||||||
@ -269,7 +272,7 @@ func (s *Service) RevealProtocolCodes(userID int) (map[string]string, error) {
|
|||||||
if item.CodeCiphertext == "" || item.CodeHash == "" {
|
if item.CodeCiphertext == "" || item.CodeHash == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
plain, err := credential.Decrypt(s.vaultRoot, item.CodeCiphertext)
|
plain, err := credential.Decrypt(vaultRoot, item.CodeCiphertext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@ -221,7 +221,12 @@ export function usePage() {
|
|||||||
Object.assign(revealedCodes, codes)
|
Object.assign(revealedCodes, codes)
|
||||||
codesRevealed.value = true
|
codesRevealed.value = true
|
||||||
closeVerifyDialog()
|
closeVerifyDialog()
|
||||||
notify('安全验证通过,授权码已解密显示', 'success')
|
const count = Object.keys(codes).length
|
||||||
|
if (count > 0) {
|
||||||
|
notify(`安全验证通过,已解密显示 ${count} 个协议授权码`, 'success')
|
||||||
|
} else {
|
||||||
|
notify('安全验证通过,当前授权码未保留加密密文,可点击重新生成', 'warning')
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
notify(error?.message || '验证失败,请检查密码是否正确')
|
notify(error?.message || '验证失败,请检查密码是否正确')
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@ -70,6 +70,18 @@
|
|||||||
复制
|
复制
|
||||||
</el-button>
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
|
<template v-else-if="codesRevealed && !revealedCodes[item.protocol]">
|
||||||
|
<span class="unconfigured-tip">旧版授权码未保留密文,请点击重新生成</span>
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
link
|
||||||
|
size="small"
|
||||||
|
class="copy-btn"
|
||||||
|
@click="generateProtocolCode(item)"
|
||||||
|
>
|
||||||
|
重新生成
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<span class="masked-code">••••••••••••••••</span>
|
<span class="masked-code">••••••••••••••••</span>
|
||||||
<el-button
|
<el-button
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user