added encryption/decryption strategy

This commit is contained in:
0xdcarns
2022-01-28 15:33:30 -05:00
parent 749e6f464d
commit 0015d6fdf8
14 changed files with 318 additions and 111 deletions

View File

@@ -73,7 +73,7 @@ func AutoLogin(client nodepb.NodeServiceClient, network string) error {
return err
}
tokenstring := []byte(res.Data)
err = os.WriteFile(home+"nettoken-"+network, tokenstring, 0644) // TODO: Proper permissions?
err = os.WriteFile(home+"nettoken-"+network, tokenstring, 0600) // TODO: Proper permissions?
if err != nil {
return err
}
@@ -83,8 +83,7 @@ func AutoLogin(client nodepb.NodeServiceClient, network string) error {
// StoreSecret - stores auth secret locally
func StoreSecret(key string, network string) error {
d1 := []byte(key)
err := os.WriteFile(ncutils.GetNetclientPathSpecific()+"secret-"+network, d1, 0644)
return err
return os.WriteFile(ncutils.GetNetclientPathSpecific()+"secret-"+network, d1, 0600)
}
// RetrieveSecret - fetches secret locally
@@ -93,6 +92,17 @@ func RetrieveSecret(network string) (string, error) {
return string(dat), err
}
// StoreTrafficKey - stores traffic key
func StoreTrafficKey(key string, network string) error {
return os.WriteFile(ncutils.GetNetclientPathSpecific()+"traffic-"+network, []byte(key), 0600)
}
// RetrieveTrafficKey - reads traffic file locally
func RetrieveTrafficKey(network string) (string, error) {
dat, err := os.ReadFile(ncutils.GetNetclientPathSpecific() + "traffic-" + network)
return string(dat), err
}
// Configuraion - struct for mac and pass
type Configuration struct {
MacAddress string