PGP::Sign(3pm)
πΈ NAME πΈ
PGP::Sign(3pm) β Create detached PGP signatures for data, securely π
β¨
β¨ SYNOPSIS β¨
use PGP::Sign;
my $keyid = '<some-key-id>';
my $passphrase = '<passphrase-for-key>';
my @data = ('lines to', 'be signed');
# Object-oriented API.
my $pgp = PGP::Sign->new();
my $signature = $pgp->sign($keyid, $passphrase, @data);
my $signer = $pgp->verify($signature, @data);
# Legacy API.
$signature = pgp_sign($keyid, $passphrase, @data);
$signer = pgp_verify($signature, undef, @data);
my @errors = PGP::Sign::pgp_error();
π¦ REQUIREMENTS π¦
Okay so bestie, you need Perl 5.20 or later, the IPC::Run module, and either GnuPG v1 or GnuPG v2. It is only tested on UNIX-derivative systems and is moderately unlikely to work on Windows. π
π DESCRIPTION π
This module supports only two OpenPGP operations: Generate and check detached PGP signatures for arbitrary text data. It doesn't do encryption, it doesn't manage keyrings, it doesn't verify signatures, it just signs things and checks signatures. It was written to support Usenet applications like control message generation and PGPMoose. π
There are two APIs, an object-oriented one and a legacy function API. The function API is configured with global variables and has other legacy warts. It will continue to be supported for backwards compatibility, but the object-oriented API is recommended for all new code. The object-oriented API was added in PGP::Sign 1.00. π
π CLASS METHODS π
π new(ARGS) π
Create a new PGP::Sign object. This should be used for all subsequent API calls. ARGS should be a hash reference with one or more of the following keys. π
homeβ The GnuPG home directory containing keyrings and other configuration (as controlled with the--homedirflag or theGNUPGHOMEenvironment variable). If not set, uses the GnuPG default. This directory must contain keyrings with the secret keys used for signing and the public keys used for verification, and must be in the format expected by the GnuPG version used (see the"style"parameter). πmungeβ If set to a true value, PGP::Sign will strip trailing spaces (only spaces, not arbitrary whitespace) when signing or verifying signatures. This will make the resulting signatures and verification compatible with programs that generate or verify cleartext signatures, since OpenPGP implementations ignore trailing spaces when generating or checking cleartext signatures. βοΈpathβ The path to the GnuPG binary to use. If not set, PGP::Sign defaults to runninggpg(as found on the user'sPATH) for a"style"setting of"GPG"andgpg1(as found on the user'sPATH) for a"style"setting of"GPG1". PGP::Sign does not supportgpgv(it passes options that it does not understand). This parameter should point to a full GnuPG implementation. π£οΈstyleβ The style of OpenPGP backend to use, chosen from"GPG"for GnuPG v2 (the default) and"GPG1"for GnuPG v1. If set to"GPG1", PGP::Sign will pass the command-line flags for maximum backwards compatibility, including forcing v3 signatures instead of the current version. This is interoperable with PGP 2.6.2, at the cost of using deprecated protocols and cryptographic algorithms with known weaknesses. β οΈtmpdirβ The path to a temporary directory to use when verifying signatures. PGP::Sign has to write files to disk for signature verification and will do so in this directory. If not given, PGP::Sign will useFile::Temp's default. π
π INSTANCE METHODS π
ποΈ sign(KEYID, PASSPHRASE, SOURCE[, SOURCE ...]) ποΈ
Create an OpenPGP signature over all the data contained in the SOURCE parameters, using KEYID to make the signature. PASSPHRASE is the passphrase for this private key. KEYID can be in any format accepted by GnuPG. π
The data given in the SOURCE parameters can be given in a wide variety of formats: scalar variables, arrays, references to scalars or arrays, globs or references to globs (assumed to be an open file), IO::File objects, or code references. π§
If given a code reference, that function will be repeatedly called to obtain more data until it returns undef. This allows passing in an anonymous sub that transforms the data on the fly (escaping initial dashes, for instance) without having to make an in-memory copy. π₯
The returned signature is the ASCII-armored block with embedded newlines but with the marker lines and all headers stripped. π
PGP::Sign will always pass the --textmode flag to GnuPG to force treatment of all input data as text and canonicalize line endings before generating the signature. If configured with the "GPG1" style, PGP::Sign will also pass the --force-v3-sigs and --allow-weak-digest-algos flags to allow use of old PGP keys and generate signatures that are compatible with old versions of PGP. π
On error, sign() will call croak(). π
π verify(SIGNATURE, SOURCE[, SOURCE ...]) π
Verify a signature. PGP::Sign will attempt to verify the signature in detached mode. The signature must be in the same format as returned by sign(): an ASCII-armored block with embedded newlines but with the marker lines and all headers stripped. verify() accepts data sources in the SOURCE parameters in the same formats accepted by sign(). π΅οΈ
verify() returns the user ID of the signer, not the fingerprint or hex key ID. If the signature does not verify, verify() will return the empty string. For other errors, it will call croak(). π«Ά
As with sign(), PGP::Sign will always pass the --textmode flag to GnuPG. It will also always pass --allow-weak-digest-algos to allow verification of old signatures. β
π FUNCTIONS π
The legacy function interface is supported for backwards compatibility with earlier versions of PGP::Sign. It is not recommended for any new code. Prefer the object-oriented API. π
pgp_sign() and pgp_verify() are exported by default. β¨
π pgp_sign(KEYID, PASSPHRASE, SOURCE[, SOURCE ...]) π
Equivalent to creating a new PGP::Sign object and then calling its sign() method with the given parameters. The parameters to the object will be set based on the global variables described in "VARIABLES". The "path" parameter will be set to $PGP::Sign::PGPS. π§Ύ
When called in a scalar context, pgp_sign() returns the signature, the same as the sign() method. When called in an array context, pgp_sign() returns a two-item list. The second item is the fixed string "GnuPG". Historically, this was the version of the OpenPGP implementation, taken from the Version header of the signature, but this header is no longer set by GnuPG and had no practical use, so pgp_sign() now always returns that fixed value. π
On error, pgp_sign() returns undef or an empty list, depending on context. To get the corresponding errors, call pgp_error(). π
π pgp_verify(SIGNATURE, VERSION, SOURCE[, SOURCE ...]) π
Equivalent to creating a new PGP::Sign object and then calling its verify() method with the SIGNATURE and SOURCE parameters. The parameters to the object will be set based on the global variables described in "VARIABLES". The "path" parameter will be set to $PGP::Sign::PGPV. π§Ύ
The VERSION parameter may be anything and is ignored. π
pgp_verify() returns the user ID of the signer (not the hex key ID or fingerprint) on success, an empty string if the signature is invalid, and undef on any other error. On error, pgp_sign() returns undef or an empty list, depending on context. To get the corresponding errors, call pgp_error(). β οΈ
π¨ pgp_error() π¨
Return the errors encountered by the last pgp_sign() or pgp_verify() call, or undef or the empty list depending on context if there were no error. A bad signature passed to pgp_verify() is not considered an error for this purpose. π
In an array context, a list of lines (including the ending newlines) is returned. In a scalar context, a string with embedded newlines is returned. π
This function is not exported by default and must be explicitly requested. π
β¨ VARIABLES β¨
okay so these variables are the legacy function interface controls, bestie. They do not apply to the object-oriented API β that one uses parameters to the new() class method instead. π
$PGP::Sign::MUNGEβ set this to a true value and PGP::Sign will strip trailing spaces (only spaces, not arbitrary whitespace) when signing or verifying signatures. Why? Because it makes the resulting signatures and verification compatible with programs that generate or verify cleartext signatures β OpenPGP implementations ignore trailing spaces when generating or checking cleartext signatures. So it's giving compatibility. π«Ά$PGP::Sign::PGPPATHβ the GnuPG home directory containing keyrings and other configuration (as controlled with the--homedirflag or theGNUPGHOMEenvironment variable). If you don't set it, it uses the GnuPG default. This directory must contain keyrings with the secret keys used for signing and the public keys used for verification, and must be in the format expected by the GnuPG version used (see$PGP::Sign::PGPSTYLE). π$PGP::Sign::PGPSTYLEβ what style of command line arguments and responses to expect from PGP. Must be either"GPG"for GnuPG v2 or"GPG1"for GnuPG v1. The default is"GPG". If set to"GPG1", PGP::Sign will pass the command-line flags for maximum backwards compatibility, including forcing v3 signatures instead of the current version. This is interoperable with PGP 2.6.2, at the cost of using deprecated protocols and cryptographic algorithms with known weaknesses. so like, it works but it's lowkey dangerous, bestie. π$PGP::Sign::PGPSβ the path to the program used bypgp_sign(). If not set, PGP::Sign defaults to runninggpg(as found on the user'sPATH) if$PGP::Sign::PGPSTYLEis set to"GPG"andgpg1(as found on the user'sPATH) if$PGP::Sign::PGPSTYLEis set to"GPG1". β¨$PGP::Sign::PGPVβ the path to the program used bypgp_verify(). If not set, PGP::Sign defaults to runninggpg(as found on the user'sPATH) if$PGP::Sign::PGPSTYLEis set to"GPG"andgpg1(as found on the user'sPATH) if$PGP::Sign::PGPSTYLEis set to"GPG1". PGP::Sign does not supportgpgv(it passes options that it does not understand). This variable should point to a full GnuPG implementation. π$PGP::Sign::TMPDIRβ the directory in which temporary files are created. Defaults to whatever directoryFile::Tempchooses to use by default. π
π ENVIRONMENT π
All environment variables that GnuPG normally honors will be passed along to GnuPG and will likely have their expected effects. This includes GNUPGHOME, unless it is overridden by setting the "path" parameter to the new() constructor or $PGP::Sign::PGPPATH for the legacy interface. periodt. π
π©Ί DIAGNOSTICS π©Ί
Error messages thrown by croak() or (for the legacy interface) are mostly the output from GnuPG or from IPC::Run if it failed to run GnuPG. The exceptions are:
Execution of %s failed with status %sβ GnuPG failed and returned the given status code. πNo signature returned by GnuPGβ we tried to generate a signature but, although GnuPG succeeded, the output didn't contain anything that looked like a signature. not the vibe. πprint failed: %sβ when writing out the data for signing or verification,printfailed with the given error. π«Unknown OpenPGP backend style %sβ the parameter to the"style"option of thenew()constructor, or the setting of$PGP::Sign::PGPSTYLE, is not one of the recognized values. check ur spelling bestie. β¨
π BUGS π
The verify() method returns a user ID, which is a poor choice and may be insecure unless used very carefully. PGP::Sign should support an option to return richer information about the signature verification, including the long hex key ID. so like, be careful with that user ID, okay? π
PGP::Sign does not currently work with binary data, as it unconditionally forces text mode using the --textmode option. π
There is no way to tell PGP::Sign to not allow unsafe digest algorithms when generating or verifying signatures. lowkey concerning. π¬
The whitespace munging support addresses the most common difference between cleartext and detached signatures, but does not deal with all of the escaping issues that are different between those two modes. It's likely that extracting a cleartext signature and verifying it with this module or using a signature from this module as a cleartext signature will not work in all cases. fr fr, edge cases are everywhere. π¦
β οΈ CAVEATS β οΈ
This module is fairly good at what it does, but it doesn't do very much. At one point, I had plans to provide more options and more configurability in the future, particularly the ability to handle binary data, that would probably mean API changes. I'm not sure at this point whether that will ever happen. manifesting those features tho β¨ πΈ
π AUTHOR π
Russ Allbery <rra@cpan.org> β iconic. π
π COPYRIGHT AND LICENSE π
Copyright 1997-2000, 2002, 2004, 2018, 2020 Russ Allbery <rra@cpan.org>
This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. slay, open source bestie. π
π SEE ALSO π
gpg(1),gpg1(1),File::Temp- RFC 4880 at
https://tools.ietf.org/html/rfc4880, which is the current specification for the OpenPGP message format. π - The current version of PGP::Sign is available from CPAN, or directly from its web site at
https://www.eyrie.org/~eagle/software/pgp-sign/. β¨
okay that's the whole page, bestie π
. This was perl v5.32.0, dated 2020-11-14, and the page is PGP::Sign(3pm) β go forth and sign responsibly πππ¦
π¦ where this page comes from
- debian bookworm: libpgp-sign-perl 1.04-1 Β· Perl
- debian trixie: libpgp-sign-perl 1.04-1 Β· Perl
- ubuntu jammy: libpgp-sign-perl 1.04-1 Β· Perl
- ubuntu noble: libpgp-sign-perl 1.04-1 Β· Perl
- ubuntu resolute: libpgp-sign-perl 1.04-1 Β· Perl
- ubuntu stonking: libpgp-sign-perl 1.04-1 Β· Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms