| 1 |
root |
1.1 |
=head1 NAME |
| 2 |
|
|
|
| 3 |
|
|
Net::FCP::Key::SSK - manage SSK keys. |
| 4 |
|
|
|
| 5 |
|
|
=head1 SYNOPSIS |
| 6 |
|
|
|
| 7 |
|
|
use Net::FCP::Key::SSK; |
| 8 |
|
|
|
| 9 |
|
|
my $key = new Net::FCP::Key::SSK $public, $private[, $crypto] |
| 10 |
|
|
my $key = new_from_file Net::FCP::Key::SSK $path; |
| 11 |
|
|
my $key = new_from_fcp Net::FCP::Key::SSK $fcp; |
| 12 |
|
|
my $key = new_from_string Net::FCP::Key::SSK $string; |
| 13 |
|
|
|
| 14 |
|
|
$key->as_string; |
| 15 |
|
|
$key->save ($path); |
| 16 |
|
|
|
| 17 |
|
|
my $ssk_public_uri = $key->gen_pub ($name); |
| 18 |
|
|
my $ssk_private_uri = $key->gen_priv ($name); |
| 19 |
|
|
|
| 20 |
|
|
=head1 DESCRIPTION |
| 21 |
|
|
|
| 22 |
|
|
=head2 THE Net::FCP::Key::SSK CLASS |
| 23 |
|
|
|
| 24 |
|
|
=over 4 |
| 25 |
|
|
|
| 26 |
|
|
=cut |
| 27 |
|
|
|
| 28 |
|
|
package Net::FCP::Key::SSK; |
| 29 |
|
|
|
| 30 |
|
|
use Carp; |
| 31 |
|
|
|
| 32 |
|
|
no warnings; |
| 33 |
|
|
|
| 34 |
|
|
=item my $key = new Net::FCP::Key::SSK $public, $private[, $crypto] |
| 35 |
|
|
|
| 36 |
|
|
=item my $key = new_from_file Net::FCP::Key::SSK $path; |
| 37 |
|
|
|
| 38 |
|
|
=item my $key = new_from_fcp Net::FCP::Key::SSK $fcp; |
| 39 |
|
|
|
| 40 |
|
|
Various way to create a SSK key object. |
| 41 |
|
|
|
| 42 |
|
|
=cut |
| 43 |
|
|
|
| 44 |
|
|
sub new { |
| 45 |
|
|
my $class = shift; |
| 46 |
|
|
|
| 47 |
|
|
bless { |
| 48 |
|
|
pub => $_[0], |
| 49 |
|
|
pri => $_[1], |
| 50 |
|
|
ent => $_[2], |
| 51 |
|
|
}, $class; |
| 52 |
|
|
} |
| 53 |
|
|
|
| 54 |
|
|
sub new_from_fcp { |
| 55 |
|
|
my ($class, $fcp) = @_; |
| 56 |
|
|
|
| 57 |
|
|
$class->new (@{ $fcp->generate_svk_pair }) |
| 58 |
|
|
} |
| 59 |
|
|
|
| 60 |
|
|
sub new_from_string { |
| 61 |
|
|
my ($class, $string) = @_; |
| 62 |
|
|
|
| 63 |
|
|
$class->new ((split /[\x00-\x1f,]/, $string)[0,1,2]) |
| 64 |
|
|
} |
| 65 |
|
|
|
| 66 |
|
|
sub new_from_file { |
| 67 |
|
|
my ($class, $path) = @_; |
| 68 |
|
|
|
| 69 |
|
|
open my $fh, "<", $path |
| 70 |
|
|
or croak "$path: $!"; |
| 71 |
|
|
|
| 72 |
|
|
$class->new_from_string (scalar readline $fh); |
| 73 |
|
|
} |
| 74 |
|
|
|
| 75 |
|
|
=item $key->save ($path) |
| 76 |
|
|
|
| 77 |
|
|
Write the key to the givne file. Unencrypted. |
| 78 |
|
|
|
| 79 |
|
|
=cut |
| 80 |
|
|
|
| 81 |
|
|
sub save { |
| 82 |
|
|
my ($self, $path) = @_; |
| 83 |
|
|
|
| 84 |
|
|
open my $fh, ">", $path |
| 85 |
|
|
or croak "$path: $!"; |
| 86 |
|
|
|
| 87 |
|
|
print $fh $self->as_string, "\n"; |
| 88 |
|
|
} |
| 89 |
|
|
|
| 90 |
|
|
=item $key->as_string |
| 91 |
|
|
|
| 92 |
|
|
Returns a stringified version fo the key data (in no standard format). |
| 93 |
|
|
|
| 94 |
|
|
=cut |
| 95 |
|
|
|
| 96 |
|
|
sub as_string { |
| 97 |
|
|
my ($self) = @_; |
| 98 |
|
|
|
| 99 |
|
|
"$self->{pub},$self->{pri},$self->{ent}"; |
| 100 |
|
|
} |
| 101 |
|
|
|
| 102 |
|
|
=item my $puburi = $key->gen_pub ($name) |
| 103 |
|
|
|
| 104 |
|
|
Build a public SSK subkey with the given name and return it as a URI without |
| 105 |
|
|
C<freenet:>-prefix. |
| 106 |
|
|
|
| 107 |
|
|
=cut |
| 108 |
|
|
|
| 109 |
|
|
sub gen_pub { |
| 110 |
|
|
my ($self, $name) = @_; |
| 111 |
|
|
|
| 112 |
|
|
"SSK\@$self->{pub}PAgM,$self->{ent}/$name"; |
| 113 |
|
|
} |
| 114 |
|
|
|
| 115 |
|
|
=item my $privuri = $key->gen_priv ($name) |
| 116 |
|
|
|
| 117 |
|
|
Build a private SSK subkey with the given name and return it as a URI without |
| 118 |
|
|
C<freenet:>-prefix. |
| 119 |
|
|
|
| 120 |
|
|
=cut |
| 121 |
|
|
|
| 122 |
|
|
sub gen_priv { |
| 123 |
|
|
my ($self, $name) = @_; |
| 124 |
|
|
|
| 125 |
|
|
"SSK\@$self->{pri},$self->{ent}/$name"; |
| 126 |
|
|
} |
| 127 |
|
|
|
| 128 |
|
|
=back |
| 129 |
|
|
|
| 130 |
|
|
=head1 SEE ALSO |
| 131 |
|
|
|
| 132 |
|
|
L<Net::FCP>. |
| 133 |
|
|
|
| 134 |
|
|
=head1 BUGS |
| 135 |
|
|
|
| 136 |
|
|
Not heavily tested. |
| 137 |
|
|
|
| 138 |
|
|
=head1 AUTHOR |
| 139 |
|
|
|
| 140 |
|
|
Marc Lehmann <pcg@goof.com> |
| 141 |
root |
1.2 |
http://home.schmorp.de/ |
| 142 |
root |
1.1 |
|
| 143 |
|
|
=cut |
| 144 |
|
|
|
| 145 |
|
|
1; |
| 146 |
|
|
|