[Pkg-privacy-commits] [msva-perl] 332/356: Add GnuPGKey_to_OpenSSH_fpr

Ximin Luo infinity0 at moszumanska.debian.org
Mon Aug 24 07:42:10 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch debian
in repository msva-perl.

commit f9871e32622786e24bd5ad32f6849e6e6235b323
Author: David Bremner <bremner at unb.ca>
Date:   Thu Apr 28 08:50:52 2011 -0300

    Add GnuPGKey_to_OpenSSH_fpr
    
    This copies sshfpr from monkeysphere, and pastes it into the skeleton of
    OpenPGKey_to_OpenSSH_pub. Monkeyprogramming at its finest.
---
 Crypt/Monkeysphere/Keytrans.pm                     | 37 +++++++++++++++++++++-
 .../40.keytrans/{10.openpgp2ssh.t => 20.sshfpr.t}  | 11 ++-----
 2 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/Crypt/Monkeysphere/Keytrans.pm b/Crypt/Monkeysphere/Keytrans.pm
index 1754a76..16542c1 100644
--- a/Crypt/Monkeysphere/Keytrans.pm
+++ b/Crypt/Monkeysphere/Keytrans.pm
@@ -7,7 +7,7 @@ use Carp;
 use MIME::Base64;
 
 use Exporter qw(import);
-our @EXPORT_OK=qw(GnuPGKey_to_OpenSSH_pub);
+our @EXPORT_OK=qw(GnuPGKey_to_OpenSSH_pub GnuPGKey_to_OpenSSH_fpr);
 
 
 # takes a Math::BigInt and returns it properly packed for openssh output.
@@ -47,6 +47,41 @@ sub openssh_rsa_pubkey_pack {
 	openssh_mpi_pack($modulus);
 }
 
+# calculate/print the fingerprint of an openssh-style keyblob:
+
+sub sshfpr {
+  my $keyblob = shift;
+  use Digest::MD5;
+  return join(':', map({unpack("H*", $_)} split(//, Digest::MD5::md5($keyblob))));
+}
+
+=pod
+
+=head2 GnuPGKey_to_OpenSSH_fpr
+
+Find the openssh compatible fingerprint of an (RSA) GnuPG::Key
+
+B<Note> you will need to add add bits and (RSA) to the string to
+exactly match the output of ssh-keygen -l.
+
+=head3 Arguments
+
+key - GnuPG::Key object
+
+=cut
+
+sub GnuPGKey_to_OpenSSH_fpr {
+  my $key = shift;
+
+  croak("not a GnuPG::Key!")
+    unless($key->isa('GnuPG::Key'));
+
+  croak("Not an RSA key!")
+    unless $key->algo_num == 1;
+
+  return sshfpr(openssh_rsa_pubkey_pack(@{$key->pubkey_data}), '');
+}
+
 =pod
 
 =head2 GnuPGKey_to_OpenSSH_pub
diff --git a/unit-tests/40.keytrans/10.openpgp2ssh.t b/unit-tests/40.keytrans/20.sshfpr.t
similarity index 79%
copy from unit-tests/40.keytrans/10.openpgp2ssh.t
copy to unit-tests/40.keytrans/20.sshfpr.t
index ed042fa..d00a4b6 100644
--- a/unit-tests/40.keytrans/10.openpgp2ssh.t
+++ b/unit-tests/40.keytrans/20.sshfpr.t
@@ -1,7 +1,7 @@
 # -*- perl -*-
 use Test::More;
 
-use Crypt::Monkeysphere::Keytrans qw(GnuPGKey_to_OpenSSH_pub);
+use Crypt::Monkeysphere::Keytrans qw(GnuPGKey_to_OpenSSH_fpr);
 use GnuPG::Interface;
 use File::Temp qw(tempdir);
 
@@ -29,7 +29,7 @@ IMHmPE33qqvifV9dFGlIGa4a3tmGjJvjhKmNSJGJWG9wRK3C2BrJdQVF9sk2FHXd
 ";
 
 
-my $sshdata = "AAAAB3NzaC1yc2EAAAADAQABAAAAgQCyYbB4CxKJLyjPndaAAMvqGg8sC1rG6s7ggqruYfR7uzGMXhpkwLYPH12rYFxAVFHvntYtWhfeJE6nKnEuTPu9XHtshzcsZe1NKRlTDj4hYkVSivMf+8BNi02jx4bJHPJJCq8aCTG15p9DqucJ/MS5InSLFRPgMkPh2w/Qu1AJ4Q==";
+my $sshdata = "e6:b3:db:be:c6:5d:f7:65:f2:bb:6e:06:69:36:f5:e5";
 
 
 my $input = IO::Handle->new();
@@ -47,11 +47,6 @@ waitpid($pid, 0);
 my @keys = $gnupg->get_public_keys();
 
 foreach $key (@keys) {
-  my $output = GnuPGKey_to_OpenSSH_pub($key);
+  my $output = GnuPGKey_to_OpenSSH_fpr($key);
   is($sshdata, $output);
 }
-
-
-
-
-

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/msva-perl.git



More information about the Pkg-privacy-commits mailing list