@@ -87,20 +87,23 @@ func CreateConfFile(filename string, password string, plaintextNames bool, logN
87
87
if aessiv {
88
88
cf .FeatureFlags = append (cf .FeatureFlags , knownFlags [FlagAESSIV ])
89
89
}
90
-
91
- // Generate new random master key
92
- var key []byte
93
- if devrandom {
94
- key = randBytesDevRandom (cryptocore .KeyLen )
95
- } else {
96
- key = cryptocore .RandBytes (cryptocore .KeyLen )
90
+ {
91
+ // Generate new random master key
92
+ var key []byte
93
+ if devrandom {
94
+ key = randBytesDevRandom (cryptocore .KeyLen )
95
+ } else {
96
+ key = cryptocore .RandBytes (cryptocore .KeyLen )
97
+ }
98
+ // Encrypt it using the password
99
+ // This sets ScryptObject and EncryptedKey
100
+ // Note: this looks at the FeatureFlags, so call it AFTER setting them.
101
+ cf .EncryptKey (key , password , logN )
102
+ for i := range key {
103
+ key [i ] = 0
104
+ }
105
+ // key runs out of scope here
97
106
}
98
-
99
- // Encrypt it using the password
100
- // This sets ScryptObject and EncryptedKey
101
- // Note: this looks at the FeatureFlags, so call it AFTER setting them.
102
- cf .EncryptKey (key , password , logN )
103
-
104
107
// Write file to disk
105
108
return cf .WriteFile ()
106
109
}
@@ -197,14 +200,17 @@ func LoadConfFile(filename string, password string) ([]byte, *ConfFile, error) {
197
200
// Uses scrypt with cost parameter logN and stores the scrypt parameters in
198
201
// cf.ScryptObject.
199
202
func (cf * ConfFile ) EncryptKey (key []byte , password string , logN int ) {
200
- // Generate derived key from password
203
+ // Generate scrypt- derived key from password
201
204
cf .ScryptObject = NewScryptKDF (logN )
202
205
scryptHash := cf .ScryptObject .DeriveKey (password )
203
-
204
206
// Lock master key using password-based key
205
207
useHKDF := cf .IsFeatureFlagSet (FlagHKDF )
206
208
ce := getKeyEncrypter (scryptHash , useHKDF )
207
209
cf .EncryptedKey = ce .EncryptBlock (key , 0 , nil )
210
+ // Purge scrypt-derived key
211
+ for i := range scryptHash {
212
+ scryptHash [i ] = 0
213
+ }
208
214
}
209
215
210
216
// WriteFile - write out config in JSON format to file "filename.tmp"
0 commit comments