From 04d4b908dba2d8f4fac47134127f450a9d063611 Mon Sep 17 00:00:00 2001 From: Costa Huang Date: Thu, 13 Dec 2018 15:54:52 -0500 Subject: [PATCH] API-15 # Delete the Salt and use environment variable to generate the salt --- .dockerignore | 3 ++- .gitignore | 3 ++- encryption.go | 2 -- utils/generate_salt_file.go | 31 +++++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 utils/generate_salt_file.go diff --git a/.dockerignore b/.dockerignore index afbc551..f8d8061 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,3 @@ vendor -Dockerfile \ No newline at end of file +Dockerfile +salt.go \ No newline at end of file diff --git a/.gitignore b/.gitignore index 12852ca..3fe9c63 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ cmd/portwarden/portwarden_backup/* vendor/* **/*.portwarden -**/*.decrypted.zip \ No newline at end of file +**/*.decrypted.zip +salt.go \ No newline at end of file diff --git a/encryption.go b/encryption.go index 7d9a2e2..89ced60 100644 --- a/encryption.go +++ b/encryption.go @@ -14,8 +14,6 @@ import ( ) const ( - Salt = `,(@0vd<)D6c3:5jI;4BZ(#Gx2IZ6B>` - ErrMessageAuthenticationFailed = "cipher: message authentication failed" ErrWrongBackupPassphrase = "wrong backup passphrase entered" ) diff --git a/utils/generate_salt_file.go b/utils/generate_salt_file.go new file mode 100644 index 0000000..1fb19c6 --- /dev/null +++ b/utils/generate_salt_file.go @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "io/ioutil" + "log" + "os" +) + +const ( + Template = `package portwarden + +const ( + Salt = "%v" +) +` +) + +func main() { + Salt := os.Getenv("Salt") + if len(Salt) == 0 { + log.Fatal("Salt not detected in Environment Variable `Salt`") + } + err := ioutil.WriteFile("./salt.go", []byte(fmt.Sprintf(Template, Salt)), 0644) + if err != nil { + if len(Salt) == 0 { + log.Fatalf("Error writing salt file: %v", err) + } + } + +}