Saphir 0.0.1
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 +7 -0
- data/Manual.pdf +0 -0
- data/Rakefile +2 -0
- data/lib/Saphir.rb +3 -0
- data/lib/Saphir/BNCClient.rb +70 -0
- data/lib/Saphir/BNCServer.rb +114 -0
- data/lib/Saphir/version.rb +3 -0
- data/lib/ssl.cert +13 -0
- data/lib/ssl.key +15 -0
- metadata +95 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 83119804a0355776a24c81d69cc9544396418fc1
|
|
4
|
+
data.tar.gz: 7550842d3ed9d685ce43e3ce5d282d2f7b4dd5ae
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d15d9492a508d7b746ae9a6102b670aa7b582b85467814f5c73dbf234523b4701489341e47f77613f2fa20fa5d6f8c01cf8b827991a4fd524e20ef3a045a78eb
|
|
7
|
+
data.tar.gz: 3d26cd70aebe1fda964e02bc3ebf85e00b9bcf9bb97debf67fde901c3904d41d94a9e21a33dba269fa7e8a4095a708976a2322472dff2851d7acb8245706df04
|
data/Manual.pdf
ADDED
|
Binary file
|
data/Rakefile
ADDED
data/lib/Saphir.rb
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'socket'
|
|
2
|
+
require 'openssl'
|
|
3
|
+
|
|
4
|
+
module Saphir
|
|
5
|
+
class BNCClient
|
|
6
|
+
#Set client properties
|
|
7
|
+
def initialize(server, password = "nopassword", port=7789, useSSL=true)
|
|
8
|
+
@port = port
|
|
9
|
+
@server = server
|
|
10
|
+
@password = password
|
|
11
|
+
@useSSL = useSSL
|
|
12
|
+
#Set the default certificate path
|
|
13
|
+
@certFile = "#{File.dirname(__FILE__)}/../ssl.cert"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
#Change the default certificate
|
|
17
|
+
def setSSLCertificate(certFile)
|
|
18
|
+
if File.exist?(certFile)
|
|
19
|
+
@certFile = certFile
|
|
20
|
+
else
|
|
21
|
+
puts "ERROR: File does not exist!"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
#Start the client
|
|
26
|
+
def start()
|
|
27
|
+
#Create a basic tcp socket
|
|
28
|
+
socket = TCPSocket.open(@server, @port)
|
|
29
|
+
|
|
30
|
+
#Check if ssl is enabled
|
|
31
|
+
if @useSSL
|
|
32
|
+
#Load certificate
|
|
33
|
+
expectedCert = OpenSSL::X509::Certificate.new(File.open(@certFile))
|
|
34
|
+
#Create a ssl tunnel for the tcp socket
|
|
35
|
+
s_socket = OpenSSL::SSL::SSLSocket.new(socket)
|
|
36
|
+
s_socket.sync_close = true
|
|
37
|
+
#Connect to the server
|
|
38
|
+
s_socket.connect
|
|
39
|
+
|
|
40
|
+
#If the server and client certificate differ through an error and quit the script
|
|
41
|
+
if s_socket.peer_cert.to_s != expectedCert.to_s
|
|
42
|
+
stderrr.puts "Unexpected certificate"
|
|
43
|
+
exit(1)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
#Use the tunnel for communication
|
|
47
|
+
@socket = s_socket
|
|
48
|
+
else
|
|
49
|
+
#Use the basic socket for communication
|
|
50
|
+
@socket = socket
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
#Send a message to the server
|
|
55
|
+
def sendMessage(msg)
|
|
56
|
+
@socket.puts("#{@password}$$$#{msg}\000")
|
|
57
|
+
|
|
58
|
+
#Get the server response and forward it to the application using BCPClient
|
|
59
|
+
response = @socket.gets()
|
|
60
|
+
response = response.chomp[0..-2]
|
|
61
|
+
response
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
#Close the server connection
|
|
65
|
+
def close()
|
|
66
|
+
@socket.puts("EXT\000")
|
|
67
|
+
@socket.close
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
require 'socket'
|
|
2
|
+
require 'openssl'
|
|
3
|
+
|
|
4
|
+
module Saphir
|
|
5
|
+
class BNCServer
|
|
6
|
+
#Set server properties
|
|
7
|
+
def initialize(password="nopassword", port=7789, useSSL=true, enableLog=true)
|
|
8
|
+
@port = port
|
|
9
|
+
@password = password
|
|
10
|
+
@useSSL = useSSL
|
|
11
|
+
@enableLog = enableLog
|
|
12
|
+
#Set the default certificate path
|
|
13
|
+
@certFile = "#{File.dirname(__FILE__)}/../ssl.cert"
|
|
14
|
+
@keyFile = "#{File.dirname(__FILE__)}/../ssl.key"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
#Change the default certificate
|
|
18
|
+
def setSSLCertificate(certFile)
|
|
19
|
+
if File.exist?(certFile)
|
|
20
|
+
@certFile = certFile
|
|
21
|
+
else
|
|
22
|
+
puts "ERROR: File does not exist!"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
#Change the default key
|
|
27
|
+
def setSSLKey(keyFile)
|
|
28
|
+
if File.exist?(keyFile)
|
|
29
|
+
@keyFile = keyFile
|
|
30
|
+
else
|
|
31
|
+
puts "ERROR: File does not exist!"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
#Start the server
|
|
36
|
+
def start
|
|
37
|
+
#Create a basic tcp server
|
|
38
|
+
s_server = TCPServer.open(@port)
|
|
39
|
+
|
|
40
|
+
#Check if ssl was enabled
|
|
41
|
+
if @useSSL
|
|
42
|
+
#If enabled create an ssl tunnel for the tcp server
|
|
43
|
+
sslContext = OpenSSL::SSL::SSLContext.new
|
|
44
|
+
sslContext.cert = OpenSSL::X509::Certificate.new(File.open(@certFile));
|
|
45
|
+
sslContext.key = OpenSSL::PKey::RSA.new(File.open(@keyFile));
|
|
46
|
+
|
|
47
|
+
ssl_server = OpenSSL::SSL::SSLServer.new(s_server, sslContext)
|
|
48
|
+
ssl_server.start_immediately = true
|
|
49
|
+
|
|
50
|
+
#Use the tunnel for communication
|
|
51
|
+
server = ssl_server
|
|
52
|
+
else
|
|
53
|
+
#If disabled use the basic tcp server
|
|
54
|
+
server = s_server
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
loop do
|
|
58
|
+
#Try to start a new thread for each incoming request
|
|
59
|
+
begin
|
|
60
|
+
Thread.start(server.accept) do |client|
|
|
61
|
+
#Get client info
|
|
62
|
+
sock_domain, remote_port, remote_hostname, remote_ip = client.peeraddr
|
|
63
|
+
puts "Accepted request from #{remote_hostname} (#{remote_ip})" if @enableLog
|
|
64
|
+
|
|
65
|
+
#Start processing the request
|
|
66
|
+
while request = client.gets
|
|
67
|
+
#Read the password from the request
|
|
68
|
+
password = request[0..request.index('$$$')-1]
|
|
69
|
+
#Set request to be the content of the actual request
|
|
70
|
+
request = request[request.index('$$$')+3..-2]
|
|
71
|
+
|
|
72
|
+
#Verify the password
|
|
73
|
+
if @password == password
|
|
74
|
+
#Try to process the command from the request
|
|
75
|
+
begin
|
|
76
|
+
#Check if the command will be processed by BCPServer
|
|
77
|
+
case request[0..2]
|
|
78
|
+
when "HLO"
|
|
79
|
+
#Send 'Hello' to the client
|
|
80
|
+
client.puts "Hello\000"
|
|
81
|
+
when "EXT"
|
|
82
|
+
#Close the connection
|
|
83
|
+
puts "#{remote_ip}$ Closing connection..." if @enableLog
|
|
84
|
+
client.close
|
|
85
|
+
else
|
|
86
|
+
#If no BCPServer command is found forward the request to the application that implemented BCPServer
|
|
87
|
+
begin
|
|
88
|
+
puts "#{remote_ip}$ Request: #{request}" if @enableLog
|
|
89
|
+
response = yield request[0..-1]
|
|
90
|
+
client.puts "#{response}\000"
|
|
91
|
+
rescue
|
|
92
|
+
client.puts "Request received\000"
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
rescue
|
|
96
|
+
#Through an error if the request cannot be processed
|
|
97
|
+
puts "Invalid request from #{remote_ip}" if @enableLog
|
|
98
|
+
client.puts "ERROR: INVALID REQUEST\000"
|
|
99
|
+
end
|
|
100
|
+
else
|
|
101
|
+
#If the password is wrong return an error
|
|
102
|
+
puts "Invalid password from #{remote_ip}" if @enableLog
|
|
103
|
+
client.puts "ERROR: INVALID PASSWORD\000"
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
rescue
|
|
108
|
+
#If the request is invalid through an error
|
|
109
|
+
puts "ERROR: Invalid connection request" if @enableLog
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
data/lib/ssl.cert
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
|
2
|
+
MIICAzCCAWwCCQCUOjeM7uZU2TANBgkqhkiG9w0BAQUFADBGMQswCQYDVQQGEwJV
|
|
3
|
+
SzEPMA0GA1UECBMGTG9uZG9uMQ8wDQYDVQQHEwZMb25kb24xFTATBgNVBAoTDE1h
|
|
4
|
+
cnZpbiBQZXRlcjAeFw0xNDA3MTYxNzE3MjVaFw0xNTA3MTYxNzE3MjVaMEYxCzAJ
|
|
5
|
+
BgNVBAYTAlVLMQ8wDQYDVQQIEwZMb25kb24xDzANBgNVBAcTBkxvbmRvbjEVMBMG
|
|
6
|
+
A1UEChMMTWFydmluIFBldGVyMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDj
|
|
7
|
+
s/QLHHHbSq7CI5jTgfZRxerlEcCBk6Pdd34Brp/mA4E1okfgY9WoiAhl2epkku/b
|
|
8
|
+
O2Sg7nTSf8+w/JXl8BJDLdgviydc0zFzT/D7R8KuFB9WVFXUvpTwEQPiU88+FUg4
|
|
9
|
+
9vXuiMIylJU+cOez1pdYFJ3JXjbV6rGmmI2zsHvNdwIDAQABMA0GCSqGSIb3DQEB
|
|
10
|
+
BQUAA4GBACL44oml5IY1ZGA2KBgN+FB+B/w7K6irBwlqAQ7fWauHpFk/i0C84g+K
|
|
11
|
+
EB5Nmd3OQ6VdeMEIo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+jmnM5fLV80JHCNSJfggepVn4It5UAbf
|
|
14
|
+
4XT24EjOIDB9WN05dbSZFdZuiLl3x00u8SWVkzIxKsAM
|
|
15
|
+
-----END RSA PRIVATE KEY-----
|
metadata
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: Saphir
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Sapphirus (Marvin Peter)
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-07-18 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ~>
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.6'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.6'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: openssl
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - '>='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
description: "THIS IS JUST A BETA!!!\n\n\n \t\t\t\t\t\tCurrent features:\n\n \t\t\t\t\t\t1)
|
|
56
|
+
A server and client for basic network communication\n"
|
|
57
|
+
email:
|
|
58
|
+
- mail@Sapphirus.cf
|
|
59
|
+
executables: []
|
|
60
|
+
extensions: []
|
|
61
|
+
extra_rdoc_files: []
|
|
62
|
+
files:
|
|
63
|
+
- Rakefile
|
|
64
|
+
- Manual.pdf
|
|
65
|
+
- lib/Saphir.rb
|
|
66
|
+
- lib/Saphir/version.rb
|
|
67
|
+
- lib/Saphir/BNCClient.rb
|
|
68
|
+
- lib/Saphir/BNCServer.rb
|
|
69
|
+
- lib/ssl.cert
|
|
70
|
+
- lib/ssl.key
|
|
71
|
+
homepage: ''
|
|
72
|
+
licenses:
|
|
73
|
+
- MIT
|
|
74
|
+
metadata: {}
|
|
75
|
+
post_install_message:
|
|
76
|
+
rdoc_options: []
|
|
77
|
+
require_paths:
|
|
78
|
+
- lib
|
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - '>='
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '0'
|
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - '>='
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
requirements: []
|
|
90
|
+
rubyforge_project:
|
|
91
|
+
rubygems_version: 2.0.14
|
|
92
|
+
signing_key:
|
|
93
|
+
specification_version: 4
|
|
94
|
+
summary: A collection of useful ruby functions
|
|
95
|
+
test_files: []
|