Class: CARPS::Peer

Inherits:
UserConfig show all
Defined in:
lib/carps/crypt/peer.rb

Overview

Peers

Instance Method Summary collapse

Methods inherited from UserConfig

load

Methods inherited from YamlConfig

#fail_hard, #read

Constructor Details

#initialize(addr) ⇒ Peer

Create a new peer



64
65
66
# File 'lib/carps/crypt/peer.rb', line 64

def initialize addr
   @addr = addr
end

Instance Method Details

#addrObject



68
69
70
# File 'lib/carps/crypt/peer.rb', line 68

def addr
   @addr
end

#saveObject

Save as YAML file in .peers



95
96
97
98
99
100
101
102
# File 'lib/carps/crypt/peer.rb', line 95

def save
   y = emit.to_yaml 
   begin
      write_file_in ".peers/", y
   rescue StandardError => e
      UI::warn "Could not save Peer in .peers/"
   end
end

#verify(mail) ⇒ Object

Perform a verification on an email



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/carps/crypt/peer.rb', line 78

def verify mail
   sig, dig = mail.crypt 
   begin
      pass = @peer_key.sysverify dig, sig
   rescue OpenSSL::PKey::DSAError => e
      UI::warn "Someone sent you an invalid signature: #{e.message}"
      return false
   end
   if pass
      return true
   else
      UI::warn "Someone has attempted to spoof an email from #{mail.from}", mail.to_s 
      return false
   end
end

#your_key(key) ⇒ Object

Tell this peer its key



73
74
75
# File 'lib/carps/crypt/peer.rb', line 73

def your_key key
   @peer_key = key
end