1use warnings; 2use strict; 3use Test::More tests => 13; 4use Test::Exception; 5 6use Crypt::MatrixSSL3 qw( :DEFAULT :Error ); 7 8my $p12File = 't/cert/testserver.p12'; 9my $p12File_nopass = 't/cert/testserver_nopass.p12'; 10my $p12File_badca = 't/cert/testserver_badca.p12'; 11my $importPass = 'thepass'; 12 13 14is PS_PARSE_FAIL, _load_pkcs12('no such', undef, undef, 0), 15 'bad file'; 16is PS_CERT_AUTH_FAIL, _load_pkcs12($p12File_badca, undef, undef, 0), 17 'bad cert chain'; 18 19is PS_SUCCESS, _load_pkcs12($p12File_nopass, undef, undef, 0), 20 'not encrypted: NO PASSWORD'; 21is PS_SUCCESS, _load_pkcs12($p12File_nopass, '', undef, 0), 22 'not encrypted: EMPTY PASSWORD'; 23is PS_PARSE_FAIL, _load_pkcs12($p12File_nopass, 'a_n_y', undef, 0), 24 'not encrypted: ANY PASSWORD'; 25is PS_SUCCESS, _load_pkcs12($p12File_nopass, undef, '', 0), 26 'not encrypted: EMPTY MAC PASSWORD'; 27is PS_SUCCESS, _load_pkcs12($p12File_nopass, undef, 'a_n_y', 0), 28 'not encrypted: ANY MAC PASSWORD'; 29 30is PS_PARSE_FAIL, _load_pkcs12($p12File, undef, undef, 0), 31 'encrypted: NO PASSWORD'; 32is PS_PARSE_FAIL, _load_pkcs12($p12File, '', undef, 0), 33 'encrypted: EMPTY PASSWORD'; 34is PS_PARSE_FAIL, _load_pkcs12($p12File, 'wrong', undef, 0), 35 'encrypted: WRONG PASSWORD'; 36is PS_SUCCESS, _load_pkcs12($p12File, $importPass, undef, 0), 37 'encrypted: RIGHT PASSWORD'; 38is PS_SUCCESS, _load_pkcs12($p12File, $importPass, '', 0), 39 'encrypted: RIGHT PASSWORD, EMPTY MAC PASSWORD'; 40is PS_SUCCESS, _load_pkcs12($p12File, $importPass, 'a_n_y', 0), 41 'encrypted: RIGHT PASSWORD, ANY MAC PASSWORD'; 42 43 44sub _load_pkcs12 { 45 my $keys = Crypt::MatrixSSL3::Keys->new(); 46 return $keys->load_pkcs12($_[0], $_[1], $_[2], $_[3]); 47} 48 49