duritong / trocla

A password store for password creation and retrieval
Other
76 stars 17 forks source link

Reset doesn't work with SSL encryption #52

Closed fe80 closed 3 years ago

fe80 commented 7 years ago

Hi,

I've found a issue with reset password and SSL Encryption:

irb(main):001:0> require 'trocla'
=> true
irb(main):002:0> trocla = Trocla.new
=> #<Trocla:0x00000002bc90b0 @config_file="/etc/troclarc.yaml">
irb(main):003:0> trocla_get('toto', 'plain', {})
NoMethodError: undefined method `trocla_get' for main:Object
    from (irb):3
    from /bin/irb:12:in `<main>'
irb(main):004:0> trocla.get_password('toto', 'plain', {})
=> "toto"
irb(main):005:0> trocla.reset_password('toto', 'plain', {})
NoMethodError: undefined method `scan' for nil:NilClass
    from /usr/local/share/gems/gems/trocla-0.2.3/lib/trocla/encryptions/ssl.rb:7:in `encrypt'
    from /usr/local/share/gems/gems/trocla-0.2.3/lib/trocla.rb:129:in `encrypt'
    from /usr/local/share/gems/gems/trocla-0.2.3/lib/trocla.rb:76:in `set_password'
    from /usr/local/share/gems/gems/trocla-0.2.3/lib/trocla.rb:60:in `reset_password'
    from (irb):5
    from /bin/irb:12:in `<main>'

reset_password set en password with nil value, and it doesn't work for :

   def encrypt(value)
     ciphertext = ''
     value.scan(/.{0,#{chunksize}}/m).each do |chunk|
       ciphertext += Base64.encode64(public_key.public_encrypt(chunk)).gsub("\n",'')+"\n" if chunk
     end
     ciphertext
   end

Without SSL it's ok:

irb(main):001:0> require 'trocla'
=> true
irb(main):002:0> trocla = Trocla.new
=> #<Trocla:0x000055e708b9e390 @config_file="/home/steffy/.troclarc.yaml">
irb(main):003:0> trocla.get_password('toto', 'plain', {})
=> "A2XvkVfO_86DF][!"
irb(main):004:0> trocla.reset_password('toto', 'plain', {})
=> "[7+Y2eGQFs)rsbV-"