nexpose 5.2.0 → 5.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/nexpose/ajax.rb +5 -1
- data/lib/nexpose/api_request.rb +12 -5
- data/lib/nexpose/connection.rb +45 -5
- data/lib/nexpose/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66875e048dcb1dd081e1ccc2fb97b11820d21539
|
4
|
+
data.tar.gz: 3aa8c1daab1a48863388b39a19e5e59c42dbde4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c5dc066cb954cb27640d9d95d571c584958f6645323e1f50473409a26a7d84ea6bdc864fb739a9ef6d75bd2c19c080f60ba4936fb7bce77d622cc28e327aba2
|
7
|
+
data.tar.gz: 17cb67e994f1d621feb14640a92b2c7418b40a37e288e72617483538be157982a04c5c7b683102a6e52f9d63b84838db20ebb04092613ce9a00caadeb38c4e79
|
data/Gemfile.lock
CHANGED
data/lib/nexpose/ajax.rb
CHANGED
@@ -135,7 +135,11 @@ module Nexpose
|
|
135
135
|
http = Net::HTTP.new(nsc.host, nsc.port)
|
136
136
|
http.read_timeout = timeout if timeout
|
137
137
|
http.use_ssl = true
|
138
|
-
|
138
|
+
if nsc.trust_store.nil?
|
139
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
140
|
+
else
|
141
|
+
http.cert_store = nsc.trust_store
|
142
|
+
end
|
139
143
|
http
|
140
144
|
end
|
141
145
|
|
data/lib/nexpose/api_request.rb
CHANGED
@@ -17,11 +17,14 @@ module Nexpose
|
|
17
17
|
attr_reader :raw_response
|
18
18
|
attr_reader :raw_response_data
|
19
19
|
|
20
|
-
|
20
|
+
attr_reader :trust_store
|
21
|
+
|
22
|
+
def initialize(req, url, api_version = '1.1', trust_store = nil)
|
21
23
|
@url = url
|
22
24
|
@req = req
|
23
25
|
@api_version = api_version
|
24
26
|
@url = @url.sub('API_VERSION', @api_version)
|
27
|
+
@trust_store = trust_store
|
25
28
|
prepare_http_client
|
26
29
|
end
|
27
30
|
|
@@ -34,7 +37,11 @@ module Nexpose
|
|
34
37
|
# a confirmation when the nexpose host is not localhost. In a perfect world, we would present
|
35
38
|
# the server signature before accepting it, but this requires either a direct callback inside
|
36
39
|
# of this module back to whatever UI, or opens a race condition between accept and attempt.
|
37
|
-
@
|
40
|
+
if @trust_store.nil?
|
41
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
42
|
+
else
|
43
|
+
@http.cert_store = @trust_store
|
44
|
+
end
|
38
45
|
@headers = {'Content-Type' => 'text/xml'}
|
39
46
|
@success = false
|
40
47
|
end
|
@@ -93,7 +100,7 @@ module Nexpose
|
|
93
100
|
# drops our HTTP connection before processing. We try 5 times to establish a
|
94
101
|
# connection in these situations. The actual exception occurs in the Ruby
|
95
102
|
# http library, which is why we use such generic error classes.
|
96
|
-
rescue OpenSSL::SSL::SSLError
|
103
|
+
rescue OpenSSL::SSL::SSLError => e
|
97
104
|
if @conn_tries < 5
|
98
105
|
@conn_tries += 1
|
99
106
|
retry
|
@@ -133,8 +140,8 @@ module Nexpose
|
|
133
140
|
@res.root.attributes(*args)
|
134
141
|
end
|
135
142
|
|
136
|
-
def self.execute(url, req, api_version='1.1', options = {})
|
137
|
-
obj = self.new(req.to_s, url, api_version)
|
143
|
+
def self.execute(url, req, api_version = '1.1', options = {}, trust_store = nil)
|
144
|
+
obj = self.new(req.to_s, url, api_version, trust_store)
|
138
145
|
obj.execute(options)
|
139
146
|
raise APIError.new(obj, "Action failed: #{obj.error}") unless obj.success
|
140
147
|
obj
|
data/lib/nexpose/connection.rb
CHANGED
@@ -8,6 +8,19 @@ module Nexpose
|
|
8
8
|
# # Create a new Nexpose::Connection from a URI or "URI" String
|
9
9
|
# nsc = Connection.from_uri('https://10.1.40.10:3780', 'nxadmin', 'password')
|
10
10
|
#
|
11
|
+
# # Create a new Nexpose::Connection with a specific port
|
12
|
+
# nsc = Connection.new('10.1.40.10', 'nxadmin', 'password', 443)
|
13
|
+
#
|
14
|
+
# # Create a new Nexpose::Connection with a silo identifier
|
15
|
+
# nsc = Connection.new('10.1.40.10', 'nxadmin', 'password', 3780, 'default')
|
16
|
+
#
|
17
|
+
# # Create a new Nexpose::Connection with a two-factor authentication (2FA) token
|
18
|
+
# nsc = Connection.new('10.1.40.10', 'nxadmin', 'password', 3780, nil, '123456')
|
19
|
+
#
|
20
|
+
# # Create a new Nexpose::Connection with an excplicitly trusted web certificate
|
21
|
+
# trusted_cert = ::File.read('cert.pem')
|
22
|
+
# nsc = Connection.new('10.1.40.10', 'nxadmin', 'password', 3780, nil, nil, trusted_cert)
|
23
|
+
#
|
11
24
|
# # Login to NSC and Establish a Session ID
|
12
25
|
# nsc.login
|
13
26
|
#
|
@@ -44,20 +57,34 @@ module Nexpose
|
|
44
57
|
# The last XML response received by this object, useful for debugging.
|
45
58
|
attr_reader :response_xml
|
46
59
|
|
60
|
+
# The trust store to validate connections against if any
|
61
|
+
attr_reader :trust_store
|
62
|
+
|
47
63
|
# A constructor to load a Connection object from a URI
|
48
|
-
def self.from_uri(uri, user, pass, silo_id = nil, token = nil)
|
64
|
+
def self.from_uri(uri, user, pass, silo_id = nil, token = nil, trust_cert = nil)
|
49
65
|
uri = URI.parse(uri)
|
50
|
-
new(uri.host, user, pass, uri.port, silo_id, token)
|
66
|
+
new(uri.host, user, pass, uri.port, silo_id, token, trust_cert)
|
51
67
|
end
|
52
68
|
|
53
69
|
# A constructor for Connection
|
54
|
-
|
70
|
+
#
|
71
|
+
# @param [String] ip The IP address or hostname/FQDN of the Nexpose console.
|
72
|
+
# @param [String] user The username for Nexpose sessions.
|
73
|
+
# @param [String] pass The password for Nexpose sessions.
|
74
|
+
# @param [Fixnum] port The port number of the Nexpose console.
|
75
|
+
# @param [String] silo_id The silo identifier for Nexpose sessions.
|
76
|
+
# @param [String] token The two-factor authentication (2FA) token for Nexpose sessions.
|
77
|
+
# @param [String] trust_cert The PEM-formatted web certificate of the Nexpose console. Used for SSL validation.
|
78
|
+
def initialize(ip, user, pass, port = 3780, silo_id = nil, token = nil, trust_cert = nil)
|
55
79
|
@host = ip
|
56
80
|
@port = port
|
57
81
|
@username = user
|
58
82
|
@password = pass
|
59
83
|
@token = token
|
60
84
|
@silo_id = silo_id
|
85
|
+
unless trust_cert.nil?
|
86
|
+
@trust_store = create_trust_store(trust_cert)
|
87
|
+
end
|
61
88
|
@session_id = nil
|
62
89
|
@url = "https://#{@host}:#{@port}/api/API_VERSION/xml"
|
63
90
|
end
|
@@ -88,7 +115,7 @@ module Nexpose
|
|
88
115
|
def execute(xml, version = '1.1', options = {})
|
89
116
|
@request_xml = xml.to_s
|
90
117
|
@api_version = version
|
91
|
-
response = APIRequest.execute(@url, @request_xml, @api_version, options)
|
118
|
+
response = APIRequest.execute(@url, @request_xml, @api_version, options, @trust_store)
|
92
119
|
@response_xml = response.raw_response_data
|
93
120
|
response
|
94
121
|
end
|
@@ -104,7 +131,11 @@ module Nexpose
|
|
104
131
|
uri = URI.parse(url)
|
105
132
|
http = Net::HTTP.new(@host, @port)
|
106
133
|
http.use_ssl = true
|
107
|
-
|
134
|
+
if @trust_store.nil?
|
135
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE # XXX: security issue
|
136
|
+
else
|
137
|
+
http.cert_store = @trust_store
|
138
|
+
end
|
108
139
|
headers = {'Cookie' => "nexposeCCSessionID=#{@session_id}"}
|
109
140
|
resp = http.get(uri.to_s, headers)
|
110
141
|
|
@@ -114,5 +145,14 @@ module Nexpose
|
|
114
145
|
resp.body
|
115
146
|
end
|
116
147
|
end
|
148
|
+
|
149
|
+
def create_trust_store(trust_cert)
|
150
|
+
store = OpenSSL::X509::Store.new
|
151
|
+
store.trust
|
152
|
+
store.add_cert(OpenSSL::X509::Certificate.new(trust_cert))
|
153
|
+
store
|
154
|
+
end
|
155
|
+
|
156
|
+
private :create_trust_store
|
117
157
|
end
|
118
158
|
end
|
data/lib/nexpose/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nexpose
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HD Moore
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2017-
|
16
|
+
date: 2017-02-14 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: bundler
|