github.com/cozy/cozy-stack@v0.0.0-20240603063001-31110fa4cae1/pkg/keyring/stub.go (about) 1 package keyring 2 3 import ( 4 "fmt" 5 6 "github.com/cozy/cozy-stack/pkg/utils" 7 ) 8 9 // Stub is a minimal *UNSECURE* implementation of [Keyring]. 10 // 11 // As the credentials should remain the same between several 12 // executions of the stack, we are using some credentials generated 13 // with a seed defined at build time. It is obviously not a good idea 14 // from a security point of view, and it should not be used to store 15 // sensible data. This implem is not safe and should never be used in 16 // production. 17 type Stub struct { 18 credsEncryptor *NACLKey 19 credsDecryptor *NACLKey 20 } 21 22 // NewStub instantiate a new [Stub]. 23 func NewStub() (*Stub, error) { 24 r := utils.NewSeededRand(42) 25 26 credsEncryptor, credsDecryptor, err := GenerateKeyPair(r) 27 if err != nil { 28 return nil, fmt.Errorf("failed to generate NACL key pair: %w", err) 29 } 30 31 return &Stub{credsEncryptor, credsDecryptor}, nil 32 } 33 34 func (s *Stub) CredentialsEncryptorKey() *NACLKey { 35 return s.credsEncryptor 36 } 37 38 func (s *Stub) CredentialsDecryptorKey() *NACLKey { 39 return s.credsDecryptor 40 }