EzSSL 0.0.4 → 0.0.5

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ezssl.rb +60 -0
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5680630e7ae64e9a8e228615bcfef3389edd5bf74ac58cc92fb8dce85c2039d0
4
- data.tar.gz: 3c797a767ac64ae1de5353c7ac2f9199d448f7e4e24fc7d27d5389aac24fdf9d
3
+ metadata.gz: 4f4af8b7f05ef4af024970829b47f06efab3bdb4da0444a8d57a06b7ea146af1
4
+ data.tar.gz: fcdb8597e1977fca10c5d04dba0e191728ac9a482bbbf6759e72370ef56e6ca8
5
5
  SHA512:
6
- metadata.gz: fa8e6d140cd892a49d2f95fca9e5add92ef4a8544857f99d44c66b42ed6c089897dcb583c8176f082a6373f0cb24e7b469d0978fb85e41d2241f46b48794b4a5
7
- data.tar.gz: bb7f920c5c036b9202de771bf76dbfec7691b042e8bc426e71462fae2a07195b132e6672639a8c2be3c92ab6cf12a0c3e6716531853b5af62ff5fda9af1deba0
6
+ metadata.gz: 96edb214b6f10451a6d2634bbae8975fd1fdf4440ccff09a6150172a8acbde5f09d4b4fd43bfde0ded174407f165cebc565da6e2b2eed13d9fd06c68bfa5eecc
7
+ data.tar.gz: 31486a4e8e0c4ce854ec17ddfe30dddf7aae3ae9b4c763c8b31357e3a2e88b20a938f3fed98c6f3aad5f66cbefe008c3d9202d38d7abdc5341c2d7288510f2f4
@@ -1,7 +1,9 @@
1
1
  require 'openssl'
2
2
  require 'socket'
3
3
  module EzSSL
4
+
4
5
  class Server
6
+
5
7
  attr_reader :read
6
8
  def initialize(ip,port,length=2048)
7
9
  @socket=TCPServer.open(ip,port)
@@ -9,6 +11,10 @@ module EzSSL
9
11
  @pubkey=@pair.public_key
10
12
  @read=@pubkey.public_encrypt('hello').length
11
13
  end
14
+
15
+ # Accepts a client connection, and returns a Handle object for communication
16
+ #
17
+ # @return [Object] The Handle object
12
18
  def accept()
13
19
  client=@socket.accept
14
20
  client.puts @pubkey.to_s
@@ -21,12 +27,20 @@ module EzSSL
21
27
  end
22
28
  return Handle.new(client,key,self)
23
29
  end
30
+
31
+ # Decrypt a message without direct access to the private key
32
+ #
33
+ # @param msg [String] The encrypted message
34
+ # @return [String] The decrypted message
24
35
  def decrypt(msg)
25
36
  return @pair.private_decrypt(msg)
26
37
  end
27
38
  end
28
39
 
29
40
  class Client
41
+
42
+ attr_reader :key, :pubkey
43
+
30
44
  def initialize(ip,port,length=2048)
31
45
  @pair=OpenSSL::PKey::RSA.new(length)
32
46
  @pubkey=@pair.public_key
@@ -42,10 +56,28 @@ module EzSSL
42
56
  @socket.puts @pubkey.to_s
43
57
  @key=OpenSSL::PKey::RSA.new(key)
44
58
  end
59
+
60
+ # Returns the maximum length of string that can be encypted with a given key
61
+ #
62
+ # @param [Object] The OpenSSL object to test
63
+ # @return [Integer] The maximum length of string that can be encrypted with the given key
64
+ def max_len(key)
65
+ return key.public_encrypt('test').length
66
+ end
67
+
68
+ # Sends a string (msg) to the server
69
+ #
70
+ # @param msg [String] The sting being sent to the server
71
+ # @raise [ArgumentError] if the message being sent is too large for the OpenSSL::PKey::RSA object
45
72
  def puts(msg)
73
+ raise ArgumentError, "Message is too large to encrypt with the current key. (Max Length:#{max_len(@key)})" if msg.length > max_len(@key)
46
74
  @socket.write @key.public_encrypt(msg)
47
75
  return nil
48
76
  end
77
+
78
+ # Recieves a string from the server
79
+ #
80
+ # @return [String] The message from the server
49
81
  def gets()
50
82
  msg=@socket.read(@read)
51
83
  return @pair.private_decrypt(msg)
@@ -53,21 +85,49 @@ module EzSSL
53
85
  end
54
86
 
55
87
  private
88
+
89
+ # The object that allows communication from Server to Client.
56
90
  class Handle
91
+
57
92
  def initialize(client,key,server)
93
+ # The represented client
58
94
  @client=client
95
+ # The public key of the represented client
59
96
  @key=OpenSSL::PKey::RSA.new(key)
97
+ @read=@key.public_encrypt('test lol').length
60
98
  @server=server
61
99
  end
100
+
101
+ # Sends a string (msg) to the represented client
102
+ #
103
+ # @param msg [String] The message being sent to the client
104
+ # @raise [ArgumentError] if the message being sent is too large for the OpenSSL::PKey::RSA object
62
105
  def puts(msg)
106
+ raise ArgumentError, "Message is too large to encrypt with the current key. (Max Length:#{max_len(@key)})" if msg.length > max_len(@key)
63
107
  @client.write @key.public_encrypt(msg)
108
+ return nil
64
109
  end
110
+
111
+ # Returns the maximum length of string that can be encypted with a given key
112
+ #
113
+ # @param [Object] The OpenSSL object to test
114
+ # @return [Integer] The maximum length of string that can be encrypted with the given key
115
+ def max_len(key)
116
+ return key.public_encrypt('test').length
117
+ end
118
+
119
+ # Recieves a string from the client
120
+ #
121
+ # @return [String] The message sent from the client
65
122
  def gets()
66
123
  msg=@client.read(@server.read)
67
124
  return @server.decrypt(msg)
68
125
  end
126
+
127
+ # Closes the client remotely
69
128
  def close
70
129
  @client.close
71
130
  end
131
+
72
132
  end
73
133
  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.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Reinheart
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-08 00:00:00.000000000 Z
11
+ date: 2019-11-10 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
@@ -18,7 +18,7 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - lib/ezssl.rb
21
- homepage: ''
21
+ homepage: https://rubygems.org/gems/EzSSL
22
22
  licenses:
23
23
  - MIT
24
24
  metadata:
@@ -41,5 +41,5 @@ requirements: []
41
41
  rubygems_version: 3.0.3
42
42
  signing_key:
43
43
  specification_version: 4
44
- summary: Easily maie secure socket connections
44
+ summary: Easily make secure socket connections
45
45
  test_files: []