add option to change password for locked_secretbox in trees-create

This commit is contained in:
matthias 2018-05-19 12:12:30 +02:00
parent ed0bbfb274
commit cc048ab937

View File

@ -27,16 +27,20 @@ end
def usage def usage
puts "USAGE:" puts "USAGE:"
puts " trees-create --password PASSWORD [OPTIONS]" puts " trees-create --password PASSWORD [OPTIONS]"
puts " trees-create --password PASSWORD --old-password PASSWORD OPTIONS"
puts puts
puts "OPTIONS may include:" puts "OPTIONS may include:"
puts " --opslimit OPSLIMIT -- argon2 ops limit, integer in 3..10, or one of" puts " --opslimit OPSLIMIT -- argon2 ops limit, integer in 3..10, or one of"
puts " 'interactive', 'moderate', 'sensitive'" puts " 'interactive', 'moderate', 'sensitive'"
puts " --memlimit MEMLIMIT -- argon2 memory limit, in bytes, or one of" puts " --memlimit MEMLIMIT -- argon2 memory limit, in bytes, or one of"
puts " 'interactive', 'moderate', 'sensitive'" puts " 'interactive', 'moderate', 'sensitive'"
puts " --salt SALT -- hex encoded salt for password digest," puts " --salt SALT -- hex encoded salt for password digest,"
puts " #{StorageKey::SALT_BYTES} bytes in length" puts " #{StorageKey::SALT_BYTES} bytes in length"
puts " --nonce NONCE -- hex encoded nonce for secretbox encryption of" puts " --nonce NONCE -- hex encoded nonce for secretbox encryption of"
puts " private key, #{StorageKey::NONCE_BYTES} bytes in length" puts " private key, #{StorageKey::NONCE_BYTES} bytes in length"
puts " --secretbox SECRETBOX -- hex encoded secretbox"
puts
puts "for password change all options are required"
exit 1 exit 1
end end
@ -46,6 +50,9 @@ def main
while ARGV.any? while ARGV.any?
case ARGV.first case ARGV.first
when "--old-password"
ARGV.shift
old_password = ARGV.shift
when "--password" when "--password"
ARGV.shift ARGV.shift
password = ARGV.shift password = ARGV.shift
@ -61,12 +68,19 @@ def main
when "--nonce" when "--nonce"
ARGV.shift ARGV.shift
st.sk_nonce = ARGV.shift st.sk_nonce = ARGV.shift
when "--secretbox"
ARGV.shift
st.locked_secretbox = ARGV.shift
else else
usage usage
end end
end end
usage unless password usage unless password
st.generate_new_keypair(password) if old_password.nil?
st.generate_new_keypair(password)
else
st.change_password(old_password, password)
end
puts st.to_s puts st.to_s
end end
@ -121,6 +135,14 @@ class StorageKey
) )
end end
def change_password(old_password, password)
key = self.decrypt_key(old_password)
self.encrypt_key(
key: key,
password: password
)
end
def to_s def to_s
attrs = [:public_key, :locked_secretbox, :sk_nonce, :pwhash_opslimit, attrs = [:public_key, :locked_secretbox, :sk_nonce, :pwhash_opslimit,
:pwhash_memlimit, :pwhash_salt] :pwhash_memlimit, :pwhash_salt]