Subject: | PATCH: Support for reading a PKCS10 file in DER format |
Hi Ionut,
Thanks for applying my last patch. This one adds support for reading DER encoded files in the new_from_file method.
I copied the interface style from the Crypt-OpenSSL-X509 module.
Cheers
Dave
Subject: | pkcs10_new_from_file_format.patch |
diff -Naur old/MANIFEST new/MANIFEST
--- old/MANIFEST 2013-08-21 16:53:03.000000000 +1000
+++ new/MANIFEST 2015-08-09 16:48:34.387844267 +1000
@@ -7,6 +7,7 @@
README
t/Mytest.t
t/CSR.csr
+t/CSR.der
PKCS10.pm
META.yml Module meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)
diff -Naur old/PKCS10.pm new/PKCS10.pm
--- old/PKCS10.pm 2015-08-08 16:11:32.000000000 +1000
+++ new/PKCS10.pm 2015-08-09 16:50:13.498523190 +1000
@@ -92,6 +92,12 @@
my $req = Crypt::OpenSSL::PKCS10->new_from_file("CSR.csr");
+Can also specify the format of the PKCS10 file, either DER or PEM format. Here are some examples:
+
+ my $req = Crypt::OpenSSL::PKCS10->new_from_file("CSR.csr", Crypt::OpenSSL::PKCS10::FORMAT_PEM());
+
+ my $req = Crypt::OpenSSL::PKCS10->new_from_file("CSR.der", Crypt::OpenSSL::PKCS10::FORMAT_ASN1());
+
=back
=head1 Instance Methods
diff -Naur old/PKCS10.xs new/PKCS10.xs
--- old/PKCS10.xs 2015-08-08 16:11:32.000000000 +1000
+++ new/PKCS10.xs 2015-08-09 16:48:22.469048278 +1000
@@ -32,6 +32,9 @@
if (New(0, p_var, p_size, p_type) == NULL) \
{ PACKAGE_CROAK("unable to alloc buffer"); }
+#define FORMAT_ASN1 1
+#define FORMAT_PEM 3
+
//int add_ext_raw(STACK_OF(X509_REQUEST) *sk, int nid, unsigned char *value, int length);
//int add_ext(STACK_OF(X509_REQUEST) *sk, int nid, char *value);
X509_NAME *parse_name(char *str, long chtype, int multirdn);
@@ -312,6 +315,8 @@
{"NID_netscape_comment", NID_netscape_comment},
{"NID_ext_key_usage", NID_ext_key_usage},
{"NID_subject_key_identifier", NID_subject_key_identifier},
+ {"FORMAT_ASN1", FORMAT_ASN1},
+ {"FORMAT_PEM", FORMAT_PEM},
{Nullch,0}};
char *name;
@@ -669,9 +674,10 @@
RETVAL
SV*
-new_from_file(class, filename_SV)
+new_from_file(class, filename_SV, format = FORMAT_PEM)
SV* class;
SV* filename_SV;
+ int format;
PREINIT:
unsigned char* filename;
@@ -682,7 +688,11 @@
CODE:
filename = SvPV(filename_SV, filename_length);
fp = fopen(filename, "r");
- req = PEM_read_X509_REQ (fp, NULL, NULL, NULL);
+ if (format == FORMAT_ASN1)
+ req = d2i_X509_REQ_fp (fp, NULL);
+ else
+ req = PEM_read_X509_REQ (fp, NULL, NULL, NULL);
+
fclose(fp);
RETVAL = make_pkcs10_obj(class, req, NULL, NULL, NULL);
diff -Naur old/t/CSR.der new/t/CSR.der
--- old/t/CSR.der 1970-01-01 10:00:00.000000000 +1000
+++ new/t/CSR.der 2015-08-09 16:42:23.526428029 +1000
@@ -0,0 +1,6 @@
+0«0 0f10 UDE10
+UNRW10
+UFoo1!0U
+Internet Widgits Pty Ltd10Ufoo.der.bar.com0"0
*H÷
0
+ Àó(