CI / Web-Barrierefreiheitspruefung (axe, Tastatur, Reflow, Textabstaende) (push) Canceled after 0s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (push) Canceled after 0s
CI / Core-Modul (Build/Vet/Test) (push) Canceled after 0s
CI / DMS-Modul Supply-Chain-Scan (govulncheck) (push) Canceled after 0s
CI / Web (dms-browser) (push) Canceled after 0s
CI / Web (pdf-viewer) (push) Canceled after 0s
CI / Web (shl) (push) Canceled after 0s
CI / DMS-Modul (Lint/Build/Test/Coverage/Artefakt) (push) Canceled after 0s
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package trigger
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
|
|
dmscrypto "gitea.perlbach24.de/scripte/nexarch/dms/internal/crypto"
|
|
)
|
|
|
|
// Vault verpackt/entpackt das Webhook-Geheimnis mit dem Tenant-KEK
|
|
// (Envelope-Verschluesselung wie FDN-09/FDN-22, kein Klartext-Fallback).
|
|
type Vault interface {
|
|
Seal(ctx context.Context, tenantSlug, plaintext string) (wrappedDEK, ciphertext []byte, err error)
|
|
Open(ctx context.Context, tenantSlug string, wrappedDEK, ciphertext []byte) (string, error)
|
|
}
|
|
|
|
// CryptoVault implementiert Vault ueber den vorhandenen dmscrypto.Service.
|
|
type CryptoVault struct {
|
|
Crypto *dmscrypto.Service
|
|
}
|
|
|
|
func (v CryptoVault) Seal(ctx context.Context, tenantSlug, plaintext string) ([]byte, []byte, error) {
|
|
env, err := v.Crypto.Seal(ctx, tenantSlug, bytes.NewReader([]byte(plaintext)))
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
ciphertext, err := io.ReadAll(env.Ciphertext)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
return env.WrappedDEK, ciphertext, nil
|
|
}
|
|
|
|
func (v CryptoVault) Open(ctx context.Context, tenantSlug string, wrappedDEK, ciphertext []byte) (string, error) {
|
|
r, err := v.Crypto.Open(ctx, tenantSlug, wrappedDEK, bytes.NewReader(ciphertext))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
plaintext, err := io.ReadAll(r)
|
|
if err != nil {
|
|
return "", fmt.Errorf("trigger: geheimnis entschluesseln: %w", err)
|
|
}
|
|
return string(plaintext), nil
|
|
}
|