Class: Salmon::EncryptedSlap

Inherits:
Slap
  • Object
show all
Defined in:
lib/salmon/encrypted_slap.rb

Instance Attribute Summary

Attributes inherited from Slap

#aes_key, #author, #author_id, #iv, #magic_sig, #parsed_data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Slap

b64_to_n, build_key, create_by_user_and_activity, decode64url, from_xml, parse_key, #verified_for_key?

Class Method Details

.payload(activity, user, aes_key_hash) ⇒ String

Encrypt the magic sig


63
64
65
# File 'lib/salmon/encrypted_slap.rb', line 63

def self.payload(activity, user, aes_key_hash)
  user.person.aes_encrypt(activity, aes_key_hash)
end

Instance Method Details

#header(person) ⇒ String

Construct an encrypted header


10
11
12
13
14
15
16
# File 'lib/salmon/encrypted_slap.rb', line 10

def header(person)
  "    <encrypted_header>\n      \#{person.encrypt(plaintext_header)}\n    </encrypted_header>\n"
end

#parse_data(user) ⇒ Object

Decrypts an encrypted magic sig envelope


50
51
52
# File 'lib/salmon/encrypted_slap.rb', line 50

def parse_data(user)
  user.aes_decrypt(super, {'key' => self.aes_key, 'iv' => self.iv})
end

#plaintext_headerObject


18
19
20
21
22
23
24
25
26
# File 'lib/salmon/encrypted_slap.rb', line 18

def plaintext_header
  header ="<decrypted_header>\n<iv>\#{iv}</iv>\n<aes_key>\#{aes_key}</aes_key>\n<author_id>\#{@author.diaspora_handle}</author_id>\n</decrypted_header>\n"
end

#process_header(doc) ⇒ Hash

Takes in a doc of the header and sets the author id returns an empty hash


41
42
43
44
45
# File 'lib/salmon/encrypted_slap.rb', line 41

def process_header(doc)
  self.author_id   = doc.search('author_id').text
  self.aes_key     = doc.search('aes_key').text
  self.iv          = doc.search('iv').text
end

#salmon_header(doc, user) ⇒ Nokogiri::Doc

Decrypts and parses out the salmon header


56
57
58
59
# File 'lib/salmon/encrypted_slap.rb', line 56

def salmon_header(doc, user)
  header = user.decrypt(doc.search('encrypted_header').text)
  Nokogiri::XML(header)
end

#xml_for(person) ⇒ String, Boolean


29
30
31
32
33
34
35
36
# File 'lib/salmon/encrypted_slap.rb', line 29

def xml_for(person)
  begin
   super 
  rescue OpenSSL::PKey::RSAError => e
    Rails.logger.info("event => :invalid_rsa_key, :identifier => #{person.diaspora_handle}")
    false
  end
end