spikex / strongbox

Secures ActiveRecord attributes with public key encryption
http://stuff-things.net/2009/04/17/introducing-strongbox/
MIT License
398 stars 42 forks source link

Enable migration to/from :symmetric encryption #17

Closed jmileham closed 10 years ago

jmileham commented 13 years ago

Hi Spike,

Wondered if you'd be interested in this patch. It allows decryption of symmetrically encrypted columns even when :symmetric => :never, and decryption of asymmetrically-encrypted columns even when :symmetric => :always, which allows developers to change their implementation against a live database without having to get their hands dirty.

I understand that it muddies the semantics of :always and :never for the purposes of decryption, but it does uphold the guarantee that any subsequent encryption will follow the expected semantics (and tellingly didn't require modification of any existing tests to implement). The patch enables behavior that previously would've resulted in somewhat mysterious errors, e.g. this trace from a decrypt of a model that was switched to symmetric encryption:

/usr/ruby1.9.2/lib/ruby/1.9.1/base64.rb:58:in `decode64'
.bundle/gems/ruby/1.9.1/gems/strongbox-0.4.6/lib/strongbox/lock.rb:82:in `decrypt'

Perhaps a flag (maybe :enable_migration) to allow the developer to opt into the modified semantics would be a good addition if a change like this makes you nervous, or perhaps that's too much.

Or perhaps you just want to keep it simple and not go there at all. Anyway, great plugin.

Thanks, -john

spikex commented 13 years ago

I'm on the fence about an additional flag. On the one hand, I like the clean it just works aspect. On the other, it does as, you say, muddy the semantics.