EzSSL 0.0.8 → 0.0.9
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.
- checksums.yaml +4 -4
- data/lib/ezssl.rb +73 -100
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f381e57cd92893ee88b828ed535e451972d2a1d88a3aed3cb78961f8b4cdfa75
|
4
|
+
data.tar.gz: 7cf236a5ba8f17b493ffb29fd0f5d195b0b1fd911f87403bd6b1fde66802da34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a150f6ff4ad094d50ce9fa88ebe7314ff9aa80e04f6c450528804438fe87bcd5af9130f343397f0dd6be86c5c02850a7faa4f591ac94ee40a09c05fb62dc345d
|
7
|
+
data.tar.gz: fcc9c4607d96b41ecf8f81e44f3b20040cfc07bcb9565736894a54090e7428054faddc9ee79d4ace1e93028aa6b036f2651327fb624e865c5c6dcd6ca767cdd4
|
data/lib/ezssl.rb
CHANGED
@@ -1,131 +1,104 @@
|
|
1
1
|
require 'openssl'
|
2
2
|
require 'socket'
|
3
3
|
module EzSSL
|
4
|
-
|
5
4
|
class Server
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
13
|
-
@pubkey=@pair.public_key
|
14
|
-
@read=@pubkey.public_encrypt('hello').length # byte length to be read by the Handle object
|
5
|
+
attr_reader :pubkey
|
6
|
+
@@rsa=OpenSSL::PKey::RSA.new(2048)
|
7
|
+
def initialize(ip,port)
|
8
|
+
@server=TCPServer.new(ip,port)
|
15
9
|
end
|
16
|
-
|
17
|
-
# Accepts a client connection, and returns a Handle object for communication
|
18
|
-
#
|
19
|
-
# @return [Object] The Handle object
|
20
10
|
def accept()
|
21
|
-
client=@
|
22
|
-
|
23
|
-
go=true
|
24
|
-
key=''
|
25
|
-
while go
|
26
|
-
msg=client.gets
|
27
|
-
key+=msg
|
28
|
-
go=false if msg=="-----END PUBLIC KEY-----\n"
|
29
|
-
end
|
30
|
-
return Handle.new(client,key,self)
|
11
|
+
client=@server.accept
|
12
|
+
return Handle.new(client,self)
|
31
13
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
def decrypt(msg)
|
38
|
-
return @pair.private_decrypt(msg)
|
14
|
+
def rsa_decrypt(msg)
|
15
|
+
return @@rsa.private_decrypt(msg)
|
16
|
+
end
|
17
|
+
def pubkey
|
18
|
+
return @@rsa.public_key.to_s
|
39
19
|
end
|
40
|
-
|
41
20
|
end
|
42
|
-
|
21
|
+
|
43
22
|
class Client
|
44
|
-
|
45
|
-
attr_reader :key, :pubkey, :length, :max
|
46
|
-
|
47
|
-
def initialize(ip,port,length=2048)
|
48
|
-
@length=length # bit length of private key
|
49
|
-
@pair=OpenSSL::PKey::RSA.new(length)
|
50
|
-
@pubkey=@pair.public_key # clients public key
|
23
|
+
def initialize(ip,port)
|
51
24
|
@socket=TCPSocket.new(ip,port)
|
52
|
-
@
|
53
|
-
|
54
|
-
|
55
|
-
|
25
|
+
@rsa=OpenSSL::PKey::RSA.new(2048)
|
26
|
+
@cip=OpenSSL::Cipher::AES256.new(:CBC).encrypt()
|
27
|
+
@dec=OpenSSL::Cipher::AES256.new(:CBC).decrypt()
|
28
|
+
#server=>client
|
56
29
|
key=''
|
57
|
-
|
58
|
-
|
59
|
-
key+=
|
60
|
-
|
30
|
+
line=@socket.gets
|
31
|
+
until line=="\n"
|
32
|
+
key+=line
|
33
|
+
line=@socket.gets
|
61
34
|
end
|
62
|
-
|
63
|
-
|
64
|
-
@socket.puts
|
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
|
35
|
+
@server_rsa=OpenSSL::PKey::RSA.new(key)
|
36
|
+
@socket.puts @rsa.public_key.to_s
|
37
|
+
@socket.puts ""
|
69
38
|
end
|
70
|
-
|
71
|
-
# Sends a string (msg) to the server
|
72
|
-
#
|
73
|
-
# @param msg [String] The sting being sent to the server
|
74
|
-
# @raise [ArgumentError] if the message being sent is too large for the OpenSSL::PKey::RSA object
|
39
|
+
|
75
40
|
def puts(msg)
|
76
|
-
|
77
|
-
|
41
|
+
key=@cip.random_key()
|
42
|
+
iv=@cip.random_iv()
|
43
|
+
enc=@cip.update(msg)+@cip.final
|
44
|
+
@socket.write(iv)
|
45
|
+
@socket.write(@server_rsa.public_encrypt(key))
|
46
|
+
@socket.puts enc.length
|
47
|
+
@socket.write(enc)
|
78
48
|
end
|
79
|
-
|
80
|
-
# Recieves a string from the server
|
81
|
-
#
|
82
|
-
# @return [String] The message from the server
|
49
|
+
|
83
50
|
def gets()
|
84
|
-
|
85
|
-
|
51
|
+
@dec.iv=@socket.read(16)
|
52
|
+
@dec.key=@rsa.private_decrypt(@socket.read(256))
|
53
|
+
len=@socket.gets.to_i
|
54
|
+
msg=@socket.read(len)
|
55
|
+
return @dec.update(msg)+@dec.final
|
86
56
|
end
|
57
|
+
|
87
58
|
end
|
88
|
-
|
59
|
+
|
89
60
|
private
|
90
|
-
|
91
|
-
# The object that allows communication from Server to Client.
|
92
61
|
class Handle
|
93
|
-
|
94
|
-
# the client already has the servers pubkey, and the server has the clients pubkey
|
95
|
-
|
96
|
-
def initialize(client,key,server)
|
97
|
-
# The represented client
|
62
|
+
def initialize(client,server)
|
98
63
|
@client=client
|
99
|
-
# The public key of the represented client
|
100
|
-
@key=OpenSSL::PKey::RSA.new(key)
|
101
64
|
@server=server
|
102
|
-
@
|
103
|
-
|
104
|
-
|
65
|
+
@cip=OpenSSL::Cipher::AES256.new(:CBC).encrypt()
|
66
|
+
@dec=OpenSSL::Cipher::AES256.new(:CBC).decrypt()
|
67
|
+
#swap rsa keys
|
68
|
+
#server=>client
|
69
|
+
client.puts server.pubkey
|
70
|
+
client.puts ""
|
71
|
+
#client=>server
|
72
|
+
key=''
|
73
|
+
line=client.gets
|
74
|
+
until line=="\n"
|
75
|
+
key+=line
|
76
|
+
line=client.gets
|
77
|
+
end
|
78
|
+
#make rsa key
|
79
|
+
@rsa=OpenSSL::PKey::RSA.new(key)
|
105
80
|
end
|
106
|
-
|
107
|
-
# Sends a string (msg) to the represented client
|
108
|
-
#
|
109
|
-
# @param msg [String] The message being sent to the client
|
110
|
-
# @raise [ArgumentError] if the message being sent is too large for the OpenSSL::PKey::RSA object
|
81
|
+
|
111
82
|
def puts(msg)
|
112
|
-
|
113
|
-
|
83
|
+
key=@cip.random_key()
|
84
|
+
iv=@cip.random_iv()
|
85
|
+
enc=@cip.update(msg)+@cip.final
|
86
|
+
@client.write(iv)
|
87
|
+
@client.write(@rsa.public_encrypt(key))
|
88
|
+
@client.puts enc.length
|
89
|
+
@client.write(enc)
|
114
90
|
end
|
115
|
-
|
116
|
-
# Recieves a string from the client
|
117
|
-
#
|
118
|
-
# @return [String] The message sent from the client
|
91
|
+
|
119
92
|
def gets()
|
120
|
-
|
121
|
-
|
93
|
+
@dec.iv=@client.read(16)
|
94
|
+
@dec.key=@server.rsa_decrypt(@client.read(256))
|
95
|
+
len=@client.gets.to_i
|
96
|
+
msg=@client.read(len)
|
97
|
+
return @dec.update(msg)+@dec.final
|
122
98
|
end
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
@client.close
|
99
|
+
|
100
|
+
def close()
|
101
|
+
@client.close()
|
127
102
|
end
|
128
|
-
|
129
103
|
end
|
130
|
-
|
131
104
|
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
|
+
version: 0.0.9
|
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-
|
11
|
+
date: 2020-02-18 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
|
@@ -39,7 +39,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
requirements: []
|
42
|
-
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.7.6.2
|
43
44
|
signing_key:
|
44
45
|
specification_version: 4
|
45
46
|
summary: Easily make secure socket connections
|