Module: Cryptosphere::Handshake
- Defined in:
- lib/cryptosphere/protocol/handshake.rb
Class Method Summary collapse
- .decode_request(recipient, message) ⇒ Object
- .decode_response(recipient, sender, message) ⇒ Object
- .encode_request(sender, recipient) ⇒ Object
- .encode_response(sender, recipient, secret = Cryptosphere.random_bytes(32)) ⇒ Object
Class Method Details
.decode_request(recipient, message) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/cryptosphere/protocol/handshake.rb', line 12 def decode_request(recipient, ) bytes = PUBKEY_SIZE / 8 signature, = [0...bytes], [bytes..-1] # FIXME: this should be encrypted :( sender_key = Cryptosphere.verify!(sender_key, , signature) sender_key end |
.decode_response(recipient, sender, message) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/cryptosphere/protocol/handshake.rb', line 29 def decode_response(recipient, sender, ) bytes = PUBKEY_SIZE / 8 signature, = [0...bytes], [bytes..-1] Cryptosphere.verify!(sender.public_key, , signature) cipher = AsymmetricCipher.new(recipient.private_key) cipher.private_decrypt() end |
.encode_request(sender, recipient) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/cryptosphere/protocol/handshake.rb', line 5 def encode_request(sender, recipient) # TODO: encrypt sender's public key # Sure would be nice to have some Curve25519 here = sender.public_key Cryptosphere.sign(sender.private_key, ) + end |
.encode_response(sender, recipient, secret = Cryptosphere.random_bytes(32)) ⇒ Object
23 24 25 26 27 |
# File 'lib/cryptosphere/protocol/handshake.rb', line 23 def encode_response(sender, recipient, secret = Cryptosphere.random_bytes(32)) cipher = AsymmetricCipher.new(recipient.public_key) = cipher.public_encrypt(secret) Cryptosphere.sign(sender.private_key, ) + end |