ssl_expiry_ng 1.0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.rubocop.yml +33 -0
- data/.travis.yml +66 -0
- data/CHANGELOG.md +23 -0
- data/CODEOWNERS +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +103 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/check-ssl +64 -0
- data/lib/ssl_expiry/errors.rb +5 -0
- data/lib/ssl_expiry/version.rb +5 -0
- data/lib/ssl_expiry.rb +101 -0
- data/spec/spec_helper.rb +28 -0
- data/spec/ssl_expiry_spec.rb +9 -0
- data/ssl_expiry.gemspec +31 -0
- data/testing/check-ssl +66 -0
- metadata +169 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2cd52e2fa19b5d3f9c21730d152c7fdd1fb3bad0d20142200b0e9ed138248f2c
|
4
|
+
data.tar.gz: 7c5325dc03f59a20c1de8413ccc1d1066ae017a6a716117a56dedb1812691c1f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 21795128d99a21d89ed2d978d997390653467c81fa0999fef1bf1f9b4eb19302060a6acea21570ea565a6f50539fc3631fb731fd460b2003e49e2848adf03577
|
7
|
+
data.tar.gz: 6c51af8dfbb3ef34a3b0d088a558260851dcee288105d549d2546c66956e4c308a7ded6083d6b1f233283f7b119e4011d0b7bd70b1082102a9d27434213a4fd2
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
Layout/IndentationWidth:
|
2
|
+
Width: 4
|
3
|
+
|
4
|
+
Layout/LineLength:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Metrics/AbcSize:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Metrics/BlockLength:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Metrics/CyclomaticComplexity:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Metrics/MethodLength:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Metrics/PerceivedComplexity:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/GlobalVars:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/RaiseArgs:
|
26
|
+
EnforcedStyle: compact
|
27
|
+
|
28
|
+
Style/RedundantBegin:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Style/WordArray:
|
32
|
+
EnforcedStyle: brackets
|
33
|
+
|
data/.travis.yml
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
matrix:
|
2
|
+
include:
|
3
|
+
- language: ruby
|
4
|
+
name: "Bundler (rvm 2.4.4 & bundler 1.17.3)"
|
5
|
+
rvm: 2.4.4
|
6
|
+
before_install:
|
7
|
+
- gem install bundler -v 1.17.3
|
8
|
+
- language: ruby
|
9
|
+
name: "Bundler (rvm 2.4.4 & bundler 2.0.1)"
|
10
|
+
rvm: 2.4.4
|
11
|
+
before_install:
|
12
|
+
- gem install bundler -v 2.0.1
|
13
|
+
- language: ruby
|
14
|
+
name: "Bundler (rvm 2.5.3 & bundler 2.0.1)"
|
15
|
+
rvm: 2.5.3
|
16
|
+
before_install:
|
17
|
+
- gem install bundler -v 2.0.1
|
18
|
+
- language: ruby
|
19
|
+
name: "Bundler (rvm 2.6.1 & bundler 2.0.1)"
|
20
|
+
rvm: 2.6.1
|
21
|
+
before_install:
|
22
|
+
- gem install bundler -v 2.0.1
|
23
|
+
- language: ruby
|
24
|
+
name: "Rubocop (rvm 2.4.4)"
|
25
|
+
env: SKIP_INTERPRETER=true
|
26
|
+
rvm: 2.4.4
|
27
|
+
before_install:
|
28
|
+
- git clone https://github.com/TravisToolbox/rubocop-travis.git
|
29
|
+
install:
|
30
|
+
- ./rubocop-travis/install.sh
|
31
|
+
script:
|
32
|
+
- ./rubocop-travis/scan.sh
|
33
|
+
- language: ruby
|
34
|
+
name: "Rubocop (rvm 2.5.3)"
|
35
|
+
env: SKIP_INTERPRETER=true
|
36
|
+
rvm: 2.5.3
|
37
|
+
before_install:
|
38
|
+
- git clone https://github.com/TravisToolbox/rubocop-travis.git
|
39
|
+
install:
|
40
|
+
- ./rubocop-travis/install.sh
|
41
|
+
script:
|
42
|
+
- ./rubocop-travis/scan.sh
|
43
|
+
- language: ruby
|
44
|
+
name: "Rubocop (rvm 2.6.1)"
|
45
|
+
env: SKIP_INTERPRETER=true
|
46
|
+
rvm: 2.6.1
|
47
|
+
before_install:
|
48
|
+
- git clone https://github.com/TravisToolbox/rubocop-travis.git
|
49
|
+
install:
|
50
|
+
- ./rubocop-travis/install.sh
|
51
|
+
script:
|
52
|
+
- ./rubocop-travis/scan.sh
|
53
|
+
- language: ruby
|
54
|
+
name: "Link Checker (rvm 2.6.1)"
|
55
|
+
rvm: 2.6.1
|
56
|
+
before_install:
|
57
|
+
- mkdir travis
|
58
|
+
- git clone https://github.com/TravisToolbox/awesomebot-travis.git travis/awesomebot
|
59
|
+
install:
|
60
|
+
- ./travis/awesomebot/install.sh
|
61
|
+
script:
|
62
|
+
- ./travis/awesomebot/scan.sh
|
63
|
+
notifications:
|
64
|
+
email: false
|
65
|
+
slack:
|
66
|
+
secure: u3UC7xkXbiXgWeWkay1G2VBNzUfa6FUvLK4LtkxiaYeF/Y7uQ9As8EZ/0xeTHpr014XY8zTNwdYVntp5hBASxuH+43sWZKIeCRy0YxtQ97f6/0mRSKUVul73XvYcHMns/42Ho17OcAae70r9I59zKJSSz4I9+QnSkoCn1CgYzXGw8u4C9+WLxIbXyG7bKFwhsiIsHOJiBgWy+V9QG5tZfvlQwMwIAlQ0dkwiIkQ3DMq2NpCawFhL0as8f6VatJZMU+D3CG9EU28965rdrivAZ1emJky5HFJ/ZKeacTtbDijFTpeFS7G6ZH+4LavdyFjWCH3hsdIgQ3AhL/F/JjioIIOL6U9pnJbmnihHaxLM/l9wOovmmbjoe/mZPmTtdoUUebY1RBeAp+3l5xz4HOb8zIaPDoejMs75gysXboXQSSLW6oga6XKUNBLyf8PNc5KowoLh2Q2CZV0HyJHwlp3jCUA2E5cL04iGaLpcDTP+vm4zrHD4ICd89EQumyXesowxcyahWTPlH5+CxHSxsJ66peRHHqEW4Si9zR0ssWjmhfzGcoIfMVwPOFwOG/qxvxFAM24tCyOwaSmW1vQXSVFsZ7FHap+lG9yKOKV9Q2ZBREPX0pAJ8ST6zVE6Q4ppOv7t8nGALhjSsXzIOoWqfZdvH0ktyJYo6bpEw/e8YdmRfw8=
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
## 1.0.3 (February 7, 2020)
|
2
|
+
|
3
|
+
IMPROVEMENTS:
|
4
|
+
|
5
|
+
* Allow the specification of a custom port. ([@TGWolf][])
|
6
|
+
|
7
|
+
## 1.0.2 (June 28, 2019)
|
8
|
+
|
9
|
+
IMPROVEMENTS:
|
10
|
+
|
11
|
+
* Clean up tweaks based on updates to rubocop. ([@TGWolf][])
|
12
|
+
|
13
|
+
## 1.0.1 (May 8, 2019)
|
14
|
+
|
15
|
+
CHANGES:
|
16
|
+
|
17
|
+
* Minor clean up of code, especially the CLI tool ([@TGWolf][])
|
18
|
+
|
19
|
+
## 1.0.0 (February 21, 2019)
|
20
|
+
|
21
|
+
* Initial Release ([@TGWolf][])
|
22
|
+
|
23
|
+
[@TGWolf]: https://github.com/TGWolf
|
data/CODEOWNERS
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at tim.gurney@timgurney.net. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Tim Gurney aka Wolf
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
[![Build Status](https://img.shields.io/travis/AntiPhotonltd/ssl_expiry/master.svg)](https://travis-ci.org/AntiPhotonltd/ssl_expiry)
|
2
|
+
[![Software License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.md)
|
3
|
+
[![Release](https://img.shields.io/github/release/AntiPhotonltd/ssl_expiry.svg)](https://github.com/AntiPhotonltd/ssl_expiry/releases/latest)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/ssl_expiry.svg)](https://badge.fury.io/rb/ssl_expiry)
|
5
|
+
[![Github commits (since latest release)](https://img.shields.io/github/commits-since/AntiPhotonltd/ssl_expiry/latest.svg)](https://github.com/AntiPhotonltd/ssl_expiry/commits)
|
6
|
+
[![GitHub repo size in bytes](https://img.shields.io/github/repo-size/AntiPhotonltd/ssl_expiry.svg)](https://github.com/AntiPhotonltd/ssl_expiry)
|
7
|
+
[![GitHub contributors](https://img.shields.io/github/contributors/AntiPhotonltd/ssl_expiry.svg)](https://github.com/AntiPhotonltd/ssl_expiry)
|
8
|
+
|
9
|
+
# SSL Expiry
|
10
|
+
|
11
|
+
This is a simple little gem for checking when an SSL will expire.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'ssl_expiry'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install ssl_expiry
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
### Simple Usage
|
32
|
+
```ruby
|
33
|
+
require 'ssl_expiry'
|
34
|
+
|
35
|
+
SSLExpiry::SSLExpiry.check_certificates('antiphoton.com')
|
36
|
+
|
37
|
+
Results:
|
38
|
+
{"antiphoton.com"=>{"status"=>200, "expires_on"=>"09 Mar 2019", "expires_in"=>16, "common_name"=>"antiphoton.com", "issuer"=>"COMODO CA Limited"}}
|
39
|
+
```
|
40
|
+
|
41
|
+
### Displaying the output
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
require 'ssl_expiry'
|
45
|
+
|
46
|
+
results = SSLExpiry::SSLExpiry.check_certificates(['antiphoton.com','wolfsoftware.com'])
|
47
|
+
SSLExpiry::SSLExpiry.display_results(results)
|
48
|
+
```
|
49
|
+
|
50
|
+
This would give the following output
|
51
|
+
|
52
|
+
```shell
|
53
|
+
----------------------------------------------------------------------------------------------------
|
54
|
+
Domain | Status
|
55
|
+
----------------------------------------------------------------------------------------------------
|
56
|
+
antiphoton.com | expires on 09 Mar 2019 (in 16 days) [CN=antiphoton.com]
|
57
|
+
wolfsoftware.com | expires on 12 Sep 2019 (in 203 days) [CN=*.wolfsoftware.com]
|
58
|
+
----------------------------------------------------------------------------------------------------
|
59
|
+
```
|
60
|
+
|
61
|
+
## Command Line Tools
|
62
|
+
|
63
|
+
There is a command line tool included with this gem.
|
64
|
+
|
65
|
+
```shell
|
66
|
+
check-ssl -d antiphoton.com
|
67
|
+
|
68
|
+
----------------------------------------------------------------------------------------------------
|
69
|
+
Domain | Status
|
70
|
+
----------------------------------------------------------------------------------------------------
|
71
|
+
antiphoton.com | expires on 09 Mar 2019 (in 16 days) [CN=antiphoton.com]
|
72
|
+
----------------------------------------------------------------------------------------------------
|
73
|
+
```
|
74
|
+
|
75
|
+
### Custom port
|
76
|
+
|
77
|
+
If you want to check an SSL expiry on a custom port you can do this by adding the port to the end of the domain.
|
78
|
+
|
79
|
+
```
|
80
|
+
check-ssl -d antiphoton.com:8080
|
81
|
+
```
|
82
|
+
|
83
|
+
## Development
|
84
|
+
|
85
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
86
|
+
|
87
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
88
|
+
|
89
|
+
## Testing
|
90
|
+
|
91
|
+
For local testing make sure that you run `bundle exec rspec spec` and then `rake install` to install the gem locally.
|
92
|
+
|
93
|
+
## Contributing
|
94
|
+
|
95
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/AntiPhotonltd/ssl_expiry. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
96
|
+
|
97
|
+
## License
|
98
|
+
|
99
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
100
|
+
|
101
|
+
## Code of Conduct
|
102
|
+
|
103
|
+
Everyone interacting in the SSLExpiry project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/AntiPhotonltd/ssl_expiry/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ssl_expiry"
|
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__)
|
data/bin/setup
ADDED
data/exe/check-ssl
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
require 'ssl_expiry'
|
6
|
+
|
7
|
+
# -------------------------------------------------------------------------------- #
|
8
|
+
# Process Arguments #
|
9
|
+
# -------------------------------------------------------------------------------- #
|
10
|
+
# This function will process the input from the command line and work out what it #
|
11
|
+
# is that the user wants to see. #
|
12
|
+
# #
|
13
|
+
# This is the main processing function where all the processing logic is handled. #
|
14
|
+
# -------------------------------------------------------------------------------- #
|
15
|
+
|
16
|
+
def process_arguments
|
17
|
+
options = {}
|
18
|
+
# Enforce the presence of
|
19
|
+
mandatory = %I[domain]
|
20
|
+
|
21
|
+
optparse = OptionParser.new do |opts|
|
22
|
+
opts.banner = "Usage: #{$PROGRAM_NAME}"
|
23
|
+
|
24
|
+
opts.on('-h', '--help', 'Display this screen') do
|
25
|
+
puts opts
|
26
|
+
exit(1)
|
27
|
+
end
|
28
|
+
opts.on('-d', '--domain string', 'The domain name to check') do |domain|
|
29
|
+
options[:domain] = domain
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
optparse.parse!
|
35
|
+
options[:message] = ARGF.read unless STDIN.tty? # override message parameter if data is piped in
|
36
|
+
missing = mandatory.select { |param| options[param].nil? }
|
37
|
+
raise OptionParser::MissingArgument.new(missing.join(', ')) unless missing.empty?
|
38
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
|
39
|
+
puts e.to_s
|
40
|
+
puts optparse
|
41
|
+
exit
|
42
|
+
end
|
43
|
+
|
44
|
+
results = SSLExpiry::SSLExpiry.check_certificates(options[:domain])
|
45
|
+
SSLExpiry::SSLExpiry.display_results(results)
|
46
|
+
end
|
47
|
+
|
48
|
+
# -------------------------------------------------------------------------------- #
|
49
|
+
# Main() #
|
50
|
+
# -------------------------------------------------------------------------------- #
|
51
|
+
# The main function where all of the heavy lifting and script config is done. #
|
52
|
+
# -------------------------------------------------------------------------------- #
|
53
|
+
|
54
|
+
def main
|
55
|
+
process_arguments
|
56
|
+
end
|
57
|
+
|
58
|
+
main
|
59
|
+
|
60
|
+
# -------------------------------------------------------------------------------- #
|
61
|
+
# End of Script #
|
62
|
+
# -------------------------------------------------------------------------------- #
|
63
|
+
# This is the end - nothing more to see here. #
|
64
|
+
# -------------------------------------------------------------------------------- #
|
data/lib/ssl_expiry.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ssl_expiry/errors'
|
4
|
+
require 'ssl_expiry/version'
|
5
|
+
|
6
|
+
require 'net/http'
|
7
|
+
require 'openssl'
|
8
|
+
|
9
|
+
#
|
10
|
+
# Docs to follow
|
11
|
+
#
|
12
|
+
module SSLExpiry
|
13
|
+
#
|
14
|
+
# Docs to follow
|
15
|
+
#
|
16
|
+
class SSLExpiry
|
17
|
+
def self.get_cert(domain_name, supplied_port = nil, verify = false)
|
18
|
+
begin
|
19
|
+
cert = nil
|
20
|
+
|
21
|
+
uri = URI::HTTPS.build(host: domain_name)
|
22
|
+
|
23
|
+
port = if supplied_port.nil?
|
24
|
+
uri.port
|
25
|
+
else
|
26
|
+
supplied_port
|
27
|
+
end
|
28
|
+
|
29
|
+
http = Net::HTTP.new(uri.host, port)
|
30
|
+
|
31
|
+
http.use_ssl = true
|
32
|
+
http.verify_mode = verify ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
|
33
|
+
http.open_timeout = 5
|
34
|
+
http.read_timeout = 5
|
35
|
+
http.ssl_timeout = 5
|
36
|
+
|
37
|
+
http.start do |h|
|
38
|
+
cert = h.peer_cert
|
39
|
+
end
|
40
|
+
|
41
|
+
cert
|
42
|
+
rescue SocketError, SystemCallError => e
|
43
|
+
raise SSLError.new "Bad URL? #{e.message}"
|
44
|
+
rescue Net::OpenTimeout
|
45
|
+
raise SSLError.new 'Timed out. Is the site up?'
|
46
|
+
rescue OpenSSL::SSL::SSLError => e
|
47
|
+
raise SSLError.new "We're trying to validate your certificate using TLSv1 It looks like your server doesn't accept it: [#{$ERROR_INFO.message}]" if e.message =~ /sslv3.+tlsv1 alert/i
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.check_certificates(domains, date_format = '%d %b %Y')
|
52
|
+
results = {}
|
53
|
+
|
54
|
+
domains = domains.split(',') unless domains.is_a?(Array)
|
55
|
+
|
56
|
+
domains.each do |domain|
|
57
|
+
begin
|
58
|
+
parts = domain.split(':')
|
59
|
+
|
60
|
+
cert = if parts.length == 2
|
61
|
+
get_cert(parts[0], parts[1])
|
62
|
+
else
|
63
|
+
get_cert(parts[0])
|
64
|
+
end
|
65
|
+
rescue SSLError => e
|
66
|
+
results[domain] = { 'status' => 400, 'error' => e.message }
|
67
|
+
next
|
68
|
+
end
|
69
|
+
|
70
|
+
begin
|
71
|
+
common_name = cert.subject.to_a.select { |name, _data, _type| name == 'CN' }.first[1]
|
72
|
+
issuer = cert.issuer.to_a.select { |name, _data, _type| name == 'O' }.first[1]
|
73
|
+
expires_on = cert.not_after
|
74
|
+
num_days = ((expires_on - Time.now) / 864_00).to_i
|
75
|
+
|
76
|
+
results[domain] = { 'status' => 200, 'expires_on' => expires_on.strftime(date_format), 'expires_in' => num_days, 'common_name' => common_name, 'issuer' => issuer }
|
77
|
+
rescue StandardError
|
78
|
+
results[domain] = { 'status' => 400, 'error' => 'Parsing error' }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
results.sort
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.display_results(results, width = 120)
|
85
|
+
delim = '-' * width
|
86
|
+
|
87
|
+
puts(delim)
|
88
|
+
printf(" %-30<header1>s | %<header2>s\n", header1: 'Domain', header2: 'Status')
|
89
|
+
puts(delim)
|
90
|
+
results.each do |domain, details|
|
91
|
+
status = if details['status'] == 400
|
92
|
+
details['error']
|
93
|
+
else
|
94
|
+
format('expires on %<expires_in>s (in %<expires_on>s days) [CN=%<common_name>s]', expires_in: details['expires_on'], expires_on: details['expires_in'], common_name: details['common_name'])
|
95
|
+
end
|
96
|
+
printf(" %-30<domain>s | %<status>s\n", domain: domain, status: status)
|
97
|
+
end
|
98
|
+
puts(delim)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'ssl_expiry'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
# Enable flags like --only-failures and --next-failure
|
8
|
+
config.example_status_persistence_file_path = '.rspec_status'
|
9
|
+
|
10
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
11
|
+
config.disable_monkey_patching!
|
12
|
+
|
13
|
+
config.expect_with :rspec do |c|
|
14
|
+
c.syntax = :expect
|
15
|
+
end
|
16
|
+
|
17
|
+
original_stderr = $stderr
|
18
|
+
original_stdout = $stdout
|
19
|
+
config.before(:all) do
|
20
|
+
# Redirect stderr and stdout
|
21
|
+
$stderr = File.open(File::NULL, 'w')
|
22
|
+
$stdout = File.open(File::NULL, 'w')
|
23
|
+
end
|
24
|
+
config.after(:all) do
|
25
|
+
$stderr = original_stderr
|
26
|
+
$stdout = original_stdout
|
27
|
+
end
|
28
|
+
end
|
data/ssl_expiry.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "ssl_expiry/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ssl_expiry_ng"
|
8
|
+
spec.version = SSLExpiry::VERSION
|
9
|
+
spec.authors = ['Tim Gurney aka Wolf']
|
10
|
+
spec.email = ['wolf@tgwolf.com']
|
11
|
+
|
12
|
+
spec.summary = %q{A simple gem checking for ssl expiry.}
|
13
|
+
spec.description = %q{A simple gem checking for ssl expiry.}
|
14
|
+
spec.homepage = 'https://github.com/AntiPhotonltd/ssl_expiry'
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", ">= 1.17", "< 3.0"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
|
26
|
+
spec.add_development_dependency 'openssl', '~> 3'
|
27
|
+
spec.add_development_dependency 'net-http-persistent', '~> 4'
|
28
|
+
|
29
|
+
spec.add_runtime_dependency 'openssl', '~> 3'
|
30
|
+
spec.add_runtime_dependency 'net-http-persistent', '~> 4'
|
31
|
+
end
|
data/testing/check-ssl
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
|
6
|
+
require 'optparse'
|
7
|
+
require 'ssl_expiry'
|
8
|
+
|
9
|
+
# -------------------------------------------------------------------------------- #
|
10
|
+
# Process Arguments #
|
11
|
+
# -------------------------------------------------------------------------------- #
|
12
|
+
# This function will process the input from the command line and work out what it #
|
13
|
+
# is that the user wants to see. #
|
14
|
+
# #
|
15
|
+
# This is the main processing function where all the processing logic is handled. #
|
16
|
+
# -------------------------------------------------------------------------------- #
|
17
|
+
|
18
|
+
def process_arguments
|
19
|
+
options = {}
|
20
|
+
# Enforce the presence of
|
21
|
+
mandatory = %I[domain]
|
22
|
+
|
23
|
+
optparse = OptionParser.new do |opts|
|
24
|
+
opts.banner = "Usage: #{$PROGRAM_NAME}"
|
25
|
+
|
26
|
+
opts.on('-h', '--help', 'Display this screen') do
|
27
|
+
puts opts
|
28
|
+
exit(1)
|
29
|
+
end
|
30
|
+
opts.on('-d', '--domain string', 'The domain name to check') do |domain|
|
31
|
+
options[:domain] = domain
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
optparse.parse!
|
37
|
+
options[:message] = ARGF.read unless STDIN.tty? # override message parameter if data is piped in
|
38
|
+
missing = mandatory.select { |param| options[param].nil? }
|
39
|
+
raise OptionParser::MissingArgument.new(missing.join(', ')) unless missing.empty?
|
40
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
|
41
|
+
puts e.to_s
|
42
|
+
puts optparse
|
43
|
+
exit
|
44
|
+
end
|
45
|
+
|
46
|
+
results = SSLExpiry::SSLExpiry.check_certificates(options[:domain])
|
47
|
+
SSLExpiry::SSLExpiry.display_results(results)
|
48
|
+
end
|
49
|
+
|
50
|
+
# -------------------------------------------------------------------------------- #
|
51
|
+
# Main() #
|
52
|
+
# -------------------------------------------------------------------------------- #
|
53
|
+
# The main function where all of the heavy lifting and script config is done. #
|
54
|
+
# -------------------------------------------------------------------------------- #
|
55
|
+
|
56
|
+
def main
|
57
|
+
process_arguments
|
58
|
+
end
|
59
|
+
|
60
|
+
main
|
61
|
+
|
62
|
+
# -------------------------------------------------------------------------------- #
|
63
|
+
# End of Script #
|
64
|
+
# -------------------------------------------------------------------------------- #
|
65
|
+
# This is the end - nothing more to see here. #
|
66
|
+
# -------------------------------------------------------------------------------- #
|
metadata
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ssl_expiry_ng
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.3.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Gurney aka Wolf
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-12-23 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.17'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3.0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.17'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '10.0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '10.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: openssl
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: net-http-persistent
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '4'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '4'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: openssl
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '3'
|
96
|
+
type: :runtime
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '3'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: net-http-persistent
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '4'
|
110
|
+
type: :runtime
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '4'
|
117
|
+
description: A simple gem checking for ssl expiry.
|
118
|
+
email:
|
119
|
+
- wolf@tgwolf.com
|
120
|
+
executables:
|
121
|
+
- check-ssl
|
122
|
+
extensions: []
|
123
|
+
extra_rdoc_files: []
|
124
|
+
files:
|
125
|
+
- ".gitignore"
|
126
|
+
- ".rspec"
|
127
|
+
- ".rubocop.yml"
|
128
|
+
- ".travis.yml"
|
129
|
+
- CHANGELOG.md
|
130
|
+
- CODEOWNERS
|
131
|
+
- CODE_OF_CONDUCT.md
|
132
|
+
- Gemfile
|
133
|
+
- LICENSE.txt
|
134
|
+
- README.md
|
135
|
+
- Rakefile
|
136
|
+
- bin/console
|
137
|
+
- bin/setup
|
138
|
+
- exe/check-ssl
|
139
|
+
- lib/ssl_expiry.rb
|
140
|
+
- lib/ssl_expiry/errors.rb
|
141
|
+
- lib/ssl_expiry/version.rb
|
142
|
+
- spec/spec_helper.rb
|
143
|
+
- spec/ssl_expiry_spec.rb
|
144
|
+
- ssl_expiry.gemspec
|
145
|
+
- testing/check-ssl
|
146
|
+
homepage: https://github.com/AntiPhotonltd/ssl_expiry
|
147
|
+
licenses:
|
148
|
+
- MIT
|
149
|
+
metadata: {}
|
150
|
+
post_install_message:
|
151
|
+
rdoc_options: []
|
152
|
+
require_paths:
|
153
|
+
- lib
|
154
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
requirements: []
|
165
|
+
rubygems_version: 3.4.19
|
166
|
+
signing_key:
|
167
|
+
specification_version: 4
|
168
|
+
summary: A simple gem checking for ssl expiry.
|
169
|
+
test_files: []
|