more implementation of runtime unlock
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-12-28 11:14:16 +11:00
parent 9203e09d2d
commit 484acd1822
7 changed files with 115 additions and 43 deletions

30
models/key.go Normal file
View 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")
}
}