Codebase list libcrypt-smime-perl / b65a7fd
Imported Upstream version 0.17 Salvatore Bonaccorso 7 years ago
10 changed file(s) with 106 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
00 Revision history for Crypt::SMIME
1
2 0.17 Tue Jun 21 12:24:18 JST 2016
3 - New function: setPrivateKeyPkcs12(), Patch by MIK [...]
4 cpan.org:
5 https://rt.cpan.org/Public/Bug/Display.html?id=115490
16
27 0.16 Mon Oct 5 10:57:44 JST 2015
38 - Constants FORMAT_ASN1, FORMAT_PEM, and FORMAT_SMIME can now
33 "Ymirlink <tl@tripletail.jp>"
44 ],
55 "dynamic_config" : 1,
6 "generated_by" : "ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.150005",
6 "generated_by" : "ExtUtils::MakeMaker version 7.0401, CPAN::Meta::Converter version 2.150001",
77 "license" : [
88 "unknown"
99 ],
4141 }
4242 },
4343 "release_status" : "stable",
44 "version" : "0.16",
45 "x_serialization_backend" : "JSON::PP version 2.27203"
44 "version" : "0.17"
4645 }
1111 ExtUtils::MakeMaker: '0'
1212 ExtUtils::PkgConfig: '0'
1313 dynamic_config: 1
14 generated_by: 'ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.150005'
14 generated_by: 'ExtUtils::MakeMaker version 7.0401, CPAN::Meta::Converter version 2.150001'
1515 license: unknown
1616 meta-spec:
1717 url: http://module-build.sourceforge.net/META-spec-v1.4.html
2323 - inc
2424 requires:
2525 XSLoader: '0'
26 version: '0.16'
27 x_serialization_backend: 'CPAN::Meta::YAML version 0.012'
26 version: '0.17'
100100 if it fails to load the key.
101101 J<< ja;
102102 対応しているフォーマットは PEM のみ。鍵の読み込みに失敗した場合はdieする。
103 >>
104
105 =item setPrivateKeyPkcs12()
106
107 $smime->setPrivateKeyPkcs12($key, $pkcs12);
108 $smime->setPrivateKeyPkcs12($key, $pkcs12, $password);
109
110 Load a private key and its X.509 certificate from PKCS#12 into the instance.
111 The private key will be used for signing and decryption. The method dies if
112 it fails to load PKCS12.
113 J<< ja;
114 秘密鍵およびその X.509 証明書を PKCS#12 から読み込んで設定する。秘密鍵は署名と復号の際に用いられる。
115 読み込みに失敗した場合は die する。
103116 >>
104117
105118 =item setPublicKey()
1414 );
1515 Exporter::export_ok_tags('constants');
1616
17 our $VERSION = '0.16';
17 our $VERSION = '0.17';
1818
1919 XSLoader::load(__PACKAGE__, $VERSION);
2020
8181
8282 The private key and certificate must be encoded in PEM format. The method dies
8383 if it fails to load the key.
84
85
86 =item setPrivateKeyPkcs12()
87
88 $smime->setPrivateKeyPkcs12($key, $pkcs12);
89 $smime->setPrivateKeyPkcs12($key, $pkcs12, $password);
90
91 Load a private key and its X.509 certificate from PKCS#12 into the instance.
92 The private key will be used for signing and decryption. The method dies if
93 it fails to load PKCS12.
8494
8595
8696 =item setPublicKey()
22 #if defined(HAVE_SYS_TIME_H)
33 # include <sys/time.h>
44 #endif
5 #include <openssl/rand.h>
56 #include <openssl/crypto.h>
67 #include <openssl/pem.h>
78 #include <openssl/err.h>
481482 SvREFCNT_inc(ST(0));
482483 RETVAL = ST(0);
483484
485 OUTPUT:
486 RETVAL
487
488 SV*
489 setPrivateKeyPkcs12(Crypt_SMIME this, SV* pkcs12, char* password = "")
490 PROTOTYPE: $$$;$
491 PREINIT:
492 BIO *bio;
493 PKCS12 *p12;
494 int success = 0;
495 CODE:
496 if (this->priv_cert) {
497 X509_free(this->priv_cert);
498 this->priv_cert = NULL;
499 }
500 if (this->priv_key) {
501 EVP_PKEY_free(this->priv_key);
502 this->priv_key = NULL;
503 }
504
505 if (SvOK(pkcs12)) {
506 if (bio = BIO_new_mem_buf(SvPV_nolen(pkcs12), SvCUR(pkcs12))) {
507 if (p12 = d2i_PKCS12_bio(bio, NULL)) {
508 success = PKCS12_parse(p12, password, &this->priv_key, &this->priv_cert, NULL);
509 }
510 BIO_free(bio);
511 }
512 }
513
514 if (!success || this->priv_key == NULL || this->priv_cert == NULL) {
515 OPENSSL_CROAK("Crypt::SMIME#setPrivateKeyPkcs12: failed");
516 }
517 this->priv_key_is_tainted = SvTAINTED(ST(1));
518 this->priv_cert_is_tainted = SvTAINTED(ST(1));
519
520 SvREFCNT_inc(ST(0));
521 RETVAL = ST(0);
484522 OUTPUT:
485523 RETVAL
486524
7070 ファイル名ではなく、鍵本体を渡す。
7171
7272 対応しているフォーマットは PEM のみ。鍵の読み込みに失敗した場合はdieする。
73
74 =item setPrivateKeyPkcs12()
75
76 $smime->setPrivateKeyPkcs12($key, $pkcs12);
77 $smime->setPrivateKeyPkcs12($key, $pkcs12, $password);
78
79 秘密鍵およびその X.509 証明書を PKCS#12 から読み込んで設定する。秘密鍵は署名と復号の際に用いられる。
80 読み込みに失敗した場合は die する。
7381
7482 =item setPublicKey()
7583
1616 );
1717 Exporter::export_ok_tags('constants');
1818
19 our $VERSION = '0.16';
19 our $VERSION = '0.17';
2020
2121 XSLoader::load(__PACKAGE__, $VERSION);
2222
272272 if it fails to load the key.
273273
274274
275 =item setPrivateKeyPkcs12()
276
277 $smime->setPrivateKeyPkcs12($key, $pkcs12);
278 $smime->setPrivateKeyPkcs12($key, $pkcs12, $password);
279
280 Load a private key and its X.509 certificate from PKCS#12 into the instance.
281 The private key will be used for signing and decryption. The method dies if
282 it fails to load PKCS12.
283
284
275285 =item setPublicKey()
276286
277287 $smime->setPublicKey($crt);
77 use Test::Exception;
88 use Config;
99
10 my (%key, %csr, %crt);
10 my (%key, %csr, %crt, %p12);
1111 do {
1212 my $OPENSSL = do {
1313 if (defined(my $prefix = ExtUtils::PkgConfig->variable('openssl', 'prefix'))) {
4848 (undef, $key{$i}) = tempfile(UNLINK => 1);
4949 (undef, $csr{$i}) = tempfile(UNLINK => 1);
5050 (undef, $crt{$i}) = tempfile(UNLINK => 1);
51 (undef, $p12{$i}) = tempfile(UNLINK => 1);
5152
5253 system(qq{$OPENSSL genrsa -out $key{$i} >$DEVNULL 2>&1}) and die $!;
5354 system(qq{$OPENSSL req -new -key $key{$i} -out $csr{$i} -config $conf_file >$DEVNULL 2>&1}) and die $!;
5455 system(qq{$OPENSSL x509 -in $csr{$i} -out $crt{$i} -req -signkey $key{$i} -set_serial $i >$DEVNULL 2>&1}) and die $!;
56 system(qq{$OPENSSL pkcs12 -export -out $p12{$i} -inkey $key{$i} -in $crt{$i} -passout pass:Secret123 >$DEVNULL 2>&1}) and die $!;
5557 }
5658 };
5759
7173 return scalar <$fh>;
7274 }
7375
76 sub p12 {
77 my $i = shift;
78
79 local $/;
80 open my $fh, '<', $p12{$i} or die $!;
81 binmode $fh;
82 return scalar <$fh>;
83 }
84
7485 my $plain = q{From: alice@example.org
7586 To: bob@example.org
7687 Subject: Crypt::SMIME test
8596 $verify =~ s/\r?\n|\r/\r\n/g;
8697
8798 #-----------------------
88 plan tests => 24;
99 plan tests => 25;
89100 use_ok('Crypt::SMIME');
90101
91102 my $smime;
127138 $smime->setPrivateKey(key(2), crt(2));
128139 ok($decrypted = $smime->decrypt($encrypted), 'decrypt (by recipient\'s key)');
129140
141 $smime->setPrivateKeyPkcs12(p12(2), 'Secret123');
142 ok($decrypted = $smime->decrypt($encrypted), 'decrypt (by recipient\'s PKCS12 key)');
143
130144 1;