passive_circl 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 20426057d1a9c6e5cd7eb6d6c8e7ed9aaa3d22899350c3650d603530c06ab981
4
+ data.tar.gz: 516af177819a02c7fc92877eb7cad1b3efdad3d3ad7a5a18f22d74c2afde2d13
5
+ SHA512:
6
+ metadata.gz: dc1c159d9fcb742ee995ae8fe8399a2d3525ce7ba475f9c778520be6e53bf1f905990485689081690227e9a9b0c7c2212bcc987be46b1f5f0272c8bcd0ee4055
7
+ data.tar.gz: a34a7ec536bbdcee785c064b2209347fbaf05b6a0438114172824a0ca7f5c43bac8a872b784d698dd804266bb1e88c5ae9588f69faa48a0de42b840ee1d8a430
@@ -0,0 +1,52 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ Gemfile.lock
46
+ .ruby-version
47
+ .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+
52
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in passive_circl.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Manabu Niseki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,34 @@
1
+ # passive_circl
2
+
3
+ [![Build Status](https://travis-ci.com/ninoseki/passive_circl.svg?branch=master)](https://travis-ci.com/ninoseki/passive_circl)
4
+ [![Coverage Status](https://coveralls.io/repos/github/ninoseki/passive_circl/badge.svg?branch=master)](https://coveralls.io/github/ninoseki/passive_circl?branch=master)
5
+ [![CodeFactor](https://www.codefactor.io/repository/github/ninoseki/passive_circl/badge)](https://www.codefactor.io/repository/github/ninoseki/passive_circl)
6
+
7
+ [CIRCL](https://www.circl.lu/) Passive DNS/SSL API wrapper for Ruby.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ gem install passive_circl
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ruby
18
+ require "passive_circl"
19
+
20
+ # when given nothing, it tries to load username and password from ENV["CIRCL_PASSIVE_USERNAME] and ENV["CIRCL_PASSIVE_PASSWORD"]
21
+ api = PassiveCIRCL::API.new
22
+ # or you can set them manually
23
+ api = PassiveCIRCL::API.new(username: "USERNAME", password: "PASSWORD")
24
+
25
+ api.dns.query("www.circl.lu")
26
+
27
+ api.ssl.query("172.228.24.0/28")
28
+ api.ssl.cquery("c46fed822dadac3f31f9bb4d1a78a1d9eae4567b")
29
+ api.ssl.cfetch("7c552ab044c76d1df4f5ddf358807bfdcd07fa57")
30
+ ```
31
+
32
+ ## License
33
+
34
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "passive_circl"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "passive_circl/version"
4
+
5
+ require "passive_circl/clients/base"
6
+
7
+ require "passive_circl/clients/ssl"
8
+ require "passive_circl/clients/dns"
9
+
10
+ require "passive_circl/api"
11
+
12
+ module PassiveCIRCL
13
+ class Error < StandardError; end
14
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PassiveCIRCL
4
+ class API
5
+ attr_reader :dns
6
+ attr_reader :ssl
7
+
8
+ def initialize(username: ENV["CIRCL_PASSIVE_USERNAME"], password: ENV["CIRCL_PASSIVE_PASSWORD"])
9
+ @dns = Clients::DNS.new(username: username, password: password)
10
+ @ssl = Clients::SSL.new(username: username, password: password)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "net/https"
5
+ require "uri"
6
+
7
+ module PassiveCIRCL
8
+ module Clients
9
+ class Base
10
+ HOST = "www.circl.lu"
11
+ BASE_URL = "https://#{HOST}"
12
+
13
+ def initialize(username:, password:)
14
+ @username = username
15
+ @password = password
16
+ end
17
+
18
+ private
19
+
20
+ def url_for(path)
21
+ URI(BASE_URL + path)
22
+ end
23
+
24
+ def https_options
25
+ if proxy = ENV["HTTPS_PROXY"] || ENV["https_proxy"]
26
+ uri = URI(proxy)
27
+ {
28
+ proxy_address: uri.hostname,
29
+ proxy_port: uri.port,
30
+ proxy_from_env: false,
31
+ use_ssl: true
32
+ }
33
+ else
34
+ { use_ssl: true }
35
+ end
36
+ end
37
+
38
+ def request(req)
39
+ Net::HTTP.start(HOST, 443, https_options) do |http|
40
+ response = http.request(req)
41
+
42
+ code = response.code.to_i
43
+ raise Error, "Unsupported response code returned: #{code}" if code != 200
44
+
45
+ body = response.body
46
+ content_type = response["Content-Type"].to_s
47
+
48
+ if content_type.include?("application/json")
49
+ yield JSON.parse body
50
+ else
51
+ list = body.lines.map { |line| JSON.parse line }
52
+ yield list
53
+ end
54
+ end
55
+ end
56
+
57
+ def _get(path, params = {}, &block)
58
+ uri = url_for(path)
59
+ uri.query = URI.encode_www_form(params)
60
+ get = Net::HTTP::Get.new(uri)
61
+ get.basic_auth @username, @password
62
+
63
+ request(get, &block)
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PassiveCIRCL
4
+ module Clients
5
+ class DNS < Base
6
+ def query(value)
7
+ _get("/pdns/query/#{value}") { |json| json }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PassiveCIRCL
4
+ module Clients
5
+ class SSL < Base
6
+ VERSION = "v2"
7
+
8
+ def query(cidr)
9
+ _get("/query/#{cidr}") { |json| json }
10
+ end
11
+
12
+ def cquery(fingerprint)
13
+ _get("/cquery/#{fingerprint}") { |json| json }
14
+ end
15
+
16
+ def cfetch(fingerprint)
17
+ _get("/cfetch/#{fingerprint}") { |json| json }
18
+ end
19
+
20
+ private
21
+
22
+ def url_for(path)
23
+ URI(BASE_URL + "/#{VERSION}pssl" + path)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PassiveCIRCL
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "passive_circl/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "passive_circl"
9
+ spec.version = PassiveCIRCL::VERSION
10
+ spec.authors = ["Manabu Niseki"]
11
+ spec.email = ["manabu.niseki@gmail.com"]
12
+
13
+ spec.summary = "CIRCL Passive DNS/SSL API wrapper for Ruby"
14
+ spec.description = "CIRCL Passive DNS/SSL API wrapper for Ruby"
15
+ spec.homepage = "https://github.com/ninoseki/passive_circl"
16
+ spec.license = "MIT"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 2.0"
28
+ spec.add_development_dependency "coveralls", "~> 0.8"
29
+ spec.add_development_dependency "rake", "~> 12.3"
30
+ spec.add_development_dependency "rspec", "~> 3.8"
31
+ spec.add_development_dependency "vcr", "~> 5.0"
32
+ spec.add_development_dependency "webmock", "~> 3.7"
33
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: passive_circl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Manabu Niseki
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-01 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
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.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.7'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.7'
97
+ description: CIRCL Passive DNS/SSL API wrapper for Ruby
98
+ email:
99
+ - manabu.niseki@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - lib/passive_circl.rb
114
+ - lib/passive_circl/api.rb
115
+ - lib/passive_circl/clients/base.rb
116
+ - lib/passive_circl/clients/dns.rb
117
+ - lib/passive_circl/clients/ssl.rb
118
+ - lib/passive_circl/version.rb
119
+ - passive_circl.gemspec
120
+ homepage: https://github.com/ninoseki/passive_circl
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubygems_version: 3.0.4
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: CIRCL Passive DNS/SSL API wrapper for Ruby
143
+ test_files: []