nova 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +19 -0
  3. data/README.md +29 -0
  4. data/bin/nova +8 -0
  5. data/lib/generator/template/new_install/galaxy/some_star.rb +3 -0
  6. data/lib/generator/template/new_install/supernova.yml +16 -0
  7. data/lib/nova.rb +49 -0
  8. data/lib/nova/cli.rb +62 -0
  9. data/lib/nova/commands/server.rb +71 -0
  10. data/lib/nova/common.rb +17 -0
  11. data/lib/nova/common/event_handler.rb +165 -0
  12. data/lib/nova/common/event_handler/event.rb +147 -0
  13. data/lib/nova/common/features.rb +93 -0
  14. data/lib/nova/common/features/feature.rb +65 -0
  15. data/lib/nova/common/metadata.rb +65 -0
  16. data/lib/nova/common/metadata/data.rb +171 -0
  17. data/lib/nova/common/star_management.rb +164 -0
  18. data/lib/nova/constructor.rb +84 -0
  19. data/lib/nova/exceptions.rb +16 -0
  20. data/lib/nova/project.rb +199 -0
  21. data/lib/nova/remote.rb +10 -0
  22. data/lib/nova/remote/fake.rb +51 -0
  23. data/lib/nova/remote/fake/commands.rb +44 -0
  24. data/lib/nova/remote/fake/file_system.rb +76 -0
  25. data/lib/nova/remote/fake/operating_system.rb +52 -0
  26. data/lib/nova/remote/fake/platform.rb +89 -0
  27. data/lib/nova/star.rb +25 -0
  28. data/lib/nova/starbound.rb +14 -0
  29. data/lib/nova/starbound/client.rb +59 -0
  30. data/lib/nova/starbound/encryptor.rb +134 -0
  31. data/lib/nova/starbound/encryptors.rb +13 -0
  32. data/lib/nova/starbound/encryptors/openssl.rb +122 -0
  33. data/lib/nova/starbound/encryptors/plaintext.rb +64 -0
  34. data/lib/nova/starbound/encryptors/rbnacl.rb +67 -0
  35. data/lib/nova/starbound/protocol.rb +81 -0
  36. data/lib/nova/starbound/protocol/encryption.rb +48 -0
  37. data/lib/nova/starbound/protocol/exceptions.rb +38 -0
  38. data/lib/nova/starbound/protocol/messages.rb +116 -0
  39. data/lib/nova/starbound/protocol/packet.rb +267 -0
  40. data/lib/nova/starbound/protocol/socket.rb +231 -0
  41. data/lib/nova/starbound/server.rb +182 -0
  42. data/lib/nova/version.rb +5 -0
  43. data/spec/constructor_spec.rb +20 -0
  44. data/spec/local_spec.rb +26 -0
  45. data/spec/nova_spec.rb +7 -0
  46. data/spec/spec_helper.rb +19 -0
  47. data/spec/star/some_type.rb +27 -0
  48. data/spec/star_spec.rb +107 -0
  49. data/spec/starbound/encryptor_spec.rb +33 -0
  50. data/spec/starbound/openssl_encryptor_spec.rb +80 -0
  51. data/spec/starbound/packet_spec.rb +61 -0
  52. data/spec/starbound/plaintext_encryptor_spec.rb +27 -0
  53. data/spec/starbound/protocol_spec.rb +163 -0
  54. data/spec/starbound/rbnacl_encryptor_spec.rb +70 -0
  55. metadata +166 -0
