Subject: | PATCH: get_pubkey support |
Hi Ionut,
I need this patch applied. Hope it looks all right.
Cheers
Dave
Subject: | pkcs10_get_pubkey.patch |
diff -Naur old/PKCS10.pm new/PKCS10.pm
--- old/PKCS10.pm 2014-09-17 04:49:27.000000000 +1000
+++ new/PKCS10.pm 2015-08-07 19:42:59.727822217 +1000
@@ -58,6 +58,7 @@
$req->sign();
$req->write_pem_req('request.pem');
$req->write_pem_pk('pk.pem');
+ print $req->get_pubkey();
print $req->get_pem_req();
=head1 ABSTRACT
@@ -135,6 +136,12 @@
$req->sign();
+=item get_pubkey()
+
+Returns the PEM encoding of the PKCS10 public key.
+
+ $req->get_pubkey();
+
=item get_pem_req()
Returns the PEM encoding of the PKCS10 request.
diff -Naur old/PKCS10.xs new/PKCS10.xs
--- old/PKCS10.xs 2014-09-17 04:48:21.000000000 +1000
+++ new/PKCS10.xs 2015-08-07 19:41:46.128669944 +1000
@@ -417,6 +417,51 @@
RETVAL
SV*
+get_pubkey(pkcs10)
+ pkcs10Data *pkcs10;
+
+ PREINIT:
+ EVP_PKEY *pkey;
+ BIO *bio;
+
+ CODE:
+
+ pkey = X509_REQ_get_pubkey(pkcs10->req);
+ bio = sv_bio_create();
+
+ if (pkey == NULL) {
+
+ BIO_free_all(bio);
+ EVP_PKEY_free(pkey);
+ croak("Public Key is unavailable\n");
+ }
+
+ if (pkey->type == EVP_PKEY_RSA) {
+
+ PEM_write_bio_RSAPublicKey(bio, pkey->pkey.rsa);
+
+ } else if (pkey->type == EVP_PKEY_DSA) {
+
+ PEM_write_bio_DSA_PUBKEY(bio, pkey->pkey.dsa);
+#ifndef OPENSSL_NO_EC
+ } else if ( pkey->type == EVP_PKEY_EC ) {
+ PEM_write_bio_EC_PUBKEY(bio, pkey->pkey.ec);
+#endif
+ } else {
+
+ BIO_free_all(bio);
+ EVP_PKEY_free(pkey);
+ croak("Wrong Algorithm type\n");
+ }
+ EVP_PKEY_free(pkey);
+
+ RETVAL = sv_bio_final(bio);
+
+ OUTPUT:
+ RETVAL
+
+
+SV*
get_pem_req(pkcs10,...)
pkcs10Data *pkcs10;
diff -Naur old/t/Mytest.t new/t/Mytest.t
--- old/t/Mytest.t 2014-04-18 03:35:14.000000000 +1000
+++ new/t/Mytest.t 2015-08-07 19:42:01.168905453 +1000
@@ -29,6 +29,7 @@
print STDERR $req->get_pem_req();
print STDERR $req->subject()."\n";
print STDERR $req->keyinfo()."\n";
+print STDERR $req->get_pubkey()."\n";
ok($req);
}
@@ -46,6 +47,7 @@
print STDERR $req->get_pem_req();
print STDERR $req->subject()."\n";
print STDERR $req->keyinfo()."\n";
+print STDERR $req->get_pubkey()."\n";
ok($req);
}
@@ -53,5 +55,6 @@
my $req = Crypt::OpenSSL::PKCS10->new_from_file("t/CSR.csr");
print STDERR $req->subject()."\n";
print STDERR $req->keyinfo()."\n";
+print STDERR $req->get_pubkey()."\n";
ok($req);
}