gem-guardian 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7e343f954f0d514206e5bcc10d935a094d916ee1456cbb4774a113c909e879dc
4
+ data.tar.gz: 2230036e48e13af43b32090d1cbe4b933785b5407fda0f8376bebd41763615fe
5
+ SHA512:
6
+ metadata.gz: 36bf27a64fb281d8e50a81a9efdadc5e83ee694e81e79cb46c36799f443568f917934001f10568a1f417740688cabd204aa26154fd791145416b7d25c3d837dc
7
+ data.tar.gz: 9e5331025935a3a5d007b2f684e59110cf0bbe79deaacb1e93b976aa06075ea9e52f7199c3ff92b2c90c5317b9da7c5eb03e796724b2966a1f23c37c738426e3
@@ -0,0 +1,32 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ pull_request:
9
+
10
+ permissions:
11
+ contents: read
12
+
13
+ jobs:
14
+ build:
15
+ runs-on: ubuntu-latest
16
+ name: Ruby ${{ matrix.ruby }}
17
+ strategy:
18
+ matrix:
19
+ ruby:
20
+ - '3.2.11'
21
+
22
+ steps:
23
+ - uses: actions/checkout@v6
24
+ with:
25
+ persist-credentials: false
26
+ - name: Set up Ruby
27
+ uses: ruby/setup-ruby@v1
28
+ with:
29
+ ruby-version: ${{ matrix.ruby }}
30
+ bundler-cache: true
31
+ - name: Run the default task
32
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
10
+ *.gem
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.2
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ - Initial MVP codebase.
6
+ - Verify explicit gems or all gems in `Gemfile.lock`.
7
+ - Fetch expected SHA256 checksums from RubyGems.org versions API.
8
+ - Fetch `.gem` artifacts from RubyGems.org and verify SHA256 locally.
@@ -0,0 +1,14 @@
1
+ # Code of Conduct
2
+
3
+ "cdc-parallel" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
4
+
5
+ * Participants will be tolerant of opposing views.
6
+ * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
7
+ * When interpreting the words and actions of others, participants should always assume good intentions.
8
+ * Behaviour which can be reasonably considered harassment will not be tolerated.
9
+
10
+ If you have concerns about behaviour within this project, please open an issue at:
11
+
12
+ https://github.com/kanutocd/gem-guardian/issues/new
13
+
14
+ Please note that GitHub issues are public. Do not include sensitive personal information in your report.
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ gem "pry", "~> 0.16.0"
8
+ gem "rake", "~> 13.4"
9
+ gem "minitest", "~> 6.0"
10
+ gem "rubocop", "~> 1.87"
11
+ gem "simplecov", "~> 0.22.0"
12
+ gem "steep", "~> 2.0"
13
+ gem "yard", "~> 0.9.44"
14
+ gem "rubocop-minitest", "~> 0.39.1"
15
+ gem "rubocop-rake", "~> 0.7.1"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Ken C. Demanawa
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,97 @@
1
+ # gem-guardian
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/gem-guardian.svg)](https://badge.fury.io/rb/gem-guardian)
4
+ [![CI](https://github.com/kanutocd/gem-guardian/workflows/CI/badge.svg)](https://github.com/kanutocd/gem-guardian/actions)
5
+ [![Ruby Version](https://img.shields.io/badge/ruby-%3E%3D%203.2-ruby.svg)](https://www.ruby-lang.org/en/)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+
9
+ Consumer-side integrity verification for Ruby gems.
10
+
11
+ `gem-guardian` verifies downloaded `.gem` artifacts against the SHA256 checksum reported by RubyGems.org. It is intentionally small: no Bundler monkeypatching, no install hooks, and no custom publishing flow required.
12
+
13
+ ## Why
14
+
15
+ RubyGems.org displays SHA256 checksums for published gem artifacts, and modern Bundler can store checksums in `Gemfile.lock`. But there is still room for a simple consumer-side verification workflow that can be run explicitly in CI or locally.
16
+
17
+ This MVP verifies:
18
+
19
+ ```text
20
+ Gemfile.lock / explicit gem version
21
+
22
+ RubyGems.org expected SHA256
23
+
24
+ Downloaded .gem artifact
25
+
26
+ Local SHA256 comparison
27
+ ```
28
+
29
+ This proves that the local artifact matches what RubyGems.org serves. It does **not** yet prove source provenance such as signed tag → CI build → published gem.
30
+
31
+ ## Installation
32
+
33
+ From a local checkout:
34
+
35
+ ```bash
36
+ gem build gem-guardian.gemspec
37
+ gem install ./gem-guardian-0.1.0.gem
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ Verify all gems in `Gemfile.lock`:
43
+
44
+ ```bash
45
+ gem-guardian verify
46
+ ```
47
+
48
+ Verify a specific gem version:
49
+
50
+ ```bash
51
+ gem-guardian verify cdc-sidekiq:0.1.1
52
+ gem-guardian verify ratomic:0.4.1
53
+ ```
54
+
55
+ Verify a platform gem:
56
+
57
+ ```bash
58
+ gem-guardian verify nokogiri:1.18.9:x86_64-linux
59
+ ```
60
+
61
+ Use a non-default lockfile:
62
+
63
+ ```bash
64
+ gem-guardian verify --lockfile path/to/Gemfile.lock
65
+ ```
66
+
67
+ ## Exit codes
68
+
69
+ - `0` — all verified artifacts matched
70
+ - `1` — mismatch, missing checksum, fetch error, or lockfile error
71
+ - `2` — CLI usage error
72
+
73
+ ## MVP constraints
74
+
75
+ - Uses RubyGems.org as the checksum source of truth.
76
+ - Downloads artifacts from RubyGems.org `/downloads/<gem-file>.gem`.
77
+ - Caches downloaded artifacts under the system temp directory.
78
+ - Does not integrate into Bundler install hooks.
79
+ - Does not yet verify Sigstore, SLSA, GitHub Actions provenance, or signed git tags.
80
+
81
+ ## Roadmap
82
+
83
+ - `gem-guardian lock` to emit or update checksum metadata.
84
+ - Support Bundler 2.6 `CHECKSUMS` sections as an offline expected-checksum source.
85
+ - Provenance verification for gems published through Trusted Publishing.
86
+ - GitHub Release checksum/signature discovery.
87
+ - Machine-readable JSON output for CI.
88
+
89
+
90
+ ## License
91
+
92
+ [MIT](./LICENSE.txt)
93
+
94
+
95
+ ## Code of Conduct
96
+
97
+ Everyone interacting in the Gem::Guardian project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/kanutocd/gem-guardian/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rake/testtask"
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << "test"
7
+ t.pattern = "test/**/*_test.rb"
8
+ end
9
+
10
+ task default: :test
11
+
12
+ namespace :rbs do
13
+ desc "Remove generated RBS prototype files"
14
+ task :clobber do
15
+ sh "rm -rf tmp/sig"
16
+ end
17
+
18
+ desc "Generate disposable RBS prototypes into tmp/sig"
19
+ task :prototype do
20
+ sh "rm -rf tmp/sig"
21
+ sh "mkdir -p tmp/sig"
22
+ sh "bundle exec rbs prototype rb --out-dir=tmp/sig --base-dir=lib lib"
23
+
24
+ unless Dir.exist?("sig")
25
+ puts "sig/ does not exist; seeding curated signatures from tmp/sig"
26
+ sh "cp -R tmp/sig sig"
27
+ end
28
+ end
29
+
30
+ desc "Validate curated RBS signatures with Steep"
31
+ task :validate do
32
+ sh "bundle exec steep check"
33
+ end
34
+
35
+ desc "Open diff between curated and generated signatures"
36
+ task :diff do
37
+ sh "diff -ru sig tmp/sig || true"
38
+ end
39
+
40
+ desc "Generate disposable RBS prototypes and validate curated signatures"
41
+ task check: %i[prototype validate]
42
+ end
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "gem/guardian"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require "irb"
11
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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/exe/gem-guardian ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "gem/guardian"
5
+
6
+ exit Gem::Guardian::CLI.start(ARGV)
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/gem/guardian/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "gem-guardian"
7
+ spec.version = Gem::Guardian::VERSION
8
+ spec.authors = ["Kenneth Demanawa"]
9
+ spec.email = ["kenneth.c.demanawa@gmail.com"]
10
+
11
+ spec.summary = "Consumer-side integrity verification for Ruby gems."
12
+ spec.description = "Verifies Ruby gem artifacts against RubyGems SHA256 checksums using Gemfile.lock or explicit gem names."
13
+ spec.homepage = "https://github.com/kanutocd/gem-guardian"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 3.2"
16
+
17
+ spec.metadata = {
18
+ "homepage_uri" => spec.homepage,
19
+ "source_code_uri" => spec.homepage,
20
+ "changelog_uri" => "#{spec.homepage}/blob/main/CHANGELOG.md",
21
+ "rubygems_mfa_required" => "true"
22
+ }
23
+
24
+ spec.files = Dir.chdir(__dir__) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{\A(?:test|spec|features)/})
27
+ end
28
+ rescue StandardError
29
+ Dir["lib/**/*", "exe/*", "README.md", "LICENSE.txt", "CHANGELOG.md"]
30
+ end
31
+
32
+ spec.bindir = "exe"
33
+ spec.executables = ["gem-guardian"]
34
+ spec.require_paths = ["lib"]
35
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "tmpdir"
5
+
6
+ module Gem
7
+ module Guardian
8
+ class ArtifactStore
9
+ def initialize(client:, cache_dir: File.join(Dir.tmpdir, "gem-guardian"))
10
+ @client = client
11
+ @cache_dir = cache_dir
12
+ end
13
+
14
+ def path_for(dependency)
15
+ FileUtils.mkdir_p(@cache_dir)
16
+ path = File.join(@cache_dir, dependency.gem_filename)
17
+ return path if File.file?(path)
18
+
19
+ @client.download_gem(dependency, path)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "digest"
4
+
5
+ module Gem
6
+ module Guardian
7
+ module Checksum
8
+ module_function
9
+
10
+ def sha256_file(path)
11
+ Digest::SHA256.file(path).hexdigest
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gem
4
+ module Guardian
5
+ class CLI
6
+ def self.start(argv)
7
+ new(argv).run
8
+ end
9
+
10
+ def initialize(argv, stdout: $stdout, stderr: $stderr)
11
+ @argv = argv.dup
12
+ @stdout = stdout
13
+ @stderr = stderr
14
+ end
15
+
16
+ def run
17
+ command = @argv.shift
18
+ case command
19
+ when "verify"
20
+ verify
21
+ when "version", "--version", "-v"
22
+ @stdout.puts VERSION
23
+ 0
24
+ when "help", "--help", "-h", nil
25
+ usage
26
+ 0
27
+ else
28
+ @stderr.puts "Unknown command: #{command}"
29
+ usage(@stderr)
30
+ 2
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def verify
37
+ lockfile = option_value("--lockfile") || "Gemfile.lock"
38
+ gems = @argv
39
+ dependencies = if gems.empty?
40
+ LockfileParser.new(lockfile).dependencies
41
+ else
42
+ gems.map { |spec| parse_gem_spec(spec) }
43
+ end
44
+
45
+ if dependencies.empty?
46
+ @stderr.puts "No gems found to verify."
47
+ return 1
48
+ end
49
+
50
+ results = Verifier.new.verify_all(dependencies)
51
+ print_results(results)
52
+ results.all?(&:ok?) ? 0 : 1
53
+ rescue Error => e
54
+ @stderr.puts e.message
55
+ 1
56
+ end
57
+
58
+ def parse_gem_spec(spec)
59
+ name, version, platform = spec.split(":", 3)
60
+ raise Error, "Expected GEM:VERSION[:PLATFORM], got: #{spec}" if name.to_s.empty? || version.to_s.empty?
61
+
62
+ Dependency.new(name:, version:, platform: platform || "ruby")
63
+ end
64
+
65
+ def option_value(name)
66
+ index = @argv.index(name)
67
+ return unless index
68
+
69
+ value = @argv[index + 1]
70
+ raise Error, "#{name} requires a value" unless value
71
+
72
+ @argv.slice!(index, 2)
73
+ value
74
+ end
75
+
76
+ def print_results(results)
77
+ results.each do |result|
78
+ dependency = result.dependency
79
+ label = "#{dependency.name} #{dependency.version} #{dependency.platform}"
80
+ case result.status
81
+ when :ok
82
+ @stdout.puts "PASS #{label}"
83
+ @stdout.puts " sha256 #{result.actual_sha256}"
84
+ when :mismatch
85
+ @stdout.puts "FAIL #{label}"
86
+ @stdout.puts " expected #{result.expected_sha256}"
87
+ @stdout.puts " actual #{result.actual_sha256}"
88
+ else
89
+ @stdout.puts "ERROR #{label}"
90
+ @stdout.puts " #{result.error.class}: #{result.error.message}"
91
+ end
92
+ end
93
+ end
94
+
95
+ def usage(io = @stdout)
96
+ io.puts <<~USAGE
97
+ gem-guardian #{VERSION}
98
+
99
+ Usage:
100
+ gem-guardian verify [--lockfile Gemfile.lock]
101
+ gem-guardian verify GEM:VERSION[:PLATFORM] [GEM:VERSION[:PLATFORM] ...]
102
+ gem-guardian version
103
+
104
+ Examples:
105
+ gem-guardian verify
106
+ gem-guardian verify sidekiq:8.0.8
107
+ gem-guardian verify nokogiri:1.18.9:x86_64-linux
108
+ USAGE
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gem
4
+ module Guardian
5
+ Dependency = Data.define(:name, :version, :platform) do
6
+ def gem_filename
7
+ platform_suffix = platform && platform != "ruby" ? "-#{platform}" : ""
8
+ "#{name}-#{version}#{platform_suffix}.gem"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gem
4
+ module Guardian
5
+ Error = Class.new(StandardError)
6
+ ChecksumNotFound = Class.new(Error)
7
+ ArtifactFetchError = Class.new(Error)
8
+ LockfileError = Class.new(Error)
9
+ end
10
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gem
4
+ module Guardian
5
+ class LockfileParser
6
+ GEM_LINE = /^ {4}([A-Za-z0-9_.-]+) \(([^)]+)\)/
7
+
8
+ def initialize(path = "Gemfile.lock")
9
+ @path = path
10
+ end
11
+
12
+ def dependencies
13
+ raise LockfileError, "Lockfile not found: #{@path}" unless File.file?(@path)
14
+
15
+ specs_section = false
16
+ File.readlines(@path, chomp: true).filter_map do |line|
17
+ specs_section = true if line == " specs:"
18
+ specs_section = false if specs_section && line.match?(/^[A-Z]/)
19
+ next unless specs_section
20
+
21
+ match = GEM_LINE.match(line)
22
+ next unless match
23
+
24
+ name = match[1]
25
+ version_and_platform = match[2]
26
+ version, platform = split_version_and_platform(version_and_platform)
27
+ Dependency.new(name:, version:, platform:)
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ # Bundler renders native platforms as `1.2.3-x86_64-linux` in the spec line.
34
+ # Ruby versions remain plain, for example `1.2.3`.
35
+ def split_version_and_platform(value)
36
+ version, platform = value.split("-", 2)
37
+ [version, platform || "ruby"]
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "net/http"
5
+ require "uri"
6
+
7
+ module Gem
8
+ module Guardian
9
+ class RubygemsClient
10
+ DEFAULT_HOST = "https://rubygems.org"
11
+
12
+ def initialize(host: DEFAULT_HOST, http: Net::HTTP)
13
+ @host = host.delete_suffix("/")
14
+ @http = http
15
+ end
16
+
17
+ def expected_sha256(dependency)
18
+ versions = JSON.parse(get("/api/v1/versions/#{dependency.name}.json"))
19
+ version = versions.find do |item|
20
+ item["number"] == dependency.version && platform_matches?(item["platform"], dependency.platform)
21
+ end
22
+
23
+ sha = version && (version["sha"] || version["sha256"] || version["checksum"])
24
+ raise ChecksumNotFound, "No SHA256 found for #{dependency.name} #{dependency.version} #{dependency.platform}" if blank?(sha)
25
+
26
+ sha.downcase
27
+ end
28
+
29
+ def download_gem(dependency, destination)
30
+ body = get("/downloads/#{dependency.gem_filename}")
31
+ File.binwrite(destination, body)
32
+ destination
33
+ rescue StandardError => e
34
+ raise ArtifactFetchError, "Could not fetch #{dependency.gem_filename}: #{e.message}"
35
+ end
36
+
37
+ private
38
+
39
+ def get(path)
40
+ uri = URI("#{@host}#{path}")
41
+ response = @http.get_response(uri)
42
+ return response.body if response.is_a?(Net::HTTPSuccess)
43
+
44
+ raise Error, "GET #{uri} failed with #{response.code} #{response.message}"
45
+ end
46
+
47
+ def platform_matches?(remote_platform, wanted_platform)
48
+ normalized_remote = remote_platform.to_s.empty? ? "ruby" : remote_platform.to_s
49
+ normalized_wanted = wanted_platform.to_s.empty? ? "ruby" : wanted_platform.to_s
50
+ normalized_remote == normalized_wanted
51
+ end
52
+
53
+ def blank?(value)
54
+ value.nil? || value.to_s.empty?
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gem
4
+ module Guardian
5
+ VerificationResult = Data.define(:dependency, :expected_sha256, :actual_sha256, :artifact_path, :status, :error) do
6
+ def ok?
7
+ status == :ok
8
+ end
9
+ end
10
+
11
+ class Verifier
12
+ def initialize(client: RubygemsClient.new, artifact_store: nil)
13
+ @client = client
14
+ @artifact_store = artifact_store || ArtifactStore.new(client: @client)
15
+ end
16
+
17
+ def verify(dependency)
18
+ expected = @client.expected_sha256(dependency)
19
+ artifact_path = @artifact_store.path_for(dependency)
20
+ actual = Checksum.sha256_file(artifact_path)
21
+ status = secure_compare(expected, actual) ? :ok : :mismatch
22
+
23
+ VerificationResult.new(
24
+ dependency:,
25
+ expected_sha256: expected,
26
+ actual_sha256: actual,
27
+ artifact_path:,
28
+ status:,
29
+ error: nil
30
+ )
31
+ rescue StandardError => e
32
+ VerificationResult.new(
33
+ dependency:,
34
+ expected_sha256: nil,
35
+ actual_sha256: nil,
36
+ artifact_path: nil,
37
+ status: :error,
38
+ error: e
39
+ )
40
+ end
41
+
42
+ def verify_all(dependencies)
43
+ dependencies.map { |dependency| verify(dependency) }
44
+ end
45
+
46
+ private
47
+
48
+ def secure_compare(left, right)
49
+ left = left.to_s
50
+ right = right.to_s
51
+ return false unless left.bytesize == right.bytesize
52
+
53
+ left.bytes.zip(right.bytes).reduce(0) { |memo, (a, b)| memo | (a ^ b) }.zero?
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gem
4
+ module Guardian
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "guardian/version"
4
+ require_relative "guardian/error"
5
+ require_relative "guardian/checksum"
6
+ require_relative "guardian/dependency"
7
+ require_relative "guardian/lockfile_parser"
8
+ require_relative "guardian/rubygems_client"
9
+ require_relative "guardian/artifact_store"
10
+ require_relative "guardian/verifier"
11
+ require_relative "guardian/cli"
data/mise.toml ADDED
@@ -0,0 +1,2 @@
1
+ [tools]
2
+ ruby = "3.2"
@@ -0,0 +1,13 @@
1
+ module Gem
2
+ module Guardian
3
+ class ArtifactStore
4
+ @client: untyped
5
+
6
+ @cache_dir: untyped
7
+
8
+ def initialize: (client: untyped, ?cache_dir: untyped) -> void
9
+
10
+ def path_for: (untyped dependency) -> untyped
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module Gem
2
+ module Guardian
3
+ module Checksum
4
+ def self?.sha256_file: (untyped path) -> untyped
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,29 @@
1
+ module Gem
2
+ module Guardian
3
+ class CLI
4
+ @argv: untyped
5
+
6
+ @stdout: untyped
7
+
8
+ @stderr: untyped
9
+
10
+ def self.start: (untyped argv) -> untyped
11
+
12
+ def initialize: (untyped argv, ?stdout: untyped, ?stderr: untyped) -> void
13
+
14
+ def run: () -> untyped
15
+
16
+ private
17
+
18
+ def verify: () -> untyped
19
+
20
+ def parse_gem_spec: (untyped spec) -> untyped
21
+
22
+ def option_value: (untyped name) -> (nil | untyped)
23
+
24
+ def print_results: (untyped results) -> untyped
25
+
26
+ def usage: (?untyped io) -> untyped
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ module Gem
2
+ module Guardian
3
+ Dependency: untyped
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module Gem
2
+ module Guardian
3
+ Error: untyped
4
+
5
+ ChecksumNotFound: untyped
6
+
7
+ ArtifactFetchError: untyped
8
+
9
+ LockfileError: untyped
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ module Gem
2
+ module Guardian
3
+ class LockfileParser
4
+ @path: untyped
5
+
6
+ GEM_LINE: ::Regexp
7
+
8
+ def initialize: (?::String path) -> void
9
+
10
+ def dependencies: () -> untyped
11
+
12
+ private
13
+
14
+ # Bundler renders native platforms as `1.2.3-x86_64-linux` in the spec line.
15
+ # Ruby versions remain plain, for example `1.2.3`.
16
+ def split_version_and_platform: (untyped value) -> ::Array[untyped]
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ module Gem
2
+ module Guardian
3
+ class RubygemsClient
4
+ @host: untyped
5
+
6
+ @http: untyped
7
+
8
+ DEFAULT_HOST: "https://rubygems.org"
9
+
10
+ def initialize: (?host: untyped, ?http: untyped) -> void
11
+
12
+ def expected_sha256: (untyped dependency) -> untyped
13
+
14
+ def download_gem: (untyped dependency, untyped destination) -> untyped
15
+
16
+ private
17
+
18
+ def get: (untyped path) -> untyped
19
+
20
+ def platform_matches?: (untyped remote_platform, untyped wanted_platform) -> untyped
21
+
22
+ def blank?: (untyped value) -> untyped
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ module Gem
2
+ module Guardian
3
+ VerificationResult: untyped
4
+
5
+ class Verifier
6
+ @client: untyped
7
+
8
+ @artifact_store: untyped
9
+
10
+ def initialize: (?client: untyped, ?artifact_store: untyped?) -> void
11
+
12
+ def verify: (untyped dependency) -> untyped
13
+
14
+ def verify_all: (untyped dependencies) -> untyped
15
+
16
+ private
17
+
18
+ def secure_compare: (untyped left, untyped right) -> (false | untyped)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ module Gem
2
+ module Guardian
3
+ VERSION: "0.1.0"
4
+ end
5
+ end
File without changes
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem-guardian
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kenneth Demanawa
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2026-06-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Verifies Ruby gem artifacts against RubyGems SHA256 checksums using Gemfile.lock
14
+ or explicit gem names.
15
+ email:
16
+ - kenneth.c.demanawa@gmail.com
17
+ executables:
18
+ - gem-guardian
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".github/workflows/main.yml"
23
+ - ".gitignore"
24
+ - ".rubocop.yml"
25
+ - ".ruby-version"
26
+ - CHANGELOG.md
27
+ - CODE_OF_CONDUCT.md
28
+ - Gemfile
29
+ - LICENSE.txt
30
+ - README.md
31
+ - Rakefile
32
+ - bin/console
33
+ - bin/setup
34
+ - exe/gem-guardian
35
+ - gem-guardian.gemspec
36
+ - lib/gem/guardian.rb
37
+ - lib/gem/guardian/artifact_store.rb
38
+ - lib/gem/guardian/checksum.rb
39
+ - lib/gem/guardian/cli.rb
40
+ - lib/gem/guardian/dependency.rb
41
+ - lib/gem/guardian/error.rb
42
+ - lib/gem/guardian/lockfile_parser.rb
43
+ - lib/gem/guardian/rubygems_client.rb
44
+ - lib/gem/guardian/verifier.rb
45
+ - lib/gem/guardian/version.rb
46
+ - mise.toml
47
+ - sig/gem/guardian.rbs
48
+ - sig/gem/guardian/artifact_store.rbs
49
+ - sig/gem/guardian/checksum.rbs
50
+ - sig/gem/guardian/cli.rbs
51
+ - sig/gem/guardian/dependency.rbs
52
+ - sig/gem/guardian/error.rbs
53
+ - sig/gem/guardian/lockfile_parser.rbs
54
+ - sig/gem/guardian/rubygems_client.rbs
55
+ - sig/gem/guardian/verifier.rbs
56
+ - sig/gem/guardian/version.rbs
57
+ homepage: https://github.com/kanutocd/gem-guardian
58
+ licenses:
59
+ - MIT
60
+ metadata:
61
+ homepage_uri: https://github.com/kanutocd/gem-guardian
62
+ source_code_uri: https://github.com/kanutocd/gem-guardian
63
+ changelog_uri: https://github.com/kanutocd/gem-guardian/blob/main/CHANGELOG.md
64
+ rubygems_mfa_required: 'true'
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '3.2'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubygems_version: 3.4.19
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Consumer-side integrity verification for Ruby gems.
84
+ test_files: []