proofmode-cli 0.14.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: 7e74fa1b7f3b750d1a7344398ca66c12fa67183145c5d8598dae8a56568ebef1
4
+ data.tar.gz: 2c520165f6442e87f894e4d3f27f7fc3ec29edc44578f98b79d6f5d9650e110c
5
+ SHA512:
6
+ metadata.gz: 06eade015cf33979f62e80945d7a0ae9d889aa68e6429f62f82bc2b547e9eb32406febf657ea29158c65773101cf12bb0c398d8ab96cec9c8ecbfb7302a4d933
7
+ data.tar.gz: 05edb8fea873f67773ffab138c8d60471b9b6033eb9c1c985eccdc56598451a08ce16b65eab0811781cd1b8d60de496bfc8843ed2555eaa3e465fbc076d5880e
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # ProofMode Ruby CLI
2
+
3
+ `proofmode`, the command-line interface for [ProofMode](https://proofmode.org), on the `proofmode` gem (UniFFI bindings to the Rust library). It has `check` and `generate`, with the same options as the Rust CLI, which also has `sign`. The four tools are compared in [CLI_DOCUMENTATION.md](../../CLI_DOCUMENTATION.md).
4
+
5
+ ## Install
6
+
7
+ `proofmode-cli` and the `proofmode` gem it depends on are published to rubygems.org on each release. No release has published `proofmode-cli` yet: as of 2026-12-01 the newest `proofmode` gem there is 0.8.4, from before this tool existed, so until the next release build both gems from a checkout, as below. Once published:
8
+
9
+ ```bash
10
+ gem install proofmode-cli
11
+ proofmode --help
12
+ ```
13
+
14
+ `proofmode` bundles a native library, so it is a platform gem, and the release publishes it for x86_64 Linux only. The library needs nothing installed beyond glibc. On another platform, build both gems from a checkout of this repository (Linux or macOS, with Rust installed):
15
+
16
+ ```bash
17
+ scripts/build_ruby_gem.sh # builds ruby/proofmode-<version>-<platform>.gem
18
+ (cd cli/ruby && gem build proofmode-cli.gemspec)
19
+ gem install ruby/proofmode-*.gem cli/ruby/proofmode-cli-*.gem
20
+ ```
21
+
22
+ ## Check
23
+
24
+ ```bash
25
+ proofmode check -f photo.jpg -f bundle.zip
26
+ proofmode check -d ./media -o results.json
27
+ proofmode check --url https://example.org/photo.jpg
28
+ proofmode check --cid bafy... --gateway https://ipfs.io
29
+ proofmode check -f photo.jpg --c2pa-trust-anchors trust.pem --media thumbnail
30
+ ```
31
+
32
+ - `-f, --file FILE` (repeatable) and `-d, --dir DIR`: files to check (a directory's top-level files)
33
+ - `-u, --url URL` (repeatable): a file, or an IPFS directory served as a TAR export, fetched over HTTP with Net::HTTP (redirects followed)
34
+ - `-c, --cid CID` (repeatable): an IPFS CID, fetched through `--gateway` or the default gateways in turn
35
+ - Use one kind of source per run: `--file`/`--dir`, `--url` or `--cid`
36
+ - `-o, --output-file FILE`: write the JSON result to a file instead of stdout
37
+ - `--c2pa-trust-anchors PEM_FILE`: C2PA trust anchor roots; manifests that chain to one validate as Trusted rather than Valid
38
+ - `--cawg-trust-anchors PEM_FILE`: CAWG X.509 identity roots (S/MIME); identities that chain to one are Trusted
39
+ - `--cawg-allowed-list PEM_FILE`: CAWG identity certificates trusted as they are
40
+ - `--media none|thumbnail|full`: media to include per file (default none)
41
+ - `--thumbnail-max-dim PIXELS`: longest edge of generated thumbnails (default 1024)
42
+ - `--max-input-bytes BYTES`: the most bytes of input the check holds, and so the largest file it reads (default 8 GiB, 4 GiB per file); a larger file is listed in `errors`, unread
43
+ - `--gateway GATEWAY`: IPFS gateway for `--cid`, path-style (`https://ipfs.io`) or subdomain (`dweb.link`)
44
+
45
+ ## Generate
46
+
47
+ ```bash
48
+ PROOFMODE_PGP_PASSPHRASE='a long passphrase' proofmode generate -f photo.jpg -s ./proofs -e you@example.org
49
+ proofmode generate -f photo.jpg -s ./proofs --description "City hall" # unsigned
50
+ ```
51
+
52
+ This runs the library's own generator, the one the Rust `proofmode` command uses. It writes each proof to `<storage>/proofmode/<sha256>/` (default storage `./proofmode`): `<sha256>.proof.json`, `<sha256>.proof.csv` and, for media in a format that can carry one, `<sha256>.c2pa.<ext>`, a copy with the proof in a C2PA manifest.
53
+
54
+ - `-p, --passphrase PASS` or `PROOFMODE_PGP_PASSPHRASE`: sign the proof. The key is kept at `<storage>/pgp/secret.asc`, encrypted with the passphrase, and made on the first signed run, which needs `-e, --email EMAIL` for its user ID. A signed proof also has `<sha256>.asc` (over the media), `<sha256>.proof.json.asc`, `<sha256>.proof.csv.asc` and `pubkey.asc`, and `proofmode check -f photo.jpg -d <storage>/proofmode/<sha256>` verifies it. Without a passphrase the proof is unsigned, and the run says so.
55
+ - `--description`, `--location`, `--event-type`, `--tags`: recorded in the proof.
56
+
57
+ ## Development
58
+
59
+ From the repository root:
60
+
61
+ ```bash
62
+ cargo make test-ruby-cli # builds the proofmode gem (scripts/build_ruby_gem.sh) and runs the tests
63
+ cargo make cli-ruby -- check -f tests/fixtures/CA.jpg
64
+ ```
data/bin/proofmode ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require "proofmode_cli"
3
+
4
+ ProofmodeCli::CLI.start
@@ -0,0 +1,3 @@
1
+ module ProofmodeCli
2
+ VERSION = "0.14.0"
3
+ end
@@ -0,0 +1,231 @@
1
+ # `proofmode check` and `proofmode generate`, with the same commands and check
2
+ # options as the Rust, Node.js and Python CLIs.
3
+ require "json"
4
+ require "net/http"
5
+ require "openssl"
6
+ require "optparse"
7
+ require "pathname"
8
+ require "proofmode"
9
+ require_relative "proofmode_cli/version"
10
+
11
+ module ProofmodeCli
12
+ PASSPHRASE_ENV = "PROOFMODE_PGP_PASSPHRASE".freeze
13
+ UNSIGNED_NOTICE = "Note: these proofs are not PGP-signed. " \
14
+ "Pass --passphrase or set #{PASSPHRASE_ENV} to sign them.".freeze
15
+ MEDIA = { "none" => Proofmode::MediaReturn::NONE,
16
+ "thumbnail" => Proofmode::MediaReturn::THUMBNAIL,
17
+ "full" => Proofmode::MediaReturn::FULL }.freeze
18
+
19
+ class Failure < StandardError; end
20
+
21
+ # HTTP for --url and --cid with Net::HTTP. The library decides what to
22
+ # request; this returns each final response as received, following
23
+ # redirects as the contract asks.
24
+ class UrlFetcher < Proofmode::UrlFetcher
25
+ MAX_REDIRECTS = 5
26
+ TIMEOUT_SECONDS = 45
27
+
28
+ def get(url, accept)
29
+ uri = URI(url)
30
+ MAX_REDIRECTS.downto(0) do |left|
31
+ response = request(uri, accept)
32
+ location = response["location"]
33
+ unless response.is_a?(Net::HTTPRedirection) && location
34
+ return Proofmode::HttpResponse.new(status: response.code.to_i, content_type: response["content-type"],
35
+ body: response.body.to_s.b)
36
+ end
37
+ raise Proofmode::ProofModeError::Io.new(reason: "too many redirects from #{url}") if left.zero?
38
+
39
+ uri = uri.merge(location)
40
+ end
41
+ rescue SystemCallError, IOError, SocketError, Timeout::Error, OpenSSL::SSL::SSLError, URI::Error => e
42
+ raise Proofmode::ProofModeError::Io.new(reason: e.message)
43
+ end
44
+
45
+ private
46
+
47
+ def request(uri, accept)
48
+ Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https",
49
+ open_timeout: TIMEOUT_SECONDS, read_timeout: TIMEOUT_SECONDS) do |http|
50
+ req = Net::HTTP::Get.new(uri)
51
+ req["Accept"] = accept if accept
52
+ http.request(req)
53
+ end
54
+ end
55
+ end
56
+
57
+ # Every error the generated bindings raise: the ProofModeError variants and
58
+ # uniffi's InternalError (a panic in the library).
59
+ LIBRARY_ERRORS = [Proofmode::ProofModeError::Io, Proofmode::ProofModeError::Generation,
60
+ Proofmode::ProofModeError::Check, Proofmode::InternalError].freeze
61
+
62
+ # A library error's own text: the ProofModeError variants carry it in
63
+ # `reason`, and their `message` is the bindings' `Class(reason="...")` form.
64
+ def self.library_message(error)
65
+ error.respond_to?(:reason) ? error.reason : error.message
66
+ end
67
+
68
+ class CLI
69
+ def self.start(argv = ARGV)
70
+ new.run(argv)
71
+ rescue Failure, OptionParser::ParseError => e
72
+ warn e.message
73
+ exit 1
74
+ end
75
+
76
+ def run(argv)
77
+ command = argv.shift
78
+ case command
79
+ when "check" then check(argv)
80
+ when "generate" then generate(argv)
81
+ when "--version", "-v" then puts VERSION
82
+ when "--help", "-h", nil then puts usage
83
+ else raise Failure, "Unknown command: #{command}\n#{usage}"
84
+ end
85
+ end
86
+
87
+ private
88
+
89
+ def usage
90
+ "Usage: proofmode <check|generate> [options] (proofmode <command> --help for options)"
91
+ end
92
+
93
+ def collect_files(files, dirs)
94
+ files.each { |f| raise Failure, "File not found: #{f}" unless File.file?(f) }
95
+ paths = files.dup
96
+ dirs.each do |dir|
97
+ raise Failure, "Cannot read directory #{dir}" unless File.directory?(dir)
98
+
99
+ paths.concat(Dir.children(dir).sort.map { |n| File.join(dir, n) }.select { |p| File.file?(p) })
100
+ end
101
+ raise Failure, "No files specified" if paths.empty?
102
+
103
+ paths
104
+ end
105
+
106
+ # The PEM file a check flag names, or nil when the flag is not given.
107
+ # Checked for PEM here so an error names the flag and the file; the
108
+ # library still rejects a PEM it cannot load.
109
+ def read_pem(flag, pem_file)
110
+ return nil unless pem_file
111
+
112
+ begin
113
+ pem = File.read(pem_file, encoding: "UTF-8")
114
+ rescue SystemCallError => e
115
+ raise Failure, "Cannot read #{flag} #{pem_file}: #{e.message.sub(/ @ .*/, "")}"
116
+ end
117
+ unless pem.valid_encoding? && pem.include?("-----BEGIN")
118
+ raise Failure, "Invalid #{flag} #{pem_file}: contains no PEM certificates"
119
+ end
120
+
121
+ pem
122
+ end
123
+
124
+ def check(argv)
125
+ opts = { files: [], dirs: [], urls: [], cids: [], media: "none" }
126
+ OptionParser.new do |o|
127
+ o.banner = "Usage: proofmode check [options]"
128
+ o.on("-f", "--file FILE", "File to check (repeatable)") { |v| opts[:files] << v }
129
+ o.on("-d", "--dir DIR", "Directory whose files to check") { |v| opts[:dirs] << v }
130
+ o.on("-u", "--url URL", "URL of a file or proof bundle to check (repeatable)") { |v| opts[:urls] << v }
131
+ o.on("-c", "--cid CID", "IPFS CID to check (repeatable)") { |v| opts[:cids] << v }
132
+ o.on("-o", "--output-file FILE", "Write the JSON result to this file") { |v| opts[:output] = v }
133
+ o.on("--c2pa-trust-anchors PEM_FILE", "C2PA trust anchor roots; matches validate as Trusted") { |v| opts[:trust] = v }
134
+ o.on("--cawg-trust-anchors PEM_FILE", "CAWG X.509 identity roots (S/MIME); matches are Trusted") do |v|
135
+ opts[:cawg_trust] = v
136
+ end
137
+ o.on("--cawg-allowed-list PEM_FILE", "CAWG identity certificates trusted as they are") { |v| opts[:cawg_allowed] = v }
138
+ o.on("--media MEDIA", MEDIA.keys, "none (default), thumbnail or full") { |v| opts[:media] = v }
139
+ o.on("--thumbnail-max-dim PIXELS", Integer, "Longest edge of thumbnails (default 1024)") do |v|
140
+ unless v.positive? && v <= 0xFFFF_FFFF
141
+ raise Failure, "--thumbnail-max-dim must be a whole number of pixels from 1 to 4294967295"
142
+ end
143
+
144
+ opts[:max_dim] = v
145
+ end
146
+ o.on("--gateway GATEWAY", "IPFS gateway for --cid, path-style (https://ipfs.io) or subdomain (dweb.link)") do |v|
147
+ opts[:gateway] = v
148
+ end
149
+ o.on("--max-input-bytes BYTES", Integer,
150
+ "Most bytes of input the check holds, and so the largest file it reads (default 8 GiB)") do |v|
151
+ unless v.positive? && v <= 0xFFFF_FFFF_FFFF_FFFF
152
+ raise Failure, "--max-input-bytes must be a whole number of bytes, 1 or more"
153
+ end
154
+
155
+ opts[:max_input_bytes] = v
156
+ end
157
+ end.parse!(argv)
158
+
159
+ options = Proofmode::CheckOptions.new(
160
+ c2pa_trust_anchors: read_pem("--c2pa-trust-anchors", opts[:trust]),
161
+ cawg_trust_anchors: read_pem("--cawg-trust-anchors", opts[:cawg_trust]),
162
+ cawg_allowed_list: read_pem("--cawg-allowed-list", opts[:cawg_allowed]),
163
+ media: MEDIA.fetch(opts[:media]), thumbnail_max_dim: opts[:max_dim], gateway: opts[:gateway],
164
+ max_input_bytes: opts[:max_input_bytes]
165
+ )
166
+ sources = [opts[:files].any? || opts[:dirs].any?, opts[:urls].any?, opts[:cids].any?]
167
+ raise Failure, "Use one of --file/--dir, --url or --cid" if sources.count(true) > 1
168
+
169
+ begin
170
+ result = if opts[:urls].any?
171
+ Proofmode.check_urls(opts[:urls], UrlFetcher.new, options)
172
+ elsif opts[:cids].any?
173
+ Proofmode.check_cids(opts[:cids], UrlFetcher.new, options)
174
+ else
175
+ Proofmode.check_files(collect_files(opts[:files], opts[:dirs]), options)
176
+ end
177
+ rescue *LIBRARY_ERRORS => e
178
+ raise Failure, "Verification failed: #{ProofmodeCli.library_message(e)}"
179
+ end
180
+ text = JSON.pretty_generate(JSON.parse(result))
181
+ if opts[:output]
182
+ begin
183
+ File.write(opts[:output], text)
184
+ rescue SystemCallError => e
185
+ raise Failure, "Cannot write #{opts[:output]}: #{e.message.sub(/ @ .*/, "")}"
186
+ end
187
+ warn "Results written to #{opts[:output]}"
188
+ else
189
+ puts text
190
+ end
191
+ end
192
+
193
+ def generate(argv)
194
+ opts = { files: [], dirs: [], storage: "./proofmode", proof: {} }
195
+ OptionParser.new do |o|
196
+ o.banner = "Usage: proofmode generate [options]"
197
+ o.on("-f", "--file FILE", "File to generate a proof for") { |v| opts[:files] << v }
198
+ o.on("-d", "--dir DIR", "Directory whose files to generate proofs for") { |v| opts[:dirs] << v }
199
+ o.on("-s", "--storage DIR", "Storage directory (default ./proofmode)") { |v| opts[:storage] = v }
200
+ o.on("-e", "--email EMAIL", "Email for the user ID of a new signing key (needed the first time)") do |v|
201
+ opts[:proof][:email] = v
202
+ end
203
+ o.on("-p", "--passphrase PASS",
204
+ "Passphrase of the signing key at <storage>/pgp/secret.asc, created on first use " \
205
+ "(or set #{PASSPHRASE_ENV}). Without one, proofs are unsigned") { |v| opts[:proof][:passphrase] = v }
206
+ o.on("--description TEXT", "Description metadata") { |v| opts[:proof][:description] = v }
207
+ o.on("--location TEXT", "Location metadata") { |v| opts[:proof][:location] = v }
208
+ o.on("--event-type TEXT", "Event type metadata") { |v| opts[:proof][:event_type] = v }
209
+ o.on("--tags TEXT", "Tags metadata") { |v| opts[:proof][:tags] = v }
210
+ end.parse!(argv)
211
+
212
+ paths = collect_files(opts[:files], opts[:dirs])
213
+ # An empty passphrase is passed on: the library refuses it.
214
+ passphrase = opts[:proof][:passphrase] || ENV.fetch(PASSPHRASE_ENV, nil)
215
+ warn UNSIGNED_NOTICE unless passphrase
216
+ options = Proofmode::FileProofOptions.new(**opts[:proof], passphrase: passphrase)
217
+ failed = false
218
+ paths.each do |path|
219
+ name = File.basename(path)
220
+ begin
221
+ digest = Proofmode.generate_proof_for_file(path, opts[:storage], options)
222
+ warn "Generated proof for #{name}: #{digest}"
223
+ rescue *LIBRARY_ERRORS => e
224
+ warn "Failed to generate proof for #{name}: #{ProofmodeCli.library_message(e)}"
225
+ failed = true
226
+ end
227
+ end
228
+ exit(failed ? 1 : 0)
229
+ end
230
+ end
231
+ end
@@ -0,0 +1,25 @@
1
+ require_relative "lib/proofmode_cli/version"
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "proofmode-cli"
5
+ s.version = ProofmodeCli::VERSION
6
+ s.summary = "Command-line interface for ProofMode"
7
+ s.description = "Check and generate ProofMode proofs from the command line, using the proofmode gem"
8
+ s.authors = ["Guardian Project"]
9
+ s.email = "support@guardianproject.info"
10
+ s.homepage = "https://proofmode.org"
11
+ s.license = "Apache-2.0"
12
+
13
+ s.files = Dir["lib/**/*.rb"] + ["bin/proofmode", "README.md", "proofmode-cli.gemspec"]
14
+ s.bindir = "bin"
15
+ s.executables = ["proofmode"]
16
+ s.require_paths = ["lib"]
17
+ s.required_ruby_version = ">= 3.2.0"
18
+
19
+ s.add_dependency "proofmode", ProofmodeCli::VERSION
20
+
21
+ s.metadata = {
22
+ "source_code_uri" => "https://gitlab.com/guardianproject/proofmode/proofmode-rust",
23
+ "bug_tracker_uri" => "https://gitlab.com/guardianproject/proofmode/proofmode-rust/-/issues"
24
+ }
25
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: proofmode-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.14.0
5
+ platform: ruby
6
+ authors:
7
+ - Guardian Project
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-12-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: proofmode
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.14.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.14.0
27
+ description: Check and generate ProofMode proofs from the command line, using the
28
+ proofmode gem
29
+ email: support@guardianproject.info
30
+ executables:
31
+ - proofmode
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - README.md
36
+ - bin/proofmode
37
+ - lib/proofmode_cli.rb
38
+ - lib/proofmode_cli/version.rb
39
+ - proofmode-cli.gemspec
40
+ homepage: https://proofmode.org
41
+ licenses:
42
+ - Apache-2.0
43
+ metadata:
44
+ source_code_uri: https://gitlab.com/guardianproject/proofmode/proofmode-rust
45
+ bug_tracker_uri: https://gitlab.com/guardianproject/proofmode/proofmode-rust/-/issues
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.4.19
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Command-line interface for ProofMode
65
+ test_files: []