the salmon now encrypts the activity, and stores the aes key in the header

This commit is contained in:
ilya 2010-09-28 13:22:19 -07:00
parent 6eede48f9f
commit c7d29b29c8
2 changed files with 23 additions and 8 deletions

View file

@ -41,7 +41,19 @@ end
module Salmon
class SalmonSlap
attr_accessor :magic_sig, :author, :author_email, :parsed_data, :data_type, :sig
attr_accessor :magic_sig, :author, :author_email, :aes_key, :iv, :parsed_data,
:data_type, :sig
def self.create(user, activity)
salmon = self.new
salmon.author = user.person
aes_key_hash = user.person.gen_aes_key
salmon.aes_key = aes_key_hash['key']
salmon.iv = aes_key_hash['iv']
salmon.magic_sig = MagicSigEnvelope.create(user , user.person.aes_encrypt(activity, aes_key_hash))
salmon
end
def self.parse(xml)
slap = self.new
doc = Nokogiri::XML(xml)
@ -65,13 +77,6 @@ module Salmon
slap
end
def self.create(user, activity)
salmon = self.new
salmon.author = user.person
salmon.magic_sig = MagicSigEnvelope.create(user , activity)
salmon
end
def to_xml
xml =<<ENTRY
<?xml version='1.0' encoding='UTF-8'?>

View file

@ -18,7 +18,17 @@ describe Salmon do
it 'has no parsed_data' do
created_salmon.parsed_data.should be nil
end
it 'sets aes and iv key' do
created_salmon.aes_key.should_not be nil
created_salmon.iv.should_not be nil
end
it 'should make the data in the signature encrypted with that key' do
key_hash = {'key' => created_salmon.aes_key, 'iv' => created_salmon.iv}
decoded_string = Salmon::SalmonSlap.decode64url(created_salmon.magic_sig.data)
user.aes_decrypt(decoded_string, key_hash).to_s.should == post.to_diaspora_xml.to_s
end
end
context 'round trip' do