Skip to content

Commit

Permalink
import Crypt::OpenPGP 0.17 from CPAN
Browse files Browse the repository at this point in the history
git-cpan-module: Crypt::OpenPGP
git-cpan-version: 0.17
  • Loading branch information
Benjamin Trott authored and Benjamin Trott committed Dec 10, 2009
1 parent d374ef0 commit b097cd8
Show file tree
Hide file tree
Showing 15 changed files with 453 additions and 249 deletions.
17 changes: 16 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
$Id: Changes,v 1.55 2001/08/16 01:04:56 btrott Exp $
$Id: Changes,v 1.60 2001/09/16 04:48:53 btrott Exp $

Revision history for Crypt::OpenPGP

0.17 2001.09.15
- Added Crypt::OpenPGP::Config to hold per-instance configuration
information, either specified through the constructor, or set
in a config file. Reads from existing PGP/GnuPG config files.
- Added --compat arg to bin/pgplet for demonstration of usage of
Compat flag to constructor, which then gets propagated down to
methods, selects keyrings, etc.
- Made keyring selection based on compatibility mode, if given.
- Automatically read in appropriate config file if Compat flag
given.
- Added tests for encrypting/decrypting block of text to t/06-cipher.t.
- Added --sdk option to Makefile.Pl to bypass interactive prompts.
- Removed Crypt::DES_EDE3 from this distribution, moved into its own
distribution.

0.16 2001.08.15
- Took stupid extraneous files out of lib. Ick.

Expand Down
5 changes: 4 additions & 1 deletion MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Makefile.PL
README
ToDo
bin/pgplet
lib/Crypt/DES_EDE3.pm
lib/Crypt/OpenPGP.pm
lib/Crypt/OpenPGP/Armour.pm
lib/Crypt/OpenPGP/Buffer.pm
Expand All @@ -14,6 +13,7 @@ lib/Crypt/OpenPGP/Certificate.pm
lib/Crypt/OpenPGP/Cipher.pm
lib/Crypt/OpenPGP/Ciphertext.pm
lib/Crypt/OpenPGP/Compressed.pm
lib/Crypt/OpenPGP/Config.pm
lib/Crypt/OpenPGP/Constants.pm
lib/Crypt/OpenPGP/Digest.pm
lib/Crypt/OpenPGP/ErrorHandler.pm
Expand Down Expand Up @@ -52,10 +52,13 @@ t/05-packets.t
t/06-cipher.t
t/07-digest.t
t/08-compress.t
t/09-config.t
t/10-keyring.t
t/11-encrypt.t
t/12-sign.t
t/13-keygen.t
t/samples/cfg.gnupg
t/samples/cfg.pgp2
t/samples/gpg/ring.pub
t/samples/gpg/ring.sec
t/test-common.pl
119 changes: 67 additions & 52 deletions Makefile.PL
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# $Id: Makefile.PL,v 1.9 2001/07/31 07:03:52 btrott Exp $
# $Id: Makefile.PL,v 1.11 2001/09/16 04:48:53 btrott Exp $

use ExtUtils::MakeMaker qw( prompt WriteMakefile );
use strict;

my $is_sdk = 0;
for my $arg (@ARGV) {
$is_sdk = 1, last if $arg eq '--sdk';
}

