EzSSL 0.0.4

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 +7 -0
  2. data/lib/ezssl.rb +73 -0
  3. metadata +45 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5680630e7ae64e9a8e228615bcfef3389edd5bf74ac58cc92fb8dce85c2039d0
4
+ data.tar.gz: 3c797a767ac64ae1de5353c7ac2f9199d448f7e4e24fc7d27d5389aac24fdf9d
5
+ SHA512:
6
+ metadata.gz: fa8e6d140cd892a49d2f95fca9e5add92ef4a8544857f99d44c66b42ed6c089897dcb583c8176f082a6373f0cb24e7b469d0978fb85e41d2241f46b48794b4a5
7
+ data.tar.gz: bb7f920c5c036b9202de771bf76dbfec7691b042e8bc426e71462fae2a07195b132e6672639a8c2be3c92ab6cf12a0c3e6716531853b5af62ff5fda9af1deba0
@@ -0,0 +1,73 @@
1
+ require 'openssl'
2
+ require 'socket'
3
+ module EzSSL
4
+ class Server
5
+ attr_reader :read
6
+ def initialize(ip,port,length=2048)
7
+ @socket=TCPServer.open(ip,port)
8
+ @pair=OpenSSL::PKey::RSA.new(length)
9
+ @pubkey=@pair.public_key
10
+ @read=@pubkey.public_encrypt('hello').length
11
+ end
12
+ def accept()
13
+ client=@socket.accept
14
+ client.puts @pubkey.to_s
15
+ go=true
16
+ key=''
17
+ while go
18
+ msg=client.gets
19
+ key+=msg
20
+ go=false if msg=="-----END PUBLIC KEY-----\n"
21
+ end
22
+ return Handle.new(client,key,self)
23
+ end
24
+ def decrypt(msg)
25
+ return @pair.private_decrypt(msg)
26
+ end
27
+ end
28
+
29
+ class Client
30
+ def initialize(ip,port,length=2048)
31
+ @pair=OpenSSL::PKey::RSA.new(length)
32
+ @pubkey=@pair.public_key
33
+ @socket=TCPSocket.new(ip,port)
34
+ @read=@pubkey.public_encrypt('hello').length
35
+ go=true
36
+ key=''
37
+ while go
38
+ msg=@socket.gets
39
+ key+=msg
40
+ go=false if msg=="-----END PUBLIC KEY-----\n"
41
+ end
42
+ @socket.puts @pubkey.to_s
43
+ @key=OpenSSL::PKey::RSA.new(key)
44
+ end
45
+ def puts(msg)
46
+ @socket.write @key.public_encrypt(msg)
47
+ return nil
48
+ end
49
+ def gets()
50
+ msg=@socket.read(@read)
51
+ return @pair.private_decrypt(msg)
52
+ end
53
+ end
54
+
55
+ private
56
+ class Handle
57
+ def initialize(client,key,server)
58
+ @client=client
59
+ @key=OpenSSL::PKey::RSA.new(key)
60
+ @server=server
61
+ end
62
+ def puts(msg)
63
+ @client.write @key.public_encrypt(msg)
64
+ end
65
+ def gets()
66
+ msg=@client.read(@server.read)
67
+ return @server.decrypt(msg)
68
+ end
69
+ def close
70
+ @client.close
71
+ end
72
+ end
73
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: EzSSL
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Lucas Reinheart
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-11-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: OpenSSL is confusing to people new to socket programming, so i aim to
14
+ make the process easier
15
+ email: zachtonap@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/ezssl.rb
21
+ homepage: ''
22
+ licenses:
23
+ - MIT
24
+ metadata:
25
+ source_code_uri: https://github.com/lonelylittlelucas/ezssl
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubygems_version: 3.0.3
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Easily maie secure socket connections
45
+ test_files: []