Compare commits
3 Commits
main
...
b9aaf8ddac
| Author | SHA1 | Date | |
|---|---|---|---|
| b9aaf8ddac | |||
| e10b4cec82 | |||
| 4adeeae1db |
17
README.md
17
README.md
@@ -184,7 +184,6 @@ Creates a new unlocker of the specified type:
|
|||||||
- `passphrase`: Traditional passphrase-protected unlocker
|
- `passphrase`: Traditional passphrase-protected unlocker
|
||||||
- `pgp`: Uses an existing GPG key for encryption/decryption
|
- `pgp`: Uses an existing GPG key for encryption/decryption
|
||||||
- `keychain`: macOS Keychain integration (macOS only)
|
- `keychain`: macOS Keychain integration (macOS only)
|
||||||
- `secure-enclave`: Hardware-backed Secure Enclave protection (macOS only)
|
|
||||||
|
|
||||||
**Options:**
|
**Options:**
|
||||||
- `--keyid <id>`: GPG key ID (optional for PGP type, uses default key if not specified)
|
- `--keyid <id>`: GPG key ID (optional for PGP type, uses default key if not specified)
|
||||||
@@ -287,11 +286,11 @@ Unlockers provide different authentication methods to access the long-term keys:
|
|||||||
- Automatic unlocking when Keychain is unlocked
|
- Automatic unlocking when Keychain is unlocked
|
||||||
- Cross-application integration
|
- Cross-application integration
|
||||||
|
|
||||||
4. **Secure Enclave Unlockers** (macOS):
|
4. **Secure Enclave Unlockers** (macOS - planned):
|
||||||
- Hardware-backed key storage using Apple Secure Enclave
|
- Hardware-backed key storage using Apple Secure Enclave
|
||||||
- Uses `sc_auth` / CryptoTokenKit for SE key management (no Apple Developer Program required)
|
- Currently partially implemented but non-functional
|
||||||
- ECIES encryption: vault long-term key encrypted directly by SE hardware
|
- Requires Apple Developer Program membership and code signing entitlements
|
||||||
- Protected by biometric authentication (Touch ID) or system password
|
- Full implementation blocked by entitlement requirements
|
||||||
|
|
||||||
Each vault maintains its own set of unlockers and one long-term key. The long-term key is encrypted to each unlocker, allowing any authorized unlocker to access vault secrets.
|
Each vault maintains its own set of unlockers and one long-term key. The long-term key is encrypted to each unlocker, allowing any authorized unlocker to access vault secrets.
|
||||||
|
|
||||||
@@ -331,7 +330,8 @@ Each vault maintains its own set of unlockers and one long-term key. The long-te
|
|||||||
|
|
||||||
- Hardware token support via PGP/GPG integration
|
- Hardware token support via PGP/GPG integration
|
||||||
- macOS Keychain integration for system-level security
|
- macOS Keychain integration for system-level security
|
||||||
- Secure Enclave integration for hardware-backed key protection (macOS, via `sc_auth` / CryptoTokenKit)
|
- Secure Enclave support planned (requires paid Apple Developer Program for
|
||||||
|
signed entitlements to access the SEP and doxxing myself to Apple)
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
@@ -385,7 +385,6 @@ secret vault remove personal --force
|
|||||||
secret unlocker add passphrase # Password-based
|
secret unlocker add passphrase # Password-based
|
||||||
secret unlocker add pgp --keyid ABCD1234 # GPG key
|
secret unlocker add pgp --keyid ABCD1234 # GPG key
|
||||||
secret unlocker add keychain # macOS Keychain (macOS only)
|
secret unlocker add keychain # macOS Keychain (macOS only)
|
||||||
secret unlocker add secure-enclave # macOS Secure Enclave (macOS only)
|
|
||||||
|
|
||||||
# List unlockers
|
# List unlockers
|
||||||
secret unlocker list
|
secret unlocker list
|
||||||
@@ -444,7 +443,7 @@ secret decrypt encryption/mykey --input document.txt.age --output document.txt
|
|||||||
|
|
||||||
### Cross-Platform Support
|
### Cross-Platform Support
|
||||||
|
|
||||||
- **macOS**: Full support including Keychain and Secure Enclave integration
|
- **macOS**: Full support including Keychain and planned Secure Enclave integration
|
||||||
- **Linux**: Full support (excluding macOS-specific features)
|
- **Linux**: Full support (excluding macOS-specific features)
|
||||||
|
|
||||||
## Security Considerations
|
## Security Considerations
|
||||||
@@ -488,7 +487,7 @@ go test -tags=integration -v ./internal/cli # Integration tests
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- **Multiple Authentication Methods**: Supports passphrase, PGP, macOS Keychain, and Secure Enclave unlockers
|
- **Multiple Authentication Methods**: Supports passphrase, PGP, and macOS Keychain unlockers
|
||||||
- **Vault Isolation**: Complete separation between different vaults
|
- **Vault Isolation**: Complete separation between different vaults
|
||||||
- **Per-Secret Encryption**: Each secret has its own encryption key
|
- **Per-Secret Encryption**: Each secret has its own encryption key
|
||||||
- **BIP39 Mnemonic Support**: Keyless operation using mnemonic phrases
|
- **BIP39 Mnemonic Support**: Keyless operation using mnemonic phrases
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|||||||
@@ -24,12 +24,12 @@ type realVault struct {
|
|||||||
func (v *realVault) GetDirectory() (string, error) {
|
func (v *realVault) GetDirectory() (string, error) {
|
||||||
return filepath.Join(v.stateDir, "vaults.d", v.name), nil
|
return filepath.Join(v.stateDir, "vaults.d", v.name), nil
|
||||||
}
|
}
|
||||||
func (v *realVault) GetName() string { return v.name }
|
func (v *realVault) GetName() string { return v.name }
|
||||||
func (v *realVault) GetFilesystem() afero.Fs { return v.fs }
|
func (v *realVault) GetFilesystem() afero.Fs { return v.fs }
|
||||||
|
|
||||||
// Unused by getLongTermPrivateKey — these satisfy VaultInterface.
|
// Unused by getLongTermPrivateKey — these satisfy VaultInterface.
|
||||||
func (v *realVault) AddSecret(string, *memguard.LockedBuffer, bool) error { panic("not used") }
|
func (v *realVault) AddSecret(string, *memguard.LockedBuffer, bool) error { panic("not used") }
|
||||||
func (v *realVault) GetCurrentUnlocker() (Unlocker, error) { panic("not used") }
|
func (v *realVault) GetCurrentUnlocker() (Unlocker, error) { panic("not used") }
|
||||||
func (v *realVault) CreatePassphraseUnlocker(*memguard.LockedBuffer) (*PassphraseUnlocker, error) {
|
func (v *realVault) CreatePassphraseUnlocker(*memguard.LockedBuffer) (*PassphraseUnlocker, error) {
|
||||||
panic("not used")
|
panic("not used")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -284,11 +284,11 @@ func TestSecretNameValidation(t *testing.T) {
|
|||||||
{"valid/path/name", true},
|
{"valid/path/name", true},
|
||||||
{"123valid", true},
|
{"123valid", true},
|
||||||
{"", false},
|
{"", false},
|
||||||
{"Valid-Upper-Name", true}, // uppercase allowed
|
{"Valid-Upper-Name", true}, // uppercase allowed
|
||||||
{"2025-11-21-ber1app1-vaultik-test-bucket-AKI", true}, // real-world uppercase key ID
|
{"2025-11-21-ber1app1-vaultik-test-bucket-AKI", true}, // real-world uppercase key ID
|
||||||
{"MixedCase/Path/Name", true}, // mixed case with path
|
{"MixedCase/Path/Name", true}, // mixed case with path
|
||||||
{"invalid name", false}, // space not allowed
|
{"invalid name", false}, // space not allowed
|
||||||
{"invalid@name", false}, // @ not allowed
|
{"invalid@name", false}, // @ not allowed
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|||||||
@@ -60,10 +60,7 @@ func (s *SecureEnclaveUnlocker) GetIdentity() (*age.X25519Identity, error) {
|
|||||||
encryptedPath := filepath.Join(s.Directory, seLongtermFilename)
|
encryptedPath := filepath.Join(s.Directory, seLongtermFilename)
|
||||||
encryptedData, err := afero.ReadFile(s.fs, encryptedPath)
|
encryptedData, err := afero.ReadFile(s.fs, encryptedPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf("failed to read SE-encrypted long-term key: %w", err)
|
||||||
"failed to read SE-encrypted long-term key: %w",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugWith("Read SE-encrypted long-term key",
|
DebugWith("Read SE-encrypted long-term key",
|
||||||
@@ -73,10 +70,7 @@ func (s *SecureEnclaveUnlocker) GetIdentity() (*age.X25519Identity, error) {
|
|||||||
// Decrypt using the Secure Enclave (ECDH happens inside SE hardware)
|
// Decrypt using the Secure Enclave (ECDH happens inside SE hardware)
|
||||||
decryptedData, err := macse.Decrypt(seKeyLabel, encryptedData)
|
decryptedData, err := macse.Decrypt(seKeyLabel, encryptedData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf("failed to decrypt long-term key with SE: %w", err)
|
||||||
"failed to decrypt long-term key with SE: %w",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the decrypted long-term private key
|
// Parse the decrypted long-term private key
|
||||||
@@ -88,10 +82,7 @@ func (s *SecureEnclaveUnlocker) GetIdentity() (*age.X25519Identity, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf("failed to parse long-term private key: %w", err)
|
||||||
"failed to parse long-term private key: %w",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugWith("Successfully decrypted long-term key via SE",
|
DebugWith("Successfully decrypted long-term key via SE",
|
||||||
@@ -174,11 +165,7 @@ func (s *SecureEnclaveUnlocker) getSEKeyInfo() (label string, hash string, err e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewSecureEnclaveUnlocker creates a new SecureEnclaveUnlocker instance.
|
// NewSecureEnclaveUnlocker creates a new SecureEnclaveUnlocker instance.
|
||||||
func NewSecureEnclaveUnlocker(
|
func NewSecureEnclaveUnlocker(fs afero.Fs, directory string, metadata UnlockerMetadata) *SecureEnclaveUnlocker {
|
||||||
fs afero.Fs,
|
|
||||||
directory string,
|
|
||||||
metadata UnlockerMetadata,
|
|
||||||
) *SecureEnclaveUnlocker {
|
|
||||||
return &SecureEnclaveUnlocker{
|
return &SecureEnclaveUnlocker{
|
||||||
Directory: directory,
|
Directory: directory,
|
||||||
Metadata: metadata,
|
Metadata: metadata,
|
||||||
@@ -195,22 +182,13 @@ func generateSEKeyLabel(vaultName string) (string, error) {
|
|||||||
|
|
||||||
enrollmentDate := time.Now().UTC().Format("2006-01-02")
|
enrollmentDate := time.Now().UTC().Format("2006-01-02")
|
||||||
|
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf("%s.%s-%s-%s", seKeyLabelPrefix, vaultName, hostname, enrollmentDate), nil
|
||||||
"%s.%s-%s-%s",
|
|
||||||
seKeyLabelPrefix,
|
|
||||||
vaultName,
|
|
||||||
hostname,
|
|
||||||
enrollmentDate,
|
|
||||||
), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateSecureEnclaveUnlocker creates a new SE unlocker.
|
// CreateSecureEnclaveUnlocker creates a new SE unlocker.
|
||||||
// The vault's long-term private key is encrypted directly by the Secure Enclave
|
// The vault's long-term private key is encrypted directly by the Secure Enclave
|
||||||
// using ECIES. No intermediate age keypair is used.
|
// using ECIES. No intermediate age keypair is used.
|
||||||
func CreateSecureEnclaveUnlocker(
|
func CreateSecureEnclaveUnlocker(fs afero.Fs, stateDir string) (*SecureEnclaveUnlocker, error) {
|
||||||
fs afero.Fs,
|
|
||||||
stateDir string,
|
|
||||||
) (*SecureEnclaveUnlocker, error) {
|
|
||||||
if err := checkMacOSAvailable(); err != nil {
|
if err := checkMacOSAvailable(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -238,20 +216,14 @@ func CreateSecureEnclaveUnlocker(
|
|||||||
// Step 2: Get the vault's long-term private key
|
// Step 2: Get the vault's long-term private key
|
||||||
ltPrivKeyData, err := getLongTermKeyForSE(fs, vault)
|
ltPrivKeyData, err := getLongTermKeyForSE(fs, vault)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf("failed to get long-term private key: %w", err)
|
||||||
"failed to get long-term private key: %w",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
defer ltPrivKeyData.Destroy()
|
defer ltPrivKeyData.Destroy()
|
||||||
|
|
||||||
// Step 3: Encrypt the long-term key directly with the SE (ECIES)
|
// Step 3: Encrypt the long-term key directly with the SE (ECIES)
|
||||||
encryptedLtKey, err := macse.Encrypt(seKeyLabel, ltPrivKeyData.Bytes())
|
encryptedLtKey, err := macse.Encrypt(seKeyLabel, ltPrivKeyData.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf("failed to encrypt long-term key with SE: %w", err)
|
||||||
"failed to encrypt long-term key with SE: %w",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 4: Create unlocker directory and write files
|
// Step 4: Create unlocker directory and write files
|
||||||
@@ -263,19 +235,13 @@ func CreateSecureEnclaveUnlocker(
|
|||||||
unlockerDirName := fmt.Sprintf("se-%s", filepath.Base(seKeyLabel))
|
unlockerDirName := fmt.Sprintf("se-%s", filepath.Base(seKeyLabel))
|
||||||
unlockerDir := filepath.Join(vaultDir, "unlockers.d", unlockerDirName)
|
unlockerDir := filepath.Join(vaultDir, "unlockers.d", unlockerDirName)
|
||||||
if err := fs.MkdirAll(unlockerDir, DirPerms); err != nil {
|
if err := fs.MkdirAll(unlockerDir, DirPerms); err != nil {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf("failed to create unlocker directory: %w", err)
|
||||||
"failed to create unlocker directory: %w",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write SE-encrypted long-term key
|
// Write SE-encrypted long-term key
|
||||||
ltKeyPath := filepath.Join(unlockerDir, seLongtermFilename)
|
ltKeyPath := filepath.Join(unlockerDir, seLongtermFilename)
|
||||||
if err := afero.WriteFile(fs, ltKeyPath, encryptedLtKey, FilePerms); err != nil {
|
if err := afero.WriteFile(fs, ltKeyPath, encryptedLtKey, FilePerms); err != nil {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf("failed to write SE-encrypted long-term key: %w", err)
|
||||||
"failed to write SE-encrypted long-term key: %w",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write metadata
|
// Write metadata
|
||||||
@@ -308,40 +274,12 @@ func CreateSecureEnclaveUnlocker(
|
|||||||
|
|
||||||
// getLongTermKeyForSE retrieves the vault's long-term private key
|
// getLongTermKeyForSE retrieves the vault's long-term private key
|
||||||
// either from the mnemonic env var or by unlocking via the current unlocker.
|
// either from the mnemonic env var or by unlocking via the current unlocker.
|
||||||
func getLongTermKeyForSE(
|
func getLongTermKeyForSE(fs afero.Fs, vault VaultInterface) (*memguard.LockedBuffer, error) {
|
||||||
fs afero.Fs,
|
|
||||||
vault VaultInterface,
|
|
||||||
) (*memguard.LockedBuffer, error) {
|
|
||||||
envMnemonic := os.Getenv(EnvMnemonic)
|
envMnemonic := os.Getenv(EnvMnemonic)
|
||||||
if envMnemonic != "" {
|
if envMnemonic != "" {
|
||||||
// Read vault metadata to get the correct derivation index
|
ltIdentity, err := agehd.DeriveIdentity(envMnemonic, 0)
|
||||||
vaultDir, err := vault.GetDirectory()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get vault directory: %w", err)
|
return nil, fmt.Errorf("failed to derive long-term key from mnemonic: %w", err)
|
||||||
}
|
|
||||||
|
|
||||||
metadataPath := filepath.Join(vaultDir, "vault-metadata.json")
|
|
||||||
metadataBytes, err := afero.ReadFile(fs, metadataPath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to read vault metadata: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var metadata VaultMetadata
|
|
||||||
if err := json.Unmarshal(metadataBytes, &metadata); err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to parse vault metadata: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use mnemonic with the vault's actual derivation index
|
|
||||||
ltIdentity, err := agehd.DeriveIdentity(
|
|
||||||
envMnemonic,
|
|
||||||
metadata.DerivationIndex,
|
|
||||||
)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf(
|
|
||||||
"failed to derive long-term key from mnemonic: %w",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return memguard.NewBufferFromBytes([]byte(ltIdentity.String())), nil
|
return memguard.NewBufferFromBytes([]byte(ltIdentity.String())), nil
|
||||||
@@ -354,29 +292,17 @@ func getLongTermKeyForSE(
|
|||||||
|
|
||||||
currentIdentity, err := currentUnlocker.GetIdentity()
|
currentIdentity, err := currentUnlocker.GetIdentity()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf("failed to get current unlocker identity: %w", err)
|
||||||
"failed to get current unlocker identity: %w",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// All unlocker types store longterm.age in their directory
|
// All unlocker types store longterm.age in their directory
|
||||||
longtermPath := filepath.Join(
|
longtermPath := filepath.Join(currentUnlocker.GetDirectory(), "longterm.age")
|
||||||
currentUnlocker.GetDirectory(),
|
|
||||||
"longterm.age",
|
|
||||||
)
|
|
||||||
encryptedLtKey, err := afero.ReadFile(fs, longtermPath)
|
encryptedLtKey, err := afero.ReadFile(fs, longtermPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf("failed to read encrypted long-term key: %w", err)
|
||||||
"failed to read encrypted long-term key: %w",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ltPrivKeyBuffer, err := DecryptWithIdentity(
|
ltPrivKeyBuffer, err := DecryptWithIdentity(encryptedLtKey, currentIdentity)
|
||||||
encryptedLtKey,
|
|
||||||
currentIdentity,
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to decrypt long-term key: %w", err)
|
return nil, fmt.Errorf("failed to decrypt long-term key: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,10 @@
|
|||||||
package secret
|
package secret
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"filippo.io/age"
|
"filippo.io/age"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
)
|
)
|
||||||
|
|
||||||
var errSENotSupported = fmt.Errorf(
|
|
||||||
"secure enclave unlockers are only supported on macOS",
|
|
||||||
)
|
|
||||||
|
|
||||||
// SecureEnclaveUnlockerMetadata is a stub for non-Darwin platforms.
|
// SecureEnclaveUnlockerMetadata is a stub for non-Darwin platforms.
|
||||||
type SecureEnclaveUnlockerMetadata struct {
|
type SecureEnclaveUnlockerMetadata struct {
|
||||||
UnlockerMetadata
|
UnlockerMetadata
|
||||||
@@ -28,57 +22,42 @@ type SecureEnclaveUnlocker struct {
|
|||||||
fs afero.Fs
|
fs afero.Fs
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetIdentity returns an error on non-Darwin platforms.
|
// GetIdentity panics on non-Darwin platforms.
|
||||||
func (s *SecureEnclaveUnlocker) GetIdentity() (*age.X25519Identity, error) {
|
func (s *SecureEnclaveUnlocker) GetIdentity() (*age.X25519Identity, error) {
|
||||||
return nil, errSENotSupported
|
panic("secure enclave unlockers are only supported on macOS")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetType returns the unlocker type.
|
// GetType panics on non-Darwin platforms.
|
||||||
func (s *SecureEnclaveUnlocker) GetType() string {
|
func (s *SecureEnclaveUnlocker) GetType() string {
|
||||||
return "secure-enclave"
|
panic("secure enclave unlockers are only supported on macOS")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMetadata returns the unlocker metadata.
|
// GetMetadata panics on non-Darwin platforms.
|
||||||
func (s *SecureEnclaveUnlocker) GetMetadata() UnlockerMetadata {
|
func (s *SecureEnclaveUnlocker) GetMetadata() UnlockerMetadata {
|
||||||
return s.Metadata
|
panic("secure enclave unlockers are only supported on macOS")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDirectory returns the unlocker directory.
|
// GetDirectory panics on non-Darwin platforms.
|
||||||
func (s *SecureEnclaveUnlocker) GetDirectory() string {
|
func (s *SecureEnclaveUnlocker) GetDirectory() string {
|
||||||
return s.Directory
|
panic("secure enclave unlockers are only supported on macOS")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetID returns the unlocker ID.
|
// GetID panics on non-Darwin platforms.
|
||||||
func (s *SecureEnclaveUnlocker) GetID() string {
|
func (s *SecureEnclaveUnlocker) GetID() string {
|
||||||
return fmt.Sprintf(
|
panic("secure enclave unlockers are only supported on macOS")
|
||||||
"%s-secure-enclave",
|
|
||||||
s.Metadata.CreatedAt.Format("2006-01-02.15.04"),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove returns an error on non-Darwin platforms.
|
// Remove panics on non-Darwin platforms.
|
||||||
func (s *SecureEnclaveUnlocker) Remove() error {
|
func (s *SecureEnclaveUnlocker) Remove() error {
|
||||||
return errSENotSupported
|
panic("secure enclave unlockers are only supported on macOS")
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSecureEnclaveUnlocker creates a stub SecureEnclaveUnlocker on non-Darwin platforms.
|
// NewSecureEnclaveUnlocker panics on non-Darwin platforms.
|
||||||
// The returned instance's methods that require macOS functionality will return errors.
|
func NewSecureEnclaveUnlocker(_ afero.Fs, _ string, _ UnlockerMetadata) *SecureEnclaveUnlocker {
|
||||||
func NewSecureEnclaveUnlocker(
|
panic("secure enclave unlockers are only supported on macOS")
|
||||||
fs afero.Fs,
|
|
||||||
directory string,
|
|
||||||
metadata UnlockerMetadata,
|
|
||||||
) *SecureEnclaveUnlocker {
|
|
||||||
return &SecureEnclaveUnlocker{
|
|
||||||
Directory: directory,
|
|
||||||
Metadata: metadata,
|
|
||||||
fs: fs,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateSecureEnclaveUnlocker returns an error on non-Darwin platforms.
|
// CreateSecureEnclaveUnlocker panics on non-Darwin platforms.
|
||||||
func CreateSecureEnclaveUnlocker(
|
func CreateSecureEnclaveUnlocker(_ afero.Fs, _ string) (*SecureEnclaveUnlocker, error) {
|
||||||
_ afero.Fs,
|
panic("secure enclave unlockers are only supported on macOS")
|
||||||
_ string,
|
|
||||||
) (*SecureEnclaveUnlocker, error) {
|
|
||||||
return nil, errSENotSupported
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,90 +0,0 @@
|
|||||||
//go:build !darwin
|
|
||||||
// +build !darwin
|
|
||||||
|
|
||||||
package secret
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/spf13/afero"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestNewSecureEnclaveUnlocker(t *testing.T) {
|
|
||||||
fs := afero.NewMemMapFs()
|
|
||||||
dir := "/tmp/test-se-unlocker"
|
|
||||||
metadata := UnlockerMetadata{
|
|
||||||
Type: "secure-enclave",
|
|
||||||
CreatedAt: time.Date(2026, 1, 15, 10, 30, 0, 0, time.UTC),
|
|
||||||
Flags: []string{"secure-enclave", "macos"},
|
|
||||||
}
|
|
||||||
|
|
||||||
unlocker := NewSecureEnclaveUnlocker(fs, dir, metadata)
|
|
||||||
require.NotNil(t, unlocker, "NewSecureEnclaveUnlocker should return a valid instance")
|
|
||||||
|
|
||||||
// Test GetType returns correct type
|
|
||||||
assert.Equal(t, "secure-enclave", unlocker.GetType())
|
|
||||||
|
|
||||||
// Test GetMetadata returns the metadata we passed in
|
|
||||||
assert.Equal(t, metadata, unlocker.GetMetadata())
|
|
||||||
|
|
||||||
// Test GetDirectory returns the directory we passed in
|
|
||||||
assert.Equal(t, dir, unlocker.GetDirectory())
|
|
||||||
|
|
||||||
// Test GetID returns a formatted string with the creation timestamp
|
|
||||||
expectedID := "2026-01-15.10.30-secure-enclave"
|
|
||||||
assert.Equal(t, expectedID, unlocker.GetID())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSecureEnclaveUnlockerGetIdentityReturnsError(t *testing.T) {
|
|
||||||
fs := afero.NewMemMapFs()
|
|
||||||
metadata := UnlockerMetadata{
|
|
||||||
Type: "secure-enclave",
|
|
||||||
CreatedAt: time.Now().UTC(),
|
|
||||||
}
|
|
||||||
|
|
||||||
unlocker := NewSecureEnclaveUnlocker(fs, "/tmp/test", metadata)
|
|
||||||
|
|
||||||
identity, err := unlocker.GetIdentity()
|
|
||||||
assert.Nil(t, identity)
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.ErrorIs(t, err, errSENotSupported)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSecureEnclaveUnlockerRemoveReturnsError(t *testing.T) {
|
|
||||||
fs := afero.NewMemMapFs()
|
|
||||||
metadata := UnlockerMetadata{
|
|
||||||
Type: "secure-enclave",
|
|
||||||
CreatedAt: time.Now().UTC(),
|
|
||||||
}
|
|
||||||
|
|
||||||
unlocker := NewSecureEnclaveUnlocker(fs, "/tmp/test", metadata)
|
|
||||||
|
|
||||||
err := unlocker.Remove()
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.ErrorIs(t, err, errSENotSupported)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCreateSecureEnclaveUnlockerReturnsError(t *testing.T) {
|
|
||||||
fs := afero.NewMemMapFs()
|
|
||||||
|
|
||||||
unlocker, err := CreateSecureEnclaveUnlocker(fs, "/tmp/test")
|
|
||||||
assert.Nil(t, unlocker)
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.ErrorIs(t, err, errSENotSupported)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSecureEnclaveUnlockerImplementsInterface(t *testing.T) {
|
|
||||||
fs := afero.NewMemMapFs()
|
|
||||||
metadata := UnlockerMetadata{
|
|
||||||
Type: "secure-enclave",
|
|
||||||
CreatedAt: time.Now().UTC(),
|
|
||||||
}
|
|
||||||
|
|
||||||
unlocker := NewSecureEnclaveUnlocker(fs, "/tmp/test", metadata)
|
|
||||||
|
|
||||||
// Verify the stub implements the Unlocker interface
|
|
||||||
var _ Unlocker = unlocker
|
|
||||||
}
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
//go:build darwin
|
|
||||||
// +build darwin
|
|
||||||
|
|
||||||
package secret
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/spf13/afero"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestNewSecureEnclaveUnlocker(t *testing.T) {
|
|
||||||
fs := afero.NewMemMapFs()
|
|
||||||
dir := "/tmp/test-se-unlocker"
|
|
||||||
metadata := UnlockerMetadata{
|
|
||||||
Type: "secure-enclave",
|
|
||||||
CreatedAt: time.Date(2026, 1, 15, 10, 30, 0, 0, time.UTC),
|
|
||||||
Flags: []string{"secure-enclave", "macos"},
|
|
||||||
}
|
|
||||||
|
|
||||||
unlocker := NewSecureEnclaveUnlocker(fs, dir, metadata)
|
|
||||||
require.NotNil(t, unlocker, "NewSecureEnclaveUnlocker should return a valid instance")
|
|
||||||
|
|
||||||
// Test GetType returns correct type
|
|
||||||
assert.Equal(t, seUnlockerType, unlocker.GetType())
|
|
||||||
|
|
||||||
// Test GetMetadata returns the metadata we passed in
|
|
||||||
assert.Equal(t, metadata, unlocker.GetMetadata())
|
|
||||||
|
|
||||||
// Test GetDirectory returns the directory we passed in
|
|
||||||
assert.Equal(t, dir, unlocker.GetDirectory())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSecureEnclaveUnlockerImplementsInterface(t *testing.T) {
|
|
||||||
fs := afero.NewMemMapFs()
|
|
||||||
metadata := UnlockerMetadata{
|
|
||||||
Type: "secure-enclave",
|
|
||||||
CreatedAt: time.Now().UTC(),
|
|
||||||
}
|
|
||||||
|
|
||||||
unlocker := NewSecureEnclaveUnlocker(fs, "/tmp/test", metadata)
|
|
||||||
|
|
||||||
// Verify the darwin implementation implements the Unlocker interface
|
|
||||||
var _ Unlocker = unlocker
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSecureEnclaveUnlockerGetIDFormat(t *testing.T) {
|
|
||||||
fs := afero.NewMemMapFs()
|
|
||||||
metadata := UnlockerMetadata{
|
|
||||||
Type: "secure-enclave",
|
|
||||||
CreatedAt: time.Date(2026, 3, 10, 14, 30, 0, 0, time.UTC),
|
|
||||||
}
|
|
||||||
|
|
||||||
unlocker := NewSecureEnclaveUnlocker(fs, "/tmp/test", metadata)
|
|
||||||
id := unlocker.GetID()
|
|
||||||
|
|
||||||
// ID should contain the timestamp and "secure-enclave" type
|
|
||||||
assert.Contains(t, id, "2026-03-10.14.30")
|
|
||||||
assert.Contains(t, id, seUnlockerType)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGenerateSEKeyLabel(t *testing.T) {
|
|
||||||
label, err := generateSEKeyLabel("test-vault")
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Label should contain the prefix and vault name
|
|
||||||
assert.Contains(t, label, seKeyLabelPrefix)
|
|
||||||
assert.Contains(t, label, "test-vault")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSecureEnclaveUnlockerGetIdentityMissingFile(t *testing.T) {
|
|
||||||
fs := afero.NewMemMapFs()
|
|
||||||
dir := "/tmp/test-se-unlocker-missing"
|
|
||||||
|
|
||||||
// Create unlocker directory with metadata but no encrypted key file
|
|
||||||
require.NoError(t, fs.MkdirAll(dir, DirPerms))
|
|
||||||
|
|
||||||
metadataJSON := `{
|
|
||||||
"type": "secure-enclave",
|
|
||||||
"createdAt": "2026-01-15T10:30:00Z",
|
|
||||||
"seKeyLabel": "berlin.sneak.app.secret.se.test",
|
|
||||||
"seKeyHash": "abc123"
|
|
||||||
}`
|
|
||||||
require.NoError(t, afero.WriteFile(fs, dir+"/unlocker-metadata.json", []byte(metadataJSON), FilePerms))
|
|
||||||
|
|
||||||
metadata := UnlockerMetadata{
|
|
||||||
Type: "secure-enclave",
|
|
||||||
CreatedAt: time.Date(2026, 1, 15, 10, 30, 0, 0, time.UTC),
|
|
||||||
}
|
|
||||||
|
|
||||||
unlocker := NewSecureEnclaveUnlocker(fs, dir, metadata)
|
|
||||||
|
|
||||||
// GetIdentity should fail because the encrypted longterm key file is missing
|
|
||||||
identity, err := unlocker.GetIdentity()
|
|
||||||
assert.Nil(t, identity)
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.Contains(t, err.Error(), "failed to read SE-encrypted long-term key")
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user