carps 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/PostInstall.txt CHANGED
@@ -5,7 +5,7 @@
5
5
  o
6
6
  ><> ><> ><>
7
7
 
8
- Thank you for installing CARPS 0.2.3
8
+ Thank you for installing CARPS 0.3.0
9
9
 
10
10
  For help, run:
11
11
 
@@ -45,7 +45,6 @@ module CARPS
45
45
  @sender = sender
46
46
  @mail = []
47
47
  @peers = {}
48
- @secure = false
49
48
  # Semaphore to make sure only one thread can send mail at any one time
50
49
  @ssemaphore = Mutex.new
51
50
  # Semaphore to make sure only one thread can receive mail at any one time
@@ -125,16 +124,17 @@ module CARPS
125
124
  @mail.each_index do |index|
126
125
  mail = @mail[index]
127
126
  from = mail.from
128
- if secure from
129
- unless @peers[from].verify mail
127
+ peer = @peers[from]
128
+ if peer
129
+ unless peer.verify mail
130
130
  remove_mail index
131
131
  next
132
132
  end
133
- end
134
- pass = appropriate?(mail, type, must_be_from)
135
- if pass
136
- remove_mail index
137
- return mail
133
+ pass = appropriate? mail, type, must_be_from
134
+ if pass
135
+ remove_mail index
136
+ return mail
137
+ end
138
138
  end
139
139
  end
140
140
  nil
@@ -150,23 +150,28 @@ module CARPS
150
150
  pass and @manager.belong? mail
151
151
  end
152
152
 
153
+ # Was the mail message appropriate? (To a degree)
154
+ def insecure_appropriate? mail, type, must_be_from
155
+ pass = mail.class == type
156
+ if must_be_from
157
+ pass = pass and mail.from == must_be_from
158
+ end
159
+ pass
160
+ end
161
+
162
+
153
163
  # Remove a mail message
154
164
  def remove_mail index
155
165
  @mail[index].delete
156
166
  @mail.delete_at index
157
167
  end
158
168
 
159
- # Communication with someone is secure if there is a peer for them
160
- def secure addr
161
- @peers.member? addr
162
- end
163
-
164
169
  # Insecurely see if there is an appropriate message in the mail box
165
170
  def insecure_search type, must_be_from
166
171
  @rsemaphore.synchronize do
167
172
  @mail.each_index do |index|
168
173
  mail = @mail[index]
169
- pass = appropriate?(mail, type, must_be_from)
174
+ pass = insecure_appropriate? mail, type, must_be_from
170
175
  if pass
171
176
  remove_mail index
172
177
  return mail
@@ -33,6 +33,8 @@ require "digest/md5"
33
33
 
34
34
  require "openssl"
35
35
 
36
+ require "set"
37
+
36
38
  module CARPS
37
39
 
38
40
  # High level CARPS mail client supporting strong cryptographic message signing.
@@ -51,6 +53,7 @@ module CARPS
51
53
  @mailbox = mailbox
52
54
  @private_key = get_keys
53
55
  @public_key = @private_key.public_key
56
+ @current_handshakes = Set.new
54
57
  # Load the old peers
55
58
  load_peers
56
59
  end
@@ -61,6 +64,7 @@ module CARPS
61
64
  puts "No need for handshake: " + to + " is already a known peer."
62
65
  else
63
66
  puts "Offering cryptographic handshake to #{to}"
67
+ @current_handshakes.add to
64
68
  # Create a new peer
65
69
  peer = Peer.new to
66
70
  @mailbox.add_peer peer
@@ -73,7 +77,11 @@ module CARPS
73
77
  # Send our key
74
78
  send to, PublicKey.new(@public_key)
75
79
  # Receive an okay message
76
- read AcceptHandshake, to
80
+ #
81
+ # Has to be insecure for now... :(
82
+ #
83
+ # This is because the client may not know the session yet.
84
+ @mailbox.insecure_read AcceptHandshake, to
77
85
  puts "Established spoof-proof communications with #{to}"
78
86
  end
79
87
  end
@@ -99,18 +107,21 @@ module CARPS
99
107
  # See if the user accepts the handshake.
100
108
  accept = accept_handshake? from
101
109
  if accept
102
- # Send our key to the peer
103
- send from, PublicKey.new(@public_key)
104
- # Get their key
105
- peer_key = @mailbox.insecure_read PublicKey, from
106
- # Create a new peer
107
- peer = Peer.new from
108
- @mailbox.add_peer peer
109
- peer.your_key peer_key.key
110
- peer.save
111
- # Send an okay message
112
- send from, AcceptHandshake.new
113
- puts "Established spoof-proof communications with #{from}."
110
+ Thread.fork do
111
+ @current_handshakes.add from
112
+ # Send our key to the peer
113
+ send from, PublicKey.new(@public_key)
114
+ # Get their key
115
+ peer_key = @mailbox.insecure_read PublicKey, from
116
+ # Create a new peer
117
+ peer = Peer.new from
118
+ @mailbox.add_peer peer
119
+ peer.your_key peer_key.key
120
+ peer.save
121
+ # Send an okay message
122
+ send from, AcceptHandshake.new
123
+ puts "Established spoof-proof communications with #{from}."
124
+ end
114
125
  end
115
126
  end
116
127
  end
@@ -122,6 +133,11 @@ module CARPS
122
133
 
123
134
  # Send a message
124
135
  def send to, message
136
+ unless @mailbox.peer?(to) or @current_handshakes.include?(to)
137
+ Thread.fork do
138
+ handshake to
139
+ end
140
+ end
125
141
  text = message.emit
126
142
  # The mailbox tags the message with a session key
127
143
  text = @mailbox.tag text
data/lib/carps.rb CHANGED
@@ -41,5 +41,5 @@ require "carps/wizard"
41
41
  #
42
42
  # The CARPS module which functions as a namespace for CARPS classes.
43
43
  module CARPS
44
- VERSION = '0.2.3'
44
+ VERSION = '0.3.0'
45
45
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
7
  - 3
9
- version: 0.2.3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Morrice
@@ -257,7 +257,7 @@ post_install_message: |
257
257
  o
258
258
  ><> ><> ><>
259
259
 
260
- Thank you for installing CARPS 0.2.3
260
+ Thank you for installing CARPS 0.3.0
261
261
 
262
262
  For help, run:
263
263