Skip to content
Extraits de code Groupes Projets
encryptable.rb 1,13 ko
Newer Older
  • Learn to ignore specific revisions
  • Raphael's avatar
    Raphael a validé
      module Encryptable
       def signable_string
         ""
       end
        def verify_creator_signature
          verify_signature(creator_signature, person)
        end
        
        def verify_signature(signature, person)
          return false unless signature && person.key_fingerprint
          validity = nil
    
          Rails.logger.info("Verifying sig on #{signable_string} from person #{person.real_name}")
    
          GPGME::verify(signature, signable_string, 
    
            {:armor => true, :always_trust => true}){ |signature_analysis|
    
            #puts signature_analysis
    
            validity =  signature_analysis.status == GPGME::GPG_ERR_NO_ERROR &&
                signature_analysis.fpr == person.key_fingerprint
    
    Raphael's avatar
    Raphael a validé
          }
          return validity
        end
        
        protected
        def sign_if_mine
          if self.person == User.owner
            self.creator_signature = sign
          end
        end
    
        def sign
    
          sign_with_key(User.owner.key)
        end
    
        def sign_with_key(key)
    
          Rails.logger.info("Signing #{signable_string} with key for person #{self.person.real_name}")
    
    Raphael's avatar
    Raphael a validé
          GPGME::sign(signable_string,nil,
    
              {:armor=> true, :mode => GPGME::SIG_MODE_DETACH, :signers => [key]})
    
    Raphael's avatar
    Raphael a validé
        end
      end