@@ -0,0 +1,61 @@
1
+ require 'stringio'
2
+
3
+ describe Nova::Starbound::Protocol::Packet do
4
+
5
+ context 'building responses' do
6
+ subject { described_class.build_response :nul, "hello", :packet_id => 1, :packet_type => 1 }
7
+
8
+ its(:struct) { should be :response }
9
+ its(:response_id) { should be 1 }
10
+ its(:packet_response_id) { should be 1 }
11
+ its(:response_type) { should be 1 }
12
+ its(:type) { should be :nul }
13
+ its(:body) { should eq "hello" }
14
+ its(:size) { should be "hello".length }
15
+
16
+ it "returns the number type if it can't find it" do
17
+ packet = described_class.build_response :nul, "hello"
18
+
19
+ packet[:packet_type] = 1043
20
+
21
+ expect(packet.type).to be 1043
22
+ end
23
+ end
24
+
25
+ it "sets up expectations" do
26
+ packet = NovaHelper.build_packet
27
+
28
+ expect {
29
+ packet.expect(:echo)
30
+ }.to raise_error(Nova::Starbound::UnacceptablePacketError)
31
+ end
32
+
33
+ it "responds to missing methods" do
34
+ packet = NovaHelper.build_packet
35
+ packet[:something] = 1
36
+
37
+ expect(packet).to be_respond_to_missing :something
38
+ end
39
+
40
+ context 'builds from socket' do
41
+ subject {
42
+ str = StringIO.new "\x00\x0b\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00" + (" " * 24) + "hello world\x00"
43
+ described_class.from_socket(str)
44
+ }
45
+
46
+ its(:struct) { should be :packet }
47
+ its(:packet_id) { should be 1 }
48
+ its(:type) { should be :nul }
49
+ its(:nonce) { should be_empty }
50
+ its(:body) { should eq "hello world" }
51
+
52
+ it "raises error if it can't determine the struct type" do
53
+ str = StringIO.new "\xff\x0b\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00" + (" " * 24) + "hello world\x00"
54
+
55
+ expect {
56
+ described_class.from_socket(str)
57
+ }.to raise_error(Nova::Starbound::NoStructError)
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,27 @@
1
+ describe Nova::Starbound::Encryptors::Plaintext do
2
+ it "is available" do
3
+ expect(described_class).to be_available
4
+ end
5
+
6
+ it "is plaintext" do
7
+ expect(described_class).to be_plaintext
8
+ end
9
+
10
+ it "encrypts correctly" do
11
+ packet = NovaHelper.build_packet
12
+
13
+ out_packet = subject.encrypt(packet)
14
+ expect(out_packet.body).to eq packet.body
15
+ expect(out_packet.nonce.length).to be 24
16
+ end
17
+
18
+ it "decrypts correctly" do
19
+ packet = NovaHelper.build_packet
20
+
21
+ packet[:nonce] = Random.new.bytes(24)
22
+ out_packet = subject.decrypt(packet)
23
+
24
+ expect(out_packet.body).to eq packet.body
25
+ expect(out_packet[:nonce]).to eq packet[:nonce]
26
+ end
27
+ end
@@ -0,0 +1,163 @@
1
+ require 'stringio'
2
+
3
+ describe Nova::Starbound::Protocol do
4
+ before :each do
5
+ @server = UNIXServer.open("protocol.sock")
6
+ @client = UNIXSocket.open("protocol.sock")
7
+ @server_client = @server.accept
8
+ end
9
+
10
+ after :each do
11
+ @client.close if @client && !@client.closed?
12
+ @server_client.close if @server_client && !@server_client.closed?
13
+ @server.close if @server
14
+ File.delete("protocol.sock")
15
+ end
16
+
17
+ it "initializes correctly" do
18
+ expect(subject).to be_a Nova::Starbound::Protocol
19
+
20
+ expect(subject.state).to be :offline
21
+ end
22
+
23
+ context "client performing handshake" do
24
+ subject { described_class.new(:threaded => false, :type => :client) }
25
+
26
+ before :each do
27
+ subject.socket = @client
28
+ @thread = Thread.start { subject.handshake }
29
+ sleep 0.1
30
+ end
31
+
32
+ it "sends the protocol version" do
33
+ pack = NovaHelper.packet_from_socket(@server_client)
34
+ expect(pack.body).to eq Nova::VERSION
35
+ expect(subject.state).to be :handshake
36
+
37
+ @thread.exit
38
+ end
39
+
40
+ it "checks versions" do
41
+ pack = NovaHelper.packet_from_socket(@server_client)
42
+ @server_client.write NovaHelper.build_response(:protocol_version, "200.0.0", pack)
43
+
44
+ expect {
45
+ @thread.join
46
+ }.to raise_error Nova::Starbound::IncompatibleRemoteError
47
+ end
48
+
49
+ it "checks for encryption" do
50
+
51
+ pack = NovaHelper.packet_from_socket(@server_client)
52
+ @server_client.write NovaHelper.build_response(:protocol_version, Nova::VERSION, pack)
53
+
54
+ encrypt = NovaHelper.packet_from_socket(@server_client)
55
+ expect(encrypt.body).to eq "rbnacl/1.0.0\nopenssl/rsa-4096/aes-256-cbc\nplaintext"
56
+
57
+ @thread.exit
58
+ end
59
+
60
+ it "does encryption" do
61
+ pack = NovaHelper.packet_from_socket(@server_client)
62
+ @server_client.write NovaHelper.build_response(:protocol_version, Nova::VERSION, pack)
63
+
64
+ encrypt = NovaHelper.packet_from_socket(@server_client)
65
+ expect(encrypt.body).to eq "rbnacl/1.0.0\nopenssl/rsa-4096/aes-256-cbc\nplaintext"
66
+ enc = Nova::Starbound::Encryptors::RbNaCl.new
67
+ enc.private_key!
68
+
69
+ @server_client.write NovaHelper.build_response(:public_key, "rbnacl/1.0.0\n" + enc.public_key, encrypt)
70
+
71
+ response = NovaHelper.packet_from_socket(@server_client)
72
+
73
+ enc.other_public_key = response.body
74
+
75
+ @thread.join
76
+ end
77
+
78
+ it "closes the socket" do
79
+ pack = NovaHelper.packet_from_socket(@server_client)
80
+ @server_client.write NovaHelper.build_response(:protocol_version, Nova::VERSION, pack)
81
+
82
+ encrypt = NovaHelper.packet_from_socket(@server_client)
83
+ expect(encrypt.body).to eq "rbnacl/1.0.0\nopenssl/rsa-4096/aes-256-cbc\nplaintext"
84
+ enc = Nova::Starbound::Encryptors::RbNaCl.new
85
+ enc.private_key!
86
+
87
+ @server_client.write NovaHelper.build_response(:public_key, "rbnacl/1.0.0\n" + enc.public_key, encrypt)
88
+ response = NovaHelper.packet_from_socket(@server_client)
89
+ enc.other_public_key = response.body
90
+
91
+ expect(subject.state).to be :online
92
+
93
+ subject.close
94
+
95
+ close_enc = NovaHelper.packet_from_socket(@server_client)
96
+ close = enc.decrypt(close_enc)
97
+ expect(close.type).to be :close
98
+ expect(close.body).to eq "0"
99
+
100
+ expect(subject.state).to be :offline
101
+ end
102
+ end
103
+
104
+ context "server performing handshake" do
105
+ subject { described_class.new(:type => :server) }
106
+
107
+ before :each do
108
+ subject.socket = @server_client
109
+ @thread = Thread.start { subject.handshake }
110
+ sleep 0.1
111
+ end
112
+
113
+ it "checks protocol versions" do
114
+ @client.write NovaHelper.build_packet(:protocol_version, "200.0.0")
115
+
116
+ expect {
117
+ @thread.join
118
+ }.to raise_error Nova::Starbound::IncompatibleRemoteError
119
+ end
120
+
121
+ it "sends back the protocol version" do
122
+ @client.write NovaHelper.build_packet(:protocol_version, Nova::VERSION)
123
+
124
+ version = NovaHelper.packet_from_socket(@client)
125
+ expect(version.body).to eq Nova::VERSION
126
+ @thread.exit
127
+ end
128
+
129
+ it "selects the correct encryption" do
130
+ @client.write NovaHelper.build_packet(:protocol_version, Nova::VERSION)
131
+ version = NovaHelper.packet_from_socket(@client)
132
+ @client.write NovaHelper.build_packet(:encryption_options, "rbnacl/1.0.0")
133
+ enc = NovaHelper.packet_from_socket(@client)
134
+ expect(enc.body.split("\n").first).to eq "rbnacl/1.0.0"
135
+ @thread.exit
136
+ end
137
+
138
+ it "does encryption" do
139
+ @client.write NovaHelper.build_packet(:protocol_version, Nova::VERSION)
140
+ version = NovaHelper.packet_from_socket(@client)
141
+ @client.write NovaHelper.build_packet(:encryption_options, "rbnacl/1.0.0", :packet_id => 2, :nonce => "")
142
+ enc_packet = NovaHelper.packet_from_socket(@client)
143
+
144
+ enc = Nova::Starbound::Encryptors::RbNaCl.new
145
+ enc.private_key!
146
+ enc.other_public_key = enc_packet.body.split("\n", 2).last
147
+
148
+ @client.write NovaHelper.build_response(:public_key, enc.public_key, enc_packet)
149
+
150
+ #expect(subject.state).to be :online
151
+ subject.on(:packet => :echo) { throw(:packet_echo) }
152
+ packet = NovaHelper.build_packet(:echo, "hello", :packet_id => 3)
153
+ enc_packet = enc.encrypt(packet)
154
+ @client.write enc_packet
155
+
156
+ expect {
157
+ subject.thread.join
158
+ }.to throw_symbol(:packet_echo)
159
+
160
+ @thread.join
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,70 @@
1
+ describe Nova::Starbound::Encryptors::RbNaCl do
2
+
3
+ it "is available" do
4
+ expect(described_class).to be_available
5
+ end
6
+
7
+ context "handling keys" do
8
+ subject { described_class.new }
9
+ its(:private_key!) { should be_a ::Crypto::PrivateKey }
10
+
11
+ it "has a public key" do
12
+ subject.private_key! # initialize the private key
13
+ expect(subject.public_key).to be_a String
14
+ end
15
+ end
16
+
17
+ before :each do
18
+ @packet = NovaHelper.build_packet
19
+ end
20
+
21
+ it "encrypts a packet successfully" do
22
+ subject.private_key!
23
+ public_key = subject.public_key
24
+
25
+ our_private = ::Crypto::PrivateKey.generate
26
+
27
+ subject.other_public_key = our_private.public_key.to_bytes
28
+ encrypted = nil
29
+
30
+ expect {
31
+ encrypted = subject.encrypt(@packet)
32
+ }.to_not raise_error
33
+
34
+ expect(encrypted).to be_instance_of Nova::Starbound::Protocol::Packet
35
+ expect(encrypted.body.bytesize).to eq encrypted[:size]
36
+ end
37
+
38
+ it "decrypts a packet successfully" do
39
+ subject.private_key!
40
+
41
+ our_private = ::Crypto::PrivateKey.generate
42
+ subject.other_public_key = our_private.public_key.to_bytes
43
+ their_public = subject.public_key
44
+
45
+ encrypted = subject.encrypt(@packet)
46
+ decrypted = nil
47
+
48
+ expect {
49
+ #decrypted = subject.decrypt(encrypted)
50
+ box = ::Crypto::Box.new(their_public, our_private)
51
+ decrypted = box.decrypt(encrypted[:nonce], encrypted[:body])
52
+ }.to_not raise_error
53
+
54
+ expect(decrypted).to eq @packet.body
55
+ end
56
+
57
+ it "raises an error on non-matching hashes" do
58
+ subject.private_key!
59
+ public_key = subject.public_key
60
+
61
+ subject.other_public_key = ::Crypto::PrivateKey.generate.public_key.to_bytes
62
+
63
+ encrypted = subject.encrypt(@packet)
64
+ encrypted.body.replace("\x00" * encrypted.size)
65
+
66
+ expect {
67
+ subject.decrypt(encrypted)
68
+ }.to raise_error(Nova::Starbound::EncryptorError)
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nova
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Rodi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: command-runner
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: os
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: packed_struct
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.18'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.18'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: |2
84
+ Software management system.
85
+ email: redjazz96@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - README.md
91
+ - LICENSE
92
+ - lib/nova/commands/server.rb
93
+ - lib/nova/remote/fake/platform.rb
94
+ - lib/nova/remote/fake/operating_system.rb
95
+ - lib/nova/remote/fake/commands.rb
96
+ - lib/nova/remote/fake/file_system.rb
97
+ - lib/nova/remote/fake.rb
98
+ - lib/nova/project.rb
99
+ - lib/nova/common/metadata/data.rb
100
+ - lib/nova/common/features.rb
101
+ - lib/nova/common/features/feature.rb
102
+ - lib/nova/common/metadata.rb
103
+ - lib/nova/common/event_handler/event.rb
104
+ - lib/nova/common/event_handler.rb
105
+ - lib/nova/common/star_management.rb
106
+ - lib/nova/version.rb
107
+ - lib/nova/remote.rb
108
+ - lib/nova/common.rb
109
+ - lib/nova/star.rb
110
+ - lib/nova/cli.rb
111
+ - lib/nova/starbound/client.rb
112
+ - lib/nova/starbound/encryptors/rbnacl.rb
113
+ - lib/nova/starbound/encryptors/openssl.rb
114
+ - lib/nova/starbound/encryptors/plaintext.rb
115
+ - lib/nova/starbound/server.rb
116
+ - lib/nova/starbound/encryptors.rb
117
+ - lib/nova/starbound/protocol/messages.rb
118
+ - lib/nova/starbound/protocol/socket.rb
119
+ - lib/nova/starbound/protocol/encryption.rb
120
+ - lib/nova/starbound/protocol/packet.rb
121
+ - lib/nova/starbound/protocol/exceptions.rb
122
+ - lib/nova/starbound/encryptor.rb
123
+ - lib/nova/starbound/protocol.rb
124
+ - lib/nova/exceptions.rb
125
+ - lib/nova/constructor.rb
126
+ - lib/nova/starbound.rb
127
+ - lib/generator/template/new_install/supernova.yml
128
+ - lib/generator/template/new_install/galaxy/some_star.rb
129
+ - lib/nova.rb
130
+ - bin/nova
131
+ - spec/constructor_spec.rb
132
+ - spec/star/some_type.rb
133
+ - spec/local_spec.rb
134
+ - spec/nova_spec.rb
135
+ - spec/spec_helper.rb
136
+ - spec/starbound/plaintext_encryptor_spec.rb
137
+ - spec/starbound/openssl_encryptor_spec.rb
138
+ - spec/starbound/encryptor_spec.rb
139
+ - spec/starbound/protocol_spec.rb
140
+ - spec/starbound/packet_spec.rb
141
+ - spec/starbound/rbnacl_encryptor_spec.rb
142
+ - spec/star_spec.rb
143
+ homepage: http://redjazz96.github.io/nova/
144
+ licenses: []
145
+ metadata: {}
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirements: []
161
+ rubyforge_project:
162
+ rubygems_version: 2.0.0.rc.2
163
+ signing_key:
164
+ specification_version: 4
165
+ summary: Software management system. Boom.
166
+ test_files: []