/usr/share/perl5/Mail/DKIM/PrivateKey.pm is in libmail-dkim-perl 0.39-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | #!/usr/bin/perl
# Copyright 2005-2007 Messiah College. All rights reserved.
# Jason Long <jlong@messiah.edu>
#
# Copyright (c) 2004 Anthony D. Urso. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
use strict;
use warnings;
=head1 NAME
Mail::DKIM::PrivateKey - a private key loaded in memory for DKIM signing
=head1 SYNOPSIS
my $key1 = Mail::DKIM::PrivateKey->load(
File => "/path/to/private.key");
my $key2 = Mail::DKIM::PrivateKey->load(
Data => $base64);
# use the loaded key in a DKIM signing object
my $dkim = Mail::DKIM::Signer->new(
Key => $key2,
);
=cut
package Mail::DKIM::PrivateKey;
use base "Mail::DKIM::Key";
use Carp;
*calculate_EM = \&Mail::DKIM::Key::calculate_EM;
=head1 CONSTRUCTOR
=head2 load() - loads a private key into memory
my $key1 = Mail::DKIM::PrivateKey->load(
File => "/path/to/private.key");
Loads the Base64-encoded key from the specified file.
my $key2 = Mail::DKIM::PrivateKey->load(Data => $base64);
Loads the Base64-encoded key from a string already in memory.
my $key3 = Mail::DKIM::PrivateKey->load(Cork => $openssl_object);
Creates a Mail::DKIM::PrivateKey wrapper object for the given
OpenSSL key object. The key object should be of type
L<Crypt::OpenSSL::RSA>.
=cut
sub load
{
my $class = shift;
my %prms = @_;
my $self = bless {}, $class;
$self->{'TYPE'} = ($prms{'Type'} or "rsa");
if ($prms{'Data'}) {
$self->{'DATA'} = $prms{'Data'};
} elsif (defined $prms{'File'}) {
my @data;
open FILE, "<", $prms{'File'}
or die "Error: cannot read $prms{File}: $!\n";
while (<FILE>) {
chomp;
/^---/ and
next;
push @data, $_;
}
$self->{'DATA'} = join '', @data;
} elsif ($prms{'Cork'}) {
$self->{'CORK'} = $prms{'Cork'};
} else {
croak "missing required argument";
}
return $self;
}
=head1 METHODS
=head2 cork() - access the underlying OpenSSL key object
$openssl_object = $key->cork;
The returned object is of type L<Crypt::OpenSSL::RSA>.
=cut
sub convert {
use Crypt::OpenSSL::RSA;
my $self = shift;
$self->data or
return;
# have to PKCS1ify the privkey because openssl is too finicky...
my $pkcs = "-----BEGIN RSA PRIVATE KEY-----\n";
for (my $i = 0; $i < length $self->data; $i += 64) {
$pkcs .= substr $self->data, $i, 64;
$pkcs .= "\n";
}
$pkcs .= "-----END RSA PRIVATE KEY-----\n";
my $cork;
eval {
$cork = new_private_key Crypt::OpenSSL::RSA($pkcs);
};
$@ and
$self->errorstr($@),
return;
$cork or
return;
# segfaults on my machine
# $cork->check_key or
# return;
$self->cork($cork);
return 1;
}
#deprecated
sub sign
{
my $self = shift;
my $mail = shift;
return $self->cork->sign($mail);
}
#deprecated- use sign_digest() instead
sub sign_sha1_digest
{
my $self = shift;
my ($digest) = @_;
return $self->sign_digest("SHA-1", $digest);
}
=head2 sign_digest()
Cryptographically sign the given message digest.
$key->sign_digest("SHA-1", sha1("my message text"));
The first parameter is the name of the digest: one of "SHA-1", "SHA-256".
The second parameter is the message digest as a binary string.
The result should be the signed digest as a binary string.
=cut
sub sign_digest
{
my $self = shift;
my ($digest_algorithm, $digest) = @_;
my $rsa_priv = $self->cork;
$rsa_priv->use_no_padding;
my $k = $rsa_priv->size;
my $EM = calculate_EM($digest_algorithm, $digest, $k);
return $rsa_priv->decrypt($EM);
}
=head1 AUTHOR
Jason Long, E<lt>jlong@messiah.eduE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2006-2008 by Messiah College
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.6 or,
at your option, any later version of Perl 5 you may have available.
=cut
1;
|