Subject: | Feature to extract certificates / 証明書抽出機能 |
Hi,
I wish the feature to extract certificates included in the messages so that identity of signature will be verified and so on.
A patch is attached.
Thanks,
こんにちは。
メッセージに含まれている証明書を抽出する機能が欲しいです。署名のアイデンティティを検証したりするためです。
パッチを添付します。
よろしくおねがいします。
Subject: | Crypt-SMIME-0.13-extractCertificates-20140802.patch |
diff -ur Crypt-SMIME-0.13.orig/SMIME.mlpod Crypt-SMIME-0.13/SMIME.mlpod
--- Crypt-SMIME-0.13.orig/SMIME.mlpod 2014-05-02 14:30:33.000000000 +0900
+++ Crypt-SMIME-0.13/SMIME.mlpod 2014-08-02 14:22:58.000000000 +0900
@@ -253,6 +253,31 @@
=back
+=head2 FUNCTION
+
+=over 4
+
+=item extractCertificates()
+
+ @certs = @{Crypt::SMIME::extractCertificates($data)};
+ @certs = @{Crypt::SMIME::extractCertificates($data, $type)};
+
+Get all certificates (and CRLs, if any) included in S/MIME message or PKCS#7
+object $data. Optional $type parameter may specify type of data:
+C<Crypt::SMIME::FORMAT_SMIME> (default) for S/MIME message;
+C<Crypt::SMIME::FORMAT_ASN1> for binary format;
+C<Crypt::SMIME::FORMAT_PEM> for PEM format.
+J<< ja;
+S/MIMEã¡ãã»ã¼ã¸ã¾ãã¯PKCS#7ãªãã¸ã§ã¯ãã«å«ã¾ãã証ææ¸
+(ã証ææ¸å¤±å¹ãªã¹ã) ããã¹ã¦åå¾ããã
+ãªãã·ã§ã³ã®$typeãã©ã¡ã¼ã¿ã§ãã¼ã¿ã®ç¨®é¡ãæå®ã§ããã
+C<Crypt::SMIME::FORMAT_SMIME> (åæå¤) ã¯S/MIMEã¡ãã»ã¼ã¸ã
+C<Crypt::SMIME::FORMAT_ASN1>ã¯ãã¤ããªå½¢å¼ã
+C<Crypt::SMIME::FORMAT_PEM>ã¯PEMå½¢å¼ã
+>>
+
+=back
+
=head1 AUTHOR
Copyright 2006-2007 YMIRLINK Inc. All Rights Reserved.
diff -ur Crypt-SMIME-0.13.orig/SMIME.pod Crypt-SMIME-0.13/SMIME.pod
--- Crypt-SMIME-0.13.orig/SMIME.pod 2014-05-02 14:30:38.000000000 +0900
+++ Crypt-SMIME-0.13/SMIME.pod 2014-08-02 14:23:04.000000000 +0900
@@ -180,6 +180,24 @@
=back
+=head2 FUNCTION
+
+=over 4
+
+=item extractCertificates()
+
+ @certs = @{Crypt::SMIME::extractCertificates($data)};
+ @certs = @{Crypt::SMIME::extractCertificates($data, $type)};
+
+Get all certificates (and CRLs, if any) included in S/MIME message or PKCS#7
+object $data. Optional $type parameter may specify type of data:
+C<Crypt::SMIME::FORMAT_SMIME> (default) for S/MIME message;
+C<Crypt::SMIME::FORMAT_ASN1> for binary format;
+C<Crypt::SMIME::FORMAT_PEM> for PEM format.
+
+
+=back
+
=head1 AUTHOR
Copyright 2006-2007 YMIRLINK Inc. All Rights Reserved.
diff -ur Crypt-SMIME-0.13.orig/SMIME.xs Crypt-SMIME-0.13/SMIME.xs
--- Crypt-SMIME-0.13.orig/SMIME.xs 2014-05-07 13:02:02.000000000 +0900
+++ Crypt-SMIME-0.13/SMIME.xs 2014-08-02 13:55:34.000000000 +0900
@@ -726,6 +726,122 @@
OUTPUT:
RETVAL
+#define CRYPT_SMIME_FORMAT_ASN1 1
+#define CRYPT_SMIME_FORMAT_PEM 3
+#define CRYPT_SMIME_FORMAT_SMIME 6
+
+int
+FORMAT_ASN1()
+ PROTOTYPE:
+ CODE:
+ RETVAL = CRYPT_SMIME_FORMAT_ASN1;
+ OUTPUT:
+ RETVAL
+
+int
+FORMAT_PEM()
+ PROTOTYPE:
+ CODE:
+ RETVAL = CRYPT_SMIME_FORMAT_PEM;
+ OUTPUT:
+ RETVAL
+
+int
+FORMAT_SMIME()
+ PROTOTYPE:
+ CODE:
+ RETVAL = CRYPT_SMIME_FORMAT_SMIME;
+ OUTPUT:
+ RETVAL
+
+SV*
+extractCertificates(SV* indata, int informat=CRYPT_SMIME_FORMAT_SMIME)
+ PROTOTYPE: $;$
+ INIT:
+ BIO* bio;
+ PKCS7* p7 = NULL;
+ STACK_OF(X509)* certs = NULL;
+ STACK_OF(X509_CRL)* crls = NULL;
+ int i;
+ AV* result;
+ BUF_MEM* bufmem;
+
+ if (!SvOK(indata)) {
+ XSRETURN_UNDEF;
+ }
+ bio = BIO_new_mem_buf(SvPV_nolen(indata), SvCUR(indata));
+ if (bio == NULL) {
+ OPENSSL_CROAK(
+ "Crypt::SMIME#extractCertificates: failed to allocate a buffer"
+ );
+ }
+ switch (informat) {
+ case CRYPT_SMIME_FORMAT_SMIME:
+ p7 = SMIME_read_PKCS7(bio, NULL);
+ break;
+ case CRYPT_SMIME_FORMAT_PEM:
+ p7 = PEM_read_bio_PKCS7(bio, NULL, NULL, NULL);
+ break;
+ case CRYPT_SMIME_FORMAT_ASN1:
+ p7 = d2i_PKCS7_bio(bio, NULL);
+ break;
+ default:
+ BIO_free(bio);
+ croak("Crypt::SMIME#extractCertificates: unknown format %d",
+ informat);
+ }
+ BIO_free(bio);
+ if (p7 == NULL) {
+ XSRETURN_UNDEF;
+ }
+
+ switch (OBJ_obj2nid(p7->type)) {
+ case NID_pkcs7_signed:
+ certs = p7->d.sign->cert;
+ crls = p7->d.sign->crl;
+ break;
+ case NID_pkcs7_signedAndEnveloped:
+ certs = p7->d.signed_and_enveloped->cert;
+ crls = p7->d.signed_and_enveloped->crl;
+ break;
+ default:
+ break;
+ }
+
+ result = (AV*)sv_2mortal((SV*)newAV());
+ CODE:
+ if (certs != NULL && 0 < sk_X509_num(certs)) {
+ for (i = 0; i < sk_X509_num(certs); i++) {
+ bio = BIO_new(BIO_s_mem());
+ if (bio == NULL) {
+ PKCS7_free(p7);
+ croak("Crypt::SMIME#extractCertificates: failed to allocate a buffer");
+ }
+ PEM_write_bio_X509(bio, sk_X509_value(certs, i));
+ BIO_get_mem_ptr(bio, &bufmem);
+ av_push(result, newSVpv(bufmem->data, bufmem->length));
+ BIO_free(bio);
+ }
+ }
+ if (crls != NULL && 0 < sk_X509_CRL_num(crls)) {
+ for (i = 0; i < sk_X509_CRL_num(crls); i++) {
+ bio = BIO_new(BIO_s_mem());
+ if (bio == NULL) {
+ PKCS7_free(p7);
+ croak("Crypt::SMIME#extractCertificates: failed to allocate a buffer");
+ }
+ PEM_write_bio_X509_CRL(bio, sk_X509_CRL_value(crls, i));
+ BIO_get_mem_ptr(bio, &bufmem);
+ av_push(result, newSVpv(bufmem->data, bufmem->length));
+ BIO_free(bio);
+ }
+ }
+
+ PKCS7_free(p7);
+ RETVAL = newRV((SV*) result);
+ OUTPUT:
+ RETVAL
+
# -----------------------------------------------------------------------------
# End of File.
# -----------------------------------------------------------------------------
diff -ur Crypt-SMIME-0.13.orig/lib/SMIME/JA.pod Crypt-SMIME-0.13/lib/SMIME/JA.pod
--- Crypt-SMIME-0.13.orig/lib/SMIME/JA.pod 2014-05-02 14:30:38.000000000 +0900
+++ Crypt-SMIME-0.13/lib/SMIME/JA.pod 2014-08-02 14:23:04.000000000 +0900
@@ -150,6 +150,24 @@
=back
+=head2 é¢æ°
+
+=over 4
+
+=item extractCertificates()
+
+ @certs = @{Crypt::SMIME::extractCertificates($data)};
+ @certs = @{Crypt::SMIME::extractCertificates($data, $type)};
+
+S/MIMEã¡ãã»ã¼ã¸ã¾ãã¯PKCS#7ãªãã¸ã§ã¯ãã«å«ã¾ãã証ææ¸
+(ã証ææ¸å¤±å¹ãªã¹ã) ããã¹ã¦åå¾ããã
+ãªãã·ã§ã³ã®$typeãã©ã¡ã¼ã¿ã§ãã¼ã¿ã®ç¨®é¡ãæå®ã§ããã
+C<Crypt::SMIME::FORMAT_SMIME> (åæå¤) ã¯S/MIMEã¡ãã»ã¼ã¸ã
+C<Crypt::SMIME::FORMAT_ASN1>ã¯ãã¤ããªå½¢å¼ã
+C<Crypt::SMIME::FORMAT_PEM>ã¯PEMå½¢å¼ã
+
+=back
+
=head1 èè
Copyright 2006-2007 YMIRLINK Inc. All Rights Reserved.
diff -ur Crypt-SMIME-0.13.orig/lib/SMIME.pm Crypt-SMIME-0.13/lib/SMIME.pm
--- Crypt-SMIME-0.13.orig/lib/SMIME.pm 2014-05-07 13:06:54.000000000 +0900
+++ Crypt-SMIME-0.13/lib/SMIME.pm 2014-08-02 14:23:04.000000000 +0900
@@ -359,6 +359,24 @@
=back
+=head2 FUNCTION
+
+=over 4
+
+=item extractCertificates()
+
+ @certs = @{Crypt::SMIME::extractCertificates($data)};
+ @certs = @{Crypt::SMIME::extractCertificates($data, $type)};
+
+Get all certificates (and CRLs, if any) included in S/MIME message or PKCS#7
+object $data. Optional $type parameter may specify type of data:
+C<Crypt::SMIME::FORMAT_SMIME> (default) for S/MIME message;
+C<Crypt::SMIME::FORMAT_ASN1> for binary format;
+C<Crypt::SMIME::FORMAT_PEM> for PEM format.
+
+
+=back
+
=head1 AUTHOR
Copyright 2006-2007 YMIRLINK Inc. All Rights Reserved.