EzSSL 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ezssl.rb +25 -29
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fde201a7d5d1211ab47ce8f25d50055ed5042090b06d70c00b28bf825d82c403
4
- data.tar.gz: 3c3cddb141bbe37b8d71976b31625f48ac319d550da09b44dfff87cb7b2b0302
3
+ metadata.gz: 43edff0aff40d417ab9dbbe9daf4217324a03b473e137794f7159366098a2d3a
4
+ data.tar.gz: d227aaf919fc6dcc4e554dca40dd8d5032f2e5f24598187b9333e0332f627e5f
5
5
  SHA512:
6
- metadata.gz: 9ad69c06b2bff47e0cfd3850baaad319e723f3683d6d4290a4df9de7e3cc2b29b622105cd3e9e52606422f88966c11fad2375052b692097febf76b4c4e53f7f2
7
- data.tar.gz: f35f41e6fc7be146df4ece1cdf57ac31062a71783a78b93c580018479adaedc8fb91778f4af2e91dd5951547df560a0d13849faed31327bddd1907b3f68c93dd
6
+ metadata.gz: e3e6ac65c51a8aae19339984b32b209c2abb6370c17ed81427278f81b762cb6a177bdbf57d5ddd5155c815b2778a7bf8bef7bec2ebe3237c83fdc62e8aa83b6e
7
+ data.tar.gz: 7502c80f193ef387a2c422e6f2037eccb229eec3cc6b84a24ae96b84aac9f38e6127119993ea16339d43eea6387579a01e685ec6614bc069e15896e679f75802
@@ -3,13 +3,15 @@ require 'socket'
3
3
  module EzSSL
4
4
 
5
5
  class Server
6
+
7
+ attr_reader :read, :length
6
8
 
7
- attr_reader :read
8
9
  def initialize(ip,port,length=2048)
9
- @socket=TCPServer.open(ip,port)
10
- @pair=OpenSSL::PKey::RSA.new(length)
10
+ @length=length # bit length of private key [readable]
11
+ @socket=TCPServer.open(ip,port) # the server
12
+ @pair=OpenSSL::PKey::RSA.new(length) # the server keypair
11
13
  @pubkey=@pair.public_key
12
- @read=@pubkey.public_encrypt('hello').length
14
+ @read=@pubkey.public_encrypt('hello').length # byte length to be read by the Handle object
13
15
  end
14
16
 
15
17
  # Accepts a client connection, and returns a Handle object for communication
@@ -40,13 +42,16 @@ module EzSSL
40
42
 
41
43
  class Client
42
44
 
43
- attr_reader :key, :pubkey
45
+ attr_reader :key, :pubkey, :length, :max
44
46
 
45
47
  def initialize(ip,port,length=2048)
48
+ @length=length # bit length of private key
46
49
  @pair=OpenSSL::PKey::RSA.new(length)
47
- @pubkey=@pair.public_key
50
+ @pubkey=@pair.public_key # clients public key
48
51
  @socket=TCPSocket.new(ip,port)
49
52
  @read=@pubkey.public_encrypt('hello').length
53
+
54
+ # recieve the key frome the server
50
55
  go=true
51
56
  key=''
52
57
  while go
@@ -54,16 +59,13 @@ module EzSSL
54
59
  key+=msg
55
60
  go=false if msg=="-----END PUBLIC KEY-----\n"
56
61
  end
57
- @socket.puts @pubkey.to_s
58
- @key=OpenSSL::PKey::RSA.new(key)
59
- end
60
62
 
61
- # Returns the maximum length of string that can be encypted with a given key
62
- #
63
- # @param [Object] The OpenSSL object to test
64
- # @return [Integer] The maximum length of string that can be encrypted with the given key
65
- def max_len(key)
66
- return key.public_encrypt('test').length
63
+ #give server public key
64
+ @socket.puts @pubkey.to_s
65
+ @key=OpenSSL::PKey::RSA.new(key) # the servers public key
66
+
67
+ @max=((self.gets().to_i)/8).floor - 11
68
+ self.puts @length.to_s
67
69
  end
68
70
 
69
71
  # Sends a string (msg) to the server
@@ -71,9 +73,8 @@ module EzSSL
71
73
  # @param msg [String] The sting being sent to the server
72
74
  # @raise [ArgumentError] if the message being sent is too large for the OpenSSL::PKey::RSA object
73
75
  def puts(msg)
74
- raise ArgumentError, "Message is too large to encrypt with the current key. (Max Length:#{max_len(@key)})" if msg.length > max_len(@key)
76
+ raise ArgumentError, 'Message too big' if msg.length>@max
75
77
  @socket.write @key.public_encrypt(msg)
76
- return nil
77
78
  end
78
79
 
79
80
  # Recieves a string from the server
@@ -89,15 +90,18 @@ module EzSSL
89
90
 
90
91
  # The object that allows communication from Server to Client.
91
92
  class Handle
93
+ attr_reader :max
94
+ # the client already has the servers pubkey, and the server has the clients pubkey
92
95
 
93
- attr_reader :send
94
96
  def initialize(client,key,server)
95
97
  # The represented client
96
98
  @client=client
97
99
  # The public key of the represented client
98
100
  @key=OpenSSL::PKey::RSA.new(key)
99
- @send=max_len(@key)
100
101
  @server=server
102
+ @max=256
103
+ self.puts @server.length.to_s
104
+ @max=@max=((self.gets().to_i)/8).floor - 11
101
105
  end
102
106
 
103
107
  # Sends a string (msg) to the represented client
@@ -105,17 +109,8 @@ module EzSSL
105
109
  # @param msg [String] The message being sent to the client
106
110
  # @raise [ArgumentError] if the message being sent is too large for the OpenSSL::PKey::RSA object
107
111
  def puts(msg)
108
- raise ArgumentError, "Message is too large to encrypt with the current key. (Max Length:#{max_len(@key)})" if msg.length > max_len(@key)
112
+ raise ArgumentError, 'Message too big' if msg.length>@max
109
113
  @client.write @key.public_encrypt(msg)
110
- return nil
111
- end
112
-
113
- # Returns the maximum length of string that can be encypted with a given key
114
- #
115
- # @param [Object] The OpenSSL object to test
116
- # @return [Integer] The maximum length of string that can be encrypted with the given key
117
- def max_len(key)
118
- return key.public_encrypt('test').length
119
114
  end
120
115
 
121
116
  # Recieves a string from the client
@@ -132,4 +127,5 @@ module EzSSL
132
127
  end
133
128
 
134
129
  end
130
+
135
131
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: EzSSL
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Reinheart
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-01 00:00:00.000000000 Z
11
+ date: 2020-01-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: OpenSSL is confusing to people new to socket programming, so i aim to
14
14
  make the process easier