censu 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +13 -0
  3. data/.document +3 -0
  4. data/.gitignore +8 -0
  5. data/.rspec +1 -0
  6. data/.rubocop.yml +166 -0
  7. data/.travis.yml +12 -0
  8. data/.yardopts +1 -0
  9. data/ChangeLog.md +4 -0
  10. data/Gemfile +3 -0
  11. data/LICENSE.txt +7 -0
  12. data/README.md +76 -0
  13. data/Rakefile +21 -0
  14. data/censys.gemspec +28 -0
  15. data/lib/censys.rb +2 -0
  16. data/lib/censys/api.rb +254 -0
  17. data/lib/censys/autonomous_system.rb +43 -0
  18. data/lib/censys/certificate.rb +31 -0
  19. data/lib/censys/document.rb +48 -0
  20. data/lib/censys/document/has_asn.rb +16 -0
  21. data/lib/censys/document/has_location.rb +16 -0
  22. data/lib/censys/document/has_services.rb +21 -0
  23. data/lib/censys/exceptions.rb +16 -0
  24. data/lib/censys/ipv4.rb +26 -0
  25. data/lib/censys/location.rb +54 -0
  26. data/lib/censys/report.rb +1 -0
  27. data/lib/censys/report/metadata.rb +41 -0
  28. data/lib/censys/report/response.rb +54 -0
  29. data/lib/censys/search.rb +1 -0
  30. data/lib/censys/search/certificate.rb +19 -0
  31. data/lib/censys/search/ipv4.rb +18 -0
  32. data/lib/censys/search/metadata.rb +33 -0
  33. data/lib/censys/search/response.rb +124 -0
  34. data/lib/censys/search/result.rb +49 -0
  35. data/lib/censys/search/website.rb +18 -0
  36. data/lib/censys/version.rb +4 -0
  37. data/lib/censys/website.rb +30 -0
  38. data/spec/censys_spec.rb +8 -0
  39. data/spec/fixtures/vcr_cassettes/Censys_API/_report/certificates/should_return_certificate_response.yml +49 -0
  40. data/spec/fixtures/vcr_cassettes/Censys_API/_report/ipv4/should_return_ipv4_response.yml +52 -0
  41. data/spec/fixtures/vcr_cassettes/Censys_API/_report/websites/should_return_website_response.yml +49 -0
  42. data/spec/fixtures/vcr_cassettes/Censys_API/_search/certificates/should_return_Certificate_response.yml +397 -0
  43. data/spec/fixtures/vcr_cassettes/Censys_API/_search/ipv4/should_return_IPv4_response.yml +606 -0
  44. data/spec/fixtures/vcr_cassettes/Censys_API/_search/websites/should_return_Website_response.yml +112 -0
  45. data/spec/fixtures/vcr_cassettes/Censys_API/_view/certificates/should_return_Certificate_response.yml +143 -0
  46. data/spec/fixtures/vcr_cassettes/Censys_API/_view/ipv4/should_return_IPv4_response.yml +176 -0
  47. data/spec/fixtures/vcr_cassettes/Censys_API/_view/websites/should_return_Website_response.yml +1020 -0
  48. data/spec/report_spec.rb +60 -0
  49. data/spec/search_spec.rb +49 -0
  50. data/spec/spec_helper.rb +19 -0
  51. data/spec/view_spec.rb +48 -0
  52. metadata +219 -0
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe Censys::API do
4
+ before(:context) do
5
+ @api = Censys::API.new
6
+ end
7
+
8
+ describe "#report", :vcr do
9
+ context "ipv4" do
10
+ it "should return ipv4 response" do
11
+ params = {
12
+ query: "8.8.8.8",
13
+ field: "ports",
14
+ buckets: 10
15
+ }
16
+ report = @api.report(:ipv4, params)
17
+ expect(report).to be_a(Report::Response)
18
+ expect(report.status).to eq("ok")
19
+ expect(report.ok?).to be_truthy
20
+ expect(report.results).to be_a(Hash)
21
+ expect(report.metadata).to be_a(Report::Metadata)
22
+ expect(report.metadata.count).to be_a(Integer)
23
+ expect(report.metadata.backend_time).to be_a(Integer)
24
+ expect(report.metadata.non_null_count).to be_a(Integer)
25
+ expect(report.metadata.other_result_count).to be_a(Integer)
26
+ expect(report.metadata.buckets).to be_a(Integer)
27
+ expect(report.metadata.error_bound).to be_a(Integer)
28
+ expect(report.metadata.query).to eq("8.8.8.8")
29
+ end
30
+ end
31
+
32
+ context "websites" do
33
+ it "should return website response" do
34
+ params = {
35
+ query: "google.com",
36
+ field: "ports",
37
+ buckets: 10
38
+ }
39
+ report = @api.report(:websites, params)
40
+ expect(report).to be_a(Report::Response)
41
+ expect(report.metadata).to be_a(Report::Metadata)
42
+ expect(report.metadata.query).to eq("google.com")
43
+ end
44
+ end
45
+
46
+ context "certificates" do
47
+ it "should return certificate response" do
48
+ params = {
49
+ query: "google.com",
50
+ field: "precert",
51
+ buckets: 10
52
+ }
53
+ report = @api.report(:certificates, params)
54
+ expect(report).to be_a(Report::Response)
55
+ expect(report.metadata).to be_a(Report::Metadata)
56
+ expect(report.metadata.query).to eq("google.com")
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe Censys::API do
4
+ before(:context) do
5
+ @api = Censys::API.new
6
+ end
7
+
8
+ describe "#search", :vcr do
9
+ context "ipv4" do
10
+ it "should return IPv4 response" do
11
+ res = @api.ipv4.search(query: "dropbox.com")
12
+ expect(res).to be_a(Search::Response)
13
+ expect(res.metadata).to be_a(Search::Metadata)
14
+ expect(res.each).to be_a(Enumerator)
15
+ expect(res.pages).to be_a(Enumerator)
16
+
17
+ first = res.results.first
18
+ expect(first).to be_a(Search::IPv4)
19
+ expect(first.ip).to be_a(String)
20
+ expect(first.protocols).to be_a(Array)
21
+ end
22
+ end
23
+
24
+ context "websites" do
25
+ it "should return Website response" do
26
+ res = @api.websites.search(query: "dropbox.com")
27
+ expect(res).to be_a(Search::Response)
28
+
29
+ first = res.results.first
30
+ expect(first).to be_a(Search::Website)
31
+ expect(first.domain).to be_a(String)
32
+ expect(first.alexa_rank).to be_a(Integer)
33
+ end
34
+ end
35
+
36
+ context "certificates" do
37
+ it "should return Certificate response" do
38
+ res = @api.certificates.search(query: "dropbox.com")
39
+ expect(res).to be_a(Search::Response)
40
+
41
+ first = res.results.first
42
+ expect(first).to be_a(Search::Certificate)
43
+ expect(first.fingerprint_sha256).to be_a(String)
44
+ expect(first.subject_dn).to be_a(String)
45
+ expect(first.issuer_dn).to be_a(String)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,19 @@
1
+ require 'dotenv/load'
2
+ require 'rspec'
3
+ require 'vcr'
4
+ require 'censys'
5
+
6
+ include Censys
7
+
8
+ def authorization_field
9
+ require 'base64'
10
+ token = "#{ENV['CENSYS_ID']}:#{ENV['CENSYS_SECRET']}"
11
+ "Basic #{Base64.strict_encode64(token)}"
12
+ end
13
+
14
+ VCR.configure do |config|
15
+ config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
16
+ config.hook_into :webmock
17
+ config.configure_rspec_metadata!
18
+ config.filter_sensitive_data("<CENSORED>") { authorization_field }
19
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Censys::API do
4
+ before(:context) do
5
+ @api = Censys::API.new
6
+ end
7
+
8
+ describe "#view", :vcr do
9
+ context "ipv4" do
10
+ it "should return IPv4 response" do
11
+ view = @api.view(:ipv4, "8.8.8.8")
12
+ expect(view).to be_a(Censys::IPv4)
13
+ expect(view.tags).to be_a(Array)
14
+ expect(view.updated_at).to be_a(Time)
15
+ expect(view.autonomous_system).to be_a(AutonomousSystem)
16
+ expect(view.location).to be_a(Location)
17
+ expect(view.ports).to be_a(Hash)
18
+ expect(view.protocols).to be_a(Array)
19
+ expect(view.dig("location", "city")).to eq("Mountain View")
20
+
21
+ expect(view.ip).to eq("8.8.8.8")
22
+ expect(view.to_s).to eq("8.8.8.8")
23
+ expect(view.protocols).to be_a(Array)
24
+ end
25
+ end
26
+
27
+ context "websites" do
28
+ it "should return Website response" do
29
+ view = @api.view(:websites, "google.com")
30
+ expect(view).to be_a(Censys::Website)
31
+ expect(view.domain).to eq("google.com")
32
+ expect(view.to_s).to eq("google.com")
33
+ expect(view.alexa_rank).to be_a(Integer)
34
+ end
35
+ end
36
+
37
+ context "certificates" do
38
+ it "should return Certificate response" do
39
+ sha256 = "821a712a29d8e25915f66a9771519746c5aa73a45321fd4ca7ef644e1cadda59"
40
+ view = @api.view(:certificates, sha256)
41
+ expect(view).to be_a(Censys::Certificate)
42
+ expect(view.raw).to be_a(String)
43
+ expect(view.parsed).to be_a(Hash)
44
+ expect(view.valid_nss).to eq(true)
45
+ end
46
+ end
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,219 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: censu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Manabu Niseki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-16 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubygems-tasks
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.9'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.9'
125
+ description: Ruby API client for the Censys Internet search engine.
126
+ email: manabu.niseki@gmail.com
127
+ executables: []
128
+ extensions: []
129
+ extra_rdoc_files: []
130
+ files:
131
+ - ".codeclimate.yml"
132
+ - ".document"
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".rubocop.yml"
136
+ - ".travis.yml"
137
+ - ".yardopts"
138
+ - ChangeLog.md
139
+ - Gemfile
140
+ - LICENSE.txt
141
+ - README.md
142
+ - Rakefile
143
+ - censys.gemspec
144
+ - lib/censys.rb
145
+ - lib/censys/api.rb
146
+ - lib/censys/autonomous_system.rb
147
+ - lib/censys/certificate.rb
148
+ - lib/censys/document.rb
149
+ - lib/censys/document/has_asn.rb
150
+ - lib/censys/document/has_location.rb
151
+ - lib/censys/document/has_services.rb
152
+ - lib/censys/exceptions.rb
153
+ - lib/censys/ipv4.rb
154
+ - lib/censys/location.rb
155
+ - lib/censys/report.rb
156
+ - lib/censys/report/metadata.rb
157
+ - lib/censys/report/response.rb
158
+ - lib/censys/search.rb
159
+ - lib/censys/search/certificate.rb
160
+ - lib/censys/search/ipv4.rb
161
+ - lib/censys/search/metadata.rb
162
+ - lib/censys/search/response.rb
163
+ - lib/censys/search/result.rb
164
+ - lib/censys/search/website.rb
165
+ - lib/censys/version.rb
166
+ - lib/censys/website.rb
167
+ - spec/censys_spec.rb
168
+ - spec/fixtures/vcr_cassettes/Censys_API/_report/certificates/should_return_certificate_response.yml
169
+ - spec/fixtures/vcr_cassettes/Censys_API/_report/ipv4/should_return_ipv4_response.yml
170
+ - spec/fixtures/vcr_cassettes/Censys_API/_report/websites/should_return_website_response.yml
171
+ - spec/fixtures/vcr_cassettes/Censys_API/_search/certificates/should_return_Certificate_response.yml
172
+ - spec/fixtures/vcr_cassettes/Censys_API/_search/ipv4/should_return_IPv4_response.yml
173
+ - spec/fixtures/vcr_cassettes/Censys_API/_search/websites/should_return_Website_response.yml
174
+ - spec/fixtures/vcr_cassettes/Censys_API/_view/certificates/should_return_Certificate_response.yml
175
+ - spec/fixtures/vcr_cassettes/Censys_API/_view/ipv4/should_return_IPv4_response.yml
176
+ - spec/fixtures/vcr_cassettes/Censys_API/_view/websites/should_return_Website_response.yml
177
+ - spec/report_spec.rb
178
+ - spec/search_spec.rb
179
+ - spec/spec_helper.rb
180
+ - spec/view_spec.rb
181
+ homepage: https://github.com/ninoseki/censu
182
+ licenses:
183
+ - MIT
184
+ metadata: {}
185
+ post_install_message:
186
+ rdoc_options: []
187
+ require_paths:
188
+ - lib
189
+ required_ruby_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ required_rubygems_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ requirements: []
200
+ rubyforge_project:
201
+ rubygems_version: 2.6.11
202
+ signing_key:
203
+ specification_version: 4
204
+ summary: API client for censys.io
205
+ test_files:
206
+ - spec/censys_spec.rb
207
+ - spec/fixtures/vcr_cassettes/Censys_API/_report/certificates/should_return_certificate_response.yml
208
+ - spec/fixtures/vcr_cassettes/Censys_API/_report/ipv4/should_return_ipv4_response.yml
209
+ - spec/fixtures/vcr_cassettes/Censys_API/_report/websites/should_return_website_response.yml
210
+ - spec/fixtures/vcr_cassettes/Censys_API/_search/certificates/should_return_Certificate_response.yml
211
+ - spec/fixtures/vcr_cassettes/Censys_API/_search/ipv4/should_return_IPv4_response.yml
212
+ - spec/fixtures/vcr_cassettes/Censys_API/_search/websites/should_return_Website_response.yml
213
+ - spec/fixtures/vcr_cassettes/Censys_API/_view/certificates/should_return_Certificate_response.yml
214
+ - spec/fixtures/vcr_cassettes/Censys_API/_view/ipv4/should_return_IPv4_response.yml
215
+ - spec/fixtures/vcr_cassettes/Censys_API/_view/websites/should_return_Website_response.yml
216
+ - spec/report_spec.rb
217
+ - spec/search_spec.rb
218
+ - spec/spec_helper.rb
219
+ - spec/view_spec.rb