Skip Menu |

This queue is for tickets about the Crypt-SMIME CPAN distribution.

Report information
The Basics
Id: 97691
Status: resolved
Priority: 0/
Queue: Crypt-SMIME

People
Owner: Nobody in particular
Requestors: hatuka [...] nezumi.nu
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



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.
Hi, I posted incompleted patch. See this one. Thank you, 作りかけのものをアップしていました。こちらを使ってください。 よろしくお願いいたします。 On 2014-8月-02 土 01:43:14, NEZUMI wrote: Show quoted text
> 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-20140804.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-04 15:20:24.000000000 +0900 @@ -144,7 +144,7 @@ would rarely need to call this method directly. J<< ja; 署名用のメッセージを準備する。 -C<$prepared_mime> には著名用に修正されたMIMEメッセージを返す。 +C<$prepared_mime> には署名用に修正されたMIMEメッセージを返す。 C<$outer_header> は、S/MIMEの外側に付与するヘッダを返す。 >> @@ -252,6 +252,50 @@ >> =back + +=head2 FUNCTIONS + +=over 4 + +=item extractCertificates() + + @certs = @{Crypt::SMIME::extractCertificates($data)}; + @certs = @{Crypt::SMIME::extractCertificates($data, $type)}; + +Get all X.509 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オブジェクトに含まれるX.509証明書 +(や証明書失効リスト) をすべて取得する。 +オプションの$typeパラメータでデータの種類を指定できる。 +C<Crypt::SMIME::FORMAT_SMIME> (初期値) はS/MIMEメッセージ、 +C<Crypt::SMIME::FORMAT_ASN1>はバイナリ形式、 +C<Crypt::SMIME::FORMAT_PEM>はPEM形式。 +>> + +=item getSigners() + + @certs = @{Crypt::SMIME::getSigners($data)}; + @certs = @{Crypt::SMIME::getSigners($data, $type)}; + +Get X.509 certificates of signers included in S/MIME message or PKCS#7 object. +Optional $type parameter may specify type of data. +J<< ja; +S/MIMEメッセージまたはPKCS#7オブジェクトに含まれる、署名者の +X.509証明書を取得する。オプションの$typeパラメータでデータの種類を指定できる。 +>> + +Note that any public keys returned by this function are not verified. +check() should be executed to ensure public keys are valid. +J<< ja; +この関数が返す公開鍵は検証されていないことに注意。 +公開鍵が有効であることを確かめるにはcheck()を実行すること。 +>> + +=back =head1 AUTHOR 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-04 15:14:50.000000000 +0900 @@ -180,6 +180,37 @@ =back +=head2 FUNCTIONS + +=over 4 + +=item extractCertificates() + + @certs = @{Crypt::SMIME::extractCertificates($data)}; + @certs = @{Crypt::SMIME::extractCertificates($data, $type)}; + +Get all X.509 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. + + +=item getSigners() + + @certs = @{Crypt::SMIME::getSigners($data)}; + @certs = @{Crypt::SMIME::getSigners($data, $type)}; + +Get X.509 certificates of signers included in S/MIME message or PKCS#7 object. +Optional $type parameter may specify type of data. + + +Note that any public keys returned by this function are not verified. +check() should be executed to ensure public keys are valid. + + +=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-04 14:49:17.000000000 +0900 @@ -726,6 +726,191 @@ 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 + +SV* +getSigners(SV* indata, int informat=CRYPT_SMIME_FORMAT_SMIME) + PROTOTYPE: $;$ + INIT: + BIO* bio; + PKCS7* p7 = NULL; + STACK_OF(X509)* signers; + 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#getSigners: 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#getSigners: unknown format %d", + informat); + } + BIO_free(bio); + if (p7 == NULL) { + XSRETURN_UNDEF; + } + + signers = PKCS7_get0_signers(p7, NULL, 0); + if (signers == NULL) { + PKCS7_free(p7); + XSRETURN_UNDEF; + } + + result = (AV*)sv_2mortal((SV*)newAV()); + CODE: + if (0 < sk_X509_num(signers)) { + for (i = 0; i < sk_X509_num(signers); i++) { + bio = BIO_new(BIO_s_mem()); + if (bio == NULL) { + sk_X509_free(signers); + PKCS7_free(p7); + croak("Crypt::SMIME#getSigners: failed to allocate a buffer"); + } + PEM_write_bio_X509(bio, sk_X509_value(signers, i)); + BIO_get_mem_ptr(bio, &bufmem); + av_push(result, newSVpv(bufmem->data, bufmem->length)); + BIO_free(bio); + } + } + + sk_X509_free(signers); + 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-04 15:14:50.000000000 +0900 @@ -150,6 +150,35 @@ =back +=head2 関数 + +=over 4 + +=item extractCertificates() + + @certs = @{Crypt::SMIME::extractCertificates($data)}; + @certs = @{Crypt::SMIME::extractCertificates($data, $type)}; + +S/MIMEメッセージまたはPKCS#7オブジェクトに含まれるX.509証明書 +(や証明書失効リスト) をすべて取得する。 +オプションの$typeパラメータでデータの種類を指定できる。 +C<Crypt::SMIME::FORMAT_SMIME> (初期値) はS/MIMEメッセージ、 +C<Crypt::SMIME::FORMAT_ASN1>はバイナリ形式、 +C<Crypt::SMIME::FORMAT_PEM>はPEM形式。 + +=item getSigners() + + @certs = @{Crypt::SMIME::getSigners($data)}; + @certs = @{Crypt::SMIME::getSigners($data, $type)}; + +S/MIMEメッセージまたはPKCS#7オブジェクトに含まれる署名者の +X.509証明書を取得する。オプションの$typeパラメータでデータの種類を指定できる。 + +この関数が返す公開鍵は検証されていないことに注意。 +公開鍵が有効であることを確かめるにはcheck()を実行すること。 + +=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-04 15:14:50.000000000 +0900 @@ -359,6 +359,37 @@ =back +=head2 FUNCTIONS + +=over 4 + +=item extractCertificates() + + @certs = @{Crypt::SMIME::extractCertificates($data)}; + @certs = @{Crypt::SMIME::extractCertificates($data, $type)}; + +Get all X.509 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. + + +=item getSigners() + + @certs = @{Crypt::SMIME::getSigners($data)}; + @certs = @{Crypt::SMIME::getSigners($data, $type)}; + +Get X.509 certificates of signers included in S/MIME message or PKCS#7 object. +Optional $type parameter may specify type of data. + + +Note that any public keys returned by this function are not verified. +check() should be executed to ensure public keys are valid. + + +=back + =head1 AUTHOR Copyright 2006-2007 YMIRLINK Inc. All Rights Reserved.
パッチありがとうございます. パッチを取り込んだ Crypt-SMIME-0.14 をCPANに公開しました.