my %BASE_PREREQS = (
'Data::Buffer' => '0.04',
'MIME::Base64' => 0,
Expand All @@ -16,7 +21,7 @@ my %BASE_PREREQS = (
my %prereq = %BASE_PREREQS;

my @cryptmod = (
[ '3DES' => 'Crypt::DES' ],
[ '3DES' => 'Crypt::DES_EDE3' ],
[ 'IDEA' => 'Crypt::IDEA' ],
[ 'Blowfish' => 'Crypt::Blowfish' ],
[ 'Twofish' => 'Crypt::Twofish', '2.00' ],
Expand All @@ -35,7 +40,16 @@ my @pkmod = (
[ 'RSA' => 'Crypt::RSA' ],
);

print<<MSG;
if ($is_sdk) {
for my $list (\@cryptmod, \@dgstmod, \@pkmod) {
for my $ref (@$list) {
if ($ref->[1]) {
$prereq{$ref->[1]} = $ref->[2] ? $ref->[2] : 0;
}
}
}
} else {
print<<MSG;
This is Crypt::OpenPGP, a pure-Perl implementation of the OpenPGP
standard.
Expand All @@ -47,19 +61,19 @@ Please choose at least one from the following list (3DES is the
default).
MSG
my $i = 1;
for my $ciph (@cryptmod) {
printf " [%d] %s\n", $i++, $ciph->[0];
}
my $c = prompt("\nEnter your choices, separated by spaces:", 1);
print "\n";
my $i = 1;
for my $ciph (@cryptmod) {
printf " [%d] %s\n", $i++, $ciph->[0];
}
my $c = prompt("\nEnter your choices, separated by spaces:", 1);
print "\n";

for my $id (split /\s+/, $c) {
next unless $cryptmod[$id-1]->[1];
$prereq{ $cryptmod[$id-1]->[1] } = $cryptmod[$id-1]->[2] || '0';
}
for my $id (split /\s+/, $c) {
next unless $cryptmod[$id-1]->[1];
$prereq{ $cryptmod[$id-1]->[1] } = $cryptmod[$id-1]->[2] || '0';
}

print<<MSG;
print<<MSG;
Each of the Crypt::OpenPGP digest algorithms depends on a module
from the CPAN. You may already have the necessary module(s)
installed, in which you don't need to bother with this step.
Expand All @@ -68,21 +82,21 @@ Please choose at least one from the following list (SHA-1 is the
default).
MSG
my $i = 1;
for my $ciph (@dgstmod) {
printf " [%d] %s\n", $i++, $ciph->[0];
}
my $c = prompt("\nEnter your choices, separated by spaces:", 2);
print "\n";
my $i = 1;
for my $ciph (@dgstmod) {
printf " [%d] %s\n", $i++, $ciph->[0];
}
my $c = prompt("\nEnter your choices, separated by spaces:", 2);
print "\n";

for my $id (split /\s+/, $c) {
next unless $dgstmod[$id-1]->[1];
$prereq{ $dgstmod[$id-1]->[1] } = '0';
}
for my $id (split /\s+/, $c) {
next unless $dgstmod[$id-1]->[1];
$prereq{ $dgstmod[$id-1]->[1] } = '0';
}

=pod
print<<MSG;
print<<MSG;
Crypt::OpenPGP also requires at least one public-key implementation;
it may require more, depending on what types of keys you use in
Expand All @@ -94,32 +108,32 @@ to use with Crypt::OpenPGP. Please choose at least one from the
following list (DSA and ElGamal are the defaults).
MSG
my $i = 1;
for my $pk (@pkmod) {
printf " [%d] %s\n", $i++, $pk->[0];
}
my $c = prompt("\nEnter your choices, separated by spaces:", '1 2');
print "\n";
my $i = 1;
for my $pk (@pkmod) {
printf " [%d] %s\n", $i++, $pk->[0];
}
my $c = prompt("\nEnter your choices, separated by spaces:", '1 2');
print "\n";
for my $id (split /\s+/, $c) {
next unless $pkmod[$id-1]->[1];
$prereq{ $pkmod[$id-1]->[1] } = '0';
}
for my $id (split /\s+/, $c) {
next unless $pkmod[$id-1]->[1];
$prereq{ $pkmod[$id-1]->[1] } = '0';
}
=cut

print "\nChecking for required modules\n\n";
my(%todo, $missing);
while (my($k, $v) = each %prereq) {
unless (check_module($k, $v, \$missing)) {
$todo{$k} = $v;
print "\nChecking for required modules\n\n";
my(%todo, $missing);
while (my($k, $v) = each %prereq) {
unless (check_module($k, $v, \$missing)) {
$todo{$k} = $v;
}
}
}
use Cwd;
my $cwd = cwd();
use Cwd;
my $cwd = cwd();

if (%todo) {
print <<MSG;
if (%todo) {
print <<MSG;
Crypt::OpenPGP depends on several external modules for functionality.
Some of these modules can not be found on your system; they can be
installed automatically for you. To do so will require loading the
Expand All @@ -130,17 +144,18 @@ install them to use Crypt::OpenPGP.
MSG

while (my($k, $v) = each %todo) {
if (prompt(sprintf("%s%s not installed/out of date. Install (y/n)?",
$k, $v ? " (ver. $v)" : ""), "y") =~ /^y/) {
require CPAN; CPAN::Shell->install($k);
delete $prereq{$k};
chdir $cwd or die "Can't chdir back to $cwd: $!";
while (my($k, $v) = each %todo) {
if (prompt(sprintf("%s%s not installed/out of date. Install (y/n)?",
$k, $v ? " (ver. $v)" : ""), "y") =~ /^y/) {
require CPAN; CPAN::Shell->install($k);
delete $prereq{$k};
chdir $cwd or die "Can't chdir back to $cwd: $!";
}
}
}
print "\n";
}

print "\n";
WriteMakefile(
NAME => 'Crypt::OpenPGP',
DISTNAME => 'Crypt-OpenPGP',
Expand Down
4 changes: 2 additions & 2 deletions README
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$Id: README,v 1.6 2001/08/15 22:11:14 btrott Exp $
$Id: README,v 1.7 2001/09/16 04:48:53 btrott Exp $

This is Crypt::OpenPGP. It provides a pure-Perl implementation of the
OpenPGP standard, including support for all versions of PGP and
Expand All @@ -16,7 +16,7 @@ Crypt::OpenPGP requires the following Perl modules:
Depending on which symmetric ciphers you use, you will require
at least one of the following modules:

* Crypt::DES (for 3DES)
* Crypt::DES_EDE3 (for 3DES)
* Crypt::IDEA (for IDEA)
* Crypt::Blowfish (for Blowfish)
* Crypt::Twofish (for Twofish)
Expand Down
4 changes: 2 additions & 2 deletions ToDo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$Id: ToDo,v 1.31 2001/08/12 23:33:07 btrott Exp $
$Id: ToDo,v 1.32 2001/09/16 04:48:53 btrott Exp $

Crypt::OpenPGP todo
--------
Expand Down Expand Up @@ -26,7 +26,7 @@ xx * KeyRing::find_keyblock_by_keyid should no longer return certificate if
rings.
xx * compatibility param to encrypt and sign (and keygen, maybe), eg.
Compat => 'PGP2' turns on Version => 3 and Cipher => 'IDEA'
* read existing PGPx/GnuPG config files into Config object
xx * read existing PGPx/GnuPG config files into Config object
* smart detection and description of arbitrary files, eg. pass in some
data and give back 'RSA signed message, Version 3, probably PGP2'
xx * compressed packets
Expand Down
34 changes: 19 additions & 15 deletions bin/pgplet
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/perl -w
# $Id: pgplet,v 1.5 2001/08/15 22:21:27 btrott Exp $
# $Id: pgplet,v 1.8 2001/08/30 03:40:24 btrott Exp $

use lib 'lib';

Expand All @@ -16,10 +16,15 @@ GetOptions(\%opts, "sign|s", "encrypt|e", "detach-sign|b",
"list-public-keys", "list-secret-keys",
"fingerprint", "keyring=s", "secret-keyring=s",
"recipient|r=s@", "armour|a", "clearsign",
"enarmour", "dearmour");
"enarmour", "dearmour", "compat=s");

my $pgp = Crypt::OpenPGP->new( PubRing => $opts{keyring},
SecRing => $opts{'secret-keyring'} );
my %arg;
$arg{PubRing} = $opts{keyring} if $opts{keyring};
$arg{SecRing} = $opts{'secret-keyring'} if $opts{'secret-keyring'};
$arg{Compat} = $opts{compat} if $opts{compat};

my $pgp = Crypt::OpenPGP->new( %arg ) or
die Crypt::OpenPGP->errstr;

my @args = ($pgp, \%opts, \@ARGV);

Expand Down Expand Up @@ -48,7 +53,7 @@ if ($opts{'list-keys'} || $opts{'list-public-keys'}) {
sub do_list_keys {
my($pgp, $opts, $args, $secret) = @_;
my $fp = $opts->{fingerprint};
my $ring_file = $pgp->{ $secret ? 'SecRing' : 'PubRing' };
my $ring_file = $pgp->{cfg}->get( $secret ? 'SecRing' : 'PubRing' );
my $ring = Crypt::OpenPGP::KeyRing->new( Filename => $ring_file );
$ring->read;
my @blocks = $ring->blocks;
Expand All @@ -60,7 +65,7 @@ sub do_list_keys {
($cert->is_secret ? 'sec' : 'pub'),
$cert->key->size,
$cert->key->public_key->abbrev,
uc unpack('H*', substr $cert->key_id, -4, 4),
substr($cert->key_id_hex, -8, 8),
($kb->primary_uid || '');
if ($fp) {
my $f = $cert->fingerprint;
Expand All @@ -72,7 +77,7 @@ sub do_list_keys {
($sub->is_secret ? 'ssb' : 'sub'),
$sub->key->size,
$sub->key->public_key->abbrev,
uc unpack('H*', substr $sub->key_id, -4, 4),
substr($cert->key_id_hex, -8, 8),
}
print "\n";
}
Expand All @@ -92,7 +97,7 @@ Message is being encrypted to:
for my $cert (@$keys) {
$prompt .= sprintf " [%d] %s (ID %s)\n",
$i++, $cert->uid,
uc unpack('H*', substr $cert->key_id, -4, 4);
substr($cert->key_id_hex, -8, 8);
}
$prompt .= "
If these are the intended recipients, press <enter>. Otherwise,
Expand All @@ -114,9 +119,8 @@ Enter numeric indices, separated by spaces: ";
my $ct = $pgp->encrypt(
Recipients => $recips,
RecipientsCallback => $cb,
Compat => 'GnuPG',
Filename => $file,
Armour => $opts->{armour},
$opts->{armour} ? (Armour => $opts->{armour}) : (),
%sign_args,
) or die $pgp->errstr;
print $ct;
Expand Down Expand Up @@ -155,13 +159,12 @@ sub do_sign {
my $cert = find_default_seckey($pgp);
until ($sig) {
$sig = $pgp->sign(
Compat => 'GnuPG',
Filename => $file,
Detach => $detach,
Clearsign => $clear,
Key => $cert,
PassphraseCallback => \&passphrase_cb,
Armour => $opts->{armour},
$opts->{armour} ? (Armour => $opts->{armour}) : (),
);
unless ($sig) {
if ($pgp->errstr =~ /Bad checksum/) {
Expand Down Expand Up @@ -210,14 +213,15 @@ user "%s".
Enter passphrase: ), $cert->uid,
$cert->key->size,
$cert->key->alg,
uc unpack('H*', substr $cert->key_id, -4, 4);
substr($cert->key_id_hex, -8, 8);
prompt($prompt, '', 1);
}

sub find_default_seckey {
my($pgp) = @_;
my $ring = Crypt::OpenPGP::KeyRing->new( Filename => $pgp->{SecRing} ) or
return $pgp->error(Crypt::OpenPGP::KeyRing->errstr);
my $ring = Crypt::OpenPGP::KeyRing->new( Filename =>
$pgp->{cfg}->get('SecRing') ) or
return $pgp->error(Crypt::OpenPGP::KeyRing->errstr);
my $kb = $ring->find_keyblock_by_index(-1) or
return $pgp->error("Can't find last keyblock: " . $ring->errstr);
my $cert = $kb->signing_key;
Expand Down
Loading

0 comments on commit b097cd8

Please sign in to comment.