chelsea 0.0.1

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: cd5aa38de016f2e4f096f805b027470b5fbfb363f3dc37674fdb6f206b62a0d5
4
+ data.tar.gz: dc118d424da373efa36d8c869fc26b260de7ccf04dab3db0bbccd0a777e3c846
5
+ SHA512:
6
+ metadata.gz: 9feba5821f03db18d89da3b152a0d5165ff0fda71010d774d1d1966deac93419b2ff81b08eb2a4bac0b31215212a9fcf7f76025385f825916718ebad6212e6f0
7
+ data.tar.gz: 1c6622516b8eb4b537fcf8d3732925f89f2ad2934674d7b8c89ec7a380edc42286503bbf827b6702a372ce818c274df6124e0ffc4a9bdc3e31bde1938bc83664
@@ -0,0 +1,77 @@
1
+ version: 2.1
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: circleci/ruby:2.6.5-stretch
6
+ environment:
7
+ BUNDLE_PATH: vendor/bundle
8
+ steps:
9
+ - checkout
10
+ - run:
11
+ name: Install bundler
12
+ command: gem install bundler
13
+ - run:
14
+ name: Which bundler?
15
+ command: bundle -v
16
+ - restore_cache:
17
+ keys:
18
+ - chelsea-bundle-v2-{{ checksum "Gemfile.lock" }}
19
+ - chelsea-bundle-v2-
20
+ - run:
21
+ name: Bundle Install
22
+ command: bundle check --path vendor/bundle || bundle install
23
+ - save_cache:
24
+ key: chelsea-bundle-v2-{{ checksum "Gemfile.lock" }}
25
+ paths:
26
+ - vendor/bundle
27
+ - run:
28
+ name: Run rspec in parallel
29
+ command: |
30
+ bundle exec rspec --format progress \
31
+ --format RspecJunitFormatter \
32
+ --out test_results/rspec.xml
33
+ - store_test_results:
34
+ path: test_results
35
+ release:
36
+ docker:
37
+ - image: circleci/ruby:2.6.5-stretch
38
+ steps:
39
+ - add_ssh_keys:
40
+ fingerprints:
41
+ - "89:00:b0:ce:95:1b:d9:ef:46:c3:81:dc:75:56:b3:ca"
42
+ - checkout
43
+ - run:
44
+ name: Install gem-release
45
+ command: gem install gem-release
46
+ - run:
47
+ name: Setup Rubygems
48
+ command: bash .circleci/setup-rubygems.sh
49
+ - run:
50
+ name: Set git name
51
+ command: git config --global user.name "$GITHUB_USERNAME"
52
+ - run:
53
+ name: Set git email
54
+ command: git config --global user.email "$GITHUB_EMAIL"
55
+ - run:
56
+ name: Set git upstream
57
+ command: git branch -u origin/master
58
+ - run:
59
+ name: Bump version
60
+ command: gem bump -v patch --tag --skip-ci --push
61
+ - run:
62
+ name: Release to Rubygems
63
+ command: gem release
64
+
65
+ workflows:
66
+ version: 2.1
67
+ build_and_release:
68
+ jobs:
69
+ - build
70
+ - release:
71
+ requires:
72
+ - build
73
+ context: chelsea
74
+ filters:
75
+ branches:
76
+ only:
77
+ - master
@@ -0,0 +1,3 @@
1
+ mkdir ~/.gem
2
+ echo -e "---\r\n:rubygems_api_key: $RUBY_GEMS_API_TOKEN" > ~/.gem/credentials
3
+ chmod 0600 /home/circleci/.gem/credentials
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require ./spec/chelsea_spec.rb
@@ -0,0 +1,15 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Debug chelsea",
9
+ "type": "Ruby",
10
+ "request": "launch",
11
+ "program": "${workspaceRoot}/bin/chelsea",
12
+ "args": ["gems", "${workspaceRoot}\\chelsea.gemspec"],
13
+ }
14
+ ]
15
+ }
@@ -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 allister.beharry@gmail.com. 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
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in chelsea.gemspec
6
+ gemspec
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ chelsea (0.0.1)
5
+ bundler (~> 2.0.0)
6
+ pastel (~> 0.7.2)
7
+ rest-client (~> 2.0.2)
8
+ slop (~> 4.8.0)
9
+ tty-font (~> 0.5.0)
10
+ tty-spinner (~> 0.9.3)
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ diff-lcs (1.3)
16
+ domain_name (0.5.20190701)
17
+ unf (>= 0.0.5, < 1.0.0)
18
+ equatable (0.6.1)
19
+ http-cookie (1.0.3)
20
+ domain_name (~> 0.5)
21
+ mime-types (3.3.1)
22
+ mime-types-data (~> 3.2015)
23
+ mime-types-data (3.2019.1009)
24
+ netrc (0.11.0)
25
+ pastel (0.7.3)
26
+ equatable (~> 0.6)
27
+ tty-color (~> 0.5)
28
+ rake (10.5.0)
29
+ rest-client (2.0.2)
30
+ http-cookie (>= 1.0.2, < 2.0)
31
+ mime-types (>= 1.16, < 4.0)
32
+ netrc (~> 0.8)
33
+ rspec (3.9.0)
34
+ rspec-core (~> 3.9.0)
35
+ rspec-expectations (~> 3.9.0)
36
+ rspec-mocks (~> 3.9.0)
37
+ rspec-core (3.9.1)
38
+ rspec-support (~> 3.9.1)
39
+ rspec-expectations (3.9.1)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.9.0)
42
+ rspec-mocks (3.9.1)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.9.0)
45
+ rspec-support (3.9.2)
46
+ slop (4.8.0)
47
+ tty-color (0.5.1)
48
+ tty-cursor (0.7.1)
49
+ tty-font (0.5.0)
50
+ tty-spinner (0.9.3)
51
+ tty-cursor (~> 0.7)
52
+ unf (0.1.4)
53
+ unf_ext
54
+ unf_ext (0.0.7.6)
55
+
56
+ PLATFORMS
57
+ ruby
58
+
59
+ DEPENDENCIES
60
+ chelsea!
61
+ rake (~> 10.0)
62
+ rspec (~> 3.0)
63
+
64
+ BUNDLED WITH
65
+ 2.0.2
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2020 Sonatype
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Allister Beharry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,62 @@
1
+ # Chelsea
2
+
3
+ Chelsea is a Ruby gem designed to allow you to scan your Ruby Gem powered projects and report on any vulnerabilities in your third party dependencies. It is powered by Sonatype's OSS Index.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'chelsea'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install chelsea
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ $ chelsea
25
+ _____ _ _
26
+ / __ \| | | |
27
+ | / \/| |__ ___ | | ___ ___ __ _
28
+ | | | '_ \ / _ \| |/ __| / _ \ / _` |
29
+ | \__/\| | | || __/| |\__ \| __/| (_| |
30
+ \____/|_| |_| \___||_||___/ \___| \__,_|
31
+
32
+
33
+ Version: 0.0.1
34
+
35
+ usage: chelsea [options] ...
36
+
37
+ Options:
38
+ -f, --file do the dang thing
39
+ --version print the version
40
+ ```
41
+
42
+ Most basic usage is:
43
+
44
+ `chelsea --file name.gemspec`
45
+
46
+ ## Development
47
+
48
+ 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.
49
+
50
+ 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).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sonatype-nexus-community/chelsea. 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.
55
+
56
+ ## Code of Conduct
57
+
58
+ Everyone interacting in the Chelsea project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/sonatype-nexus-community/chelsea/blob/master/CODE_OF_CONDUCT.md).
59
+
60
+ ## Copyright
61
+
62
+ Copyright (c) 2019 Allister Beharry. See [MIT License](LICENSE.txt) for further details.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ require "./lib/chelsea"
4
+
5
+ Chelsea::CLI.new.main
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "chelsea"
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
data/chelsea ADDED
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ ruby ./bin/chelsea "$@"
@@ -0,0 +1,49 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "chelsea/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "chelsea"
8
+ spec.license = "MIT"
9
+ spec.version = Chelsea::VERSION
10
+ spec.authors = ["Allister Beharry"]
11
+ spec.email = ["allister.beharry@gmail.com"]
12
+
13
+ spec.summary = "Audit Ruby package dependencies for security vulnerabilities."
14
+ spec.homepage = "https://github.com/sonatype-nexus-community/chelsea"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/sonatype-nexus-community/chelsea"
18
+ spec.metadata["changelog_uri"] = "https://github.com/sonatype-nexus-community/chelsea/CHANGELOG"
19
+
20
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
21
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
22
+ # if spec.respond_to?(:metadata)
23
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
24
+ # else
25
+ # raise "RubyGems 2.0 or newer is required to protect against " \
26
+ # "public gem pushes."
27
+ # end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = "bin"
35
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+
39
+ spec.add_dependency "tty-font", "~> 0.5.0"
40
+ spec.add_dependency "tty-spinner", "~> 0.9.3"
41
+ spec.add_dependency "slop", "~> 4.8.0"
42
+ spec.add_dependency "pastel", "~> 0.7.2"
43
+ spec.add_dependency "rest-client", "~> 2.0.2"
44
+ spec.add_dependency "bundler", ">= 1.2.0", "< 3"
45
+
46
+ spec.add_development_dependency "rake", "~> 10.0"
47
+ spec.add_development_dependency "rspec", "~> 3.0"
48
+ spec.add_development_dependency "rspec_junit_formatter", "~> 0.4.1"
49
+ end
@@ -0,0 +1 @@
1
+ require_relative "./chelsea/cli"
@@ -0,0 +1,91 @@
1
+ require 'slop'
2
+ require 'pastel'
3
+ require_relative 'version'
4
+
5
+ module Chelsea
6
+ class CLI
7
+ def main(command_line_options=ARGV)
8
+ puts show_logo()
9
+ parser = Slop::Parser.new cli_flags()
10
+ arguments = parse_arguments(command_line_options, parser)
11
+ validate_arguments arguments
12
+
13
+ if arguments.fetch(:file)
14
+ gems(arguments[:file])
15
+ elsif set?(arguments, :help)
16
+ puts cli_flags
17
+ end
18
+ end
19
+
20
+ def set?(arguments, flag)
21
+ !arguments.fetch(flag).nil?
22
+ end
23
+
24
+ def cli_flags()
25
+ opts = Slop::Options.new
26
+ opts.banner = "usage: chelsea [options] ..."
27
+ opts.separator ""
28
+ opts.separator 'Options:'
29
+ opts.bool '-h', '--help', 'show usage'
30
+ opts.string '-f', '--file', 'do the dang thing'
31
+ opts.on '--version', 'print the version' do
32
+ puts version()
33
+ exit
34
+ end
35
+
36
+ opts
37
+ end
38
+
39
+ def validate_arguments(arguments)
40
+ if number_of_required_flags_set(arguments) < 1 && !arguments.fetch(:file)
41
+ flags_error
42
+ end
43
+ end
44
+
45
+ def number_of_required_flags_set(arguments)
46
+ minimum_flags = flags
47
+ valid_flags = minimum_flags.collect {|a| arguments.fetch(a) }.compact
48
+ valid_flags.count
49
+ end
50
+
51
+ def flags
52
+ [:file, :help]
53
+ end
54
+
55
+ def flags_error
56
+ switches = flags.collect {|f| "--#{f}"}
57
+ puts cli_flags
58
+ puts
59
+ abort "please set one of #{switches}"
60
+ end
61
+
62
+ def gems(file)
63
+ require_relative 'gems'
64
+ Chelsea::Gems.new(file, nil).execute
65
+ end
66
+
67
+ def parse_arguments(command_line_options, parser)
68
+ begin
69
+ result = parser.parse command_line_options
70
+ result.to_hash
71
+
72
+ rescue Slop::UnknownOption
73
+ # print help
74
+ puts cli_flags()
75
+ exit
76
+ end
77
+ end
78
+
79
+ def version()
80
+ Chelsea::VERSION
81
+ end
82
+
83
+ def show_logo()
84
+ @pastel = Pastel.new
85
+ require 'tty-font'
86
+ font = TTY::Font.new(:doom)
87
+ puts @pastel.green(font.write("Chelsea"))
88
+ puts @pastel.green("Version: " + version())
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,172 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pastel'
4
+ require 'tty-spinner'
5
+ require 'bundler'
6
+ require 'bundler/lockfile_parser'
7
+ require_relative 'version'
8
+
9
+ module Chelsea
10
+ class Gems
11
+ def initialize(file, options)
12
+ @file = file
13
+ @options = options
14
+ @pastel = Pastel.new
15
+ @dependencies = Hash.new()
16
+ @dependencies_versions = Hash.new()
17
+ @coordinates = Hash.new()
18
+ @coordinates["coordinates"] = Array.new()
19
+ @server_response = Array.new()
20
+
21
+ if not gemfile_lock_file_exists()
22
+ return
23
+ end
24
+
25
+ path = Pathname.new(@file)
26
+ @lockfile = Bundler::LockfileParser.new(
27
+ File.read(path)
28
+ )
29
+ end
30
+
31
+ def execute(input: $stdin, output: $stdout)
32
+ n = get_dependencies()
33
+ if n == 0
34
+ print_err "No dependencies retrieved. Exiting."
35
+ return
36
+ end
37
+ get_dependencies_versions()
38
+ get_coordinates()
39
+ n = get_vulns()
40
+ if n == 0
41
+ print_err "No vulnerability data retrieved from server. Exiting."
42
+ return
43
+ end
44
+ print_results()
45
+ end
46
+
47
+ def gemfile_lock_file_exists()
48
+ if not ::File.file? @file
49
+ return false
50
+ else
51
+ path = Pathname.new(@file)
52
+ return true
53
+ end
54
+ end
55
+
56
+ def get_dependencies()
57
+ format = "[#{@pastel.green(':spinner')}] " + @pastel.white("Parsing dependencies")
58
+ spinner = TTY::Spinner.new(format, success_mark: @pastel.green('+'), hide_cursor: true)
59
+ spinner.auto_spin()
60
+
61
+ @lockfile.specs.each do |gem|
62
+ @dependencies[gem.name] = [gem.name, gem.version]
63
+ rescue StandardError => e
64
+ spinner.stop("...failed.")
65
+ print_err "Parsing dependency line #{gem} failed."
66
+ end
67
+
68
+ c = @dependencies.count()
69
+ spinner.success("...done. Parsed #{c} dependencies.")
70
+ c
71
+ end
72
+
73
+ def get_dependencies_versions()
74
+ format = "[#{@pastel.green(':spinner')}] " + @pastel.white("Parsing versions")
75
+ spinner = TTY::Spinner.new(format, success_mark: @pastel.green('+'), hide_cursor: true)
76
+ spinner.auto_spin()
77
+ @dependencies.each do |p, r|
78
+ o = r[0]
79
+ v = r[1].to_s
80
+ if v.split('.').length == 1 then
81
+ v = v + ".0.0"
82
+ elsif v.split('.').length == 2 then
83
+ v = v + ".0"
84
+ end
85
+ @dependencies_versions[p] = v
86
+ end
87
+ c = @dependencies_versions.count()
88
+ spinner.success("...done.")
89
+ c
90
+ end
91
+
92
+ def get_coordinates()
93
+ @dependencies_versions.each do |p, v|
94
+ @coordinates["coordinates"] << "pkg:gem/#{p}@#{v}";
95
+ end
96
+ end
97
+
98
+ def get_user_agent()
99
+ user_agent = "chelsea/#{Chelsea::VERSION}"
100
+
101
+ user_agent
102
+ end
103
+
104
+ def get_vulns()
105
+ require 'json'
106
+ require 'rest-client'
107
+ format = "[#{@pastel.green(':spinner')}] " + @pastel.white("Making request to OSS Index server")
108
+ spinner = TTY::Spinner.new(format, success_mark: @pastel.green('+'), hide_cursor: true)
109
+ spinner.auto_spin()
110
+ r = RestClient.post "https://ossindex.sonatype.org/api/v3/component-report", @coordinates.to_json,
111
+ {content_type: :json, accept: :json, 'User-Agent': get_user_agent()}
112
+ if r.code == 200
113
+ @server_response = JSON.parse(r.body)
114
+ spinner.success("...done.")
115
+ @server_response.count()
116
+ else
117
+ spinner.stop("...request failed.")
118
+ print_err "Error getting data from OSS Index server. Server returned non-success code #{r.code}."
119
+ 0
120
+ end
121
+ rescue SocketError => e
122
+ spinner.stop("...request failed.")
123
+ print_err "Socket error getting data from OSS Index server."
124
+ 0
125
+ rescue RestClient::RequestFailed => e
126
+ spinner.stop("Request failed.")
127
+ print_err "Error getting data from OSS Index server:#{e.response}."
128
+ 0
129
+ rescue RestClient::ResourceNotfound => e
130
+ spinner.stop("...request failed.")
131
+ print_err "Error getting data from OSS Index server. Resource not found."
132
+ 0
133
+ rescue Errno::ECONNREFUSED => e
134
+ spinner.stop("...request failed.")
135
+ print_err "Error getting data from OSS Index server. Connection refused."
136
+ 0
137
+ rescue StandardError => e
138
+ spinner.stop("...request failed.")
139
+ print_err "UNKNOWN Error getting data from OSS Index server."
140
+ 0
141
+ end
142
+
143
+ def print_results()
144
+ puts ""
145
+ puts "Audit Results"
146
+ puts "============="
147
+ i = 0
148
+ count = @server_response.count()
149
+ @server_response.each do |r|
150
+ i += 1
151
+ package = r["coordinates"]
152
+ vulnerable = r["vulnerabilities"].length() > 0
153
+ if vulnerable
154
+ puts @pastel.red("[#{i}/#{count}] - #{package} ") + @pastel.red.bold("Vulnerable.")
155
+ r["vulnerabilities"].each do |k, v|
156
+ puts @pastel.red.bold(" #{k}:#{v}")
157
+ end
158
+ else
159
+ puts(@pastel.white("[#{i}/#{count}] - #{package} ") + @pastel.green.bold("No vulnerabilities found!"))
160
+ end
161
+ end
162
+ end
163
+
164
+ def print_err(s)
165
+ puts @pastel.red.bold(s)
166
+ end
167
+
168
+ def print_success(s)
169
+ puts @pastel.green.bold(s)
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,3 @@
1
+ module Chelsea
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,202 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chelsea
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Allister Beharry
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tty-font
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: tty-spinner
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.3
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.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: slop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 4.8.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 4.8.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: pastel
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.7.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.7.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: rest-client
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.0.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.0.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.2.0
90
+ - - "<"
91
+ - !ruby/object:Gem::Version
92
+ version: '3'
93
+ type: :runtime
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 1.2.0
100
+ - - "<"
101
+ - !ruby/object:Gem::Version
102
+ version: '3'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rake
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '10.0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '10.0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rspec
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '3.0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '3.0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: rspec_junit_formatter
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: 0.4.1
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: 0.4.1
145
+ description:
146
+ email:
147
+ - allister.beharry@gmail.com
148
+ executables:
149
+ - chelsea
150
+ - console
151
+ - setup
152
+ extensions: []
153
+ extra_rdoc_files: []
154
+ files:
155
+ - ".circleci/config.yml"
156
+ - ".circleci/setup-rubygems.sh"
157
+ - ".gitignore"
158
+ - ".rspec"
159
+ - ".vscode/launch.json"
160
+ - CODE_OF_CONDUCT.md
161
+ - Gemfile
162
+ - Gemfile.lock
163
+ - LICENSE
164
+ - LICENSE.txt
165
+ - README.md
166
+ - Rakefile
167
+ - bin/chelsea
168
+ - bin/console
169
+ - bin/setup
170
+ - chelsea
171
+ - chelsea.gemspec
172
+ - lib/chelsea.rb
173
+ - lib/chelsea/cli.rb
174
+ - lib/chelsea/gems.rb
175
+ - lib/chelsea/version.rb
176
+ homepage: https://github.com/sonatype-nexus-community/chelsea
177
+ licenses:
178
+ - MIT
179
+ metadata:
180
+ homepage_uri: https://github.com/sonatype-nexus-community/chelsea
181
+ source_code_uri: https://github.com/sonatype-nexus-community/chelsea
182
+ changelog_uri: https://github.com/sonatype-nexus-community/chelsea/CHANGELOG
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ requirements: []
198
+ rubygems_version: 3.0.3
199
+ signing_key:
200
+ specification_version: 4
201
+ summary: Audit Ruby package dependencies for security vulnerabilities.
202
+ test_files: []