more implementation of runtime unlock
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
30
models/key.go
Normal file
30
models/key.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package models
|
||||
|
||||
import "errors"
|
||||
|
||||
// TODO: Look at using shamir's secret sharing to distribute components of the secret key
|
||||
var secretKey []byte
|
||||
var secretReceived bool
|
||||
|
||||
func ReceiveKey(key string) error {
|
||||
|
||||
// confirm that the key is 32 bytes long exactly
|
||||
if len(key) != 32 {
|
||||
return errors.New("secret key provided is not exactly 32 bytes long")
|
||||
}
|
||||
|
||||
// Store the secret key so that we can access it when encrypting/decrypting
|
||||
secretKey = []byte(key)
|
||||
secretReceived = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func ProvideKey() ([]byte, error) {
|
||||
|
||||
// Provide the key when needed to decrypt/encrypt stored secrets
|
||||
if secretReceived {
|
||||
return secretKey, nil
|
||||
} else {
|
||||
return nil, errors.New("secret key has not been received")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user