class Capsium::Package::OpenPgpSigner
Signs and verifies Capsium packages with OpenPGP detached signatures (ARCHITECTURE.md section 6a) through librnp (Capsium::Package::OpenPgp). Parallel to the RSA-SHA256/X.509 Signer with the same construction semantics and the same error taxonomy (Signer::SignatureError subclasses), so loaders and the CLI handle both schemes uniformly.
The signed payload is identical to the Signer’s: the concatenation, in sorted package-relative path order, of the raw bytes of every file covered by the security.json integrity checksums. signature.sig holds the armored detached OpenPGP signature (SHA-256) over that payload; the signer’s armored public key is embedded as signature.pub.asc and security.json records:
"digitalSignatures": { "certificateType": "OpenPGP",
"publicKey": "signature.pub.asc",
"signatureFile": "signature.sig" }
Keys are OpenPGP key files (armored or binary, auto-detected); signing needs a secret key, verification a public one.
Constants
- ALGORITHM
- CERTIFICATE_TYPE
- HASH
- PUBLIC_KEY_FILE
-
Package-relative name of the embedded armored OpenPGP public key recorded in security.json digitalSignatures.publicKey.
Attributes
String
Public Class Methods
(String package_path) → void
Source
# File lib/capsium/package/open_pgp_signer.rb, line 37 def initialize(package_path) @package_path = package_path end
(String path, String secret_key_path) → String
Source
# File lib/capsium/package/open_pgp_signer.rb, line 44 def self.sign_package(path, secret_key_path) return new(path).sign(secret_key_path) unless cap?(path) Packager.new.transform_cap(path) { |dir| new(dir).sign(secret_key_path) } path end
Signs a package directory in place, or a .cap file (unpacked, signed, recompressed), with the OpenPGP secret key at secret_key_path. Returns the signed path.
(String path, ?String? public_key_path) → bool
Source
# File lib/capsium/package/open_pgp_signer.rb, line 56 def self.verify_package(path, public_key_path = nil) return new(path).verify(public_key_path) unless cap?(path) Packager.new.with_unpacked_cap(path) { |dir| new(dir).verify(public_key_path) } end
Verifies the declared OpenPGP signature of a package directory or .cap file (false on mismatch; raises typed Signer::SignatureError subclasses on structural problems, e.g. an unsigned package). public_key_path is an OpenPGP public key file; without it the key embedded in the package is used.
Public Instance Methods
(String secret_key_path) → String
Source
# File lib/capsium/package/open_pgp_signer.rb, line 71 def sign(secret_key_path) loaded = OpenPgp.load_key(secret_key_path, secret: true) File.write(public_key_path, loaded.key.export_public(armored: true)) security = Security.generate(@package_path, digital_signatures: digital_signatures) security.save_to_file signature = loaded.rnp.detached_sign( input: Rnp::Input.from_string(payload(security)), signers: loaded.key, hash: HASH, armored: true ) File.write(signature_path, signature) signature_path end
Signs the package directory in place: embeds the armored public key, regenerates security.json (checksums plus digitalSignatures with certificateType “OpenPGP”) and writes the armored detached OpenPGP signature to signature.sig.
() → bool
Source
# File lib/capsium/package/open_pgp_signer.rb, line 100 def signed? declared_security.signed? end
(?String? public_key_path) → bool
Source
# File lib/capsium/package/open_pgp_signer.rb, line 86 def verify(public_key_path = nil) signature = read_signature data = payload(declared_security) loaded = verification_key(public_key_path) signature_matches(loaded, data, signature) end
True when the declared signature verifies against the payload. Without an explicit key path, the embedded public key is used.
(?String? public_key_path) → bool
Source
# File lib/capsium/package/open_pgp_signer.rb, line 93 def verify!(public_key_path = nil) return true if verify(public_key_path) raise Signer::SignatureMismatchError, "digital signature does not match the package contents" end