Module: Diaspora::Encryptable
- Included in:
- Relayable, SignedRetraction
- Defined in:
- lib/diaspora/encryptable.rb
Instance Method Summary (collapse)
-
- (String) sign_with_key(key)
A Base64 encoded signature of #signable_string with key.
-
- (Array<String>) signable_accessors
The ROXML attrs other than author_signature and parent_author_signature.
-
- (String) signable_string
Defaults to the ROXML attrs which are not signatures.
-
- (Boolean) verify_signature(signature, person)
Check that signature is a correct signature of #signable_string by person.
Instance Method Details
- (String) sign_with_key(key)
A Base64 encoded signature of #signable_string with key
28 29 30 31 32 33 34 |
# File 'lib/diaspora/encryptable.rb', line 28 def sign_with_key(key) sig = Base64.strict_encode64(key.sign( OpenSSL::Digest::SHA256.new, signable_string )) log_hash = {:event => :sign_with_key, :status => :complete} log_hash.merge(:model_id => self.id) if self.respond_to?(:persisted?) Rails.logger.info(log_hash) sig end |
- (Array<String>) signable_accessors
The ROXML attrs other than author_signature and parent_author_signature.
37 38 39 40 41 42 43 44 45 |
# File 'lib/diaspora/encryptable.rb', line 37 def signable_accessors accessors = self.class.roxml_attrs.collect do |definition| definition.accessor end ['author_signature', 'parent_author_signature'].each do |acc| accessors.delete acc end accessors end |
- (String) signable_string
Defaults to the ROXML attrs which are not signatures.
48 49 50 51 52 |
# File 'lib/diaspora/encryptable.rb', line 48 def signable_string signable_accessors.collect{ |accessor| (self.send accessor.to_sym).to_s }.join(';') end |
- (Boolean) verify_signature(signature, person)
Check that signature is a correct signature of #signable_string by person
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/diaspora/encryptable.rb', line 8 def verify_signature(signature, person) if person.nil? Rails.logger.info("event=verify_signature status=abort reason=no_person guid=#{self.guid}") return false elsif person.public_key.nil? Rails.logger.info("event=verify_signature status=abort reason=no_key guid=#{self.guid}") return false elsif signature.nil? Rails.logger.info("event=verify_signature status=abort reason=no_signature guid=#{self.guid}") return false end log_string = "event=verify_signature status=complete guid=#{self.guid}" validity = person.public_key.verify OpenSSL::Digest::SHA256.new, Base64.decode64(signature), signable_string log_string += " validity=#{validity}" Rails.logger.info(log_string) validity end |