Merge from stable branch.
This commit is contained in:
parent
18ab306e63
commit
e9d247d2b0
@ -613,6 +613,8 @@ my $fips=0;
|
||||
|
||||
my %disabled = ( # "what" => "comment"
|
||||
"camellia" => "default",
|
||||
"capieng" => "default",
|
||||
"cms" => "default",
|
||||
"gmp" => "default",
|
||||
"mdc2" => "default",
|
||||
"rc5" => "default",
|
||||
|
@ -142,7 +142,7 @@ SDIRS= \
|
||||
bn ec rsa dsa ecdsa dh ecdh dso engine \
|
||||
buffer bio stack lhash rand err \
|
||||
evp asn1 pem x509 x509v3 conf txt_db pkcs7 pkcs12 comp ocsp ui krb5 \
|
||||
store pqueue
|
||||
store cms pqueue
|
||||
# keep in mind that the above list is adjusted by ./Configure
|
||||
# according to no-xxx arguments...
|
||||
|
||||
|
@ -7,8 +7,9 @@ rem usage:
|
||||
rem build [target] [debug opts] [assembly opts] [configure opts]
|
||||
rem
|
||||
rem target - "netware-clib" - CLib NetWare build (WinSock Sockets)
|
||||
rem - "netware-libc" - LibC NKS NetWare build (WinSock Sockets)
|
||||
rem - "netware-libc-bsdsock" - LibC NKS NetWare build (BSD Sockets)
|
||||
rem - "netware-clib-bsdsock" - CLib NetWare build (BSD Sockets)
|
||||
rem - "netware-libc" - LibC NetWare build (WinSock Sockets)
|
||||
rem - "netware-libc-bsdsock" - LibC NetWare build (BSD Sockets)
|
||||
rem
|
||||
rem debug opts - "debug" - build debug
|
||||
rem
|
||||
@ -71,10 +72,12 @@ if "%1" == "nw-nasm" set NO_ASM=
|
||||
if "%1" == "nw-nasm" set ARG_PROCESSED=YES
|
||||
if "%1" == "nw-mwasm" set ASM_MODE=nw-mwasm
|
||||
if "%1" == "nw-mwasm" set ASSEMBLER=Metrowerks
|
||||
if "%1" == "nw-mwasm" set NO_ASM=
|
||||
if "%1" == "nw-mwasm" set NO_ASM=
|
||||
if "%1" == "nw-mwasm" set ARG_PROCESSED=YES
|
||||
if "%1" == "netware-clib" set BLD_TARGET=netware-clib
|
||||
if "%1" == "netware-clib" set ARG_PROCESSED=YES
|
||||
if "%1" == "netware-clib-bsdsock" set BLD_TARGET=netware-clib-bsdsock
|
||||
if "%1" == "netware-clib-bsdsock" set ARG_PROCESSED=YES
|
||||
if "%1" == "netware-libc" set BLD_TARGET=netware-libc
|
||||
if "%1" == "netware-libc" set ARG_PROCESSED=YES
|
||||
if "%1" == "netware-libc-bsdsock" set BLD_TARGET=netware-libc-bsdsock
|
||||
@ -94,6 +97,7 @@ if "%BLD_TARGET%" == "no_target" goto no_target
|
||||
rem build the nlm make file name which includes target and debug info
|
||||
set NLM_MAKE=
|
||||
if "%BLD_TARGET%" == "netware-clib" set NLM_MAKE=netware\nlm_clib
|
||||
if "%BLD_TARGET%" == "netware-clib-bsdsock" set NLM_MAKE=netware\nlm_clib_bsdsock
|
||||
if "%BLD_TARGET%" == "netware-libc" set NLM_MAKE=netware\nlm_libc
|
||||
if "%BLD_TARGET%" == "netware-libc-bsdsock" set NLM_MAKE=netware\nlm_libc_bsdsock
|
||||
if "%DEBUG%" == "" set NLM_MAKE=%NLM_MAKE%.mak
|
||||
@ -110,7 +114,14 @@ echo Generating x86 for %ASSEMBLER% assembler
|
||||
|
||||
echo Bignum
|
||||
cd crypto\bn\asm
|
||||
perl x86.pl %ASM_MODE% > bn-nw.asm
|
||||
rem perl x86.pl %ASM_MODE% > bn-nw.asm
|
||||
perl bn-586.pl %ASM_MODE% > bn-nw.asm
|
||||
perl co-586.pl %ASM_MODE% > co-nw.asm
|
||||
cd ..\..\..
|
||||
|
||||
echo AES
|
||||
cd crypto\aes\asm
|
||||
perl aes-586.pl %ASM_MODE% > a-nw.asm
|
||||
cd ..\..\..
|
||||
|
||||
echo DES
|
||||
@ -160,6 +171,11 @@ cd crypto\rc5\asm
|
||||
perl rc5-586.pl %ASM_MODE% > r5-nw.asm
|
||||
cd ..\..\..
|
||||
|
||||
echo CPUID
|
||||
cd crypto
|
||||
perl x86cpuid.pl %ASM_MODE% > x86cpuid-nw.asm
|
||||
cd ..\
|
||||
|
||||
rem ===============================================================
|
||||
rem
|
||||
:do_config
|
||||
@ -176,8 +192,10 @@ echo mk1mf.pl options: %DEBUG% %ASM_MODE% %CONFIG_OPTS% %BLD_TARGET%
|
||||
echo .
|
||||
perl util\mk1mf.pl %DEBUG% %ASM_MODE% %CONFIG_OPTS% %BLD_TARGET% >%NLM_MAKE%
|
||||
|
||||
make -f %NLM_MAKE% vclean
|
||||
echo .
|
||||
echo The makefile "%NLM_MAKE%" has been created use your maketool to
|
||||
echo build (ex: gmake -f %NLM_MAKE%)
|
||||
echo build (ex: make -f %NLM_MAKE%)
|
||||
goto end
|
||||
|
||||
rem ===============================================================
|
||||
@ -189,8 +207,9 @@ echo .
|
||||
echo . usage: build [target] [debug opts] [assembly opts] [configure opts]
|
||||
echo .
|
||||
echo . target - "netware-clib" - CLib NetWare build (WinSock Sockets)
|
||||
echo . - "netware-libc" - LibC NKS NetWare build (WinSock Sockets)
|
||||
echo . - "netware-libc-bsdsock" - LibC NKS NetWare build (BSD Sockets)
|
||||
echo . - "netware-clib-bsdsock" - CLib NetWare build (BSD Sockets)
|
||||
echo . - "netware-libc" - LibC NetWare build (WinSock Sockets)
|
||||
echo . - "netware-libc-bsdsock" - LibC NetWare build (BSD Sockets)
|
||||
echo .
|
||||
echo . debug opts - "debug" - build debug
|
||||
echo .
|
||||
|
@ -73,6 +73,7 @@ copy %loc%\test\testsid.pem %2\openssl\test\
|
||||
copy %loc%\test\testx509.pem %2\openssl\test\
|
||||
copy %loc%\test\v3-cert1.pem %2\openssl\test\
|
||||
copy %loc%\test\v3-cert2.pem %2\openssl\test\
|
||||
copy %loc%\crypto\evp\evptests.txt %2\openssl\test\
|
||||
|
||||
rem copy the apps directory stuff
|
||||
copy %loc%\apps\client.pem %2\openssl\apps\
|
||||
|
@ -34,12 +34,17 @@ sub main()
|
||||
# delete all the output files in the output directory
|
||||
unlink <$output_path\\*.*>;
|
||||
|
||||
# open the main log file
|
||||
# open the main log file
|
||||
open(OUT, ">$log_file") || die "unable to open $log_file\n";
|
||||
|
||||
|
||||
print( OUT "========================================================\n");
|
||||
my $outFile = "$output_path\\version.out";
|
||||
system("openssl2 version (CLIB_OPT)/>$outFile");
|
||||
log_output("CHECKING FOR OPENSSL VERSION:", $outFile);
|
||||
|
||||
algorithm_tests();
|
||||
encryption_tests();
|
||||
evp_tests();
|
||||
pem_tests();
|
||||
verify_tests();
|
||||
ca_tests();
|
||||
@ -56,9 +61,10 @@ sub algorithm_tests
|
||||
{
|
||||
my $i;
|
||||
my $outFile;
|
||||
my @tests = ( rsa_test, destest, ideatest, bftest, shatest, sha1test,
|
||||
md5test, dsatest, md2test, mdc2test, rc2test, rc4test, randtest,
|
||||
dhtest, exptest );
|
||||
my @tests = ( rsa_test, destest, ideatest, bftest, bntest, shatest, sha1test,
|
||||
sha256t, sha512t, dsatest, md2test, md4test, md5test, mdc2test,
|
||||
rc2test, rc4test, rc5test, randtest, rmdtest, dhtest, ecdhtest,
|
||||
ecdsatest, ectest, exptest, casttest, hmactest );
|
||||
|
||||
print( "\nRUNNING CRYPTO ALGORITHM TESTS:\n\n");
|
||||
|
||||
@ -68,16 +74,16 @@ sub algorithm_tests
|
||||
foreach $i (@tests)
|
||||
{
|
||||
if (-e "$base_path\\$i.nlm")
|
||||
{
|
||||
{
|
||||
$outFile = "$output_path\\$i.out";
|
||||
system("$i > $outFile");
|
||||
system("$i (CLIB_OPT)/>$outFile");
|
||||
log_desc("Test: $i\.nlm:");
|
||||
log_output("", $outFile );
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
log_desc("Test: $i\.nlm: file not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,24 +115,24 @@ sub encryption_tests
|
||||
|
||||
# do encryption
|
||||
$outFile = "$output_path\\enc.out";
|
||||
system("openssl2 $i -e -bufsize 113 -k test -in $input -out $cipher > $outFile" );
|
||||
system("openssl2 $i -e -bufsize 113 -k test -in $input -out $cipher (CLIB_OPT)/>$outFile" );
|
||||
log_output("Encrypting: $input --> $cipher", $outFile);
|
||||
|
||||
# do decryption
|
||||
$outFile = "$output_path\\dec.out";
|
||||
system("openssl2 $i -d -bufsize 157 -k test -in $cipher -out $clear > $outFile");
|
||||
system("openssl2 $i -d -bufsize 157 -k test -in $cipher -out $clear (CLIB_OPT)/>$outFile");
|
||||
log_output("Decrypting: $cipher --> $clear", $outFile);
|
||||
|
||||
# compare files
|
||||
$x = compare_files( $input, $clear, 1);
|
||||
if ( $x == 0 )
|
||||
{
|
||||
print( "SUCCESS - files match: $input, $clear\n");
|
||||
print( "\rSUCCESS - files match: $input, $clear\n");
|
||||
print( OUT "SUCCESS - files match: $input, $clear\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
print( "ERROR: files don't match\n");
|
||||
print( "\rERROR: files don't match\n");
|
||||
print( OUT "ERROR: files don't match\n");
|
||||
}
|
||||
|
||||
@ -136,24 +142,24 @@ sub encryption_tests
|
||||
|
||||
# do encryption B64
|
||||
$outFile = "$output_path\\B64enc.out";
|
||||
system("openssl2 $i -a -e -bufsize 113 -k test -in $input -out $cipher > $outFile");
|
||||
system("openssl2 $i -a -e -bufsize 113 -k test -in $input -out $cipher (CLIB_OPT)/>$outFile");
|
||||
log_output("Encrypting(B64): $cipher --> $clear", $outFile);
|
||||
|
||||
# do decryption B64
|
||||
$outFile = "$output_path\\B64dec.out";
|
||||
system("openssl2 $i -a -d -bufsize 157 -k test -in $cipher -out $clear > $outFile");
|
||||
system("openssl2 $i -a -d -bufsize 157 -k test -in $cipher -out $clear (CLIB_OPT)/>$outFile");
|
||||
log_output("Decrypting(B64): $cipher --> $clear", $outFile);
|
||||
|
||||
# compare files
|
||||
$x = compare_files( $input, $clear, 1);
|
||||
if ( $x == 0 )
|
||||
{
|
||||
print( "SUCCESS - files match: $input, $clear\n");
|
||||
print( "\rSUCCESS - files match: $input, $clear\n");
|
||||
print( OUT "SUCCESS - files match: $input, $clear\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
print( "ERROR: files don't match\n");
|
||||
print( "\rERROR: files don't match\n");
|
||||
print( OUT "ERROR: files don't match\n");
|
||||
}
|
||||
|
||||
@ -199,24 +205,24 @@ sub pem_tests
|
||||
|
||||
if ($i ne "req" )
|
||||
{
|
||||
system("openssl2 $i -in $input -out $tmp_out > $outFile");
|
||||
system("openssl2 $i -in $input -out $tmp_out (CLIB_OPT)/>$outFile");
|
||||
log_output( "openssl2 $i -in $input -out $tmp_out", $outFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
system("openssl2 $i -in $input -out $tmp_out -config $OpenSSL_config > $outFile");
|
||||
system("openssl2 $i -in $input -out $tmp_out -config $OpenSSL_config (CLIB_OPT)/>$outFile");
|
||||
log_output( "openssl2 $i -in $input -out $tmp_out -config $OpenSSL_config", $outFile );
|
||||
}
|
||||
|
||||
$x = compare_files( $input, $tmp_out);
|
||||
if ( $x == 0 )
|
||||
{
|
||||
print( "SUCCESS - files match: $input, $tmp_out\n");
|
||||
print( "\rSUCCESS - files match: $input, $tmp_out\n");
|
||||
print( OUT "SUCCESS - files match: $input, $tmp_out\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
print( "ERROR: files don't match\n");
|
||||
print( "\rERROR: files don't match\n");
|
||||
print( OUT "ERROR: files don't match\n");
|
||||
}
|
||||
do_wait();
|
||||
@ -231,7 +237,8 @@ sub verify_tests
|
||||
my $i;
|
||||
my $outFile = "$output_path\\verify.out";
|
||||
|
||||
my @cert_files = <$cert_path\\*.pem>;
|
||||
$cert_path =~ s/\\/\//g;
|
||||
my @cert_files = <$cert_path/*.pem>;
|
||||
|
||||
print( "\nRUNNING VERIFY TESTS:\n\n");
|
||||
|
||||
@ -242,7 +249,7 @@ sub verify_tests
|
||||
|
||||
foreach $i (@cert_files)
|
||||
{
|
||||
system("openssl2 verify -CAfile $tmp_cert $i >$outFile");
|
||||
system("openssl2 verify -CAfile $tmp_cert $i (CLIB_OPT)/>$outFile");
|
||||
log_desc("Verifying cert: $i");
|
||||
log_output("openssl2 verify -CAfile $tmp_cert $i", $outFile);
|
||||
}
|
||||
@ -263,103 +270,103 @@ sub ssl_tests
|
||||
print( OUT "\n========================================================\n");
|
||||
print( OUT "SSL TESTS:\n\n");
|
||||
|
||||
system("ssltest -ssl2 >$outFile");
|
||||
system("ssltest -ssl2 (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv2:");
|
||||
log_output("ssltest -ssl2", $outFile);
|
||||
|
||||
system("$ssltest -ssl2 -server_auth >$outFile");
|
||||
system("$ssltest -ssl2 -server_auth (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv2 with server authentication:");
|
||||
log_output("$ssltest -ssl2 -server_auth", $outFile);
|
||||
|
||||
system("$ssltest -ssl2 -client_auth >$outFile");
|
||||
system("$ssltest -ssl2 -client_auth (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv2 with client authentication:");
|
||||
log_output("$ssltest -ssl2 -client_auth", $outFile);
|
||||
|
||||
system("$ssltest -ssl2 -server_auth -client_auth >$outFile");
|
||||
system("$ssltest -ssl2 -server_auth -client_auth (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv2 with both client and server authentication:");
|
||||
log_output("$ssltest -ssl2 -server_auth -client_auth", $outFile);
|
||||
|
||||
system("ssltest -ssl3 >$outFile");
|
||||
system("ssltest -ssl3 (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv3:");
|
||||
log_output("ssltest -ssl3", $outFile);
|
||||
|
||||
system("$ssltest -ssl3 -server_auth >$outFile");
|
||||
system("$ssltest -ssl3 -server_auth (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv3 with server authentication:");
|
||||
log_output("$ssltest -ssl3 -server_auth", $outFile);
|
||||
|
||||
system("$ssltest -ssl3 -client_auth >$outFile");
|
||||
system("$ssltest -ssl3 -client_auth (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv3 with client authentication:");
|
||||
log_output("$ssltest -ssl3 -client_auth", $outFile);
|
||||
|
||||
system("$ssltest -ssl3 -server_auth -client_auth >$outFile");
|
||||
system("$ssltest -ssl3 -server_auth -client_auth (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv3 with both client and server authentication:");
|
||||
log_output("$ssltest -ssl3 -server_auth -client_auth", $outFile);
|
||||
|
||||
system("ssltest >$outFile");
|
||||
system("ssltest (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv2/sslv3:");
|
||||
log_output("ssltest", $outFile);
|
||||
|
||||
system("$ssltest -server_auth >$outFile");
|
||||
system("$ssltest -server_auth (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv2/sslv3 with server authentication:");
|
||||
log_output("$ssltest -server_auth", $outFile);
|
||||
|
||||
system("$ssltest -client_auth >$outFile");
|
||||
system("$ssltest -client_auth (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv2/sslv3 with client authentication:");
|
||||
log_output("$ssltest -client_auth ", $outFile);
|
||||
|
||||
system("$ssltest -server_auth -client_auth >$outFile");
|
||||
system("$ssltest -server_auth -client_auth (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv2/sslv3 with both client and server authentication:");
|
||||
log_output("$ssltest -server_auth -client_auth", $outFile);
|
||||
|
||||
system("ssltest -bio_pair -ssl2 >$outFile");
|
||||
system("ssltest -bio_pair -ssl2 (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv2 via BIO pair:");
|
||||
log_output("ssltest -bio_pair -ssl2", $outFile);
|
||||
|
||||
system("ssltest -bio_pair -dhe1024dsa -v >$outFile");
|
||||
system("ssltest -bio_pair -dhe1024dsa -v (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv2/sslv3 with 1024 bit DHE via BIO pair:");
|
||||
log_output("ssltest -bio_pair -dhe1024dsa -v", $outFile);
|
||||
|
||||
system("$ssltest -bio_pair -ssl2 -server_auth >$outFile");
|
||||
system("$ssltest -bio_pair -ssl2 -server_auth (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv2 with server authentication via BIO pair:");
|
||||
log_output("$ssltest -bio_pair -ssl2 -server_auth", $outFile);
|
||||
|
||||
system("$ssltest -bio_pair -ssl2 -client_auth >$outFile");
|
||||
system("$ssltest -bio_pair -ssl2 -client_auth (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv2 with client authentication via BIO pair:");
|
||||
log_output("$ssltest -bio_pair -ssl2 -client_auth", $outFile);
|
||||
|
||||
system("$ssltest -bio_pair -ssl2 -server_auth -client_auth >$outFile");
|
||||
system("$ssltest -bio_pair -ssl2 -server_auth -client_auth (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv2 with both client and server authentication via BIO pair:");
|
||||
log_output("$ssltest -bio_pair -ssl2 -server_auth -client_auth", $outFile);
|
||||
|
||||
system("ssltest -bio_pair -ssl3 >$outFile");
|
||||
system("ssltest -bio_pair -ssl3 (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv3 via BIO pair:");
|
||||
log_output("ssltest -bio_pair -ssl3", $outFile);
|
||||
|
||||
system("$ssltest -bio_pair -ssl3 -server_auth >$outFile");
|
||||
system("$ssltest -bio_pair -ssl3 -server_auth (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv3 with server authentication via BIO pair:");
|
||||
log_output("$ssltest -bio_pair -ssl3 -server_auth", $outFile);
|
||||
|
||||
system("$ssltest -bio_pair -ssl3 -client_auth >$outFile");
|
||||
system("$ssltest -bio_pair -ssl3 -client_auth (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv3 with client authentication via BIO pair:");
|
||||
log_output("$ssltest -bio_pair -ssl3 -client_auth", $outFile);
|
||||
|
||||
system("$ssltest -bio_pair -ssl3 -server_auth -client_auth >$outFile");
|
||||
system("$ssltest -bio_pair -ssl3 -server_auth -client_auth (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv3 with both client and server authentication via BIO pair:");
|
||||
log_output("$ssltest -bio_pair -ssl3 -server_auth -client_auth", $outFile);
|
||||
|
||||
system("ssltest -bio_pair >$outFile");
|
||||
system("ssltest -bio_pair (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv2/sslv3 via BIO pair:");
|
||||
log_output("ssltest -bio_pair", $outFile);
|
||||
|
||||
system("$ssltest -bio_pair -server_auth >$outFile");
|
||||
system("$ssltest -bio_pair -server_auth (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv2/sslv3 with server authentication via BIO pair:");
|
||||
log_output("$ssltest -bio_pair -server_auth", $outFile);
|
||||
|
||||
system("$ssltest -bio_pair -client_auth >$outFile");
|
||||
system("$ssltest -bio_pair -client_auth (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv2/sslv3 with client authentication via BIO pair:");
|
||||
log_output("$ssltest -bio_pair -client_auth", $outFile);
|
||||
|
||||
system("$ssltest -bio_pair -server_auth -client_auth >$outFile");
|
||||
system("$ssltest -bio_pair -server_auth -client_auth (CLIB_OPT)/>$outFile");
|
||||
log_desc("Testing sslv2/sslv3 with both client and server authentication via BIO pair:");
|
||||
log_output("$ssltest -bio_pair -server_auth -client_auth", $outFile);
|
||||
}
|
||||
@ -389,43 +396,43 @@ sub ca_tests
|
||||
print( OUT "\n========================================================\n");
|
||||
print( OUT "CA TESTS:\n");
|
||||
|
||||
system("openssl2 req -config $CAconf -out $CAreq -keyout $CAkey -new >$outFile");
|
||||
system("openssl2 req -config $CAconf -out $CAreq -keyout $CAkey -new (CLIB_OPT)/>$outFile");
|
||||
log_desc("Make a certificate request using req:");
|
||||
log_output("openssl2 req -config $CAconf -out $CAreq -keyout $CAkey -new", $outFile);
|
||||
|
||||
system("openssl2 x509 -CAcreateserial -in $CAreq -days 30 -req -out $CAcert -signkey $CAkey >$outFile");
|
||||
system("openssl2 x509 -CAcreateserial -in $CAreq -days 30 -req -out $CAcert -signkey $CAkey (CLIB_OPT)/>$outFile");
|
||||
log_desc("Convert the certificate request into a self signed certificate using x509:");
|
||||
log_output("openssl2 x509 -CAcreateserial -in $CAreq -days 30 -req -out $CAcert -signkey $CAkey", $outFile);
|
||||
|
||||
system("openssl2 x509 -in $CAcert -x509toreq -signkey $CAkey -out $CAreq2 >$outFile");
|
||||
system("openssl2 x509 -in $CAcert -x509toreq -signkey $CAkey -out $CAreq2 (CLIB_OPT)/>$outFile");
|
||||
log_desc("Convert a certificate into a certificate request using 'x509':");
|
||||
log_output("openssl2 x509 -in $CAcert -x509toreq -signkey $CAkey -out $CAreq2", $outFile);
|
||||
|
||||
system("openssl2 req -config $OpenSSL_config -verify -in $CAreq -noout >$outFile");
|
||||
system("openssl2 req -config $OpenSSL_config -verify -in $CAreq -noout (CLIB_OPT)/>$outFile");
|
||||
log_output("openssl2 req -config $OpenSSL_config -verify -in $CAreq -noout", $outFile);
|
||||
|
||||
system("openssl2 req -config $OpenSSL_config -verify -in $CAreq2 -noout >$outFile");
|
||||
system("openssl2 req -config $OpenSSL_config -verify -in $CAreq2 -noout (CLIB_OPT)/>$outFile");
|
||||
log_output( "openssl2 req -config $OpenSSL_config -verify -in $CAreq2 -noout", $outFile);
|
||||
|
||||
system("openssl2 verify -CAfile $CAcert $CAcert >$outFile");
|
||||
system("openssl2 verify -CAfile $CAcert $CAcert (CLIB_OPT)/>$outFile");
|
||||
log_output("openssl2 verify -CAfile $CAcert $CAcert", $outFile);
|
||||
|
||||
system("openssl2 req -config $Uconf -out $Ureq -keyout $Ukey -new >$outFile");
|
||||
system("openssl2 req -config $Uconf -out $Ureq -keyout $Ukey -new (CLIB_OPT)/>$outFile");
|
||||
log_desc("Make another certificate request using req:");
|
||||
log_output("openssl2 req -config $Uconf -out $Ureq -keyout $Ukey -new", $outFile);
|
||||
|
||||
system("openssl2 x509 -CAcreateserial -in $Ureq -days 30 -req -out $Ucert -CA $CAcert -CAkey $CAkey -CAserial $CAserial >$outFile");
|
||||
system("openssl2 x509 -CAcreateserial -in $Ureq -days 30 -req -out $Ucert -CA $CAcert -CAkey $CAkey -CAserial $CAserial (CLIB_OPT)/>$outFile");
|
||||
log_desc("Sign certificate request with the just created CA via x509:");
|
||||
log_output("openssl2 x509 -CAcreateserial -in $Ureq -days 30 -req -out $Ucert -CA $CAcert -CAkey $CAkey -CAserial $CAserial", $outFile);
|
||||
|
||||
system("openssl2 verify -CAfile $CAcert $Ucert >$outFile");
|
||||
system("openssl2 verify -CAfile $CAcert $Ucert (CLIB_OPT)/>$outFile");
|
||||
log_output("openssl2 verify -CAfile $CAcert $Ucert", $outFile);
|
||||
|
||||
system("openssl2 x509 -subject -issuer -startdate -enddate -noout -in $Ucert >$outFile");
|
||||
system("openssl2 x509 -subject -issuer -startdate -enddate -noout -in $Ucert (CLIB_OPT)/>$outFile");
|
||||
log_desc("Certificate details");
|
||||
log_output("openssl2 x509 -subject -issuer -startdate -enddate -noout -in $Ucert", $outFile);
|
||||
|
||||
print(OUT "-- \n");
|
||||
print(OUT "--\n");
|
||||
print(OUT "The generated CA certificate is $CAcert\n");
|
||||
print(OUT "The generated CA private key is $CAkey\n");
|
||||
print(OUT "The current CA signing serial number is in $CAserial\n");
|
||||
@ -435,6 +442,29 @@ sub ca_tests
|
||||
print(OUT "--\n");
|
||||
}
|
||||
|
||||
############################################################################
|
||||
sub evp_tests
|
||||
{
|
||||
my $i = 'evp_test';
|
||||
|
||||
print( "\nRUNNING EVP TESTS:\n\n");
|
||||
|
||||
print( OUT "\n========================================================\n");
|
||||
print( OUT "EVP TESTS:\n\n");
|
||||
|
||||
if (-e "$base_path\\$i.nlm")
|
||||
{
|
||||
my $outFile = "$output_path\\$i.out";
|
||||
system("$i $test_path\\evptests.txt (CLIB_OPT)/>$outFile");
|
||||
log_desc("Test: $i\.nlm:");
|
||||
log_output("", $outFile );
|
||||
}
|
||||
else
|
||||
{
|
||||
log_desc("Test: $i\.nlm: file not found");
|
||||
}
|
||||
}
|
||||
|
||||
############################################################################
|
||||
sub log_output( $ $ )
|
||||
{
|
||||
@ -445,7 +475,7 @@ sub log_output( $ $ )
|
||||
|
||||
if ($desc)
|
||||
{
|
||||
print("$desc\n");
|
||||
print("\r$desc\n");
|
||||
print(OUT "$desc\n");
|
||||
}
|
||||
|
||||
@ -457,8 +487,8 @@ sub log_output( $ $ )
|
||||
# copy test output to log file
|
||||
open(IN, "<$file");
|
||||
while (<IN>)
|
||||
{
|
||||
print(OUT $_);
|
||||
{
|
||||
print(OUT $_);
|
||||
if ( $_ =~ /ERROR/ )
|
||||
{
|
||||
$error = 1;
|
||||
@ -485,13 +515,13 @@ sub log_output( $ $ )
|
||||
$key = getc;
|
||||
print("\n");
|
||||
}
|
||||
|
||||
# Several of the testing scripts run a loop loading the
|
||||
|
||||
# Several of the testing scripts run a loop loading the
|
||||
# same NLM with different options.
|
||||
# On slow NetWare machines there appears to be some delay in the
|
||||
# On slow NetWare machines there appears to be some delay in the
|
||||
# OS actually unloading the test nlms and the OS complains about.
|
||||
# the NLM already being loaded. This additional pause is to
|
||||
# to help provide a little more time for unloading before trying to
|
||||
# the NLM already being loaded. This additional pause is to
|
||||
# to help provide a little more time for unloading before trying to
|
||||
# load again.
|
||||
sleep(1);
|
||||
}
|
||||
@ -562,7 +592,7 @@ sub do_wait()
|
||||
############################################################################
|
||||
sub make_tmp_cert_file()
|
||||
{
|
||||
my @cert_files = <$cert_path\\*.pem>;
|
||||
my @cert_files = <$cert_path/*.pem>;
|
||||
|
||||
# delete the file if it already exists
|
||||
unlink($tmp_cert);
|
||||
@ -570,7 +600,7 @@ sub make_tmp_cert_file()
|
||||
open( TMP_CERT, ">$tmp_cert") || die "\nunable to open $tmp_cert\n";
|
||||
|
||||
print("building temporary cert file\n");
|
||||
|
||||
|
||||
# create a temporary cert file that contains all the certs
|
||||
foreach $i (@cert_files)
|
||||
{
|
||||
|
@ -16,75 +16,97 @@ if "a%1" == "a" goto usage
|
||||
|
||||
set LIBC_BUILD=
|
||||
set CLIB_BUILD=
|
||||
set GNUC=
|
||||
|
||||
if "%1" == "netware-clib" set CLIB_BUILD=Y
|
||||
if "%1" == "netware-clib" set LIBC_BUILD=
|
||||
|
||||
if "%1" == "netware-libc" set LIBC_BUILD=Y
|
||||
if "%1" == "netware-libc" set CLIB_BUILD=
|
||||
if "%1" == "netware-libc" set LIBC_BUILD=Y
|
||||
if "%1" == "netware-libc" set CLIB_BUILD=
|
||||
|
||||
if "%2" == "gnuc" set GNUC=Y
|
||||
if "%2" == "codewarrior" set GNUC=
|
||||
|
||||
rem Location of tools (compiler, linker, etc)
|
||||
set TOOLS=d:\i_drive\tools
|
||||
if "%NDKBASE%" == "" set NDKBASE=c:\Novell
|
||||
|
||||
rem If Perl for Win32 is not already in your path, add it here
|
||||
set PERL_PATH=
|
||||
|
||||
rem Define path to the Metrowerks command line tools
|
||||
rem or GNU Crosscompiler gcc / nlmconv
|
||||
rem ( compiler, assembler, linker)
|
||||
set METROWERKS_PATH=%TOOLS%\codewar\pdk_21\tools\command line tools
|
||||
rem set METROWERKS_PATH=%TOOLS%\codewar\PDK_40\Other Metrowerks Tools\Command Line Tools
|
||||
if "%GNUC%" == "Y" set COMPILER_PATH=c:\usr\i586-netware\bin;c:\usr\bin
|
||||
if "%GNUC%" == "" set COMPILER_PATH=c:\prg\cwcmdl40
|
||||
|
||||
rem If using gnu make define path to utility
|
||||
set GNU_MAKE_PATH=%TOOLS%\gnu
|
||||
rem set GNU_MAKE_PATH=%NDKBASE%\gnu
|
||||
set GNU_MAKE_PATH=c:\prg\tools
|
||||
|
||||
rem If using ms nmake define path to nmake
|
||||
set MS_NMAKE_PATH=%TOOLS%\msvc\600\bin
|
||||
rem set MS_NMAKE_PATH=%NDKBASE%\msvc\600\bin
|
||||
|
||||
rem If using NASM assembler define path
|
||||
set NASM_PATH=%TOOLS%\nasm
|
||||
rem set NASM_PATH=%NDKBASE%\nasm
|
||||
set NASM_PATH=c:\prg\tools
|
||||
|
||||
rem Update path to include tool paths
|
||||
set path=%path%;%METROWERKS_PATH%
|
||||
set path=%path%;%COMPILER_PATH%
|
||||
if not "%GNU_MAKE_PATH%" == "" set path=%path%;%GNU_MAKE_PATH%
|
||||
if not "%MS_NMAKE_PATH%" == "" set path=%path%;%MS_NMAKE_PATH%
|
||||
if not "%NASM_PATH%" == "" set path=%path%;%NASM_PATH%
|
||||
if not "%PERL_PATH%" == "" set path=%path%;%PERL_PATH%
|
||||
|
||||
rem Set MWCIncludes to location of Novell NDK includes
|
||||
if "%LIBC_BUILD%" == "Y" set MWCIncludes=%TOOLS%\ndk\libc\include;%TOOLS%\ndk\libc\include\winsock;.\engines
|
||||
if "%CLIB_BUILD%" == "Y" set MWCIncludes=%TOOLS%\ndk\nwsdk\include\nlm;.\engines
|
||||
set include=
|
||||
rem Set INCLUDES to location of Novell NDK includes
|
||||
if "%LIBC_BUILD%" == "Y" set INCLUDE=%NDKBASE%\ndk\libc\include;%NDKBASE%\ndk\libc\include\winsock
|
||||
if "%CLIB_BUILD%" == "Y" set INCLUDE=%NDKBASE%\ndk\nwsdk\include\nlm;%NDKBASE%\ws295sdk\include
|
||||
|
||||
rem Set Imports to location of Novell NDK import files
|
||||
if "%LIBC_BUILD%" == "Y" set IMPORTS=%TOOLS%\ndk\libc\imports
|
||||
if "%CLIB_BUILD%" == "Y" set IMPORTS=%TOOLS%\ndk\nwsdk\imports
|
||||
if "%LIBC_BUILD%" == "Y" set IMPORTS=%NDKBASE%\ndk\libc\imports
|
||||
if "%CLIB_BUILD%" == "Y" set IMPORTS=%NDKBASE%\ndk\nwsdk\imports
|
||||
|
||||
rem Set PRELUDE to the absolute path of the prelude object to link with in
|
||||
rem the Metrowerks NetWare PDK - NOTE: for Clib builds "clibpre.o" is
|
||||
rem recommended, for LibC NKS builds libcpre.o must be used
|
||||
if "%GNUC%" == "Y" goto gnuc
|
||||
if "%LIBC_BUILD%" == "Y" set PRELUDE=%IMPORTS%\libcpre.o
|
||||
if "%CLIB_BUILD%" == "Y" set PRELUDE=%IMPORTS%\clibpre.o
|
||||
rem if "%CLIB_BUILD%" == "Y" set PRELUDE=%IMPORTS%\clibpre.o
|
||||
if "%CLIB_BUILD%" == "Y" set PRELUDE=%IMPORTS%\prelude.o
|
||||
echo using MetroWerks CodeWarrior
|
||||
goto info
|
||||
|
||||
:gnuc
|
||||
if "%LIBC_BUILD%" == "Y" set PRELUDE=%IMPORTS%\libcpre.gcc.o
|
||||
rem if "%CLIB_BUILD%" == "Y" set PRELUDE=%IMPORTS%\clibpre.gcc.o
|
||||
if "%CLIB_BUILD%" == "Y" set PRELUDE=%IMPORTS%\prelude.gcc.o
|
||||
echo using GNU GCC Compiler
|
||||
|
||||
:info
|
||||
echo.
|
||||
|
||||
if "%LIBC_BUILD%" == "Y" echo Enviroment configured for LibC build
|
||||
if "%LIBC_BUILD%" == "Y" echo use "netware\build.bat netware-libc ..."
|
||||
|
||||
if "%CLIB_BUILD%" == "Y" echo Enviroment configured for CLib build
|
||||
if "%CLIB_BUILD%" == "Y" echo use "netware\build.bat netware-clib ..."
|
||||
|
||||
goto end
|
||||
|
||||
:usage
|
||||
rem ===============================================================
|
||||
echo .
|
||||
echo . No target build specified!
|
||||
echo .
|
||||
echo . usage: set_env [target]
|
||||
echo .
|
||||
echo . target - "netware-clib" - Clib build
|
||||
echo . - "netware-libc" - LibC build
|
||||
echo .
|
||||
|
||||
|
||||
echo.
|
||||
echo No target build specified!
|
||||
echo.
|
||||
echo usage: set_env [target] [compiler]
|
||||
echo.
|
||||
echo target - "netware-clib" - Clib build
|
||||
echo - "netware-libc" - LibC build
|
||||
echo.
|
||||
echo compiler - "gnuc" - GNU GCC Compiler
|
||||
echo - "codewarrior" - MetroWerks CodeWarrior (default)
|
||||
echo.
|
||||
|
||||
:end
|
||||
echo.
|
||||
|
||||
|
||||
|
@ -38,7 +38,7 @@ EXE= $(PROGRAM)$(EXE_EXT)
|
||||
E_EXE= verify asn1pars req dgst dh dhparam enc passwd gendh errstr \
|
||||
ca crl rsa rsautl dsa dsaparam ec ecparam \
|
||||
x509 genrsa gendsa s_server s_client speed \
|
||||
s_time version pkcs7 crl2pkcs7 sess_id ciphers nseq pkcs12 \
|
||||
s_time version pkcs7 cms crl2pkcs7 sess_id ciphers nseq pkcs12 \
|
||||
pkcs8 spkac smime rand engine ocsp prime
|
||||
|
||||
PROGS= $(PROGRAM).c
|
||||
@ -56,7 +56,7 @@ E_OBJ= verify.o asn1pars.o req.o dgst.o dh.o dhparam.o enc.o passwd.o gendh.o er
|
||||
x509.o genrsa.o gendsa.o s_server.o s_client.o speed.o \
|
||||
s_time.o $(A_OBJ) $(S_OBJ) $(RAND_OBJ) version.o sess_id.o \
|
||||
ciphers.o nseq.o pkcs12.o pkcs8.o spkac.o smime.o rand.o engine.o \
|
||||
ocsp.o prime.o
|
||||
ocsp.o prime.o cms.o
|
||||
|
||||
E_SRC= verify.c asn1pars.c req.c dgst.c dh.c enc.c passwd.c gendh.c errstr.c ca.c \
|
||||
pkcs7.c crl2p7.c crl.c \
|
||||
@ -64,7 +64,7 @@ E_SRC= verify.c asn1pars.c req.c dgst.c dh.c enc.c passwd.c gendh.c errstr.c ca.
|
||||
x509.c genrsa.c gendsa.c s_server.c s_client.c speed.c \
|
||||
s_time.c $(A_SRC) $(S_SRC) $(RAND_SRC) version.c sess_id.c \
|
||||
ciphers.c nseq.c pkcs12.c pkcs8.c spkac.c smime.c rand.c engine.c \
|
||||
ocsp.c prime.c
|
||||
ocsp.c prime.c cms.c
|
||||
|
||||
SRC=$(E_SRC)
|
||||
|
||||
|
@ -2010,7 +2010,7 @@ int parse_yesno(const char *str, int def)
|
||||
case 'y': /* yes */
|
||||
case 'Y': /* YES */
|
||||
case '1': /* 1 */
|
||||
ret = 0;
|
||||
ret = 1;
|
||||
break;
|
||||
default:
|
||||
ret = def;
|
||||
|
@ -2882,13 +2882,22 @@ int old_entry_print(BIO *bp, ASN1_OBJECT *obj, ASN1_STRING *str)
|
||||
p=(char *)str->data;
|
||||
for (j=str->length; j>0; j--)
|
||||
{
|
||||
#ifdef CHARSET_EBCDIC
|
||||
if ((*p >= 0x20) && (*p <= 0x7e))
|
||||
BIO_printf(bp,"%c",os_toebcdic[*p]);
|
||||
#else
|
||||
if ((*p >= ' ') && (*p <= '~'))
|
||||
BIO_printf(bp,"%c",*p);
|
||||
#endif
|
||||
else if (*p & 0x80)
|
||||
BIO_printf(bp,"\\0x%02X",*p);
|
||||
else if ((unsigned char)*p == 0xf7)
|
||||
BIO_printf(bp,"^?");
|
||||
#ifdef CHARSET_EBCDIC
|
||||
else BIO_printf(bp,"^%c",os_toebcdic[*p+0x40]);
|
||||
#else
|
||||
else BIO_printf(bp,"^%c",*p+'@');
|
||||
#endif
|
||||
p++;
|
||||
}
|
||||
BIO_printf(bp,"'\n");
|
||||
|
1347
apps/cms.c
Normal file
1347
apps/cms.c
Normal file
File diff suppressed because it is too large
Load Diff
38
apps/dsa.c
38
apps/dsa.c
@ -240,37 +240,27 @@ bad:
|
||||
goto end;
|
||||
}
|
||||
|
||||
in=BIO_new(BIO_s_file());
|
||||
out=BIO_new(BIO_s_file());
|
||||
if ((in == NULL) || (out == NULL))
|
||||
if (out == NULL)
|
||||
{
|
||||
ERR_print_errors(bio_err);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (infile == NULL)
|
||||
BIO_set_fp(in,stdin,BIO_NOCLOSE);
|
||||
else
|
||||
{
|
||||
if (BIO_read_filename(in,infile) <= 0)
|
||||
{
|
||||
perror(infile);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
BIO_printf(bio_err,"read DSA key\n");
|
||||
if (informat == FORMAT_ASN1) {
|
||||
if(pubin) dsa=d2i_DSA_PUBKEY_bio(in,NULL);
|
||||
else dsa=d2i_DSAPrivateKey_bio(in,NULL);
|
||||
} else if (informat == FORMAT_PEM) {
|
||||
if(pubin) dsa=PEM_read_bio_DSA_PUBKEY(in,NULL, NULL, NULL);
|
||||
else dsa=PEM_read_bio_DSAPrivateKey(in,NULL,NULL,passin);
|
||||
} else
|
||||
{
|
||||
BIO_printf(bio_err,"bad input format specified for key\n");
|
||||
goto end;
|
||||
}
|
||||
{
|
||||
EVP_PKEY *pkey;
|
||||
if (pubin)
|
||||
pkey = load_pubkey(bio_err, infile, informat, 1,
|
||||
passin, e, "Public Key");
|
||||
else
|
||||
pkey = load_key(bio_err, infile, informat, 1,
|
||||
passin, e, "Private Key");
|
||||
|
||||
if (pkey != NULL)
|
||||
dsa = pkey == NULL ? NULL : EVP_PKEY_get1_DSA(pkey);
|
||||
EVP_PKEY_free(pkey);
|
||||
}
|
||||
if (dsa == NULL)
|
||||
{
|
||||
BIO_printf(bio_err,"unable to load Key\n");
|
||||
|
@ -60,12 +60,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "apps.h" /* needs to be included before the openssl headers! */
|
||||
#include <openssl/e_os2.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/ocsp.h>
|
||||
#include <openssl/txt_db.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include "apps.h"
|
||||
#include <openssl/err.h>
|
||||
|
||||
/* Maximum leeway in validity period: default 5 minutes */
|
||||
#define MAX_VALIDITY_PERIOD (5 * 60)
|
||||
|
@ -28,6 +28,7 @@ extern int speed_main(int argc,char *argv[]);
|
||||
extern int s_time_main(int argc,char *argv[]);
|
||||
extern int version_main(int argc,char *argv[]);
|
||||
extern int pkcs7_main(int argc,char *argv[]);
|
||||
extern int cms_main(int argc,char *argv[]);
|
||||
extern int crl2pkcs7_main(int argc,char *argv[]);
|
||||
extern int sess_id_main(int argc,char *argv[]);
|
||||
extern int ciphers_main(int argc,char *argv[]);
|
||||
@ -109,6 +110,9 @@ FUNCTION functions[] = {
|
||||
#endif
|
||||
{FUNC_TYPE_GENERAL,"version",version_main},
|
||||
{FUNC_TYPE_GENERAL,"pkcs7",pkcs7_main},
|
||||
#ifndef OPENSSL_NO_CMS
|
||||
{FUNC_TYPE_GENERAL,"cms",cms_main},
|
||||
#endif
|
||||
{FUNC_TYPE_GENERAL,"crl2pkcs7",crl2pkcs7_main},
|
||||
{FUNC_TYPE_GENERAL,"sess_id",sess_id_main},
|
||||
#if !defined(OPENSSL_NO_SOCK) && !(defined(OPENSSL_NO_SSL2) && defined(OPENSSL_NO_SSL3))
|
||||
|
@ -43,6 +43,8 @@ foreach (@ARGV)
|
||||
{ print "#ifndef OPENSSL_NO_DH\n${str}#endif\n"; }
|
||||
elsif ( ($_ =~ /^pkcs12$/))
|
||||
{ print "#if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_SHA1)\n${str}#endif\n"; }
|
||||
elsif ( ($_ =~ /^cms$/))
|
||||
{ print "#ifndef OPENSSL_NO_CMS\n${str}#endif\n"; }
|
||||
else
|
||||
{ print $str; }
|
||||
}
|
||||
|
@ -719,8 +719,7 @@ bad:
|
||||
message */
|
||||
goto end;
|
||||
}
|
||||
if (EVP_PKEY_type(pkey->type) == EVP_PKEY_DSA ||
|
||||
EVP_PKEY_type(pkey->type) == EVP_PKEY_EC)
|
||||
else
|
||||
{
|
||||
char *randfile = NCONF_get_string(req_conf,SECTION,"RANDFILE");
|
||||
if (randfile == NULL)
|
||||
|
@ -119,24 +119,36 @@ int MAIN(int argc, char **argv)
|
||||
while(argc >= 1)
|
||||
{
|
||||
if (!strcmp(*argv,"-in")) {
|
||||
if (--argc < 1) badarg = 1;
|
||||
infile= *(++argv);
|
||||
if (--argc < 1)
|
||||
badarg = 1;
|
||||
else
|
||||
infile= *(++argv);
|
||||
} else if (!strcmp(*argv,"-out")) {
|
||||
if (--argc < 1) badarg = 1;
|
||||
outfile= *(++argv);
|
||||
if (--argc < 1)
|
||||
badarg = 1;
|
||||
else
|
||||
outfile= *(++argv);
|
||||
} else if(!strcmp(*argv, "-inkey")) {
|
||||
if (--argc < 1) badarg = 1;
|
||||
keyfile = *(++argv);
|
||||
if (--argc < 1)
|
||||
badarg = 1;
|
||||
else
|
||||
keyfile = *(++argv);
|
||||
} else if (!strcmp(*argv,"-passin")) {
|
||||
if (--argc < 1) badarg = 1;
|
||||
passargin= *(++argv);
|
||||
if (--argc < 1)
|
||||
badarg = 1;
|
||||
else
|
||||
passargin= *(++argv);
|
||||
} else if (strcmp(*argv,"-keyform") == 0) {
|
||||
if (--argc < 1) badarg = 1;
|
||||
keyform=str2fmt(*(++argv));
|
||||
if (--argc < 1)
|
||||
badarg = 1;
|
||||
else
|
||||
keyform=str2fmt(*(++argv));
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
} else if(!strcmp(*argv, "-engine")) {
|
||||
if (--argc < 1) badarg = 1;
|
||||
engine = *(++argv);
|
||||
if (--argc < 1)
|
||||
badarg = 1;
|
||||
else
|
||||
engine = *(++argv);
|
||||
#endif
|
||||
} else if(!strcmp(*argv, "-pubin")) {
|
||||
key_type = KEY_PUBKEY;
|
||||
|
@ -317,7 +317,8 @@ int MAIN(int argc, char **argv)
|
||||
int mbuf_len=0;
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
char *engine_id=NULL;
|
||||
ENGINE *e=NULL;
|
||||
char *ssl_client_engine_id=NULL;
|
||||
ENGINE *e=NULL, *ssl_client_engine=NULL;
|
||||
#endif
|
||||
#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE)
|
||||
struct timeval tv;
|
||||
@ -555,6 +556,11 @@ int MAIN(int argc, char **argv)
|
||||
if (--argc < 1) goto bad;
|
||||
engine_id = *(++argv);
|
||||
}
|
||||
else if (strcmp(*argv,"-ssl_client_engine") == 0)
|
||||
{
|
||||
if (--argc < 1) goto bad;
|
||||
ssl_client_engine_id = *(++argv);
|
||||
}
|
||||
#endif
|
||||
else if (strcmp(*argv,"-rand") == 0)
|
||||
{
|
||||
@ -590,6 +596,16 @@ bad:
|
||||
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
e = setup_engine(bio_err, engine_id, 1);
|
||||
if (ssl_client_engine_id)
|
||||
{
|
||||
ssl_client_engine = ENGINE_by_id(ssl_client_engine_id);
|
||||
if (!ssl_client_engine)
|
||||
{
|
||||
BIO_printf(bio_err,
|
||||
"Error getting client auth engine\n");
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (!app_passwd(bio_err, passarg, NULL, &pass, NULL))
|
||||
{
|
||||
@ -657,6 +673,20 @@ bad:
|
||||
goto end;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
if (ssl_client_engine)
|
||||
{
|
||||
if (!SSL_CTX_set_client_cert_engine(ctx, ssl_client_engine))
|
||||
{
|
||||
BIO_puts(bio_err, "Error setting client auth engine\n");
|
||||
ERR_print_errors(bio_err);
|
||||
ENGINE_free(ssl_client_engine);
|
||||
goto end;
|
||||
}
|
||||
ENGINE_free(ssl_client_engine);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (bugs)
|
||||
SSL_CTX_set_options(ctx,SSL_OP_ALL|off);
|
||||
else
|
||||
|
@ -333,6 +333,11 @@ static void sv_usage(void)
|
||||
BIO_printf(bio_err," -Verify arg - turn on peer certificate verification, must have a cert.\n");
|
||||
BIO_printf(bio_err," -cert arg - certificate file to use\n");
|
||||
BIO_printf(bio_err," (default is %s)\n",TEST_CERT);
|
||||
BIO_printf(bio_err," -crl_check - check the peer certificate has not been revoked by its CA.\n" \
|
||||
" The CRL(s) are appended to the certificate file\n");
|
||||
BIO_printf(bio_err," -crl_check_all - check the peer certificate has not been revoked by its CA\n" \
|
||||
" or any other CRL in the CA chain. CRL(s) are appened to the\n" \
|
||||
" the certificate file.\n");
|
||||
BIO_printf(bio_err," -certform arg - certificate format (PEM or DER) PEM default\n");
|
||||
BIO_printf(bio_err," -key arg - Private Key file to use, in cert file if\n");
|
||||
BIO_printf(bio_err," not specified (default is %s)\n",TEST_CERT);
|
||||
@ -909,7 +914,7 @@ int MAIN(int argc, char *argv[])
|
||||
{
|
||||
vflags |= X509_V_FLAG_CRL_CHECK;
|
||||
}
|
||||
else if (strcmp(*argv,"-crl_check") == 0)
|
||||
else if (strcmp(*argv,"-crl_check_all") == 0)
|
||||
{
|
||||
vflags |= X509_V_FLAG_CRL_CHECK|X509_V_FLAG_CRL_CHECK_ALL;
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ APPS=
|
||||
|
||||
LIB=$(TOP)/libcrypto.a
|
||||
LIBSRC=aes_core.c aes_misc.c aes_ecb.c aes_cbc.c aes_cfb.c aes_ofb.c \
|
||||
aes_ctr.c aes_ige.c
|
||||
LIBOBJ=aes_misc.o aes_ecb.o aes_cfb.o aes_ofb.o aes_ctr.o aes_ige.o \
|
||||
aes_ctr.c aes_ige.c aes_wrap.c
|
||||
LIBOBJ=aes_misc.o aes_ecb.o aes_cfb.o aes_ofb.o aes_ctr.o aes_ige.o aes_wrap.o \
|
||||
$(AES_ASM_OBJ)
|
||||
|
||||
SRC= $(LIBSRC)
|
||||
|
@ -134,6 +134,12 @@ void AES_bi_ige_encrypt(const unsigned char *in, unsigned char *out,
|
||||
const AES_KEY *key2, const unsigned char *ivec,
|
||||
const int enc);
|
||||
|
||||
int AES_wrap_key(AES_KEY *key, const unsigned char *iv,
|
||||
unsigned char *out,
|
||||
const unsigned char *in, unsigned int inlen);
|
||||
int AES_unwrap_key(AES_KEY *key, const unsigned char *iv,
|
||||
unsigned char *out,
|
||||
const unsigned char *in, unsigned int inlen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -37,7 +37,10 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <openssl/aes.h>
|
||||
#ifdef OPENSSL_FIPS
|
||||
#include <openssl/fips.h>
|
||||
#endif
|
||||
|
||||
#include "aes_locl.h"
|
||||
|
||||
/*
|
||||
|
259
crypto/aes/aes_wrap.c
Normal file
259
crypto/aes/aes_wrap.c
Normal file
@ -0,0 +1,259 @@
|
||||
/* crypto/aes/aes_wrap.c */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2008 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/bio.h>
|
||||
|
||||
static const unsigned char default_iv[] = {
|
||||
0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6,
|
||||
};
|
||||
|
||||
int AES_wrap_key(AES_KEY *key, const unsigned char *iv,
|
||||
unsigned char *out,
|
||||
const unsigned char *in, unsigned int inlen)
|
||||
{
|
||||
unsigned char *A, B[16], *R;
|
||||
unsigned int i, j, t;
|
||||
if ((inlen & 0x7) || (inlen < 8))
|
||||
return -1;
|
||||
A = B;
|
||||
t = 1;
|
||||
memcpy(out + 8, in, inlen);
|
||||
if (!iv)
|
||||
iv = default_iv;
|
||||
|
||||
memcpy(A, iv, 8);
|
||||
|
||||
for (j = 0; j < 6; j++)
|
||||
{
|
||||
R = out + 8;
|
||||
for (i = 0; i < inlen; i += 8, t++, R += 8)
|
||||
{
|
||||
memcpy(B + 8, R, 8);
|
||||
AES_encrypt(B, B, key);
|
||||
A[7] ^= (unsigned char)(t & 0xff);
|
||||
if (t > 0xff)
|
||||
{
|
||||
A[6] ^= (unsigned char)((t & 0xff) >> 8);
|
||||
A[5] ^= (unsigned char)((t & 0xff) >> 16);
|
||||
A[4] ^= (unsigned char)((t & 0xff) >> 24);
|
||||
}
|
||||
memcpy(R, B + 8, 8);
|
||||
}
|
||||
}
|
||||
memcpy(out, A, 8);
|
||||
return inlen + 8;
|
||||
}
|
||||
|
||||
int AES_unwrap_key(AES_KEY *key, const unsigned char *iv,
|
||||
unsigned char *out,
|
||||
const unsigned char *in, unsigned int inlen)
|
||||
{
|
||||
unsigned char *A, B[16], *R;
|
||||
unsigned int i, j, t;
|
||||
inlen -= 8;
|
||||
if (inlen & 0x7)
|
||||
return -1;
|
||||
if (inlen < 8)
|
||||
return -1;
|
||||
A = B;
|
||||
t = 6 * (inlen >> 3);
|
||||
memcpy(A, in, 8);
|
||||
memcpy(out, in + 8, inlen);
|
||||
for (j = 0; j < 6; j++)
|
||||
{
|
||||
R = out + inlen - 8;
|
||||
for (i = 0; i < inlen; i += 8, t--, R -= 8)
|
||||
{
|
||||
A[7] ^= (unsigned char)(t & 0xff);
|
||||
if (t > 0xff)
|
||||
{
|
||||
A[6] ^= (unsigned char)((t & 0xff) >> 8);
|
||||
A[5] ^= (unsigned char)((t & 0xff) >> 16);
|
||||
A[4] ^= (unsigned char)((t & 0xff) >> 24);
|
||||
}
|
||||
memcpy(B + 8, R, 8);
|
||||
AES_decrypt(B, B, key);
|
||||
memcpy(R, B + 8, 8);
|
||||
}
|
||||
}
|
||||
if (!iv)
|
||||
iv = default_iv;
|
||||
if (memcmp(A, iv, 8))
|
||||
{
|
||||
OPENSSL_cleanse(out, inlen);
|
||||
return 0;
|
||||
}
|
||||
return inlen;
|
||||
}
|
||||
|
||||
#ifdef AES_WRAP_TEST
|
||||
|
||||
int AES_wrap_unwrap_test(const unsigned char *kek, int keybits,
|
||||
const unsigned char *iv,
|
||||
const unsigned char *eout,
|
||||
const unsigned char *key, int keylen)
|
||||
{
|
||||
unsigned char *otmp = NULL, *ptmp = NULL;
|
||||
int r, ret = 0;
|
||||
AES_KEY wctx;
|
||||
otmp = OPENSSL_malloc(keylen + 8);
|
||||
ptmp = OPENSSL_malloc(keylen);
|
||||
if (!otmp || !ptmp)
|
||||
return 0;
|
||||
if (AES_set_encrypt_key(kek, keybits, &wctx))
|
||||
goto err;
|
||||
r = AES_wrap_key(&wctx, iv, otmp, key, keylen);
|
||||
if (r <= 0)
|
||||
goto err;
|
||||
|
||||
if (eout && memcmp(eout, otmp, keylen))
|
||||
goto err;
|
||||
|
||||
if (AES_set_decrypt_key(kek, keybits, &wctx))
|
||||
goto err;
|
||||
r = AES_unwrap_key(&wctx, iv, ptmp, otmp, r);
|
||||
|
||||
if (memcmp(key, ptmp, keylen))
|
||||
goto err;
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
if (otmp)
|
||||
OPENSSL_free(otmp);
|
||||
if (ptmp)
|
||||
OPENSSL_free(ptmp);
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
static const unsigned char kek[] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
|
||||
};
|
||||
|
||||
static const unsigned char key[] = {
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
|
||||
};
|
||||
|
||||
static const unsigned char e1[] = {
|
||||
0x1f, 0xa6, 0x8b, 0x0a, 0x81, 0x12, 0xb4, 0x47,
|
||||
0xae, 0xf3, 0x4b, 0xd8, 0xfb, 0x5a, 0x7b, 0x82,
|
||||
0x9d, 0x3e, 0x86, 0x23, 0x71, 0xd2, 0xcf, 0xe5
|
||||
};
|
||||
|
||||
static const unsigned char e2[] = {
|
||||
0x96, 0x77, 0x8b, 0x25, 0xae, 0x6c, 0xa4, 0x35,
|
||||
0xf9, 0x2b, 0x5b, 0x97, 0xc0, 0x50, 0xae, 0xd2,
|
||||
0x46, 0x8a, 0xb8, 0xa1, 0x7a, 0xd8, 0x4e, 0x5d
|
||||
};
|
||||
|
||||
static const unsigned char e3[] = {
|
||||
0x64, 0xe8, 0xc3, 0xf9, 0xce, 0x0f, 0x5b, 0xa2,
|
||||
0x63, 0xe9, 0x77, 0x79, 0x05, 0x81, 0x8a, 0x2a,
|
||||
0x93, 0xc8, 0x19, 0x1e, 0x7d, 0x6e, 0x8a, 0xe7
|
||||
};
|
||||
|
||||
static const unsigned char e4[] = {
|
||||
0x03, 0x1d, 0x33, 0x26, 0x4e, 0x15, 0xd3, 0x32,
|
||||
0x68, 0xf2, 0x4e, 0xc2, 0x60, 0x74, 0x3e, 0xdc,
|
||||
0xe1, 0xc6, 0xc7, 0xdd, 0xee, 0x72, 0x5a, 0x93,
|
||||
0x6b, 0xa8, 0x14, 0x91, 0x5c, 0x67, 0x62, 0xd2
|
||||
};
|
||||
|
||||
static const unsigned char e5[] = {
|
||||
0xa8, 0xf9, 0xbc, 0x16, 0x12, 0xc6, 0x8b, 0x3f,
|
||||
0xf6, 0xe6, 0xf4, 0xfb, 0xe3, 0x0e, 0x71, 0xe4,
|
||||
0x76, 0x9c, 0x8b, 0x80, 0xa3, 0x2c, 0xb8, 0x95,
|
||||
0x8c, 0xd5, 0xd1, 0x7d, 0x6b, 0x25, 0x4d, 0xa1
|
||||
};
|
||||
|
||||
static const unsigned char e6[] = {
|
||||
0x28, 0xc9, 0xf4, 0x04, 0xc4, 0xb8, 0x10, 0xf4,
|
||||
0xcb, 0xcc, 0xb3, 0x5c, 0xfb, 0x87, 0xf8, 0x26,
|
||||
0x3f, 0x57, 0x86, 0xe2, 0xd8, 0x0e, 0xd3, 0x26,
|
||||
0xcb, 0xc7, 0xf0, 0xe7, 0x1a, 0x99, 0xf4, 0x3b,
|
||||
0xfb, 0x98, 0x8b, 0x9b, 0x7a, 0x02, 0xdd, 0x21
|
||||
};
|
||||
|
||||
AES_KEY wctx, xctx;
|
||||
int ret;
|
||||
ret = AES_wrap_unwrap_test(kek, 128, NULL, e1, key, 16);
|
||||
fprintf(stderr, "Key test result %d\n", ret);
|
||||
ret = AES_wrap_unwrap_test(kek, 192, NULL, e2, key, 16);
|
||||
fprintf(stderr, "Key test result %d\n", ret);
|
||||
ret = AES_wrap_unwrap_test(kek, 256, NULL, e3, key, 16);
|
||||
fprintf(stderr, "Key test result %d\n", ret);
|
||||
ret = AES_wrap_unwrap_test(kek, 192, NULL, e4, key, 24);
|
||||
fprintf(stderr, "Key test result %d\n", ret);
|
||||
ret = AES_wrap_unwrap_test(kek, 256, NULL, e5, key, 24);
|
||||
fprintf(stderr, "Key test result %d\n", ret);
|
||||
ret = AES_wrap_unwrap_test(kek, 256, NULL, e6, key, 32);
|
||||
fprintf(stderr, "Key test result %d\n", ret);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -26,7 +26,7 @@ LIBSRC= a_object.c a_bitstr.c a_utctm.c a_gentm.c a_time.c a_int.c a_octet.c \
|
||||
t_req.c t_x509.c t_x509a.c t_crl.c t_pkey.c t_spki.c t_bitst.c \
|
||||
tasn_new.c tasn_fre.c tasn_enc.c tasn_dec.c tasn_utl.c tasn_typ.c \
|
||||
f_int.c f_string.c n_pkey.c \
|
||||
f_enum.c a_hdr.c x_pkey.c a_bool.c x_exten.c \
|
||||
f_enum.c a_hdr.c x_pkey.c a_bool.c x_exten.c asn_mime.c \
|
||||
asn1_gen.c asn1_par.c asn1_lib.c asn1_err.c a_meth.c a_bytes.c a_strnid.c \
|
||||
evp_asn1.c asn_pack.c p5_pbe.c p5_pbev2.c p8_pkey.c asn_moid.c
|
||||
LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_gentm.o a_time.o a_int.o a_octet.o \
|
||||
@ -38,7 +38,7 @@ LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_gentm.o a_time.o a_int.o a_octet.o \
|
||||
t_req.o t_x509.o t_x509a.o t_crl.o t_pkey.o t_spki.o t_bitst.o \
|
||||
tasn_new.o tasn_fre.o tasn_enc.o tasn_dec.o tasn_utl.o tasn_typ.o \
|
||||
f_int.o f_string.o n_pkey.o \
|
||||
f_enum.o a_hdr.o x_pkey.o a_bool.o x_exten.o \
|
||||
f_enum.o a_hdr.o x_pkey.o a_bool.o x_exten.o asn_mime.o \
|
||||
asn1_gen.o asn1_par.o asn1_lib.o asn1_err.o a_meth.o a_bytes.o a_strnid.o \
|
||||
evp_asn1.o asn_pack.o p5_pbe.o p5_pbev2.o p8_pkey.o asn_moid.o
|
||||
|
||||
|
@ -62,6 +62,7 @@
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/bn.h>
|
||||
|
||||
int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp)
|
||||
{
|
||||
|
@ -59,6 +59,7 @@
|
||||
#include <stdio.h>
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/objects.h>
|
||||
|
||||
int ASN1_TYPE_get(ASN1_TYPE *a)
|
||||
{
|
||||
@ -79,6 +80,31 @@ void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
|
||||
a->value.ptr=value;
|
||||
}
|
||||
|
||||
int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value)
|
||||
{
|
||||
if (!value || (type == V_ASN1_BOOLEAN))
|
||||
{
|
||||
void *p = (void *)value;
|
||||
ASN1_TYPE_set(a, type, p);
|
||||
}
|
||||
else if (type == V_ASN1_OBJECT)
|
||||
{
|
||||
ASN1_OBJECT *odup;
|
||||
odup = OBJ_dup(value);
|
||||
if (!odup)
|
||||
return 0;
|
||||
ASN1_TYPE_set(a, type, odup);
|
||||
}
|
||||
else
|
||||
{
|
||||
ASN1_STRING *sdup;
|
||||
sdup = ASN1_STRING_dup((ASN1_STRING *)value);
|
||||
if (!sdup)
|
||||
return 0;
|
||||
ASN1_TYPE_set(a, type, sdup);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
IMPLEMENT_STACK_OF(ASN1_TYPE)
|
||||
IMPLEMENT_ASN1_SET_OF(ASN1_TYPE)
|
||||
|
@ -158,7 +158,12 @@ extern "C" {
|
||||
#define MBSTRING_BMP (MBSTRING_FLAG|2)
|
||||
#define MBSTRING_UNIV (MBSTRING_FLAG|4)
|
||||
|
||||
#define SMIME_OLDMIME 0x400
|
||||
#define SMIME_CRLFEOL 0x800
|
||||
#define SMIME_STREAM 0x1000
|
||||
|
||||
struct X509_algor_st;
|
||||
DECLARE_STACK_OF(X509_ALGOR)
|
||||
|
||||
#define DECLARE_ASN1_SET_OF(type) /* filled in by mkstack.pl */
|
||||
#define IMPLEMENT_ASN1_SET_OF(type) /* nothing, no longer needed */
|
||||
@ -218,6 +223,13 @@ typedef struct asn1_object_st
|
||||
* be inserted in the memory buffer
|
||||
*/
|
||||
#define ASN1_STRING_FLAG_NDEF 0x010
|
||||
|
||||
/* This flag is used by the CMS code to indicate that a string is not
|
||||
* complete and is a place holder for content when it had all been
|
||||
* accessed. The flag will be reset when content has been written to it.
|
||||
*/
|
||||
#define ASN1_STRING_FLAG_CONT 0x020
|
||||
|
||||
/* This is the base type that holds just about everything :-) */
|
||||
typedef struct asn1_string_st
|
||||
{
|
||||
@ -311,8 +323,8 @@ typedef struct ASN1_VALUE_st ASN1_VALUE;
|
||||
int i2d_##name##_NDEF(name *a, unsigned char **out);
|
||||
|
||||
#define DECLARE_ASN1_FUNCTIONS_const(name) \
|
||||
name *name##_new(void); \
|
||||
void name##_free(name *a);
|
||||
DECLARE_ASN1_ALLOC_FUNCTIONS(name) \
|
||||
DECLARE_ASN1_ENCODE_FUNCTIONS_const(name, name)
|
||||
|
||||
#define DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \
|
||||
type *name##_new(void); \
|
||||
@ -753,6 +765,7 @@ DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
|
||||
|
||||
int ASN1_TYPE_get(ASN1_TYPE *a);
|
||||
void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
|
||||
int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value);
|
||||
|
||||
ASN1_OBJECT * ASN1_OBJECT_new(void );
|
||||
void ASN1_OBJECT_free(ASN1_OBJECT *a);
|
||||
@ -775,6 +788,7 @@ int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b);
|
||||
/* Since this is used to store all sorts of things, via macros, for now, make
|
||||
its data void * */
|
||||
int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
|
||||
void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len);
|
||||
int ASN1_STRING_length(ASN1_STRING *x);
|
||||
void ASN1_STRING_length_set(ASN1_STRING *x, int n);
|
||||
int ASN1_STRING_type(ASN1_STRING *x);
|
||||
@ -927,6 +941,12 @@ void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, char *x);
|
||||
|
||||
void *ASN1_item_dup(const ASN1_ITEM *it, void *x);
|
||||
|
||||
/* ASN1 alloc/free macros for when a type is only used internally */
|
||||
|
||||
#define M_ASN1_new_of(type) (type *)ASN1_item_new(ASN1_ITEM_rptr(type))
|
||||
#define M_ASN1_free_of(x, type) \
|
||||
ASN1_item_free(CHECKED_PTR_OF(type, x), ASN1_ITEM_rptr(type))
|
||||
|
||||
#ifndef OPENSSL_NO_FP_API
|
||||
void *ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x);
|
||||
|
||||
@ -1055,7 +1075,17 @@ void ASN1_add_oid_module(void);
|
||||
|
||||
ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf);
|
||||
ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf);
|
||||
|
||||
|
||||
typedef int asn1_output_data_fn(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
|
||||
const ASN1_ITEM *it);
|
||||
|
||||
int int_smime_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
|
||||
int ctype_nid, int econt_nid,
|
||||
STACK_OF(X509_ALGOR) *mdalgs,
|
||||
asn1_output_data_fn *data_fn,
|
||||
const ASN1_ITEM *it);
|
||||
ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it);
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
@ -1105,6 +1135,7 @@ void ERR_load_ASN1_strings(void);
|
||||
#define ASN1_F_ASN1_ITEM_VERIFY 197
|
||||
#define ASN1_F_ASN1_MBSTRING_NCOPY 122
|
||||
#define ASN1_F_ASN1_OBJECT_NEW 123
|
||||
#define ASN1_F_ASN1_OUTPUT_DATA 207
|
||||
#define ASN1_F_ASN1_PACK_STRING 124
|
||||
#define ASN1_F_ASN1_PCTX_NEW 205
|
||||
#define ASN1_F_ASN1_PKCS5_PBE_SET 125
|
||||
@ -1124,6 +1155,8 @@ void ERR_load_ASN1_strings(void);
|
||||
#define ASN1_F_ASN1_UNPACK_STRING 136
|
||||
#define ASN1_F_ASN1_UTCTIME_SET 187
|
||||
#define ASN1_F_ASN1_VERIFY 137
|
||||
#define ASN1_F_B64_READ_ASN1 208
|
||||
#define ASN1_F_B64_WRITE_ASN1 209
|
||||
#define ASN1_F_BITSTR_CB 180
|
||||
#define ASN1_F_BN_TO_ASN1_ENUMERATED 138
|
||||
#define ASN1_F_BN_TO_ASN1_INTEGER 139
|
||||
@ -1164,6 +1197,8 @@ void ERR_load_ASN1_strings(void);
|
||||
#define ASN1_F_PARSE_TAGGING 182
|
||||
#define ASN1_F_PKCS5_PBE2_SET 167
|
||||
#define ASN1_F_PKCS5_PBE_SET 202
|
||||
#define ASN1_F_SMIME_READ_ASN1 210
|
||||
#define ASN1_F_SMIME_TEXT 211
|
||||
#define ASN1_F_X509_CINF_NEW 168
|
||||
#define ASN1_F_X509_CRL_ADD0_REVOKED 169
|
||||
#define ASN1_F_X509_INFO_NEW 170
|
||||
@ -1175,6 +1210,8 @@ void ERR_load_ASN1_strings(void);
|
||||
|
||||
/* Reason codes. */
|
||||
#define ASN1_R_ADDING_OBJECT 171
|
||||
#define ASN1_R_ASN1_PARSE_ERROR 198
|
||||
#define ASN1_R_ASN1_SIG_PARSE_ERROR 199
|
||||
#define ASN1_R_AUX_ERROR 100
|
||||
#define ASN1_R_BAD_CLASS 101
|
||||
#define ASN1_R_BAD_OBJECT_HEADER 102
|
||||
@ -1221,6 +1258,7 @@ void ERR_load_ASN1_strings(void);
|
||||
#define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG 128
|
||||
#define ASN1_R_INVALID_BMPSTRING_LENGTH 129
|
||||
#define ASN1_R_INVALID_DIGIT 130
|
||||
#define ASN1_R_INVALID_MIME_TYPE 200
|
||||
#define ASN1_R_INVALID_MODIFIER 186
|
||||
#define ASN1_R_INVALID_NUMBER 187
|
||||
#define ASN1_R_INVALID_SEPARATOR 131
|
||||
@ -1230,6 +1268,9 @@ void ERR_load_ASN1_strings(void);
|
||||
#define ASN1_R_IV_TOO_LARGE 135
|
||||
#define ASN1_R_LENGTH_ERROR 136
|
||||
#define ASN1_R_LIST_ERROR 188
|
||||
#define ASN1_R_MIME_NO_CONTENT_TYPE 201
|
||||
#define ASN1_R_MIME_PARSE_ERROR 202
|
||||
#define ASN1_R_MIME_SIG_PARSE_ERROR 203
|
||||
#define ASN1_R_MISSING_EOC 137
|
||||
#define ASN1_R_MISSING_SECOND_NUMBER 138
|
||||
#define ASN1_R_MISSING_VALUE 189
|
||||
@ -1239,7 +1280,11 @@ void ERR_load_ASN1_strings(void);
|
||||
#define ASN1_R_NON_HEX_CHARACTERS 141
|
||||
#define ASN1_R_NOT_ASCII_FORMAT 190
|
||||
#define ASN1_R_NOT_ENOUGH_DATA 142
|
||||
#define ASN1_R_NO_CONTENT_TYPE 204
|
||||
#define ASN1_R_NO_MATCHING_CHOICE_TYPE 143
|
||||
#define ASN1_R_NO_MULTIPART_BODY_FAILURE 205
|
||||
#define ASN1_R_NO_MULTIPART_BOUNDARY 206
|
||||
#define ASN1_R_NO_SIG_CONTENT_TYPE 207
|
||||
#define ASN1_R_NULL_IS_WRONG_LENGTH 144
|
||||
#define ASN1_R_OBJECT_NOT_ASCII_FORMAT 191
|
||||
#define ASN1_R_ODD_NUMBER_OF_CHARS 145
|
||||
@ -1249,6 +1294,8 @@ void ERR_load_ASN1_strings(void);
|
||||
#define ASN1_R_SEQUENCE_NOT_CONSTRUCTED 149
|
||||
#define ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG 192
|
||||
#define ASN1_R_SHORT_LINE 150
|
||||
#define ASN1_R_SIG_INVALID_MIME_TYPE 208
|
||||
#define ASN1_R_STREAMING_NOT_SUPPORTED 209
|
||||
#define ASN1_R_STRING_TOO_LONG 151
|
||||
#define ASN1_R_STRING_TOO_SHORT 152
|
||||
#define ASN1_R_TAG_VALUE_TOO_HIGH 153
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* crypto/asn1/asn1_err.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
|
||||
* Copyright (c) 1999-2008 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -110,6 +110,7 @@ static ERR_STRING_DATA ASN1_str_functs[]=
|
||||
{ERR_FUNC(ASN1_F_ASN1_ITEM_VERIFY), "ASN1_item_verify"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_MBSTRING_NCOPY), "ASN1_mbstring_ncopy"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_OBJECT_NEW), "ASN1_OBJECT_new"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_OUTPUT_DATA), "ASN1_OUTPUT_DATA"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_PACK_STRING), "ASN1_pack_string"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_PCTX_NEW), "ASN1_PCTX_NEW"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_PKCS5_PBE_SET), "ASN1_PKCS5_PBE_SET"},
|
||||
@ -129,6 +130,8 @@ static ERR_STRING_DATA ASN1_str_functs[]=
|
||||
{ERR_FUNC(ASN1_F_ASN1_UNPACK_STRING), "ASN1_unpack_string"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_UTCTIME_SET), "ASN1_UTCTIME_set"},
|
||||
{ERR_FUNC(ASN1_F_ASN1_VERIFY), "ASN1_verify"},
|
||||
{ERR_FUNC(ASN1_F_B64_READ_ASN1), "B64_READ_ASN1"},
|
||||
{ERR_FUNC(ASN1_F_B64_WRITE_ASN1), "B64_WRITE_ASN1"},
|
||||
{ERR_FUNC(ASN1_F_BITSTR_CB), "BITSTR_CB"},
|
||||
{ERR_FUNC(ASN1_F_BN_TO_ASN1_ENUMERATED), "BN_to_ASN1_ENUMERATED"},
|
||||
{ERR_FUNC(ASN1_F_BN_TO_ASN1_INTEGER), "BN_to_ASN1_INTEGER"},
|
||||
@ -169,6 +172,8 @@ static ERR_STRING_DATA ASN1_str_functs[]=
|
||||
{ERR_FUNC(ASN1_F_PARSE_TAGGING), "PARSE_TAGGING"},
|
||||
{ERR_FUNC(ASN1_F_PKCS5_PBE2_SET), "PKCS5_pbe2_set"},
|
||||
{ERR_FUNC(ASN1_F_PKCS5_PBE_SET), "PKCS5_pbe_set"},
|
||||
{ERR_FUNC(ASN1_F_SMIME_READ_ASN1), "SMIME_read_ASN1"},
|
||||
{ERR_FUNC(ASN1_F_SMIME_TEXT), "SMIME_text"},
|
||||
{ERR_FUNC(ASN1_F_X509_CINF_NEW), "X509_CINF_NEW"},
|
||||
{ERR_FUNC(ASN1_F_X509_CRL_ADD0_REVOKED), "X509_CRL_add0_revoked"},
|
||||
{ERR_FUNC(ASN1_F_X509_INFO_NEW), "X509_INFO_new"},
|
||||
@ -183,6 +188,8 @@ static ERR_STRING_DATA ASN1_str_functs[]=
|
||||
static ERR_STRING_DATA ASN1_str_reasons[]=
|
||||
{
|
||||
{ERR_REASON(ASN1_R_ADDING_OBJECT) ,"adding object"},
|
||||
{ERR_REASON(ASN1_R_ASN1_PARSE_ERROR) ,"asn1 parse error"},
|
||||
{ERR_REASON(ASN1_R_ASN1_SIG_PARSE_ERROR) ,"asn1 sig parse error"},
|
||||
{ERR_REASON(ASN1_R_AUX_ERROR) ,"aux error"},
|
||||
{ERR_REASON(ASN1_R_BAD_CLASS) ,"bad class"},
|
||||
{ERR_REASON(ASN1_R_BAD_OBJECT_HEADER) ,"bad object header"},
|
||||
@ -229,6 +236,7 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
|
||||
{ERR_REASON(ASN1_R_INTEGER_TOO_LARGE_FOR_LONG),"integer too large for long"},
|
||||
{ERR_REASON(ASN1_R_INVALID_BMPSTRING_LENGTH),"invalid bmpstring length"},
|
||||
{ERR_REASON(ASN1_R_INVALID_DIGIT) ,"invalid digit"},
|
||||
{ERR_REASON(ASN1_R_INVALID_MIME_TYPE) ,"invalid mime type"},
|
||||
{ERR_REASON(ASN1_R_INVALID_MODIFIER) ,"invalid modifier"},
|
||||
{ERR_REASON(ASN1_R_INVALID_NUMBER) ,"invalid number"},
|
||||
{ERR_REASON(ASN1_R_INVALID_SEPARATOR) ,"invalid separator"},
|
||||
@ -238,6 +246,9 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
|
||||
{ERR_REASON(ASN1_R_IV_TOO_LARGE) ,"iv too large"},
|
||||
{ERR_REASON(ASN1_R_LENGTH_ERROR) ,"length error"},
|
||||
{ERR_REASON(ASN1_R_LIST_ERROR) ,"list error"},
|
||||
{ERR_REASON(ASN1_R_MIME_NO_CONTENT_TYPE) ,"mime no content type"},
|
||||
{ERR_REASON(ASN1_R_MIME_PARSE_ERROR) ,"mime parse error"},
|
||||
{ERR_REASON(ASN1_R_MIME_SIG_PARSE_ERROR) ,"mime sig parse error"},
|
||||
{ERR_REASON(ASN1_R_MISSING_EOC) ,"missing eoc"},
|
||||
{ERR_REASON(ASN1_R_MISSING_SECOND_NUMBER),"missing second number"},
|
||||
{ERR_REASON(ASN1_R_MISSING_VALUE) ,"missing value"},
|
||||
@ -247,7 +258,11 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
|
||||
{ERR_REASON(ASN1_R_NON_HEX_CHARACTERS) ,"non hex characters"},
|
||||
{ERR_REASON(ASN1_R_NOT_ASCII_FORMAT) ,"not ascii format"},
|
||||
{ERR_REASON(ASN1_R_NOT_ENOUGH_DATA) ,"not enough data"},
|
||||
{ERR_REASON(ASN1_R_NO_CONTENT_TYPE) ,"no content type"},
|
||||
{ERR_REASON(ASN1_R_NO_MATCHING_CHOICE_TYPE),"no matching choice type"},
|
||||
{ERR_REASON(ASN1_R_NO_MULTIPART_BODY_FAILURE),"no multipart body failure"},
|
||||
{ERR_REASON(ASN1_R_NO_MULTIPART_BOUNDARY),"no multipart boundary"},
|
||||
{ERR_REASON(ASN1_R_NO_SIG_CONTENT_TYPE) ,"no sig content type"},
|
||||
{ERR_REASON(ASN1_R_NULL_IS_WRONG_LENGTH) ,"null is wrong length"},
|
||||
{ERR_REASON(ASN1_R_OBJECT_NOT_ASCII_FORMAT),"object not ascii format"},
|
||||
{ERR_REASON(ASN1_R_ODD_NUMBER_OF_CHARS) ,"odd number of chars"},
|
||||
@ -257,6 +272,8 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
|
||||
{ERR_REASON(ASN1_R_SEQUENCE_NOT_CONSTRUCTED),"sequence not constructed"},
|
||||
{ERR_REASON(ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG),"sequence or set needs config"},
|
||||
{ERR_REASON(ASN1_R_SHORT_LINE) ,"short line"},
|
||||
{ERR_REASON(ASN1_R_SIG_INVALID_MIME_TYPE),"sig invalid mime type"},
|
||||
{ERR_REASON(ASN1_R_STREAMING_NOT_SUPPORTED),"streaming not supported"},
|
||||
{ERR_REASON(ASN1_R_STRING_TOO_LONG) ,"string too long"},
|
||||
{ERR_REASON(ASN1_R_STRING_TOO_SHORT) ,"string too short"},
|
||||
{ERR_REASON(ASN1_R_TAG_VALUE_TOO_HIGH) ,"tag value too high"},
|
||||
|
@ -393,6 +393,14 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
|
||||
return(1);
|
||||
}
|
||||
|
||||
void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len)
|
||||
{
|
||||
if (str->data)
|
||||
OPENSSL_free(str->data);
|
||||
str->data = data;
|
||||
str->length = len;
|
||||
}
|
||||
|
||||
ASN1_STRING *ASN1_STRING_new(void)
|
||||
{
|
||||
return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
|
||||
|
@ -169,6 +169,9 @@ extern "C" {
|
||||
#define ASN1_NDEF_SEQUENCE(tname) \
|
||||
ASN1_SEQUENCE(tname)
|
||||
|
||||
#define ASN1_NDEF_SEQUENCE_cb(tname, cb) \
|
||||
ASN1_SEQUENCE_cb(tname, cb)
|
||||
|
||||
#define ASN1_SEQUENCE_cb(tname, cb) \
|
||||
static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
|
||||
ASN1_SEQUENCE(tname)
|
||||
@ -368,6 +371,10 @@ extern "C" {
|
||||
#define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \
|
||||
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
|
||||
|
||||
/* EXPLICIT using indefinite length constructed form */
|
||||
#define ASN1_NDEF_EXP(stname, field, type, tag) \
|
||||
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_NDEF)
|
||||
|
||||
/* EXPLICIT OPTIONAL using indefinite length constructed form */
|
||||
#define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \
|
||||
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_NDEF)
|
||||
|
874
crypto/asn1/asn_mime.c
Normal file
874
crypto/asn1/asn_mime.c
Normal file
@ -0,0 +1,874 @@
|
||||
/* asn_mime.c */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-2008 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
|
||||
/* Generalised MIME like utilities for streaming ASN1. Although many
|
||||
* have a PKCS7/CMS like flavour others are more general purpose.
|
||||
*/
|
||||
|
||||
/* MIME format structures
|
||||
* Note that all are translated to lower case apart from
|
||||
* parameter values. Quotes are stripped off
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
char *param_name; /* Param name e.g. "micalg" */
|
||||
char *param_value; /* Param value e.g. "sha1" */
|
||||
} MIME_PARAM;
|
||||
|
||||
DECLARE_STACK_OF(MIME_PARAM)
|
||||
IMPLEMENT_STACK_OF(MIME_PARAM)
|
||||
|
||||
typedef struct {
|
||||
char *name; /* Name of line e.g. "content-type" */
|
||||
char *value; /* Value of line e.g. "text/plain" */
|
||||
STACK_OF(MIME_PARAM) *params; /* Zero or more parameters */
|
||||
} MIME_HEADER;
|
||||
|
||||
DECLARE_STACK_OF(MIME_HEADER)
|
||||
IMPLEMENT_STACK_OF(MIME_HEADER)
|
||||
|
||||
static char * strip_ends(char *name);
|
||||
static char * strip_start(char *name);
|
||||
static char * strip_end(char *name);
|
||||
static MIME_HEADER *mime_hdr_new(char *name, char *value);
|
||||
static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value);
|
||||
static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio);
|
||||
static int mime_hdr_cmp(const MIME_HEADER * const *a,
|
||||
const MIME_HEADER * const *b);
|
||||
static int mime_param_cmp(const MIME_PARAM * const *a,
|
||||
const MIME_PARAM * const *b);
|
||||
static void mime_param_free(MIME_PARAM *param);
|
||||
static int mime_bound_check(char *line, int linelen, char *bound, int blen);
|
||||
static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret);
|
||||
static int strip_eol(char *linebuf, int *plen);
|
||||
static MIME_HEADER *mime_hdr_find(STACK_OF(MIME_HEADER) *hdrs, char *name);
|
||||
static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name);
|
||||
static void mime_hdr_free(MIME_HEADER *hdr);
|
||||
|
||||
#define MAX_SMLEN 1024
|
||||
#define mime_debug(x) /* x */
|
||||
|
||||
/* Base 64 read and write of ASN1 structure */
|
||||
|
||||
static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
|
||||
const ASN1_ITEM *it)
|
||||
{
|
||||
BIO *b64;
|
||||
int r;
|
||||
b64 = BIO_new(BIO_f_base64());
|
||||
if(!b64)
|
||||
{
|
||||
ASN1err(ASN1_F_B64_WRITE_ASN1,ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
/* prepend the b64 BIO so all data is base64 encoded.
|
||||
*/
|
||||
out = BIO_push(b64, out);
|
||||
r = ASN1_item_i2d_bio(it, out, val);
|
||||
(void)BIO_flush(out);
|
||||
BIO_pop(out);
|
||||
BIO_free(b64);
|
||||
return r;
|
||||
}
|
||||
|
||||
static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it)
|
||||
{
|
||||
BIO *b64;
|
||||
ASN1_VALUE *val;
|
||||
if(!(b64 = BIO_new(BIO_f_base64()))) {
|
||||
ASN1err(ASN1_F_B64_READ_ASN1,ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
bio = BIO_push(b64, bio);
|
||||
val = ASN1_item_d2i_bio(it, bio, NULL);
|
||||
if(!val)
|
||||
ASN1err(ASN1_F_B64_READ_ASN1,ASN1_R_DECODE_ERROR);
|
||||
(void)BIO_flush(bio);
|
||||
bio = BIO_pop(bio);
|
||||
BIO_free(b64);
|
||||
return val;
|
||||
}
|
||||
|
||||
/* Generate the MIME "micalg" parameter from RFC3851, RFC4490 */
|
||||
|
||||
static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs)
|
||||
{
|
||||
const EVP_MD *md;
|
||||
int i, have_unknown = 0, write_comma, md_nid;
|
||||
have_unknown = 0;
|
||||
write_comma = 0;
|
||||
for (i = 0; i < sk_X509_ALGOR_num(mdalgs); i++)
|
||||
{
|
||||
if (write_comma)
|
||||
BIO_write(out, ",", 1);
|
||||
write_comma = 1;
|
||||
md_nid = OBJ_obj2nid(sk_X509_ALGOR_value(mdalgs, i)->algorithm);
|
||||
md = EVP_get_digestbynid(md_nid);
|
||||
switch(md_nid)
|
||||
{
|
||||
case NID_sha1:
|
||||
BIO_puts(out, "sha1");
|
||||
break;
|
||||
|
||||
case NID_md5:
|
||||
BIO_puts(out, "md5");
|
||||
break;
|
||||
|
||||
case NID_sha256:
|
||||
BIO_puts(out, "sha-256");
|
||||
break;
|
||||
|
||||
case NID_sha384:
|
||||
BIO_puts(out, "sha-384");
|
||||
break;
|
||||
|
||||
case NID_sha512:
|
||||
BIO_puts(out, "sha-512");
|
||||
break;
|
||||
|
||||
default:
|
||||
if (have_unknown)
|
||||
write_comma = 0;
|
||||
else
|
||||
{
|
||||
BIO_puts(out, "unknown");
|
||||
have_unknown = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
/* SMIME sender */
|
||||
|
||||
int int_smime_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
|
||||
int ctype_nid, int econt_nid,
|
||||
STACK_OF(X509_ALGOR) *mdalgs,
|
||||
asn1_output_data_fn *data_fn,
|
||||
const ASN1_ITEM *it)
|
||||
{
|
||||
char bound[33], c;
|
||||
int i;
|
||||
const char *mime_prefix, *mime_eol, *cname = "smime.p7m";
|
||||
const char *msg_type=NULL;
|
||||
if (flags & SMIME_OLDMIME)
|
||||
mime_prefix = "application/x-pkcs7-";
|
||||
else
|
||||
mime_prefix = "application/pkcs7-";
|
||||
|
||||
if (flags & SMIME_CRLFEOL)
|
||||
mime_eol = "\r\n";
|
||||
else
|
||||
mime_eol = "\n";
|
||||
if((flags & SMIME_DETACHED) && data) {
|
||||
/* We want multipart/signed */
|
||||
/* Generate a random boundary */
|
||||
RAND_pseudo_bytes((unsigned char *)bound, 32);
|
||||
for(i = 0; i < 32; i++) {
|
||||
c = bound[i] & 0xf;
|
||||
if(c < 10) c += '0';
|
||||
else c += 'A' - 10;
|
||||
bound[i] = c;
|
||||
}
|
||||
bound[32] = 0;
|
||||
BIO_printf(bio, "MIME-Version: 1.0%s", mime_eol);
|
||||
BIO_printf(bio, "Content-Type: multipart/signed;");
|
||||
BIO_printf(bio, " protocol=\"%ssignature\";", mime_prefix);
|
||||
BIO_puts(bio, " micalg=\"");
|
||||
asn1_write_micalg(bio, mdalgs);
|
||||
BIO_printf(bio, "\"; boundary=\"----%s\"%s%s",
|
||||
bound, mime_eol, mime_eol);
|
||||
BIO_printf(bio, "This is an S/MIME signed message%s%s",
|
||||
mime_eol, mime_eol);
|
||||
/* Now write out the first part */
|
||||
BIO_printf(bio, "------%s%s", bound, mime_eol);
|
||||
if (!data_fn(bio, data, val, flags, it))
|
||||
return 0;
|
||||
BIO_printf(bio, "%s------%s%s", mime_eol, bound, mime_eol);
|
||||
|
||||
/* Headers for signature */
|
||||
|
||||
BIO_printf(bio, "Content-Type: %ssignature;", mime_prefix);
|
||||
BIO_printf(bio, " name=\"smime.p7s\"%s", mime_eol);
|
||||
BIO_printf(bio, "Content-Transfer-Encoding: base64%s",
|
||||
mime_eol);
|
||||
BIO_printf(bio, "Content-Disposition: attachment;");
|
||||
BIO_printf(bio, " filename=\"smime.p7s\"%s%s",
|
||||
mime_eol, mime_eol);
|
||||
B64_write_ASN1(bio, val, NULL, 0, it);
|
||||
BIO_printf(bio,"%s------%s--%s%s", mime_eol, bound,
|
||||
mime_eol, mime_eol);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Determine smime-type header */
|
||||
|
||||
if (ctype_nid == NID_pkcs7_enveloped)
|
||||
msg_type = "enveloped-data";
|
||||
else if (ctype_nid == NID_pkcs7_signed)
|
||||
{
|
||||
if (econt_nid == NID_id_smime_ct_receipt)
|
||||
msg_type = "signed-receipt";
|
||||
else if (sk_X509_ALGOR_num(mdalgs) >= 0)
|
||||
msg_type = "signed-data";
|
||||
else
|
||||
msg_type = "certs-only";
|
||||
}
|
||||
else if (ctype_nid == NID_id_smime_ct_compressedData)
|
||||
{
|
||||
msg_type = "compressed-data";
|
||||
cname = "smime.p7z";
|
||||
}
|
||||
/* MIME headers */
|
||||
BIO_printf(bio, "MIME-Version: 1.0%s", mime_eol);
|
||||
BIO_printf(bio, "Content-Disposition: attachment;");
|
||||
BIO_printf(bio, " filename=\"%s\"%s", cname, mime_eol);
|
||||
BIO_printf(bio, "Content-Type: %smime;", mime_prefix);
|
||||
if (msg_type)
|
||||
BIO_printf(bio, " smime-type=%s;", msg_type);
|
||||
BIO_printf(bio, " name=\"%s\"%s", cname, mime_eol);
|
||||
BIO_printf(bio, "Content-Transfer-Encoding: base64%s%s",
|
||||
mime_eol, mime_eol);
|
||||
if (!B64_write_ASN1(bio, val, data, flags, it))
|
||||
return 0;
|
||||
BIO_printf(bio, "%s", mime_eol);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
/* Handle output of ASN1 data */
|
||||
|
||||
|
||||
static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
|
||||
const ASN1_ITEM *it)
|
||||
{
|
||||
BIO *tmpbio;
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
ASN1_STREAM_ARG sarg;
|
||||
|
||||
if (!(flags & SMIME_DETACHED))
|
||||
{
|
||||
SMIME_crlf_copy(data, out, flags);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!aux || !aux->asn1_cb)
|
||||
{
|
||||
ASN1err(ASN1_F_ASN1_OUTPUT_DATA,
|
||||
ASN1_R_STREAMING_NOT_SUPPORTED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sarg.out = out;
|
||||
sarg.ndef_bio = NULL;
|
||||
sarg.boundary = NULL;
|
||||
|
||||
/* Let ASN1 code prepend any needed BIOs */
|
||||
|
||||
if (aux->asn1_cb(ASN1_OP_DETACHED_PRE, &val, it, &sarg) <= 0)
|
||||
return 0;
|
||||
|
||||
/* Copy data across, passing through filter BIOs for processing */
|
||||
SMIME_crlf_copy(data, sarg.ndef_bio, flags);
|
||||
|
||||
/* Finalize structure */
|
||||
if (aux->asn1_cb(ASN1_OP_DETACHED_POST, &val, it, &sarg) <= 0)
|
||||
return 0;
|
||||
|
||||
/* Now remove any digests prepended to the BIO */
|
||||
|
||||
while (sarg.ndef_bio != out)
|
||||
{
|
||||
tmpbio = BIO_pop(sarg.ndef_bio);
|
||||
BIO_free(sarg.ndef_bio);
|
||||
sarg.ndef_bio = tmpbio;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* SMIME reader: handle multipart/signed and opaque signing.
|
||||
* in multipart case the content is placed in a memory BIO
|
||||
* pointed to by "bcont". In opaque this is set to NULL
|
||||
*/
|
||||
|
||||
ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
|
||||
{
|
||||
BIO *asnin;
|
||||
STACK_OF(MIME_HEADER) *headers = NULL;
|
||||
STACK_OF(BIO) *parts = NULL;
|
||||
MIME_HEADER *hdr;
|
||||
MIME_PARAM *prm;
|
||||
ASN1_VALUE *val;
|
||||
int ret;
|
||||
|
||||
if(bcont) *bcont = NULL;
|
||||
|
||||
if (!(headers = mime_parse_hdr(bio))) {
|
||||
ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_MIME_PARSE_ERROR);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
|
||||
sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
|
||||
ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_CONTENT_TYPE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Handle multipart/signed */
|
||||
|
||||
if(!strcmp(hdr->value, "multipart/signed")) {
|
||||
/* Split into two parts */
|
||||
prm = mime_param_find(hdr, "boundary");
|
||||
if(!prm || !prm->param_value) {
|
||||
sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
|
||||
ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_MULTIPART_BOUNDARY);
|
||||
return NULL;
|
||||
}
|
||||
ret = multi_split(bio, prm->param_value, &parts);
|
||||
sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
|
||||
if(!ret || (sk_BIO_num(parts) != 2) ) {
|
||||
ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_MULTIPART_BODY_FAILURE);
|
||||
sk_BIO_pop_free(parts, BIO_vfree);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Parse the signature piece */
|
||||
asnin = sk_BIO_value(parts, 1);
|
||||
|
||||
if (!(headers = mime_parse_hdr(asnin))) {
|
||||
ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_MIME_SIG_PARSE_ERROR);
|
||||
sk_BIO_pop_free(parts, BIO_vfree);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Get content type */
|
||||
|
||||
if(!(hdr = mime_hdr_find(headers, "content-type")) ||
|
||||
!hdr->value) {
|
||||
sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
|
||||
ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_SIG_CONTENT_TYPE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(strcmp(hdr->value, "application/x-pkcs7-signature") &&
|
||||
strcmp(hdr->value, "application/pkcs7-signature")) {
|
||||
sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
|
||||
ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_SIG_INVALID_MIME_TYPE);
|
||||
ERR_add_error_data(2, "type: ", hdr->value);
|
||||
sk_BIO_pop_free(parts, BIO_vfree);
|
||||
return NULL;
|
||||
}
|
||||
sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
|
||||
/* Read in ASN1 */
|
||||
if(!(val = b64_read_asn1(asnin, it))) {
|
||||
ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_ASN1_SIG_PARSE_ERROR);
|
||||
sk_BIO_pop_free(parts, BIO_vfree);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(bcont) {
|
||||
*bcont = sk_BIO_value(parts, 0);
|
||||
BIO_free(asnin);
|
||||
sk_BIO_free(parts);
|
||||
} else sk_BIO_pop_free(parts, BIO_vfree);
|
||||
return val;
|
||||
}
|
||||
|
||||
/* OK, if not multipart/signed try opaque signature */
|
||||
|
||||
if (strcmp (hdr->value, "application/x-pkcs7-mime") &&
|
||||
strcmp (hdr->value, "application/pkcs7-mime")) {
|
||||
ASN1err(ASN1_F_SMIME_READ_ASN1,ASN1_R_INVALID_MIME_TYPE);
|
||||
ERR_add_error_data(2, "type: ", hdr->value);
|
||||
sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
|
||||
|
||||
if(!(val = b64_read_asn1(bio, it))) {
|
||||
ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_ASN1_PARSE_ERROR);
|
||||
return NULL;
|
||||
}
|
||||
return val;
|
||||
|
||||
}
|
||||
|
||||
/* Copy text from one BIO to another making the output CRLF at EOL */
|
||||
int SMIME_crlf_copy(BIO *in, BIO *out, int flags)
|
||||
{
|
||||
BIO *bf;
|
||||
char eol;
|
||||
int len;
|
||||
char linebuf[MAX_SMLEN];
|
||||
/* Buffer output so we don't write one line at a time. This is
|
||||
* useful when streaming as we don't end up with one OCTET STRING
|
||||
* per line.
|
||||
*/
|
||||
bf = BIO_new(BIO_f_buffer());
|
||||
if (!bf)
|
||||
return 0;
|
||||
out = BIO_push(bf, out);
|
||||
if(flags & SMIME_BINARY)
|
||||
{
|
||||
while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0)
|
||||
BIO_write(out, linebuf, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(flags & SMIME_TEXT)
|
||||
BIO_printf(out, "Content-Type: text/plain\r\n\r\n");
|
||||
while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0)
|
||||
{
|
||||
eol = strip_eol(linebuf, &len);
|
||||
if (len)
|
||||
BIO_write(out, linebuf, len);
|
||||
if(eol) BIO_write(out, "\r\n", 2);
|
||||
}
|
||||
}
|
||||
(void)BIO_flush(out);
|
||||
BIO_pop(out);
|
||||
BIO_free(bf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Strip off headers if they are text/plain */
|
||||
int SMIME_text(BIO *in, BIO *out)
|
||||
{
|
||||
char iobuf[4096];
|
||||
int len;
|
||||
STACK_OF(MIME_HEADER) *headers;
|
||||
MIME_HEADER *hdr;
|
||||
|
||||
if (!(headers = mime_parse_hdr(in))) {
|
||||
ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_MIME_PARSE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
|
||||
ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_MIME_NO_CONTENT_TYPE);
|
||||
sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
|
||||
return 0;
|
||||
}
|
||||
if (strcmp (hdr->value, "text/plain")) {
|
||||
ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_INVALID_MIME_TYPE);
|
||||
ERR_add_error_data(2, "type: ", hdr->value);
|
||||
sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
|
||||
return 0;
|
||||
}
|
||||
sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
|
||||
while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0)
|
||||
BIO_write(out, iobuf, len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Split a multipart/XXX message body into component parts: result is
|
||||
* canonical parts in a STACK of bios
|
||||
*/
|
||||
|
||||
static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret)
|
||||
{
|
||||
char linebuf[MAX_SMLEN];
|
||||
int len, blen;
|
||||
int eol = 0, next_eol = 0;
|
||||
BIO *bpart = NULL;
|
||||
STACK_OF(BIO) *parts;
|
||||
char state, part, first;
|
||||
|
||||
blen = strlen(bound);
|
||||
part = 0;
|
||||
state = 0;
|
||||
first = 1;
|
||||
parts = sk_BIO_new_null();
|
||||
*ret = parts;
|
||||
while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
|
||||
state = mime_bound_check(linebuf, len, bound, blen);
|
||||
if(state == 1) {
|
||||
first = 1;
|
||||
part++;
|
||||
} else if(state == 2) {
|
||||
sk_BIO_push(parts, bpart);
|
||||
return 1;
|
||||
} else if(part) {
|
||||
/* Strip CR+LF from linebuf */
|
||||
next_eol = strip_eol(linebuf, &len);
|
||||
if(first) {
|
||||
first = 0;
|
||||
if(bpart) sk_BIO_push(parts, bpart);
|
||||
bpart = BIO_new(BIO_s_mem());
|
||||
BIO_set_mem_eof_return(bpart, 0);
|
||||
} else if (eol)
|
||||
BIO_write(bpart, "\r\n", 2);
|
||||
eol = next_eol;
|
||||
if (len)
|
||||
BIO_write(bpart, linebuf, len);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This is the big one: parse MIME header lines up to message body */
|
||||
|
||||
#define MIME_INVALID 0
|
||||
#define MIME_START 1
|
||||
#define MIME_TYPE 2
|
||||
#define MIME_NAME 3
|
||||
#define MIME_VALUE 4
|
||||
#define MIME_QUOTE 5
|
||||
#define MIME_COMMENT 6
|
||||
|
||||
|
||||
static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio)
|
||||
{
|
||||
char *p, *q, c;
|
||||
char *ntmp;
|
||||
char linebuf[MAX_SMLEN];
|
||||
MIME_HEADER *mhdr = NULL;
|
||||
STACK_OF(MIME_HEADER) *headers;
|
||||
int len, state, save_state = 0;
|
||||
|
||||
headers = sk_MIME_HEADER_new(mime_hdr_cmp);
|
||||
while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
|
||||
/* If whitespace at line start then continuation line */
|
||||
if(mhdr && isspace((unsigned char)linebuf[0])) state = MIME_NAME;
|
||||
else state = MIME_START;
|
||||
ntmp = NULL;
|
||||
/* Go through all characters */
|
||||
for(p = linebuf, q = linebuf; (c = *p) && (c!='\r') && (c!='\n'); p++) {
|
||||
|
||||
/* State machine to handle MIME headers
|
||||
* if this looks horrible that's because it *is*
|
||||
*/
|
||||
|
||||
switch(state) {
|
||||
case MIME_START:
|
||||
if(c == ':') {
|
||||
state = MIME_TYPE;
|
||||
*p = 0;
|
||||
ntmp = strip_ends(q);
|
||||
q = p + 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case MIME_TYPE:
|
||||
if(c == ';') {
|
||||
mime_debug("Found End Value\n");
|
||||
*p = 0;
|
||||
mhdr = mime_hdr_new(ntmp, strip_ends(q));
|
||||
sk_MIME_HEADER_push(headers, mhdr);
|
||||
ntmp = NULL;
|
||||
q = p + 1;
|
||||
state = MIME_NAME;
|
||||
} else if(c == '(') {
|
||||
save_state = state;
|
||||
state = MIME_COMMENT;
|
||||
}
|
||||
break;
|
||||
|
||||
case MIME_COMMENT:
|
||||
if(c == ')') {
|
||||
state = save_state;
|
||||
}
|
||||
break;
|
||||
|
||||
case MIME_NAME:
|
||||
if(c == '=') {
|
||||
state = MIME_VALUE;
|
||||
*p = 0;
|
||||
ntmp = strip_ends(q);
|
||||
q = p + 1;
|
||||
}
|
||||
break ;
|
||||
|
||||
case MIME_VALUE:
|
||||
if(c == ';') {
|
||||
state = MIME_NAME;
|
||||
*p = 0;
|
||||
mime_hdr_addparam(mhdr, ntmp, strip_ends(q));
|
||||
ntmp = NULL;
|
||||
q = p + 1;
|
||||
} else if (c == '"') {
|
||||
mime_debug("Found Quote\n");
|
||||
state = MIME_QUOTE;
|
||||
} else if(c == '(') {
|
||||
save_state = state;
|
||||
state = MIME_COMMENT;
|
||||
}
|
||||
break;
|
||||
|
||||
case MIME_QUOTE:
|
||||
if(c == '"') {
|
||||
mime_debug("Found Match Quote\n");
|
||||
state = MIME_VALUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(state == MIME_TYPE) {
|
||||
mhdr = mime_hdr_new(ntmp, strip_ends(q));
|
||||
sk_MIME_HEADER_push(headers, mhdr);
|
||||
} else if(state == MIME_VALUE)
|
||||
mime_hdr_addparam(mhdr, ntmp, strip_ends(q));
|
||||
if(p == linebuf) break; /* Blank line means end of headers */
|
||||
}
|
||||
|
||||
return headers;
|
||||
|
||||
}
|
||||
|
||||
static char *strip_ends(char *name)
|
||||
{
|
||||
return strip_end(strip_start(name));
|
||||
}
|
||||
|
||||
/* Strip a parameter of whitespace from start of param */
|
||||
static char *strip_start(char *name)
|
||||
{
|
||||
char *p, c;
|
||||
/* Look for first non white space or quote */
|
||||
for(p = name; (c = *p) ;p++) {
|
||||
if(c == '"') {
|
||||
/* Next char is start of string if non null */
|
||||
if(p[1]) return p + 1;
|
||||
/* Else null string */
|
||||
return NULL;
|
||||
}
|
||||
if(!isspace((unsigned char)c)) return p;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* As above but strip from end of string : maybe should handle brackets? */
|
||||
static char *strip_end(char *name)
|
||||
{
|
||||
char *p, c;
|
||||
if(!name) return NULL;
|
||||
/* Look for first non white space or quote */
|
||||
for(p = name + strlen(name) - 1; p >= name ;p--) {
|
||||
c = *p;
|
||||
if(c == '"') {
|
||||
if(p - 1 == name) return NULL;
|
||||
*p = 0;
|
||||
return name;
|
||||
}
|
||||
if(isspace((unsigned char)c)) *p = 0;
|
||||
else return name;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static MIME_HEADER *mime_hdr_new(char *name, char *value)
|
||||
{
|
||||
MIME_HEADER *mhdr;
|
||||
char *tmpname, *tmpval, *p;
|
||||
int c;
|
||||
if(name) {
|
||||
if(!(tmpname = BUF_strdup(name))) return NULL;
|
||||
for(p = tmpname ; *p; p++) {
|
||||
c = *p;
|
||||
if(isupper(c)) {
|
||||
c = tolower(c);
|
||||
*p = c;
|
||||
}
|
||||
}
|
||||
} else tmpname = NULL;
|
||||
if(value) {
|
||||
if(!(tmpval = BUF_strdup(value))) return NULL;
|
||||
for(p = tmpval ; *p; p++) {
|
||||
c = *p;
|
||||
if(isupper(c)) {
|
||||
c = tolower(c);
|
||||
*p = c;
|
||||
}
|
||||
}
|
||||
} else tmpval = NULL;
|
||||
mhdr = (MIME_HEADER *) OPENSSL_malloc(sizeof(MIME_HEADER));
|
||||
if(!mhdr) return NULL;
|
||||
mhdr->name = tmpname;
|
||||
mhdr->value = tmpval;
|
||||
if(!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) return NULL;
|
||||
return mhdr;
|
||||
}
|
||||
|
||||
static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
|
||||
{
|
||||
char *tmpname, *tmpval, *p;
|
||||
int c;
|
||||
MIME_PARAM *mparam;
|
||||
if(name) {
|
||||
tmpname = BUF_strdup(name);
|
||||
if(!tmpname) return 0;
|
||||
for(p = tmpname ; *p; p++) {
|
||||
c = *p;
|
||||
if(isupper(c)) {
|
||||
c = tolower(c);
|
||||
*p = c;
|
||||
}
|
||||
}
|
||||
} else tmpname = NULL;
|
||||
if(value) {
|
||||
tmpval = BUF_strdup(value);
|
||||
if(!tmpval) return 0;
|
||||
} else tmpval = NULL;
|
||||
/* Parameter values are case sensitive so leave as is */
|
||||
mparam = (MIME_PARAM *) OPENSSL_malloc(sizeof(MIME_PARAM));
|
||||
if(!mparam) return 0;
|
||||
mparam->param_name = tmpname;
|
||||
mparam->param_value = tmpval;
|
||||
sk_MIME_PARAM_push(mhdr->params, mparam);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int mime_hdr_cmp(const MIME_HEADER * const *a,
|
||||
const MIME_HEADER * const *b)
|
||||
{
|
||||
return(strcmp((*a)->name, (*b)->name));
|
||||
}
|
||||
|
||||
static int mime_param_cmp(const MIME_PARAM * const *a,
|
||||
const MIME_PARAM * const *b)
|
||||
{
|
||||
return(strcmp((*a)->param_name, (*b)->param_name));
|
||||
}
|
||||
|
||||
/* Find a header with a given name (if possible) */
|
||||
|
||||
static MIME_HEADER *mime_hdr_find(STACK_OF(MIME_HEADER) *hdrs, char *name)
|
||||
{
|
||||
MIME_HEADER htmp;
|
||||
int idx;
|
||||
htmp.name = name;
|
||||
idx = sk_MIME_HEADER_find(hdrs, &htmp);
|
||||
if(idx < 0) return NULL;
|
||||
return sk_MIME_HEADER_value(hdrs, idx);
|
||||
}
|
||||
|
||||
static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name)
|
||||
{
|
||||
MIME_PARAM param;
|
||||
int idx;
|
||||
param.param_name = name;
|
||||
idx = sk_MIME_PARAM_find(hdr->params, ¶m);
|
||||
if(idx < 0) return NULL;
|
||||
return sk_MIME_PARAM_value(hdr->params, idx);
|
||||
}
|
||||
|
||||
static void mime_hdr_free(MIME_HEADER *hdr)
|
||||
{
|
||||
if(hdr->name) OPENSSL_free(hdr->name);
|
||||
if(hdr->value) OPENSSL_free(hdr->value);
|
||||
if(hdr->params) sk_MIME_PARAM_pop_free(hdr->params, mime_param_free);
|
||||
OPENSSL_free(hdr);
|
||||
}
|
||||
|
||||
static void mime_param_free(MIME_PARAM *param)
|
||||
{
|
||||
if(param->param_name) OPENSSL_free(param->param_name);
|
||||
if(param->param_value) OPENSSL_free(param->param_value);
|
||||
OPENSSL_free(param);
|
||||
}
|
||||
|
||||
/* Check for a multipart boundary. Returns:
|
||||
* 0 : no boundary
|
||||
* 1 : part boundary
|
||||
* 2 : final boundary
|
||||
*/
|
||||
static int mime_bound_check(char *line, int linelen, char *bound, int blen)
|
||||
{
|
||||
if(linelen == -1) linelen = strlen(line);
|
||||
if(blen == -1) blen = strlen(bound);
|
||||
/* Quickly eliminate if line length too short */
|
||||
if(blen + 2 > linelen) return 0;
|
||||
/* Check for part boundary */
|
||||
if(!strncmp(line, "--", 2) && !strncmp(line + 2, bound, blen)) {
|
||||
if(!strncmp(line + blen + 2, "--", 2)) return 2;
|
||||
else return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int strip_eol(char *linebuf, int *plen)
|
||||
{
|
||||
int len = *plen;
|
||||
char *p, c;
|
||||
int is_eol = 0;
|
||||
p = linebuf + len - 1;
|
||||
for (p = linebuf + len - 1; len > 0; len--, p--)
|
||||
{
|
||||
c = *p;
|
||||
if (c == '\n')
|
||||
is_eol = 1;
|
||||
else if (c != '\r')
|
||||
break;
|
||||
}
|
||||
*plen = len;
|
||||
return is_eol;
|
||||
}
|
@ -115,8 +115,6 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
|
||||
return;
|
||||
}
|
||||
i = asn1_get_choice_selector(pval, it);
|
||||
if (asn1_cb)
|
||||
asn1_cb(ASN1_OP_FREE_PRE, pval, it);
|
||||
if ((i >= 0) && (i < it->tcount))
|
||||
{
|
||||
ASN1_VALUE **pchval;
|
||||
|
@ -66,8 +66,65 @@ ASN1_SEQUENCE(X509_ALGOR) = {
|
||||
ASN1_OPT(X509_ALGOR, parameter, ASN1_ANY)
|
||||
} ASN1_SEQUENCE_END(X509_ALGOR)
|
||||
|
||||
ASN1_ITEM_TEMPLATE(X509_ALGORS) =
|
||||
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, algorithms, X509_ALGOR)
|
||||
ASN1_ITEM_TEMPLATE_END(X509_ALGORS)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS(X509_ALGOR)
|
||||
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(X509_ALGORS, X509_ALGORS, X509_ALGORS)
|
||||
IMPLEMENT_ASN1_DUP_FUNCTION(X509_ALGOR)
|
||||
|
||||
IMPLEMENT_STACK_OF(X509_ALGOR)
|
||||
IMPLEMENT_ASN1_SET_OF(X509_ALGOR)
|
||||
|
||||
int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval)
|
||||
{
|
||||
if (!alg)
|
||||
return 0;
|
||||
if (ptype != V_ASN1_UNDEF)
|
||||
{
|
||||
if (alg->parameter == NULL)
|
||||
alg->parameter = ASN1_TYPE_new();
|
||||
if (alg->parameter == NULL)
|
||||
return 0;
|
||||
}
|
||||
if (alg)
|
||||
{
|
||||
if (alg->algorithm)
|
||||
ASN1_OBJECT_free(alg->algorithm);
|
||||
alg->algorithm = aobj;
|
||||
}
|
||||
if (ptype == 0)
|
||||
return 1;
|
||||
if (ptype == V_ASN1_UNDEF)
|
||||
{
|
||||
if (alg->parameter)
|
||||
{
|
||||
ASN1_TYPE_free(alg->parameter);
|
||||
alg->parameter = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
ASN1_TYPE_set(alg->parameter, ptype, pval);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval,
|
||||
X509_ALGOR *algor)
|
||||
{
|
||||
if (paobj)
|
||||
*paobj = algor->algorithm;
|
||||
if (pptype)
|
||||
{
|
||||
if (algor->parameter == NULL)
|
||||
{
|
||||
*pptype = V_ASN1_UNDEF;
|
||||
return;
|
||||
}
|
||||
else
|
||||
*pptype = algor->parameter->type;
|
||||
if (ppval)
|
||||
*ppval = algor->parameter->value.ptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,10 @@
|
||||
#include <string.h>
|
||||
#include <openssl/blowfish.h>
|
||||
#include <openssl/crypto.h>
|
||||
#ifdef OPENSSL_FIPS
|
||||
#include <openssl/fips.h>
|
||||
#endif
|
||||
|
||||
#include "bf_locl.h"
|
||||
#include "bf_pi.h"
|
||||
|
||||
|
@ -63,7 +63,11 @@
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/bio.h>
|
||||
#if defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_BSDSOCK)
|
||||
#include "netdb.h"
|
||||
#include <netdb.h>
|
||||
#if defined(NETWARE_CLIB)
|
||||
#include <sys/ioctl.h>
|
||||
NETDB_DEFINE_CONTEXT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_SOCK
|
||||
@ -178,11 +182,11 @@ int BIO_get_port(const char *str, unsigned short *port_ptr)
|
||||
/* Note: under VMS with SOCKETSHR, it seems like the first
|
||||
* parameter is 'char *', instead of 'const char *'
|
||||
*/
|
||||
s=getservbyname(
|
||||
#ifndef CONST_STRICT
|
||||
(char *)
|
||||
s=getservbyname((char *)str,"tcp");
|
||||
#else
|
||||
s=getservbyname(str,"tcp");
|
||||
#endif
|
||||
str,"tcp");
|
||||
if(s != NULL)
|
||||
*port_ptr=ntohs((unsigned short)s->s_port);
|
||||
CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME);
|
||||
@ -360,7 +364,11 @@ struct hostent *BIO_gethostbyname(const char *name)
|
||||
#if 1
|
||||
/* Caching gethostbyname() results forever is wrong,
|
||||
* so we have to let the true gethostbyname() worry about this */
|
||||
#if (defined(NETWARE_BSDSOCK) && !defined(__NOVELL_LIBC__))
|
||||
return gethostbyname((char*)name);
|
||||
#else
|
||||
return gethostbyname(name);
|
||||
#endif
|
||||
#else
|
||||
struct hostent *ret;
|
||||
int i,lowi=0,j;
|
||||
@ -400,11 +408,11 @@ struct hostent *BIO_gethostbyname(const char *name)
|
||||
/* Note: under VMS with SOCKETSHR, it seems like the first
|
||||
* parameter is 'char *', instead of 'const char *'
|
||||
*/
|
||||
ret=gethostbyname(
|
||||
# ifndef CONST_STRICT
|
||||
(char *)
|
||||
ret=gethostbyname((char *)name);
|
||||
# else
|
||||
ret=gethostbyname(name);
|
||||
# endif
|
||||
name);
|
||||
|
||||
if (ret == NULL)
|
||||
goto end;
|
||||
|
@ -95,6 +95,7 @@ extern "C" {
|
||||
#define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */
|
||||
#define BIO_TYPE_LINEBUFFER (20|0x0200) /* filter */
|
||||
#define BIO_TYPE_DGRAM (21|0x0400|0x0100)
|
||||
#define BIO_TYPE_COMP (23|0x0200) /* filter */
|
||||
|
||||
#define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */
|
||||
#define BIO_TYPE_FILTER 0x0200
|
||||
|
@ -208,9 +208,13 @@ static int dgram_write(BIO *b, const char *in, int inl)
|
||||
clear_socket_error();
|
||||
|
||||
if ( data->connected )
|
||||
ret=send(b->num,in,inl,0);
|
||||
ret=writesocket(b->num,in,inl);
|
||||
else
|
||||
#if defined(NETWARE_CLIB) && defined(NETWARE_BSDSOCK)
|
||||
ret=sendto(b->num, (char *)in, inl, 0, &data->peer, sizeof(data->peer));
|
||||
#else
|
||||
ret=sendto(b->num, in, inl, 0, &data->peer, sizeof(data->peer));
|
||||
#endif
|
||||
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0)
|
||||
|
@ -89,6 +89,10 @@
|
||||
#include "bio_lcl.h"
|
||||
#include <openssl/err.h>
|
||||
|
||||
#if defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB)
|
||||
#include <nwfileio.h>
|
||||
#endif
|
||||
|
||||
#if !defined(OPENSSL_NO_STDIO)
|
||||
|
||||
static int MS_CALLBACK file_write(BIO *h, const char *buf, int num);
|
||||
@ -285,9 +289,9 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
/* Under CLib there are differences in file modes
|
||||
*/
|
||||
if (num & BIO_FP_TEXT)
|
||||
_setmode(fd,O_TEXT);
|
||||
setmode(fd,O_TEXT);
|
||||
else
|
||||
_setmode(fd,O_BINARY);
|
||||
setmode(fd,O_BINARY);
|
||||
#elif defined(OPENSSL_SYS_MSDOS)
|
||||
int fd = fileno((FILE*)ptr);
|
||||
/* Set correct text/binary mode */
|
||||
|
@ -1,5 +1,18 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
# This is crypto/bn/asm/x86-mont.pl (with asciz from crypto/perlasm/x86asm.pl)
|
||||
# from OpenSSL 0.9.9-dev
|
||||
|
||||
sub ::asciz
|
||||
{ my @str=unpack("C*",shift);
|
||||
push @str,0;
|
||||
while ($#str>15) {
|
||||
&data_byte(@str[0..15]);
|
||||
foreach (0..15) { shift @str; }
|
||||
}
|
||||
&data_byte(@str) if (@str);
|
||||
}
|
||||
|
||||
# ====================================================================
|
||||
# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
|
||||
# project. The module is, however, dual licensed under OpenSSL and
|
||||
@ -26,8 +39,7 @@
|
||||
# Integer-only code [being equipped with dedicated squaring procedure]
|
||||
# gives ~40% on rsa512 sign benchmark...
|
||||
|
||||
$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
|
||||
push(@INC,"${dir}","${dir}../../perlasm");
|
||||
push(@INC,"perlasm","../../perlasm");
|
||||
require "x86asm.pl";
|
||||
|
||||
&asm_init($ARGV[0],$0);
|
||||
|
@ -58,7 +58,10 @@
|
||||
|
||||
#include <openssl/cast.h>
|
||||
#include <openssl/crypto.h>
|
||||
#ifdef OPENSSL_FIPS
|
||||
#include <openssl/fips.h>
|
||||
#endif
|
||||
|
||||
#include "cast_lcl.h"
|
||||
#include "cast_s.h"
|
||||
|
||||
|
183
crypto/cms/Makefile
Normal file
183
crypto/cms/Makefile
Normal file
@ -0,0 +1,183 @@
|
||||
#
|
||||
# OpenSSL/crypto/cms/Makefile
|
||||
#
|
||||
|
||||
DIR= cms
|
||||
TOP= ../..
|
||||
CC= cc
|
||||
INCLUDES= -I.. -I$(TOP) -I../../include
|
||||
CFLAG=-g
|
||||
MAKEFILE= Makefile
|
||||
AR= ar r
|
||||
|
||||
CFLAGS= $(INCLUDES) $(CFLAG)
|
||||
|
||||
GENERAL=Makefile
|
||||
TEST=
|
||||
APPS=
|
||||
|
||||
LIB=$(TOP)/libcrypto.a
|
||||
LIBSRC= cms_lib.c cms_asn1.c cms_att.c cms_io.c cms_smime.c cms_err.c \
|
||||
cms_sd.c cms_dd.c cms_cd.c cms_env.c cms_enc.c cms_ess.c
|
||||
LIBOBJ= cms_lib.o cms_asn1.o cms_att.o cms_io.o cms_smime.o cms_err.o \
|
||||
cms_sd.o cms_dd.o cms_cd.o cms_env.o cms_enc.o cms_ess.o
|
||||
|
||||
SRC= $(LIBSRC)
|
||||
|
||||
EXHEADER= cms.h
|
||||
HEADER= cms_lcl.h $(EXHEADER)
|
||||
|
||||
ALL= $(GENERAL) $(SRC) $(HEADER)
|
||||
|
||||
top:
|
||||
(cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
|
||||
|
||||
test:
|
||||
|
||||
all: lib
|
||||
|
||||
lib: $(LIBOBJ)
|
||||
$(AR) $(LIB) $(LIBOBJ)
|
||||
$(RANLIB) $(LIB) || echo Never mind.
|
||||
@touch lib
|
||||
|
||||
files:
|
||||
$(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
|
||||
|
||||
links:
|
||||
@$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
|
||||
@$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
|
||||
@$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
|
||||
|
||||
install:
|
||||
@[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
|
||||
@headerlist="$(EXHEADER)"; for i in $$headerlist ; \
|
||||
do \
|
||||
(cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
|
||||
chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
|
||||
done;
|
||||
|
||||
tags:
|
||||
ctags $(SRC)
|
||||
|
||||
tests:
|
||||
|
||||
lint:
|
||||
lint -DLINT $(INCLUDES) $(SRC)>fluff
|
||||
|
||||
depend:
|
||||
@[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
|
||||
$(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
|
||||
|
||||
dclean:
|
||||
$(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
|
||||
mv -f Makefile.new $(MAKEFILE)
|
||||
|
||||
clean:
|
||||
rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
cms_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
|
||||
cms_asn1.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
|
||||
cms_asn1.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
|
||||
cms_asn1.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
|
||||
cms_asn1.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
|
||||
cms_asn1.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
|
||||
cms_asn1.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
|
||||
cms_asn1.o: ../../include/openssl/opensslconf.h
|
||||
cms_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
|
||||
cms_asn1.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
|
||||
cms_asn1.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
|
||||
cms_asn1.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
|
||||
cms_asn1.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
|
||||
cms_asn1.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
|
||||
cms_asn1.o: cms.h cms_asn1.c cms_lcl.h
|
||||
cms_att.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
|
||||
cms_att.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
|
||||
cms_att.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
|
||||
cms_att.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
|
||||
cms_att.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
|
||||
cms_att.o: ../../include/openssl/err.h ../../include/openssl/evp.h
|
||||
cms_att.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
|
||||
cms_att.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
|
||||
cms_att.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
|
||||
cms_att.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
|
||||
cms_att.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
|
||||
cms_att.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
|
||||
cms_att.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
|
||||
cms_att.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
|
||||
cms_att.o: cms.h cms_att.c cms_lcl.h
|
||||
cms_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
|
||||
cms_err.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h
|
||||
cms_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
|
||||
cms_err.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
|
||||
cms_err.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
|
||||
cms_err.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
|
||||
cms_err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
|
||||
cms_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
|
||||
cms_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
|
||||
cms_err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
|
||||
cms_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
|
||||
cms_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
|
||||
cms_err.o: cms_err.c
|
||||
cms_io.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
|
||||
cms_io.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
|
||||
cms_io.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
|
||||
cms_io.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
|
||||
cms_io.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
|
||||
cms_io.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
|
||||
cms_io.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
|
||||
cms_io.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
|
||||
cms_io.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
|
||||
cms_io.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
|
||||
cms_io.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
|
||||
cms_io.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
|
||||
cms_io.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h cms.h
|
||||
cms_io.o: cms_io.c cms_lcl.h
|
||||
cms_lib.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
|
||||
cms_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
|
||||
cms_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
|
||||
cms_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
|
||||
cms_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
|
||||
cms_lib.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
|
||||
cms_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
|
||||
cms_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
|
||||
cms_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
|
||||
cms_lib.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
|
||||
cms_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
|
||||
cms_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
|
||||
cms_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h cms.h
|
||||
cms_lib.o: cms_lcl.h cms_lib.c
|
||||
cms_sd.o: ../../e_os.h ../../include/openssl/asn1.h
|
||||
cms_sd.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
|
||||
cms_sd.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h
|
||||
cms_sd.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
|
||||
cms_sd.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
|
||||
cms_sd.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
|
||||
cms_sd.o: ../../include/openssl/err.h ../../include/openssl/evp.h
|
||||
cms_sd.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
|
||||
cms_sd.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
|
||||
cms_sd.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
|
||||
cms_sd.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
|
||||
cms_sd.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
|
||||
cms_sd.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
|
||||
cms_sd.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
|
||||
cms_sd.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
|
||||
cms_sd.o: ../cryptlib.h cms_lcl.h cms_sd.c
|
||||
cms_smime.o: ../../e_os.h ../../include/openssl/asn1.h
|
||||
cms_smime.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
|
||||
cms_smime.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h
|
||||
cms_smime.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
|
||||
cms_smime.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
|
||||
cms_smime.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
|
||||
cms_smime.o: ../../include/openssl/err.h ../../include/openssl/evp.h
|
||||
cms_smime.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
|
||||
cms_smime.o: ../../include/openssl/objects.h
|
||||
cms_smime.o: ../../include/openssl/opensslconf.h
|
||||
cms_smime.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
|
||||
cms_smime.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
|
||||
cms_smime.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
|
||||
cms_smime.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
|
||||
cms_smime.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
|
||||
cms_smime.o: ../cryptlib.h cms_lcl.h cms_smime.c
|
473
crypto/cms/cms.h
Normal file
473
crypto/cms/cms.h
Normal file
@ -0,0 +1,473 @@
|
||||
/* crypto/cms/cms.h */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2008 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
|
||||
#ifndef HEADER_CMS_H
|
||||
#define HEADER_CMS_H
|
||||
|
||||
#include <openssl/x509.h>
|
||||
|
||||
#ifdef OPENSSL_NO_CMS
|
||||
#error CMS is disabled.
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct CMS_ContentInfo_st CMS_ContentInfo;
|
||||
typedef struct CMS_SignerInfo_st CMS_SignerInfo;
|
||||
typedef struct CMS_CertificateChoices CMS_CertificateChoices;
|
||||
typedef struct CMS_RevocationInfoChoice_st CMS_RevocationInfoChoice;
|
||||
typedef struct CMS_RecipientInfo_st CMS_RecipientInfo;
|
||||
typedef struct CMS_ReceiptRequest_st CMS_ReceiptRequest;
|
||||
typedef struct CMS_Receipt_st CMS_Receipt;
|
||||
|
||||
DECLARE_STACK_OF(CMS_SignerInfo)
|
||||
DECLARE_STACK_OF(GENERAL_NAMES)
|
||||
DECLARE_ASN1_FUNCTIONS_const(CMS_ContentInfo)
|
||||
DECLARE_ASN1_FUNCTIONS_const(CMS_ReceiptRequest)
|
||||
|
||||
#define CMS_SIGNERINFO_ISSUER_SERIAL 0
|
||||
#define CMS_SIGNERINFO_KEYIDENTIFIER 1
|
||||
|
||||
#define CMS_RECIPINFO_TRANS 0
|
||||
#define CMS_RECIPINFO_AGREE 1
|
||||
#define CMS_RECIPINFO_KEK 2
|
||||
#define CMS_RECIPINFO_PASS 3
|
||||
#define CMS_RECIPINFO_OTHER 4
|
||||
|
||||
/* S/MIME related flags */
|
||||
|
||||
#define CMS_TEXT 0x1
|
||||
#define CMS_NOCERTS 0x2
|
||||
#define CMS_NO_CONTENT_VERIFY 0x4
|
||||
#define CMS_NO_ATTR_VERIFY 0x8
|
||||
#define CMS_NOSIGS \
|
||||
(CMS_NO_CONTENT_VERIFY|CMS_NO_ATTR_VERIFY)
|
||||
#define CMS_NOINTERN 0x10
|
||||
#define CMS_NO_SIGNER_CERT_VERIFY 0x20
|
||||
#define CMS_NOVERIFY 0x20
|
||||
#define CMS_DETACHED 0x40
|
||||
#define CMS_BINARY 0x80
|
||||
#define CMS_NOATTR 0x100
|
||||
#define CMS_NOSMIMECAP 0x200
|
||||
#define CMS_NOOLDMIMETYPE 0x400
|
||||
#define CMS_CRLFEOL 0x800
|
||||
#define CMS_STREAM 0x1000
|
||||
#define CMS_NOCRL 0x2000
|
||||
#define CMS_PARTIAL 0x4000
|
||||
#define CMS_REUSE_DIGEST 0x8000
|
||||
#define CMS_USE_KEYID 0x10000
|
||||
|
||||
const ASN1_OBJECT *CMS_get0_type(CMS_ContentInfo *cms);
|
||||
|
||||
BIO *CMS_dataInit(CMS_ContentInfo *cms, BIO *icont);
|
||||
int CMS_dataFinal(CMS_ContentInfo *cms, BIO *bio);
|
||||
|
||||
ASN1_OCTET_STRING **CMS_get0_content(CMS_ContentInfo *cms);
|
||||
int CMS_is_detached(CMS_ContentInfo *cms);
|
||||
int CMS_set_detached(CMS_ContentInfo *cms, int detached);
|
||||
|
||||
#ifdef HEADER_PEM_H
|
||||
DECLARE_PEM_rw_const(CMS, CMS_ContentInfo)
|
||||
#endif
|
||||
|
||||
CMS_ContentInfo *d2i_CMS_bio(BIO *bp, CMS_ContentInfo **cms);
|
||||
int i2d_CMS_bio(BIO *bp, CMS_ContentInfo *cms);
|
||||
|
||||
CMS_ContentInfo *SMIME_read_CMS(BIO *bio, BIO **bcont);
|
||||
int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags);
|
||||
|
||||
int CMS_final(CMS_ContentInfo *cms, BIO *data, BIO *dcont, unsigned int flags);
|
||||
|
||||
CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
|
||||
BIO *data, unsigned int flags);
|
||||
|
||||
CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si,
|
||||
X509 *signcert, EVP_PKEY *pkey,
|
||||
STACK_OF(X509) *certs,
|
||||
unsigned int flags);
|
||||
|
||||
int CMS_data(CMS_ContentInfo *cms, BIO *out, unsigned int flags);
|
||||
CMS_ContentInfo *CMS_data_create(BIO *in, unsigned int flags);
|
||||
|
||||
int CMS_digest_verify(CMS_ContentInfo *cms, BIO *dcont, BIO *out,
|
||||
unsigned int flags);
|
||||
CMS_ContentInfo *CMS_digest_create(BIO *in, const EVP_MD *md,
|
||||
unsigned int flags);
|
||||
|
||||
int CMS_EncryptedData_decrypt(CMS_ContentInfo *cms,
|
||||
const unsigned char *key, size_t keylen,
|
||||
BIO *dcont, BIO *out, unsigned int flags);
|
||||
|
||||
CMS_ContentInfo *CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher,
|
||||
const unsigned char *key, size_t keylen,
|
||||
unsigned int flags);
|
||||
|
||||
int CMS_EncryptedData_set1_key(CMS_ContentInfo *cms, const EVP_CIPHER *ciph,
|
||||
const unsigned char *key, size_t keylen);
|
||||
|
||||
int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs,
|
||||
X509_STORE *store, BIO *dcont, BIO *out, unsigned int flags);
|
||||
|
||||
int CMS_verify_receipt(CMS_ContentInfo *rcms, CMS_ContentInfo *ocms,
|
||||
STACK_OF(X509) *certs,
|
||||
X509_STORE *store, unsigned int flags);
|
||||
|
||||
STACK_OF(X509) *CMS_get0_signers(CMS_ContentInfo *cms);
|
||||
|
||||
CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *in,
|
||||
const EVP_CIPHER *cipher, unsigned int flags);
|
||||
|
||||
int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pkey, X509 *cert,
|
||||
BIO *dcont, BIO *out,
|
||||
unsigned int flags);
|
||||
|
||||
int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert);
|
||||
int CMS_decrypt_set1_key(CMS_ContentInfo *cms,
|
||||
unsigned char *key, size_t keylen,
|
||||
unsigned char *id, size_t idlen);
|
||||
|
||||
STACK_OF(CMS_RecipientInfo) *CMS_get0_RecipientInfos(CMS_ContentInfo *cms);
|
||||
int CMS_RecipientInfo_type(CMS_RecipientInfo *ri);
|
||||
CMS_ContentInfo *CMS_EnvelopedData_create(const EVP_CIPHER *cipher);
|
||||
CMS_RecipientInfo *CMS_add1_recipient_cert(CMS_ContentInfo *cms,
|
||||
X509 *recip, unsigned int flags);
|
||||
int CMS_RecipientInfo_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pkey);
|
||||
int CMS_RecipientInfo_ktri_cert_cmp(CMS_RecipientInfo *ri, X509 *cert);
|
||||
int CMS_RecipientInfo_ktri_get0_algs(CMS_RecipientInfo *ri,
|
||||
EVP_PKEY **pk, X509 **recip,
|
||||
X509_ALGOR **palg);
|
||||
int CMS_RecipientInfo_ktri_get0_signer_id(CMS_RecipientInfo *ri,
|
||||
ASN1_OCTET_STRING **keyid,
|
||||
X509_NAME **issuer, ASN1_INTEGER **sno);
|
||||
|
||||
CMS_RecipientInfo *CMS_add0_recipient_key(CMS_ContentInfo *cms, int nid,
|
||||
unsigned char *key, size_t keylen,
|
||||
unsigned char *id, size_t idlen,
|
||||
ASN1_GENERALIZEDTIME *date,
|
||||
ASN1_OBJECT *otherTypeId,
|
||||
ASN1_TYPE *otherType);
|
||||
|
||||
int CMS_RecipientInfo_kekri_get0_id(CMS_RecipientInfo *ri,
|
||||
X509_ALGOR **palg,
|
||||
ASN1_OCTET_STRING **pid,
|
||||
ASN1_GENERALIZEDTIME **pdate,
|
||||
ASN1_OBJECT **potherid,
|
||||
ASN1_TYPE **pothertype);
|
||||
|
||||
int CMS_RecipientInfo_set0_key(CMS_RecipientInfo *ri,
|
||||
unsigned char *key, size_t keylen);
|
||||
|
||||
int CMS_RecipientInfo_kekri_id_cmp(CMS_RecipientInfo *ri,
|
||||
const unsigned char *id, size_t idlen);
|
||||
|
||||
int CMS_RecipientInfo_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri);
|
||||
|
||||
int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out,
|
||||
unsigned int flags);
|
||||
CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags);
|
||||
|
||||
int CMS_set1_eContentType(CMS_ContentInfo *cms, const ASN1_OBJECT *oid);
|
||||
const ASN1_OBJECT *CMS_get0_eContentType(CMS_ContentInfo *cms);
|
||||
|
||||
CMS_CertificateChoices *CMS_add0_CertificateChoices(CMS_ContentInfo *cms);
|
||||
int CMS_add0_cert(CMS_ContentInfo *cms, X509 *cert);
|
||||
int CMS_add1_cert(CMS_ContentInfo *cms, X509 *cert);
|
||||
STACK_OF(X509) *CMS_get1_certs(CMS_ContentInfo *cms);
|
||||
|
||||
CMS_RevocationInfoChoice *CMS_add0_RevocationInfoChoice(CMS_ContentInfo *cms);
|
||||
int CMS_add0_crl(CMS_ContentInfo *cms, X509_CRL *crl);
|
||||
STACK_OF(X509_CRL) *CMS_get1_crls(CMS_ContentInfo *cms);
|
||||
|
||||
int CMS_SignedData_init(CMS_ContentInfo *cms);
|
||||
CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
|
||||
X509 *signer, EVP_PKEY *pk, const EVP_MD *md,
|
||||
unsigned int flags);
|
||||
STACK_OF(CMS_SignerInfo) *CMS_get0_SignerInfos(CMS_ContentInfo *cms);
|
||||
|
||||
void CMS_SignerInfo_set1_signer_cert(CMS_SignerInfo *si, X509 *signer);
|
||||
int CMS_SignerInfo_get0_signer_id(CMS_SignerInfo *si,
|
||||
ASN1_OCTET_STRING **keyid,
|
||||
X509_NAME **issuer, ASN1_INTEGER **sno);
|
||||
int CMS_SignerInfo_cert_cmp(CMS_SignerInfo *si, X509 *cert);
|
||||
int CMS_set1_signers_certs(CMS_ContentInfo *cms, STACK_OF(X509) *certs,
|
||||
unsigned int flags);
|
||||
void CMS_SignerInfo_get0_algs(CMS_SignerInfo *si, EVP_PKEY **pk, X509 **signer,
|
||||
X509_ALGOR **pdig, X509_ALGOR **psig);
|
||||
int CMS_SignerInfo_sign(CMS_SignerInfo *si);
|
||||
int CMS_SignerInfo_verify(CMS_SignerInfo *si);
|
||||
int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain);
|
||||
|
||||
int CMS_add_smimecap(CMS_SignerInfo *si, STACK_OF(X509_ALGOR) *algs);
|
||||
int CMS_add_simple_smimecap(STACK_OF(X509_ALGOR) **algs,
|
||||
int algnid, int keysize);
|
||||
int CMS_add_standard_smimecap(STACK_OF(X509_ALGOR) **smcap);
|
||||
|
||||
int CMS_signed_get_attr_count(const CMS_SignerInfo *si);
|
||||
int CMS_signed_get_attr_by_NID(const CMS_SignerInfo *si, int nid,
|
||||
int lastpos);
|
||||
int CMS_signed_get_attr_by_OBJ(const CMS_SignerInfo *si, ASN1_OBJECT *obj,
|
||||
int lastpos);
|
||||
X509_ATTRIBUTE *CMS_signed_get_attr(const CMS_SignerInfo *si, int loc);
|
||||
X509_ATTRIBUTE *CMS_signed_delete_attr(CMS_SignerInfo *si, int loc);
|
||||
int CMS_signed_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr);
|
||||
int CMS_signed_add1_attr_by_OBJ(CMS_SignerInfo *si,
|
||||
const ASN1_OBJECT *obj, int type,
|
||||
const void *bytes, int len);
|
||||
int CMS_signed_add1_attr_by_NID(CMS_SignerInfo *si,
|
||||
int nid, int type,
|
||||
const void *bytes, int len);
|
||||
int CMS_signed_add1_attr_by_txt(CMS_SignerInfo *si,
|
||||
const char *attrname, int type,
|
||||
const void *bytes, int len);
|
||||
void *CMS_signed_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid,
|
||||
int lastpos, int type);
|
||||
|
||||
int CMS_unsigned_get_attr_count(const CMS_SignerInfo *si);
|
||||
int CMS_unsigned_get_attr_by_NID(const CMS_SignerInfo *si, int nid,
|
||||
int lastpos);
|
||||
int CMS_unsigned_get_attr_by_OBJ(const CMS_SignerInfo *si, ASN1_OBJECT *obj,
|
||||
int lastpos);
|
||||
X509_ATTRIBUTE *CMS_unsigned_get_attr(const CMS_SignerInfo *si, int loc);
|
||||
X509_ATTRIBUTE *CMS_unsigned_delete_attr(CMS_SignerInfo *si, int loc);
|
||||
int CMS_unsigned_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr);
|
||||
int CMS_unsigned_add1_attr_by_OBJ(CMS_SignerInfo *si,
|
||||
const ASN1_OBJECT *obj, int type,
|
||||
const void *bytes, int len);
|
||||
int CMS_unsigned_add1_attr_by_NID(CMS_SignerInfo *si,
|
||||
int nid, int type,
|
||||
const void *bytes, int len);
|
||||
int CMS_unsigned_add1_attr_by_txt(CMS_SignerInfo *si,
|
||||
const char *attrname, int type,
|
||||
const void *bytes, int len);
|
||||
void *CMS_unsigned_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid,
|
||||
int lastpos, int type);
|
||||
|
||||
#ifdef HEADER_X509V3_H
|
||||
|
||||
int CMS_get1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest **prr);
|
||||
CMS_ReceiptRequest *CMS_ReceiptRequest_create0(unsigned char *id, int idlen,
|
||||
int allorfirst,
|
||||
STACK_OF(GENERAL_NAMES) *receiptList,
|
||||
STACK_OF(GENERAL_NAMES) *receiptsTo);
|
||||
int CMS_add1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest *rr);
|
||||
void CMS_ReceiptRequest_get0_values(CMS_ReceiptRequest *rr,
|
||||
ASN1_STRING **pcid,
|
||||
int *pallorfirst,
|
||||
STACK_OF(GENERAL_NAMES) **plist,
|
||||
STACK_OF(GENERAL_NAMES) **prto);
|
||||
|
||||
#endif
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
void ERR_load_CMS_strings(void);
|
||||
|
||||
/* Error codes for the CMS functions. */
|
||||
|
||||
/* Function codes. */
|
||||
#define CMS_F_CHECK_CONTENT 99
|
||||
#define CMS_F_CMS_ADD0_CERT 164
|
||||
#define CMS_F_CMS_ADD0_RECIPIENT_KEY 100
|
||||
#define CMS_F_CMS_ADD1_RECEIPTREQUEST 158
|
||||
#define CMS_F_CMS_ADD1_RECIPIENT_CERT 101
|
||||
#define CMS_F_CMS_ADD1_SIGNER 102
|
||||
#define CMS_F_CMS_ADD1_SIGNINGTIME 103
|
||||
#define CMS_F_CMS_COMPRESS 104
|
||||
#define CMS_F_CMS_COMPRESSEDDATA_CREATE 105
|
||||
#define CMS_F_CMS_COMPRESSEDDATA_INIT_BIO 106
|
||||
#define CMS_F_CMS_COPY_CONTENT 107
|
||||
#define CMS_F_CMS_COPY_MESSAGEDIGEST 108
|
||||
#define CMS_F_CMS_DATA 109
|
||||
#define CMS_F_CMS_DATAFINAL 110
|
||||
#define CMS_F_CMS_DATAINIT 111
|
||||
#define CMS_F_CMS_DECRYPT 112
|
||||
#define CMS_F_CMS_DECRYPT_SET1_KEY 113
|
||||
#define CMS_F_CMS_DECRYPT_SET1_PKEY 114
|
||||
#define CMS_F_CMS_DIGESTALGORITHM_FIND_CTX 115
|
||||
#define CMS_F_CMS_DIGESTALGORITHM_INIT_BIO 116
|
||||
#define CMS_F_CMS_DIGESTEDDATA_DO_FINAL 117
|
||||
#define CMS_F_CMS_DIGEST_VERIFY 118
|
||||
#define CMS_F_CMS_ENCODE_RECEIPT 161
|
||||
#define CMS_F_CMS_ENCRYPT 119
|
||||
#define CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO 120
|
||||
#define CMS_F_CMS_ENCRYPTEDDATA_DECRYPT 121
|
||||
#define CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT 122
|
||||
#define CMS_F_CMS_ENCRYPTEDDATA_SET1_KEY 123
|
||||
#define CMS_F_CMS_ENVELOPEDDATA_CREATE 124
|
||||
#define CMS_F_CMS_ENVELOPEDDATA_INIT_BIO 125
|
||||
#define CMS_F_CMS_ENVELOPED_DATA_INIT 126
|
||||
#define CMS_F_CMS_FINAL 127
|
||||
#define CMS_F_CMS_GET0_CERTIFICATE_CHOICES 128
|
||||
#define CMS_F_CMS_GET0_CONTENT 129
|
||||
#define CMS_F_CMS_GET0_ECONTENT_TYPE 130
|
||||
#define CMS_F_CMS_GET0_ENVELOPED 131
|
||||
#define CMS_F_CMS_GET0_REVOCATION_CHOICES 132
|
||||
#define CMS_F_CMS_GET0_SIGNED 133
|
||||
#define CMS_F_CMS_MSGSIGDIGEST_ADD1 162
|
||||
#define CMS_F_CMS_RECEIPTREQUEST_CREATE0 159
|
||||
#define CMS_F_CMS_RECEIPT_VERIFY 160
|
||||
#define CMS_F_CMS_RECIPIENTINFO_DECRYPT 134
|
||||
#define CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT 135
|
||||
#define CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT 136
|
||||
#define CMS_F_CMS_RECIPIENTINFO_KEKRI_GET0_ID 137
|
||||
#define CMS_F_CMS_RECIPIENTINFO_KEKRI_ID_CMP 138
|
||||
#define CMS_F_CMS_RECIPIENTINFO_KTRI_CERT_CMP 139
|
||||
#define CMS_F_CMS_RECIPIENTINFO_KTRI_DECRYPT 140
|
||||
#define CMS_F_CMS_RECIPIENTINFO_KTRI_ENCRYPT 141
|
||||
#define CMS_F_CMS_RECIPIENTINFO_KTRI_GET0_ALGS 142
|
||||
#define CMS_F_CMS_RECIPIENTINFO_KTRI_GET0_SIGNER_ID 143
|
||||
#define CMS_F_CMS_RECIPIENTINFO_SET0_KEY 144
|
||||
#define CMS_F_CMS_RECIPIENTINFO_SET0_PKEY 145
|
||||
#define CMS_F_CMS_SET1_SIGNERIDENTIFIER 146
|
||||
#define CMS_F_CMS_SET_DETACHED 147
|
||||
#define CMS_F_CMS_SIGN 148
|
||||
#define CMS_F_CMS_SIGNED_DATA_INIT 149
|
||||
#define CMS_F_CMS_SIGNERINFO_CONTENT_SIGN 150
|
||||
#define CMS_F_CMS_SIGNERINFO_SIGN 151
|
||||
#define CMS_F_CMS_SIGNERINFO_VERIFY 152
|
||||
#define CMS_F_CMS_SIGNERINFO_VERIFY_CERT 153
|
||||
#define CMS_F_CMS_SIGNERINFO_VERIFY_CONTENT 154
|
||||
#define CMS_F_CMS_SIGN_RECEIPT 163
|
||||
#define CMS_F_CMS_STREAM 155
|
||||
#define CMS_F_CMS_UNCOMPRESS 156
|
||||
#define CMS_F_CMS_VERIFY 157
|
||||
|
||||
/* Reason codes. */
|
||||
#define CMS_R_ADD_SIGNER_ERROR 99
|
||||
#define CMS_R_CERTIFICATE_ALREADY_PRESENT 175
|
||||
#define CMS_R_CERTIFICATE_HAS_NO_KEYID 160
|
||||
#define CMS_R_CERTIFICATE_VERIFY_ERROR 100
|
||||
#define CMS_R_CIPHER_INITIALISATION_ERROR 101
|
||||
#define CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR 102
|
||||
#define CMS_R_CMS_DATAFINAL_ERROR 103
|
||||
#define CMS_R_CMS_LIB 104
|
||||
#define CMS_R_CONTENTIDENTIFIER_MISMATCH 170
|
||||
#define CMS_R_CONTENT_NOT_FOUND 105
|
||||
#define CMS_R_CONTENT_TYPE_MISMATCH 171
|
||||
#define CMS_R_CONTENT_TYPE_NOT_COMPRESSED_DATA 106
|
||||
#define CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA 107
|
||||
#define CMS_R_CONTENT_TYPE_NOT_SIGNED_DATA 108
|
||||
#define CMS_R_CONTENT_VERIFY_ERROR 109
|
||||
#define CMS_R_CTRL_ERROR 110
|
||||
#define CMS_R_CTRL_FAILURE 111
|
||||
#define CMS_R_DECRYPT_ERROR 112
|
||||
#define CMS_R_DIGEST_ERROR 161
|
||||
#define CMS_R_ERROR_GETTING_PUBLIC_KEY 113
|
||||
#define CMS_R_ERROR_READING_MESSAGEDIGEST_ATTRIBUTE 114
|
||||
#define CMS_R_ERROR_SETTING_KEY 115
|
||||
#define CMS_R_ERROR_SETTING_RECIPIENTINFO 116
|
||||
#define CMS_R_INVALID_ENCRYPTED_KEY_LENGTH 117
|
||||
#define CMS_R_INVALID_KEY_LENGTH 118
|
||||
#define CMS_R_MD_BIO_INIT_ERROR 119
|
||||
#define CMS_R_MESSAGEDIGEST_ATTRIBUTE_WRONG_LENGTH 120
|
||||
#define CMS_R_MESSAGEDIGEST_WRONG_LENGTH 121
|
||||
#define CMS_R_MSGSIGDIGEST_ERROR 172
|
||||
#define CMS_R_MSGSIGDIGEST_VERIFICATION_FAILURE 162
|
||||
#define CMS_R_MSGSIGDIGEST_WRONG_LENGTH 163
|
||||
#define CMS_R_NEED_ONE_SIGNER 164
|
||||
#define CMS_R_NOT_A_SIGNED_RECEIPT 165
|
||||
#define CMS_R_NOT_ENCRYPTED_DATA 122
|
||||
#define CMS_R_NOT_KEK 123
|
||||
#define CMS_R_NOT_KEY_TRANSPORT 124
|
||||
#define CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE 125
|
||||
#define CMS_R_NO_CIPHER 126
|
||||
#define CMS_R_NO_CONTENT 127
|
||||
#define CMS_R_NO_CONTENT_TYPE 173
|
||||
#define CMS_R_NO_DEFAULT_DIGEST 128
|
||||
#define CMS_R_NO_DIGEST_SET 129
|
||||
#define CMS_R_NO_KEY 130
|
||||
#define CMS_R_NO_KEY_OR_CERT 174
|
||||
#define CMS_R_NO_MATCHING_DIGEST 131
|
||||
#define CMS_R_NO_MATCHING_RECIPIENT 132
|
||||
#define CMS_R_NO_MATCHING_SIGNATURE 166
|
||||
#define CMS_R_NO_MSGSIGDIGEST 167
|
||||
#define CMS_R_NO_PRIVATE_KEY 133
|
||||
#define CMS_R_NO_PUBLIC_KEY 134
|
||||
#define CMS_R_NO_RECEIPT_REQUEST 168
|
||||
#define CMS_R_NO_SIGNERS 135
|
||||
#define CMS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 136
|
||||
#define CMS_R_RECEIPT_DECODE_ERROR 169
|
||||
#define CMS_R_RECIPIENT_ERROR 137
|
||||
#define CMS_R_SIGNER_CERTIFICATE_NOT_FOUND 138
|
||||
#define CMS_R_SIGNFINAL_ERROR 139
|
||||
#define CMS_R_SMIME_TEXT_ERROR 140
|
||||
#define CMS_R_STORE_INIT_ERROR 141
|
||||
#define CMS_R_TYPE_NOT_COMPRESSED_DATA 142
|
||||
#define CMS_R_TYPE_NOT_DATA 143
|
||||
#define CMS_R_TYPE_NOT_DIGESTED_DATA 144
|
||||
#define CMS_R_TYPE_NOT_ENCRYPTED_DATA 145
|
||||
#define CMS_R_TYPE_NOT_ENVELOPED_DATA 146
|
||||
#define CMS_R_UNABLE_TO_FINALIZE_CONTEXT 147
|
||||
#define CMS_R_UNKNOWN_CIPHER 148
|
||||
#define CMS_R_UNKNOWN_DIGEST_ALGORIHM 149
|
||||
#define CMS_R_UNKNOWN_ID 150
|
||||
#define CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM 151
|
||||
#define CMS_R_UNSUPPORTED_CONTENT_TYPE 152
|
||||
#define CMS_R_UNSUPPORTED_KEK_ALGORITHM 153
|
||||
#define CMS_R_UNSUPPORTED_RECIPIENT_TYPE 154
|
||||
#define CMS_R_UNSUPPORTED_RECPIENTINFO_TYPE 155
|
||||
#define CMS_R_UNSUPPORTED_TYPE 156
|
||||
#define CMS_R_UNWRAP_ERROR 157
|
||||
#define CMS_R_VERIFICATION_FAILURE 158
|
||||
#define CMS_R_WRAP_ERROR 159
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
346
crypto/cms/cms_asn1.c
Normal file
346
crypto/cms/cms_asn1.c
Normal file
@ -0,0 +1,346 @@
|
||||
/* crypto/cms/cms_asn1.c */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2008 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#include "cms.h"
|
||||
#include "cms_lcl.h"
|
||||
|
||||
|
||||
ASN1_SEQUENCE(CMS_IssuerAndSerialNumber) = {
|
||||
ASN1_SIMPLE(CMS_IssuerAndSerialNumber, issuer, X509_NAME),
|
||||
ASN1_SIMPLE(CMS_IssuerAndSerialNumber, serialNumber, ASN1_INTEGER)
|
||||
} ASN1_SEQUENCE_END(CMS_IssuerAndSerialNumber)
|
||||
|
||||
ASN1_SEQUENCE(CMS_OtherCertificateFormat) = {
|
||||
ASN1_SIMPLE(CMS_OtherCertificateFormat, otherCertFormat, ASN1_OBJECT),
|
||||
ASN1_OPT(CMS_OtherCertificateFormat, otherCert, ASN1_ANY)
|
||||
} ASN1_SEQUENCE_END(CMS_OtherCertificateFormat)
|
||||
|
||||
ASN1_CHOICE(CMS_CertificateChoices) = {
|
||||
ASN1_SIMPLE(CMS_CertificateChoices, d.certificate, X509),
|
||||
ASN1_IMP(CMS_CertificateChoices, d.extendedCertificate, ASN1_SEQUENCE, 0),
|
||||
ASN1_IMP(CMS_CertificateChoices, d.v1AttrCert, ASN1_SEQUENCE, 1),
|
||||
ASN1_IMP(CMS_CertificateChoices, d.v2AttrCert, ASN1_SEQUENCE, 2),
|
||||
ASN1_IMP(CMS_CertificateChoices, d.other, CMS_OtherCertificateFormat, 3)
|
||||
} ASN1_CHOICE_END(CMS_CertificateChoices)
|
||||
|
||||
ASN1_CHOICE(CMS_SignerIdentifier) = {
|
||||
ASN1_SIMPLE(CMS_SignerIdentifier, d.issuerAndSerialNumber, CMS_IssuerAndSerialNumber),
|
||||
ASN1_IMP(CMS_SignerIdentifier, d.subjectKeyIdentifier, ASN1_OCTET_STRING, 0)
|
||||
} ASN1_CHOICE_END(CMS_SignerIdentifier)
|
||||
|
||||
ASN1_NDEF_SEQUENCE(CMS_EncapsulatedContentInfo) = {
|
||||
ASN1_SIMPLE(CMS_EncapsulatedContentInfo, eContentType, ASN1_OBJECT),
|
||||
ASN1_NDEF_EXP_OPT(CMS_EncapsulatedContentInfo, eContent, ASN1_OCTET_STRING_NDEF, 0)
|
||||
} ASN1_NDEF_SEQUENCE_END(CMS_EncapsulatedContentInfo)
|
||||
|
||||
/* Minor tweak to operation: free up signer key, cert */
|
||||
static int cms_si_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||
{
|
||||
if(operation == ASN1_OP_FREE_POST)
|
||||
{
|
||||
CMS_SignerInfo *si = (CMS_SignerInfo *)*pval;
|
||||
if (si->pkey)
|
||||
EVP_PKEY_free(si->pkey);
|
||||
if (si->signer)
|
||||
X509_free(si->signer);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
ASN1_SEQUENCE_cb(CMS_SignerInfo, cms_si_cb) = {
|
||||
ASN1_SIMPLE(CMS_SignerInfo, version, LONG),
|
||||
ASN1_SIMPLE(CMS_SignerInfo, sid, CMS_SignerIdentifier),
|
||||
ASN1_SIMPLE(CMS_SignerInfo, digestAlgorithm, X509_ALGOR),
|
||||
ASN1_IMP_SET_OF_OPT(CMS_SignerInfo, signedAttrs, X509_ATTRIBUTE, 0),
|
||||
ASN1_SIMPLE(CMS_SignerInfo, signatureAlgorithm, X509_ALGOR),
|
||||
ASN1_SIMPLE(CMS_SignerInfo, signature, ASN1_OCTET_STRING),
|
||||
ASN1_IMP_SET_OF_OPT(CMS_SignerInfo, unsignedAttrs, X509_ATTRIBUTE, 1)
|
||||
} ASN1_SEQUENCE_END_cb(CMS_SignerInfo, CMS_SignerInfo)
|
||||
|
||||
ASN1_SEQUENCE(CMS_OtherRevocationInfoFormat) = {
|
||||
ASN1_SIMPLE(CMS_OtherRevocationInfoFormat, otherRevInfoFormat, ASN1_OBJECT),
|
||||
ASN1_OPT(CMS_OtherRevocationInfoFormat, otherRevInfo, ASN1_ANY)
|
||||
} ASN1_SEQUENCE_END(CMS_OtherRevocationInfoFormat)
|
||||
|
||||
ASN1_CHOICE(CMS_RevocationInfoChoice) = {
|
||||
ASN1_SIMPLE(CMS_RevocationInfoChoice, d.crl, X509_CRL),
|
||||
ASN1_IMP(CMS_RevocationInfoChoice, d.other, CMS_OtherRevocationInfoFormat, 1)
|
||||
} ASN1_CHOICE_END(CMS_RevocationInfoChoice)
|
||||
|
||||
ASN1_NDEF_SEQUENCE(CMS_SignedData) = {
|
||||
ASN1_SIMPLE(CMS_SignedData, version, LONG),
|
||||
ASN1_SET_OF(CMS_SignedData, digestAlgorithms, X509_ALGOR),
|
||||
ASN1_SIMPLE(CMS_SignedData, encapContentInfo, CMS_EncapsulatedContentInfo),
|
||||
ASN1_IMP_SET_OF_OPT(CMS_SignedData, certificates, CMS_CertificateChoices, 0),
|
||||
ASN1_IMP_SET_OF_OPT(CMS_SignedData, crls, CMS_RevocationInfoChoice, 1),
|
||||
ASN1_SET_OF(CMS_SignedData, signerInfos, CMS_SignerInfo)
|
||||
} ASN1_NDEF_SEQUENCE_END(CMS_SignedData)
|
||||
|
||||
ASN1_SEQUENCE(CMS_OriginatorInfo) = {
|
||||
ASN1_IMP_SET_OF_OPT(CMS_SignedData, certificates, CMS_CertificateChoices, 0),
|
||||
ASN1_IMP_SET_OF_OPT(CMS_SignedData, crls, CMS_RevocationInfoChoice, 1)
|
||||
} ASN1_SEQUENCE_END(CMS_OriginatorInfo)
|
||||
|
||||
ASN1_NDEF_SEQUENCE(CMS_EncryptedContentInfo) = {
|
||||
ASN1_SIMPLE(CMS_EncryptedContentInfo, contentType, ASN1_OBJECT),
|
||||
ASN1_SIMPLE(CMS_EncryptedContentInfo, contentEncryptionAlgorithm, X509_ALGOR),
|
||||
ASN1_IMP_OPT(CMS_EncryptedContentInfo, encryptedContent, ASN1_OCTET_STRING_NDEF, 0)
|
||||
} ASN1_NDEF_SEQUENCE_END(CMS_EncryptedContentInfo)
|
||||
|
||||
ASN1_SEQUENCE(CMS_KeyTransRecipientInfo) = {
|
||||
ASN1_SIMPLE(CMS_KeyTransRecipientInfo, version, LONG),
|
||||
ASN1_SIMPLE(CMS_KeyTransRecipientInfo, rid, CMS_SignerIdentifier),
|
||||
ASN1_SIMPLE(CMS_KeyTransRecipientInfo, keyEncryptionAlgorithm, X509_ALGOR),
|
||||
ASN1_SIMPLE(CMS_KeyTransRecipientInfo, encryptedKey, ASN1_OCTET_STRING)
|
||||
} ASN1_SEQUENCE_END(CMS_KeyTransRecipientInfo)
|
||||
|
||||
ASN1_SEQUENCE(CMS_OtherKeyAttribute) = {
|
||||
ASN1_SIMPLE(CMS_OtherKeyAttribute, keyAttrId, ASN1_OBJECT),
|
||||
ASN1_OPT(CMS_OtherKeyAttribute, keyAttr, ASN1_ANY)
|
||||
} ASN1_SEQUENCE_END(CMS_OtherKeyAttribute)
|
||||
|
||||
ASN1_SEQUENCE(CMS_RecipientKeyIdentifier) = {
|
||||
ASN1_SIMPLE(CMS_RecipientKeyIdentifier, subjectKeyIdentifier, ASN1_OCTET_STRING),
|
||||
ASN1_OPT(CMS_RecipientKeyIdentifier, date, ASN1_GENERALIZEDTIME),
|
||||
ASN1_OPT(CMS_RecipientKeyIdentifier, other, CMS_OtherKeyAttribute)
|
||||
} ASN1_SEQUENCE_END(CMS_RecipientKeyIdentifier)
|
||||
|
||||
ASN1_CHOICE(CMS_KeyAgreeRecipientIdentifier) = {
|
||||
ASN1_SIMPLE(CMS_KeyAgreeRecipientIdentifier, d.issuerAndSerialNumber, CMS_IssuerAndSerialNumber),
|
||||
ASN1_IMP(CMS_KeyAgreeRecipientIdentifier, d.rKeyId, CMS_RecipientKeyIdentifier, 0)
|
||||
} ASN1_CHOICE_END(CMS_KeyAgreeRecipientIdentifier)
|
||||
|
||||
ASN1_SEQUENCE(CMS_RecipientEncryptedKey) = {
|
||||
ASN1_SIMPLE(CMS_RecipientEncryptedKey, rid, CMS_KeyAgreeRecipientIdentifier),
|
||||
ASN1_SIMPLE(CMS_RecipientEncryptedKey, encryptedKey, ASN1_OCTET_STRING)
|
||||
} ASN1_SEQUENCE_END(CMS_RecipientEncryptedKey)
|
||||
|
||||
ASN1_SEQUENCE(CMS_OriginatorPublicKey) = {
|
||||
ASN1_SIMPLE(CMS_OriginatorPublicKey, algorithm, X509_ALGOR),
|
||||
ASN1_SIMPLE(CMS_OriginatorPublicKey, publicKey, ASN1_BIT_STRING)
|
||||
} ASN1_SEQUENCE_END(CMS_OriginatorPublicKey)
|
||||
|
||||
ASN1_CHOICE(CMS_OriginatorIdentifierOrKey) = {
|
||||
ASN1_SIMPLE(CMS_OriginatorIdentifierOrKey, d.issuerAndSerialNumber, CMS_IssuerAndSerialNumber),
|
||||
ASN1_IMP(CMS_OriginatorIdentifierOrKey, d.subjectKeyIdentifier, ASN1_OCTET_STRING, 0),
|
||||
ASN1_IMP(CMS_OriginatorIdentifierOrKey, d.originatorKey, CMS_OriginatorPublicKey, 1)
|
||||
} ASN1_CHOICE_END(CMS_OriginatorIdentifierOrKey)
|
||||
|
||||
ASN1_SEQUENCE(CMS_KeyAgreeRecipientInfo) = {
|
||||
ASN1_SIMPLE(CMS_KeyAgreeRecipientInfo, version, LONG),
|
||||
ASN1_EXP(CMS_KeyAgreeRecipientInfo, originator, CMS_OriginatorIdentifierOrKey, 0),
|
||||
ASN1_EXP_OPT(CMS_KeyAgreeRecipientInfo, ukm, ASN1_OCTET_STRING, 1),
|
||||
ASN1_SIMPLE(CMS_KeyAgreeRecipientInfo, keyEncryptionAlgorithm, X509_ALGOR),
|
||||
ASN1_SEQUENCE_OF(CMS_KeyAgreeRecipientInfo, recipientEncryptedKeys, CMS_RecipientEncryptedKey)
|
||||
} ASN1_SEQUENCE_END(CMS_KeyAgreeRecipientInfo)
|
||||
|
||||
ASN1_SEQUENCE(CMS_KEKIdentifier) = {
|
||||
ASN1_SIMPLE(CMS_KEKIdentifier, keyIdentifier, ASN1_OCTET_STRING),
|
||||
ASN1_OPT(CMS_KEKIdentifier, date, ASN1_GENERALIZEDTIME),
|
||||
ASN1_OPT(CMS_KEKIdentifier, other, CMS_OtherKeyAttribute)
|
||||
} ASN1_SEQUENCE_END(CMS_KEKIdentifier)
|
||||
|
||||
ASN1_SEQUENCE(CMS_KEKRecipientInfo) = {
|
||||
ASN1_SIMPLE(CMS_KEKRecipientInfo, version, LONG),
|
||||
ASN1_SIMPLE(CMS_KEKRecipientInfo, kekid, CMS_KEKIdentifier),
|
||||
ASN1_SIMPLE(CMS_KEKRecipientInfo, keyEncryptionAlgorithm, X509_ALGOR),
|
||||
ASN1_SIMPLE(CMS_KEKRecipientInfo, encryptedKey, ASN1_OCTET_STRING)
|
||||
} ASN1_SEQUENCE_END(CMS_KEKRecipientInfo)
|
||||
|
||||
ASN1_SEQUENCE(CMS_PasswordRecipientInfo) = {
|
||||
ASN1_SIMPLE(CMS_PasswordRecipientInfo, version, LONG),
|
||||
ASN1_IMP_OPT(CMS_PasswordRecipientInfo, keyDerivationAlgorithm, X509_ALGOR, 0),
|
||||
ASN1_SIMPLE(CMS_PasswordRecipientInfo, keyEncryptionAlgorithm, X509_ALGOR),
|
||||
ASN1_SIMPLE(CMS_PasswordRecipientInfo, encryptedKey, ASN1_OCTET_STRING)
|
||||
} ASN1_SEQUENCE_END(CMS_PasswordRecipientInfo)
|
||||
|
||||
ASN1_SEQUENCE(CMS_OtherRecipientInfo) = {
|
||||
ASN1_SIMPLE(CMS_OtherRecipientInfo, oriType, ASN1_OBJECT),
|
||||
ASN1_OPT(CMS_OtherRecipientInfo, oriValue, ASN1_ANY)
|
||||
} ASN1_SEQUENCE_END(CMS_OtherRecipientInfo)
|
||||
|
||||
/* Free up RecipientInfo additional data */
|
||||
static int cms_ri_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||
{
|
||||
if(operation == ASN1_OP_FREE_PRE)
|
||||
{
|
||||
CMS_RecipientInfo *ri = (CMS_RecipientInfo *)*pval;
|
||||
if (ri->type == CMS_RECIPINFO_TRANS)
|
||||
{
|
||||
CMS_KeyTransRecipientInfo *ktri = ri->d.ktri;
|
||||
if (ktri->pkey)
|
||||
EVP_PKEY_free(ktri->pkey);
|
||||
if (ktri->recip)
|
||||
X509_free(ktri->recip);
|
||||
}
|
||||
else if (ri->type == CMS_RECIPINFO_KEK)
|
||||
{
|
||||
CMS_KEKRecipientInfo *kekri = ri->d.kekri;
|
||||
if (kekri->key)
|
||||
{
|
||||
OPENSSL_cleanse(kekri->key, kekri->keylen);
|
||||
OPENSSL_free(kekri->key);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
ASN1_CHOICE_cb(CMS_RecipientInfo, cms_ri_cb) = {
|
||||
ASN1_SIMPLE(CMS_RecipientInfo, d.ktri, CMS_KeyTransRecipientInfo),
|
||||
ASN1_IMP(CMS_RecipientInfo, d.kari, CMS_KeyAgreeRecipientInfo, 1),
|
||||
ASN1_IMP(CMS_RecipientInfo, d.kekri, CMS_KEKRecipientInfo, 2),
|
||||
ASN1_IMP(CMS_RecipientInfo, d.pwri, CMS_PasswordRecipientInfo, 3),
|
||||
ASN1_IMP(CMS_RecipientInfo, d.ori, CMS_OtherRecipientInfo, 4)
|
||||
} ASN1_CHOICE_END_cb(CMS_RecipientInfo, CMS_RecipientInfo, type)
|
||||
|
||||
ASN1_NDEF_SEQUENCE(CMS_EnvelopedData) = {
|
||||
ASN1_SIMPLE(CMS_EnvelopedData, version, LONG),
|
||||
ASN1_IMP_OPT(CMS_EnvelopedData, originatorInfo, CMS_OriginatorInfo, 0),
|
||||
ASN1_SET_OF(CMS_EnvelopedData, recipientInfos, CMS_RecipientInfo),
|
||||
ASN1_SIMPLE(CMS_EnvelopedData, encryptedContentInfo, CMS_EncryptedContentInfo),
|
||||
ASN1_IMP_SET_OF_OPT(CMS_EnvelopedData, unprotectedAttrs, X509_ATTRIBUTE, 1)
|
||||
} ASN1_NDEF_SEQUENCE_END(CMS_EnvelopedData)
|
||||
|
||||
ASN1_NDEF_SEQUENCE(CMS_DigestedData) = {
|
||||
ASN1_SIMPLE(CMS_DigestedData, version, LONG),
|
||||
ASN1_SIMPLE(CMS_DigestedData, digestAlgorithm, X509_ALGOR),
|
||||
ASN1_SIMPLE(CMS_DigestedData, encapContentInfo, CMS_EncapsulatedContentInfo),
|
||||
ASN1_SIMPLE(CMS_DigestedData, digest, ASN1_OCTET_STRING)
|
||||
} ASN1_NDEF_SEQUENCE_END(CMS_DigestedData)
|
||||
|
||||
ASN1_NDEF_SEQUENCE(CMS_EncryptedData) = {
|
||||
ASN1_SIMPLE(CMS_EncryptedData, version, LONG),
|
||||
ASN1_SIMPLE(CMS_EncryptedData, encryptedContentInfo, CMS_EncryptedContentInfo),
|
||||
ASN1_IMP_SET_OF_OPT(CMS_EncryptedData, unprotectedAttrs, X509_ATTRIBUTE, 1)
|
||||
} ASN1_NDEF_SEQUENCE_END(CMS_EncryptedData)
|
||||
|
||||
ASN1_NDEF_SEQUENCE(CMS_AuthenticatedData) = {
|
||||
ASN1_SIMPLE(CMS_AuthenticatedData, version, LONG),
|
||||
ASN1_IMP_OPT(CMS_AuthenticatedData, originatorInfo, CMS_OriginatorInfo, 0),
|
||||
ASN1_SET_OF(CMS_AuthenticatedData, recipientInfos, CMS_RecipientInfo),
|
||||
ASN1_SIMPLE(CMS_AuthenticatedData, macAlgorithm, X509_ALGOR),
|
||||
ASN1_IMP(CMS_AuthenticatedData, digestAlgorithm, X509_ALGOR, 1),
|
||||
ASN1_SIMPLE(CMS_AuthenticatedData, encapContentInfo, CMS_EncapsulatedContentInfo),
|
||||
ASN1_IMP_SET_OF_OPT(CMS_AuthenticatedData, authAttrs, X509_ALGOR, 2),
|
||||
ASN1_SIMPLE(CMS_AuthenticatedData, mac, ASN1_OCTET_STRING),
|
||||
ASN1_IMP_SET_OF_OPT(CMS_AuthenticatedData, unauthAttrs, X509_ALGOR, 3)
|
||||
} ASN1_NDEF_SEQUENCE_END(CMS_AuthenticatedData)
|
||||
|
||||
ASN1_NDEF_SEQUENCE(CMS_CompressedData) = {
|
||||
ASN1_SIMPLE(CMS_CompressedData, version, LONG),
|
||||
ASN1_SIMPLE(CMS_CompressedData, compressionAlgorithm, X509_ALGOR),
|
||||
ASN1_SIMPLE(CMS_CompressedData, encapContentInfo, CMS_EncapsulatedContentInfo),
|
||||
} ASN1_NDEF_SEQUENCE_END(CMS_CompressedData)
|
||||
|
||||
/* This is the ANY DEFINED BY table for the top level ContentInfo structure */
|
||||
|
||||
ASN1_ADB_TEMPLATE(cms_default) = ASN1_EXP(CMS_ContentInfo, d.other, ASN1_ANY, 0);
|
||||
|
||||
ASN1_ADB(CMS_ContentInfo) = {
|
||||
ADB_ENTRY(NID_pkcs7_data, ASN1_NDEF_EXP(CMS_ContentInfo, d.data, ASN1_OCTET_STRING_NDEF, 0)),
|
||||
ADB_ENTRY(NID_pkcs7_signed, ASN1_NDEF_EXP(CMS_ContentInfo, d.signedData, CMS_SignedData, 0)),
|
||||
ADB_ENTRY(NID_pkcs7_enveloped, ASN1_NDEF_EXP(CMS_ContentInfo, d.envelopedData, CMS_EnvelopedData, 0)),
|
||||
ADB_ENTRY(NID_pkcs7_digest, ASN1_NDEF_EXP(CMS_ContentInfo, d.digestedData, CMS_DigestedData, 0)),
|
||||
ADB_ENTRY(NID_pkcs7_encrypted, ASN1_NDEF_EXP(CMS_ContentInfo, d.encryptedData, CMS_EncryptedData, 0)),
|
||||
ADB_ENTRY(NID_id_smime_ct_authData, ASN1_NDEF_EXP(CMS_ContentInfo, d.authenticatedData, CMS_AuthenticatedData, 0)),
|
||||
ADB_ENTRY(NID_id_smime_ct_compressedData, ASN1_NDEF_EXP(CMS_ContentInfo, d.compressedData, CMS_CompressedData, 0)),
|
||||
} ASN1_ADB_END(CMS_ContentInfo, 0, contentType, 0, &cms_default_tt, NULL);
|
||||
|
||||
ASN1_NDEF_SEQUENCE(CMS_ContentInfo) = {
|
||||
ASN1_SIMPLE(CMS_ContentInfo, contentType, ASN1_OBJECT),
|
||||
ASN1_ADB_OBJECT(CMS_ContentInfo)
|
||||
} ASN1_NDEF_SEQUENCE_END(CMS_ContentInfo)
|
||||
|
||||
/* Specials for signed attributes */
|
||||
|
||||
/* When signing attributes we want to reorder them to match the sorted
|
||||
* encoding.
|
||||
*/
|
||||
|
||||
ASN1_ITEM_TEMPLATE(CMS_Attributes_Sign) =
|
||||
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_ORDER, 0, CMS_ATTRIBUTES, X509_ATTRIBUTE)
|
||||
ASN1_ITEM_TEMPLATE_END(CMS_Attributes_Sign)
|
||||
|
||||
/* When verifying attributes we need to use the received order. So
|
||||
* we use SEQUENCE OF and tag it to SET OF
|
||||
*/
|
||||
|
||||
ASN1_ITEM_TEMPLATE(CMS_Attributes_Verify) =
|
||||
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_IMPTAG | ASN1_TFLG_UNIVERSAL,
|
||||
V_ASN1_SET, CMS_ATTRIBUTES, X509_ATTRIBUTE)
|
||||
ASN1_ITEM_TEMPLATE_END(CMS_Attributes_Verify)
|
||||
|
||||
|
||||
|
||||
ASN1_CHOICE(CMS_ReceiptsFrom) = {
|
||||
ASN1_IMP(CMS_ReceiptsFrom, d.allOrFirstTier, LONG, 0),
|
||||
ASN1_IMP_SEQUENCE_OF(CMS_ReceiptsFrom, d.receiptList, GENERAL_NAMES, 1)
|
||||
} ASN1_CHOICE_END(CMS_ReceiptsFrom)
|
||||
|
||||
ASN1_SEQUENCE(CMS_ReceiptRequest) = {
|
||||
ASN1_SIMPLE(CMS_ReceiptRequest, signedContentIdentifier, ASN1_OCTET_STRING),
|
||||
ASN1_SIMPLE(CMS_ReceiptRequest, receiptsFrom, CMS_ReceiptsFrom),
|
||||
ASN1_SEQUENCE_OF(CMS_ReceiptRequest, receiptsTo, GENERAL_NAMES)
|
||||
} ASN1_SEQUENCE_END(CMS_ReceiptRequest)
|
||||
|
||||
ASN1_SEQUENCE(CMS_Receipt) = {
|
||||
ASN1_SIMPLE(CMS_Receipt, version, LONG),
|
||||
ASN1_SIMPLE(CMS_Receipt, contentType, ASN1_OBJECT),
|
||||
ASN1_SIMPLE(CMS_Receipt, signedContentIdentifier, ASN1_OCTET_STRING),
|
||||
ASN1_SIMPLE(CMS_Receipt, originatorSignatureValue, ASN1_OCTET_STRING)
|
||||
} ASN1_SEQUENCE_END(CMS_Receipt)
|
||||
|
195
crypto/cms/cms_att.c
Normal file
195
crypto/cms/cms_att.c
Normal file
@ -0,0 +1,195 @@
|
||||
/* crypto/cms/cms_att.c */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2008 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/err.h>
|
||||
#include "cms.h"
|
||||
#include "cms_lcl.h"
|
||||
|
||||
/* CMS SignedData Attribute utilities */
|
||||
|
||||
int CMS_signed_get_attr_count(const CMS_SignerInfo *si)
|
||||
{
|
||||
return X509at_get_attr_count(si->signedAttrs);
|
||||
}
|
||||
|
||||
int CMS_signed_get_attr_by_NID(const CMS_SignerInfo *si, int nid,
|
||||
int lastpos)
|
||||
{
|
||||
return X509at_get_attr_by_NID(si->signedAttrs, nid, lastpos);
|
||||
}
|
||||
|
||||
int CMS_signed_get_attr_by_OBJ(const CMS_SignerInfo *si, ASN1_OBJECT *obj,
|
||||
int lastpos)
|
||||
{
|
||||
return X509at_get_attr_by_OBJ(si->signedAttrs, obj, lastpos);
|
||||
}
|
||||
|
||||
X509_ATTRIBUTE *CMS_signed_get_attr(const CMS_SignerInfo *si, int loc)
|
||||
{
|
||||
return X509at_get_attr(si->signedAttrs, loc);
|
||||
}
|
||||
|
||||
X509_ATTRIBUTE *CMS_signed_delete_attr(CMS_SignerInfo *si, int loc)
|
||||
{
|
||||
return X509at_delete_attr(si->signedAttrs, loc);
|
||||
}
|
||||
|
||||
int CMS_signed_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr)
|
||||
{
|
||||
if(X509at_add1_attr(&si->signedAttrs, attr)) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMS_signed_add1_attr_by_OBJ(CMS_SignerInfo *si,
|
||||
const ASN1_OBJECT *obj, int type,
|
||||
const void *bytes, int len)
|
||||
{
|
||||
if(X509at_add1_attr_by_OBJ(&si->signedAttrs, obj,
|
||||
type, bytes, len)) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMS_signed_add1_attr_by_NID(CMS_SignerInfo *si,
|
||||
int nid, int type,
|
||||
const void *bytes, int len)
|
||||
{
|
||||
if(X509at_add1_attr_by_NID(&si->signedAttrs, nid,
|
||||
type, bytes, len)) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMS_signed_add1_attr_by_txt(CMS_SignerInfo *si,
|
||||
const char *attrname, int type,
|
||||
const void *bytes, int len)
|
||||
{
|
||||
if(X509at_add1_attr_by_txt(&si->signedAttrs, attrname,
|
||||
type, bytes, len)) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *CMS_signed_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid,
|
||||
int lastpos, int type)
|
||||
{
|
||||
return X509at_get0_data_by_OBJ(si->signedAttrs, oid, lastpos, type);
|
||||
}
|
||||
|
||||
int CMS_unsigned_get_attr_count(const CMS_SignerInfo *si)
|
||||
{
|
||||
return X509at_get_attr_count(si->unsignedAttrs);
|
||||
}
|
||||
|
||||
int CMS_unsigned_get_attr_by_NID(const CMS_SignerInfo *si, int nid,
|
||||
int lastpos)
|
||||
{
|
||||
return X509at_get_attr_by_NID(si->unsignedAttrs, nid, lastpos);
|
||||
}
|
||||
|
||||
int CMS_unsigned_get_attr_by_OBJ(const CMS_SignerInfo *si, ASN1_OBJECT *obj,
|
||||
int lastpos)
|
||||
{
|
||||
return X509at_get_attr_by_OBJ(si->unsignedAttrs, obj, lastpos);
|
||||
}
|
||||
|
||||
X509_ATTRIBUTE *CMS_unsigned_get_attr(const CMS_SignerInfo *si, int loc)
|
||||
{
|
||||
return X509at_get_attr(si->unsignedAttrs, loc);
|
||||
}
|
||||
|
||||
X509_ATTRIBUTE *CMS_unsigned_delete_attr(CMS_SignerInfo *si, int loc)
|
||||
{
|
||||
return X509at_delete_attr(si->unsignedAttrs, loc);
|
||||
}
|
||||
|
||||
int CMS_unsigned_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr)
|
||||
{
|
||||
if(X509at_add1_attr(&si->unsignedAttrs, attr)) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMS_unsigned_add1_attr_by_OBJ(CMS_SignerInfo *si,
|
||||
const ASN1_OBJECT *obj, int type,
|
||||
const void *bytes, int len)
|
||||
{
|
||||
if(X509at_add1_attr_by_OBJ(&si->unsignedAttrs, obj,
|
||||
type, bytes, len)) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMS_unsigned_add1_attr_by_NID(CMS_SignerInfo *si,
|
||||
int nid, int type,
|
||||
const void *bytes, int len)
|
||||
{
|
||||
if(X509at_add1_attr_by_NID(&si->unsignedAttrs, nid,
|
||||
type, bytes, len)) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMS_unsigned_add1_attr_by_txt(CMS_SignerInfo *si,
|
||||
const char *attrname, int type,
|
||||
const void *bytes, int len)
|
||||
{
|
||||
if(X509at_add1_attr_by_txt(&si->unsignedAttrs, attrname,
|
||||
type, bytes, len)) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *CMS_unsigned_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid,
|
||||
int lastpos, int type)
|
||||
{
|
||||
return X509at_get0_data_by_OBJ(si->unsignedAttrs, oid, lastpos, type);
|
||||
}
|
||||
|
||||
/* Specific attribute cases */
|
134
crypto/cms/cms_cd.c
Normal file
134
crypto/cms/cms_cd.c
Normal file
@ -0,0 +1,134 @@
|
||||
/* crypto/cms/cms_cd.c */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2008 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/cms.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/comp.h>
|
||||
#include "cms_lcl.h"
|
||||
|
||||
DECLARE_ASN1_ITEM(CMS_CompressedData)
|
||||
|
||||
#ifdef ZLIB
|
||||
|
||||
/* CMS CompressedData Utilities */
|
||||
|
||||
CMS_ContentInfo *cms_CompressedData_create(int comp_nid)
|
||||
{
|
||||
CMS_ContentInfo *cms;
|
||||
CMS_CompressedData *cd;
|
||||
/* Will need something cleverer if there is ever more than one
|
||||
* compression algorithm or parameters have some meaning...
|
||||
*/
|
||||
if (comp_nid != NID_zlib_compression)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_COMPRESSEDDATA_CREATE,
|
||||
CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
|
||||
return NULL;
|
||||
}
|
||||
cms = CMS_ContentInfo_new();
|
||||
if (!cms)
|
||||
return NULL;
|
||||
|
||||
cd = M_ASN1_new_of(CMS_CompressedData);
|
||||
|
||||
if (!cd)
|
||||
goto err;
|
||||
|
||||
cms->contentType = OBJ_nid2obj(NID_id_smime_ct_compressedData);
|
||||
cms->d.compressedData = cd;
|
||||
|
||||
cd->version = 0;
|
||||
|
||||
X509_ALGOR_set0(cd->compressionAlgorithm,
|
||||
OBJ_nid2obj(NID_zlib_compression),
|
||||
V_ASN1_UNDEF, NULL);
|
||||
|
||||
cd->encapContentInfo->eContentType = OBJ_nid2obj(NID_pkcs7_data);
|
||||
|
||||
return cms;
|
||||
|
||||
err:
|
||||
|
||||
if (cms)
|
||||
CMS_ContentInfo_free(cms);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BIO *cms_CompressedData_init_bio(CMS_ContentInfo *cms)
|
||||
{
|
||||
CMS_CompressedData *cd;
|
||||
ASN1_OBJECT *compoid;
|
||||
if (OBJ_obj2nid(cms->contentType) != NID_id_smime_ct_compressedData)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_COMPRESSEDDATA_INIT_BIO,
|
||||
CMS_R_CONTENT_TYPE_NOT_COMPRESSED_DATA);
|
||||
return NULL;
|
||||
}
|
||||
cd = cms->d.compressedData;
|
||||
X509_ALGOR_get0(&compoid, NULL, NULL, cd->compressionAlgorithm);
|
||||
if (OBJ_obj2nid(compoid) != NID_zlib_compression)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_COMPRESSEDDATA_INIT_BIO,
|
||||
CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
|
||||
return NULL;
|
||||
}
|
||||
return BIO_new(BIO_f_zlib());
|
||||
}
|
||||
|
||||
#endif
|
148
crypto/cms/cms_dd.c
Normal file
148
crypto/cms/cms_dd.c
Normal file
@ -0,0 +1,148 @@
|
||||
/* crypto/cms/cms_dd.c */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2008 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/cms.h>
|
||||
#include "cms_lcl.h"
|
||||
|
||||
DECLARE_ASN1_ITEM(CMS_DigestedData)
|
||||
|
||||
/* CMS DigestedData Utilities */
|
||||
|
||||
CMS_ContentInfo *cms_DigestedData_create(const EVP_MD *md)
|
||||
{
|
||||
CMS_ContentInfo *cms;
|
||||
CMS_DigestedData *dd;
|
||||
cms = CMS_ContentInfo_new();
|
||||
if (!cms)
|
||||
return NULL;
|
||||
|
||||
dd = M_ASN1_new_of(CMS_DigestedData);
|
||||
|
||||
if (!dd)
|
||||
goto err;
|
||||
|
||||
cms->contentType = OBJ_nid2obj(NID_pkcs7_digest);
|
||||
cms->d.digestedData = dd;
|
||||
|
||||
dd->version = 0;
|
||||
dd->encapContentInfo->eContentType = OBJ_nid2obj(NID_pkcs7_data);
|
||||
|
||||
cms_DigestAlgorithm_set(dd->digestAlgorithm, md);
|
||||
|
||||
return cms;
|
||||
|
||||
err:
|
||||
|
||||
if (cms)
|
||||
CMS_ContentInfo_free(cms);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BIO *cms_DigestedData_init_bio(CMS_ContentInfo *cms)
|
||||
{
|
||||
CMS_DigestedData *dd;
|
||||
dd = cms->d.digestedData;
|
||||
return cms_DigestAlgorithm_init_bio(dd->digestAlgorithm);
|
||||
}
|
||||
|
||||
int cms_DigestedData_do_final(CMS_ContentInfo *cms, BIO *chain, int verify)
|
||||
{
|
||||
EVP_MD_CTX mctx;
|
||||
unsigned char md[EVP_MAX_MD_SIZE];
|
||||
unsigned int mdlen;
|
||||
int r = 0;
|
||||
CMS_DigestedData *dd;
|
||||
EVP_MD_CTX_init(&mctx);
|
||||
|
||||
dd = cms->d.digestedData;
|
||||
|
||||
if (!cms_DigestAlgorithm_find_ctx(&mctx, chain, dd->digestAlgorithm))
|
||||
goto err;
|
||||
|
||||
if (EVP_DigestFinal_ex(&mctx, md, &mdlen) <= 0)
|
||||
goto err;
|
||||
|
||||
if (verify)
|
||||
{
|
||||
if (mdlen != (unsigned int)dd->digest->length)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL,
|
||||
CMS_R_MESSAGEDIGEST_WRONG_LENGTH);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (memcmp(md, dd->digest->data, mdlen))
|
||||
CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL,
|
||||
CMS_R_VERIFICATION_FAILURE);
|
||||
else
|
||||
r = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ASN1_STRING_set(dd->digest, md, mdlen))
|
||||
goto err;
|
||||
r = 1;
|
||||
}
|
||||
|
||||
err:
|
||||
EVP_MD_CTX_cleanup(&mctx);
|
||||
|
||||
return r;
|
||||
|
||||
}
|
262
crypto/cms/cms_enc.c
Normal file
262
crypto/cms/cms_enc.c
Normal file
@ -0,0 +1,262 @@
|
||||
/* crypto/cms/cms_enc.c */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2008 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/cms.h>
|
||||
#include <openssl/rand.h>
|
||||
#include "cms_lcl.h"
|
||||
|
||||
/* CMS EncryptedData Utilities */
|
||||
|
||||
DECLARE_ASN1_ITEM(CMS_EncryptedData)
|
||||
|
||||
/* Return BIO based on EncryptedContentInfo and key */
|
||||
|
||||
BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec)
|
||||
{
|
||||
BIO *b;
|
||||
EVP_CIPHER_CTX *ctx;
|
||||
const EVP_CIPHER *ciph;
|
||||
X509_ALGOR *calg = ec->contentEncryptionAlgorithm;
|
||||
unsigned char iv[EVP_MAX_IV_LENGTH], *piv = NULL;
|
||||
|
||||
int ok = 0;
|
||||
|
||||
int enc, keep_key = 0;
|
||||
|
||||
enc = ec->cipher ? 1 : 0;
|
||||
|
||||
b = BIO_new(BIO_f_cipher());
|
||||
if (!b)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
|
||||
ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BIO_get_cipher_ctx(b, &ctx);
|
||||
|
||||
if (enc)
|
||||
{
|
||||
ciph = ec->cipher;
|
||||
/* If not keeping key set cipher to NULL so subsequent calls
|
||||
* decrypt.
|
||||
*/
|
||||
if (ec->key)
|
||||
ec->cipher = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ciph = EVP_get_cipherbyobj(calg->algorithm);
|
||||
|
||||
if (!ciph)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
|
||||
CMS_R_UNKNOWN_CIPHER);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (EVP_CipherInit_ex(ctx, ciph, NULL, NULL, NULL, enc) <= 0)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
|
||||
CMS_R_CIPHER_INITIALISATION_ERROR);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (enc)
|
||||
{
|
||||
int ivlen;
|
||||
calg->algorithm = OBJ_nid2obj(EVP_CIPHER_CTX_type(ctx));
|
||||
/* Generate a random IV if we need one */
|
||||
ivlen = EVP_CIPHER_CTX_iv_length(ctx);
|
||||
if (ivlen > 0)
|
||||
{
|
||||
if (RAND_pseudo_bytes(iv, ivlen) <= 0)
|
||||
goto err;
|
||||
piv = iv;
|
||||
}
|
||||
}
|
||||
else if (EVP_CIPHER_asn1_to_param(ctx, calg->parameter) <= 0)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
|
||||
CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR);
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
||||
if (enc && !ec->key)
|
||||
{
|
||||
/* Generate random key */
|
||||
if (!ec->keylen)
|
||||
ec->keylen = EVP_CIPHER_CTX_key_length(ctx);
|
||||
ec->key = OPENSSL_malloc(ec->keylen);
|
||||
if (!ec->key)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
|
||||
ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
if (EVP_CIPHER_CTX_rand_key(ctx, ec->key) <= 0)
|
||||
goto err;
|
||||
keep_key = 1;
|
||||
}
|
||||
else if (ec->keylen != (unsigned int)EVP_CIPHER_CTX_key_length(ctx))
|
||||
{
|
||||
/* If necessary set key length */
|
||||
if (EVP_CIPHER_CTX_set_key_length(ctx, ec->keylen) <= 0)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
|
||||
CMS_R_INVALID_KEY_LENGTH);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (EVP_CipherInit_ex(ctx, NULL, NULL, ec->key, piv, enc) <= 0)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
|
||||
CMS_R_CIPHER_INITIALISATION_ERROR);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (piv)
|
||||
{
|
||||
calg->parameter = ASN1_TYPE_new();
|
||||
if (!calg->parameter)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
|
||||
ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
if (EVP_CIPHER_param_to_asn1(ctx, calg->parameter) <= 0)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
|
||||
CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
ok = 1;
|
||||
|
||||
err:
|
||||
if (ec->key && !keep_key)
|
||||
{
|
||||
OPENSSL_cleanse(ec->key, ec->keylen);
|
||||
OPENSSL_free(ec->key);
|
||||
ec->key = NULL;
|
||||
}
|
||||
if (ok)
|
||||
return b;
|
||||
BIO_free(b);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int cms_EncryptedContent_init(CMS_EncryptedContentInfo *ec,
|
||||
const EVP_CIPHER *cipher,
|
||||
const unsigned char *key, size_t keylen)
|
||||
{
|
||||
ec->cipher = cipher;
|
||||
if (key)
|
||||
{
|
||||
ec->key = OPENSSL_malloc(keylen);
|
||||
if (!ec->key)
|
||||
return 0;
|
||||
memcpy(ec->key, key, keylen);
|
||||
}
|
||||
ec->keylen = keylen;
|
||||
if (cipher)
|
||||
ec->contentType = OBJ_nid2obj(NID_pkcs7_data);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CMS_EncryptedData_set1_key(CMS_ContentInfo *cms, const EVP_CIPHER *ciph,
|
||||
const unsigned char *key, size_t keylen)
|
||||
{
|
||||
CMS_EncryptedContentInfo *ec;
|
||||
if (!key || !keylen)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ENCRYPTEDDATA_SET1_KEY, CMS_R_NO_KEY);
|
||||
return 0;
|
||||
}
|
||||
if (ciph)
|
||||
{
|
||||
cms->d.encryptedData = M_ASN1_new_of(CMS_EncryptedData);
|
||||
if (!cms->d.encryptedData)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ENCRYPTEDDATA_SET1_KEY,
|
||||
ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
cms->contentType = OBJ_nid2obj(NID_pkcs7_encrypted);
|
||||
cms->d.encryptedData->version = 0;
|
||||
}
|
||||
else if (OBJ_obj2nid(cms->contentType) != NID_pkcs7_encrypted)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ENCRYPTEDDATA_SET1_KEY,
|
||||
CMS_R_NOT_ENCRYPTED_DATA);
|
||||
return 0;
|
||||
}
|
||||
ec = cms->d.encryptedData->encryptedContentInfo;
|
||||
return cms_EncryptedContent_init(ec, ciph, key, keylen);
|
||||
}
|
||||
|
||||
BIO *cms_EncryptedData_init_bio(CMS_ContentInfo *cms)
|
||||
{
|
||||
CMS_EncryptedData *enc = cms->d.encryptedData;
|
||||
if (enc->encryptedContentInfo->cipher && enc->unprotectedAttrs)
|
||||
enc->version = 2;
|
||||
return cms_EncryptedContent_init_bio(enc->encryptedContentInfo);
|
||||
}
|
825
crypto/cms/cms_env.c
Normal file
825
crypto/cms/cms_env.c
Normal file
@ -0,0 +1,825 @@
|
||||
/* crypto/cms/cms_env.c */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2008 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/cms.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/aes.h>
|
||||
#include "cms_lcl.h"
|
||||
|
||||
/* CMS EnvelopedData Utilities */
|
||||
|
||||
DECLARE_ASN1_ITEM(CMS_EnvelopedData)
|
||||
DECLARE_ASN1_ITEM(CMS_RecipientInfo)
|
||||
DECLARE_ASN1_ITEM(CMS_KeyTransRecipientInfo)
|
||||
DECLARE_ASN1_ITEM(CMS_KEKRecipientInfo)
|
||||
DECLARE_ASN1_ITEM(CMS_OtherKeyAttribute)
|
||||
|
||||
DECLARE_STACK_OF(CMS_RecipientInfo)
|
||||
|
||||
static CMS_EnvelopedData *cms_get0_enveloped(CMS_ContentInfo *cms)
|
||||
{
|
||||
if (OBJ_obj2nid(cms->contentType) != NID_pkcs7_enveloped)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_GET0_ENVELOPED,
|
||||
CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA);
|
||||
return NULL;
|
||||
}
|
||||
return cms->d.envelopedData;
|
||||
}
|
||||
|
||||
static CMS_EnvelopedData *cms_enveloped_data_init(CMS_ContentInfo *cms)
|
||||
{
|
||||
if (cms->d.other == NULL)
|
||||
{
|
||||
cms->d.envelopedData = M_ASN1_new_of(CMS_EnvelopedData);
|
||||
if (!cms->d.envelopedData)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ENVELOPED_DATA_INIT,
|
||||
ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
cms->d.envelopedData->version = 0;
|
||||
cms->d.envelopedData->encryptedContentInfo->contentType =
|
||||
OBJ_nid2obj(NID_pkcs7_data);
|
||||
ASN1_OBJECT_free(cms->contentType);
|
||||
cms->contentType = OBJ_nid2obj(NID_pkcs7_enveloped);
|
||||
return cms->d.envelopedData;
|
||||
}
|
||||
return cms_get0_enveloped(cms);
|
||||
}
|
||||
|
||||
STACK_OF(CMS_RecipientInfo) *CMS_get0_RecipientInfos(CMS_ContentInfo *cms)
|
||||
{
|
||||
CMS_EnvelopedData *env;
|
||||
env = cms_get0_enveloped(cms);
|
||||
if (!env)
|
||||
return NULL;
|
||||
return env->recipientInfos;
|
||||
}
|
||||
|
||||
int CMS_RecipientInfo_type(CMS_RecipientInfo *ri)
|
||||
{
|
||||
return ri->type;
|
||||
}
|
||||
|
||||
CMS_ContentInfo *CMS_EnvelopedData_create(const EVP_CIPHER *cipher)
|
||||
{
|
||||
CMS_ContentInfo *cms;
|
||||
CMS_EnvelopedData *env;
|
||||
cms = CMS_ContentInfo_new();
|
||||
if (!cms)
|
||||
goto merr;
|
||||
env = cms_enveloped_data_init(cms);
|
||||
if (!env)
|
||||
goto merr;
|
||||
if (!cms_EncryptedContent_init(env->encryptedContentInfo,
|
||||
cipher, NULL, 0))
|
||||
goto merr;
|
||||
return cms;
|
||||
merr:
|
||||
if (cms)
|
||||
CMS_ContentInfo_free(cms);
|
||||
CMSerr(CMS_F_CMS_ENVELOPEDDATA_CREATE, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Key Transport Recipient Info (KTRI) routines */
|
||||
|
||||
/* Add a recipient certificate. For now only handle key transport.
|
||||
* If we ever handle key agreement will need updating.
|
||||
*/
|
||||
|
||||
CMS_RecipientInfo *CMS_add1_recipient_cert(CMS_ContentInfo *cms,
|
||||
X509 *recip, unsigned int flags)
|
||||
{
|
||||
CMS_RecipientInfo *ri = NULL;
|
||||
CMS_KeyTransRecipientInfo *ktri;
|
||||
CMS_EnvelopedData *env;
|
||||
EVP_PKEY *pk = NULL;
|
||||
int type;
|
||||
env = cms_get0_enveloped(cms);
|
||||
if (!env)
|
||||
goto err;
|
||||
|
||||
/* Initialize recipient info */
|
||||
ri = M_ASN1_new_of(CMS_RecipientInfo);
|
||||
if (!ri)
|
||||
goto merr;
|
||||
|
||||
/* Initialize and add key transport recipient info */
|
||||
|
||||
ri->d.ktri = M_ASN1_new_of(CMS_KeyTransRecipientInfo);
|
||||
if (!ri->d.ktri)
|
||||
goto merr;
|
||||
ri->type = CMS_RECIPINFO_TRANS;
|
||||
|
||||
ktri = ri->d.ktri;
|
||||
|
||||
X509_check_purpose(recip, -1, -1);
|
||||
pk = X509_get_pubkey(recip);
|
||||
if (!pk)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ADD1_RECIPIENT_CERT,
|
||||
CMS_R_ERROR_GETTING_PUBLIC_KEY);
|
||||
goto err;
|
||||
}
|
||||
CRYPTO_add(&recip->references, 1, CRYPTO_LOCK_X509);
|
||||
ktri->pkey = pk;
|
||||
ktri->recip = recip;
|
||||
|
||||
if (flags & CMS_USE_KEYID)
|
||||
{
|
||||
ktri->version = 2;
|
||||
type = CMS_RECIPINFO_KEYIDENTIFIER;
|
||||
}
|
||||
else
|
||||
{
|
||||
ktri->version = 0;
|
||||
type = CMS_RECIPINFO_ISSUER_SERIAL;
|
||||
}
|
||||
|
||||
/* Not a typo: RecipientIdentifier and SignerIdentifier are the
|
||||
* same structure.
|
||||
*/
|
||||
|
||||
if (!cms_set1_SignerIdentifier(ktri->rid, recip, type))
|
||||
goto err;
|
||||
|
||||
/* Since we have no EVP_PKEY_ASN1_METHOD in OpenSSL 0.9.8,
|
||||
* hard code algorithm parameters.
|
||||
*/
|
||||
|
||||
if (pk->type == EVP_PKEY_RSA)
|
||||
{
|
||||
X509_ALGOR_set0(ktri->keyEncryptionAlgorithm,
|
||||
OBJ_nid2obj(NID_rsaEncryption),
|
||||
V_ASN1_NULL, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ADD1_RECIPIENT_CERT,
|
||||
CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!sk_CMS_RecipientInfo_push(env->recipientInfos, ri))
|
||||
goto merr;
|
||||
|
||||
return ri;
|
||||
|
||||
merr:
|
||||
CMSerr(CMS_F_CMS_ADD1_RECIPIENT_CERT, ERR_R_MALLOC_FAILURE);
|
||||
err:
|
||||
if (ri)
|
||||
M_ASN1_free_of(ri, CMS_RecipientInfo);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
int CMS_RecipientInfo_ktri_get0_algs(CMS_RecipientInfo *ri,
|
||||
EVP_PKEY **pk, X509 **recip,
|
||||
X509_ALGOR **palg)
|
||||
{
|
||||
CMS_KeyTransRecipientInfo *ktri;
|
||||
if (ri->type != CMS_RECIPINFO_TRANS)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_GET0_ALGS,
|
||||
CMS_R_NOT_KEY_TRANSPORT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ktri = ri->d.ktri;
|
||||
|
||||
if (pk)
|
||||
*pk = ktri->pkey;
|
||||
if (recip)
|
||||
*recip = ktri->recip;
|
||||
if (palg)
|
||||
*palg = ktri->keyEncryptionAlgorithm;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CMS_RecipientInfo_ktri_get0_signer_id(CMS_RecipientInfo *ri,
|
||||
ASN1_OCTET_STRING **keyid,
|
||||
X509_NAME **issuer, ASN1_INTEGER **sno)
|
||||
{
|
||||
CMS_KeyTransRecipientInfo *ktri;
|
||||
if (ri->type != CMS_RECIPINFO_TRANS)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_GET0_SIGNER_ID,
|
||||
CMS_R_NOT_KEY_TRANSPORT);
|
||||
return 0;
|
||||
}
|
||||
ktri = ri->d.ktri;
|
||||
|
||||
return cms_SignerIdentifier_get0_signer_id(ktri->rid,
|
||||
keyid, issuer, sno);
|
||||
}
|
||||
|
||||
int CMS_RecipientInfo_ktri_cert_cmp(CMS_RecipientInfo *ri, X509 *cert)
|
||||
{
|
||||
if (ri->type != CMS_RECIPINFO_TRANS)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_CERT_CMP,
|
||||
CMS_R_NOT_KEY_TRANSPORT);
|
||||
return -2;
|
||||
}
|
||||
return cms_SignerIdentifier_cert_cmp(ri->d.ktri->rid, cert);
|
||||
}
|
||||
|
||||
int CMS_RecipientInfo_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pkey)
|
||||
{
|
||||
if (ri->type != CMS_RECIPINFO_TRANS)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_SET0_PKEY,
|
||||
CMS_R_NOT_KEY_TRANSPORT);
|
||||
return 0;
|
||||
}
|
||||
ri->d.ktri->pkey = pkey;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Encrypt content key in key transport recipient info */
|
||||
|
||||
static int cms_RecipientInfo_ktri_encrypt(CMS_ContentInfo *cms,
|
||||
CMS_RecipientInfo *ri)
|
||||
{
|
||||
CMS_KeyTransRecipientInfo *ktri;
|
||||
CMS_EncryptedContentInfo *ec;
|
||||
unsigned char *ek = NULL;
|
||||
int eklen;
|
||||
|
||||
int ret = 0;
|
||||
|
||||
if (ri->type != CMS_RECIPINFO_TRANS)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_ENCRYPT,
|
||||
CMS_R_NOT_KEY_TRANSPORT);
|
||||
return 0;
|
||||
}
|
||||
ktri = ri->d.ktri;
|
||||
ec = cms->d.envelopedData->encryptedContentInfo;
|
||||
|
||||
eklen = EVP_PKEY_size(ktri->pkey);
|
||||
|
||||
ek = OPENSSL_malloc(eklen);
|
||||
|
||||
if (ek == NULL)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_ENCRYPT,
|
||||
ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
eklen = EVP_PKEY_encrypt(ek, ec->key, ec->keylen, ktri->pkey);
|
||||
|
||||
if (eklen <= 0)
|
||||
goto err;
|
||||
|
||||
ASN1_STRING_set0(ktri->encryptedKey, ek, eklen);
|
||||
ek = NULL;
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
if (ek)
|
||||
OPENSSL_free(ek);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
/* Decrypt content key from KTRI */
|
||||
|
||||
static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms,
|
||||
CMS_RecipientInfo *ri)
|
||||
{
|
||||
CMS_KeyTransRecipientInfo *ktri = ri->d.ktri;
|
||||
unsigned char *ek = NULL;
|
||||
int eklen;
|
||||
int ret = 0;
|
||||
|
||||
if (ktri->pkey == NULL)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_DECRYPT,
|
||||
CMS_R_NO_PRIVATE_KEY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
eklen = EVP_PKEY_size(ktri->pkey);
|
||||
|
||||
ek = OPENSSL_malloc(eklen);
|
||||
|
||||
if (ek == NULL)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_DECRYPT,
|
||||
ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
eklen = EVP_PKEY_decrypt(ek,
|
||||
ktri->encryptedKey->data,
|
||||
ktri->encryptedKey->length, ktri->pkey);
|
||||
if (eklen <= 0)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KTRI_DECRYPT, CMS_R_CMS_LIB);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
cms->d.envelopedData->encryptedContentInfo->key = ek;
|
||||
cms->d.envelopedData->encryptedContentInfo->keylen = eklen;
|
||||
|
||||
err:
|
||||
if (!ret && ek)
|
||||
OPENSSL_free(ek);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Key Encrypted Key (KEK) RecipientInfo routines */
|
||||
|
||||
int CMS_RecipientInfo_kekri_id_cmp(CMS_RecipientInfo *ri,
|
||||
const unsigned char *id, size_t idlen)
|
||||
{
|
||||
ASN1_OCTET_STRING tmp_os;
|
||||
CMS_KEKRecipientInfo *kekri;
|
||||
if (ri->type != CMS_RECIPINFO_KEK)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ID_CMP, CMS_R_NOT_KEK);
|
||||
return -2;
|
||||
}
|
||||
kekri = ri->d.kekri;
|
||||
tmp_os.type = V_ASN1_OCTET_STRING;
|
||||
tmp_os.flags = 0;
|
||||
tmp_os.data = (unsigned char *)id;
|
||||
tmp_os.length = (int)idlen;
|
||||
return ASN1_OCTET_STRING_cmp(&tmp_os, kekri->kekid->keyIdentifier);
|
||||
}
|
||||
|
||||
/* For now hard code AES key wrap info */
|
||||
|
||||
static size_t aes_wrap_keylen(int nid)
|
||||
{
|
||||
switch (nid)
|
||||
{
|
||||
case NID_id_aes128_wrap:
|
||||
return 16;
|
||||
|
||||
case NID_id_aes192_wrap:
|
||||
return 24;
|
||||
|
||||
case NID_id_aes256_wrap:
|
||||
return 32;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
CMS_RecipientInfo *CMS_add0_recipient_key(CMS_ContentInfo *cms, int nid,
|
||||
unsigned char *key, size_t keylen,
|
||||
unsigned char *id, size_t idlen,
|
||||
ASN1_GENERALIZEDTIME *date,
|
||||
ASN1_OBJECT *otherTypeId,
|
||||
ASN1_TYPE *otherType)
|
||||
{
|
||||
CMS_RecipientInfo *ri = NULL;
|
||||
CMS_EnvelopedData *env;
|
||||
CMS_KEKRecipientInfo *kekri;
|
||||
env = cms_get0_enveloped(cms);
|
||||
if (!env)
|
||||
goto err;
|
||||
|
||||
if (nid == NID_undef)
|
||||
{
|
||||
switch (keylen)
|
||||
{
|
||||
case 16:
|
||||
nid = NID_id_aes128_wrap;
|
||||
break;
|
||||
|
||||
case 24:
|
||||
nid = NID_id_aes192_wrap;
|
||||
break;
|
||||
|
||||
case 32:
|
||||
nid = NID_id_aes256_wrap;
|
||||
break;
|
||||
|
||||
default:
|
||||
CMSerr(CMS_F_CMS_ADD0_RECIPIENT_KEY,
|
||||
CMS_R_INVALID_KEY_LENGTH);
|
||||
goto err;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
size_t exp_keylen = aes_wrap_keylen(nid);
|
||||
|
||||
if (!exp_keylen)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ADD0_RECIPIENT_KEY,
|
||||
CMS_R_UNSUPPORTED_KEK_ALGORITHM);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (keylen != exp_keylen)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ADD0_RECIPIENT_KEY,
|
||||
CMS_R_INVALID_KEY_LENGTH);
|
||||
goto err;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Initialize recipient info */
|
||||
ri = M_ASN1_new_of(CMS_RecipientInfo);
|
||||
if (!ri)
|
||||
goto merr;
|
||||
|
||||
ri->d.kekri = M_ASN1_new_of(CMS_KEKRecipientInfo);
|
||||
if (!ri->d.kekri)
|
||||
goto merr;
|
||||
ri->type = CMS_RECIPINFO_KEK;
|
||||
|
||||
kekri = ri->d.kekri;
|
||||
|
||||
if (otherTypeId)
|
||||
{
|
||||
kekri->kekid->other = M_ASN1_new_of(CMS_OtherKeyAttribute);
|
||||
if (kekri->kekid->other == NULL)
|
||||
goto merr;
|
||||
}
|
||||
|
||||
if (!sk_CMS_RecipientInfo_push(env->recipientInfos, ri))
|
||||
goto merr;
|
||||
|
||||
|
||||
/* After this point no calls can fail */
|
||||
|
||||
kekri->version = 4;
|
||||
|
||||
kekri->key = key;
|
||||
kekri->keylen = keylen;
|
||||
|
||||
ASN1_STRING_set0(kekri->kekid->keyIdentifier, id, idlen);
|
||||
|
||||
kekri->kekid->date = date;
|
||||
|
||||
if (kekri->kekid->other)
|
||||
{
|
||||
kekri->kekid->other->keyAttrId = otherTypeId;
|
||||
kekri->kekid->other->keyAttr = otherType;
|
||||
}
|
||||
|
||||
X509_ALGOR_set0(kekri->keyEncryptionAlgorithm,
|
||||
OBJ_nid2obj(nid), V_ASN1_UNDEF, NULL);
|
||||
|
||||
return ri;
|
||||
|
||||
merr:
|
||||
CMSerr(CMS_F_CMS_ADD0_RECIPIENT_KEY, ERR_R_MALLOC_FAILURE);
|
||||
err:
|
||||
if (ri)
|
||||
M_ASN1_free_of(ri, CMS_RecipientInfo);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
int CMS_RecipientInfo_kekri_get0_id(CMS_RecipientInfo *ri,
|
||||
X509_ALGOR **palg,
|
||||
ASN1_OCTET_STRING **pid,
|
||||
ASN1_GENERALIZEDTIME **pdate,
|
||||
ASN1_OBJECT **potherid,
|
||||
ASN1_TYPE **pothertype)
|
||||
{
|
||||
CMS_KEKIdentifier *rkid;
|
||||
if (ri->type != CMS_RECIPINFO_KEK)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_GET0_ID, CMS_R_NOT_KEK);
|
||||
return 0;
|
||||
}
|
||||
rkid = ri->d.kekri->kekid;
|
||||
if (palg)
|
||||
*palg = ri->d.kekri->keyEncryptionAlgorithm;
|
||||
if (pid)
|
||||
*pid = rkid->keyIdentifier;
|
||||
if (pdate)
|
||||
*pdate = rkid->date;
|
||||
if (potherid)
|
||||
{
|
||||
if (rkid->other)
|
||||
*potherid = rkid->other->keyAttrId;
|
||||
else
|
||||
*potherid = NULL;
|
||||
}
|
||||
if (pothertype)
|
||||
{
|
||||
if (rkid->other)
|
||||
*pothertype = rkid->other->keyAttr;
|
||||
else
|
||||
*pothertype = NULL;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CMS_RecipientInfo_set0_key(CMS_RecipientInfo *ri,
|
||||
unsigned char *key, size_t keylen)
|
||||
{
|
||||
CMS_KEKRecipientInfo *kekri;
|
||||
if (ri->type != CMS_RECIPINFO_KEK)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_SET0_KEY, CMS_R_NOT_KEK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
kekri = ri->d.kekri;
|
||||
kekri->key = key;
|
||||
kekri->keylen = keylen;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Encrypt content key in KEK recipient info */
|
||||
|
||||
static int cms_RecipientInfo_kekri_encrypt(CMS_ContentInfo *cms,
|
||||
CMS_RecipientInfo *ri)
|
||||
{
|
||||
CMS_EncryptedContentInfo *ec;
|
||||
CMS_KEKRecipientInfo *kekri;
|
||||
AES_KEY actx;
|
||||
unsigned char *wkey = NULL;
|
||||
int wkeylen;
|
||||
int r = 0;
|
||||
|
||||
ec = cms->d.envelopedData->encryptedContentInfo;
|
||||
|
||||
kekri = ri->d.kekri;
|
||||
|
||||
if (!kekri->key)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT, CMS_R_NO_KEY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (AES_set_encrypt_key(kekri->key, kekri->keylen << 3, &actx))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT,
|
||||
CMS_R_ERROR_SETTING_KEY);
|
||||
goto err;
|
||||
}
|
||||
|
||||
wkey = OPENSSL_malloc(ec->keylen + 8);
|
||||
|
||||
if (!wkey)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT,
|
||||
ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
wkeylen = AES_wrap_key(&actx, NULL, wkey, ec->key, ec->keylen);
|
||||
|
||||
if (wkeylen <= 0)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT, CMS_R_WRAP_ERROR);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ASN1_STRING_set0(kekri->encryptedKey, wkey, wkeylen);
|
||||
|
||||
r = 1;
|
||||
|
||||
err:
|
||||
|
||||
if (!r && wkey)
|
||||
OPENSSL_free(wkey);
|
||||
OPENSSL_cleanse(&actx, sizeof(actx));
|
||||
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
/* Decrypt content key in KEK recipient info */
|
||||
|
||||
static int cms_RecipientInfo_kekri_decrypt(CMS_ContentInfo *cms,
|
||||
CMS_RecipientInfo *ri)
|
||||
{
|
||||
CMS_EncryptedContentInfo *ec;
|
||||
CMS_KEKRecipientInfo *kekri;
|
||||
AES_KEY actx;
|
||||
unsigned char *ukey = NULL;
|
||||
int ukeylen;
|
||||
int r = 0, wrap_nid;
|
||||
|
||||
ec = cms->d.envelopedData->encryptedContentInfo;
|
||||
|
||||
kekri = ri->d.kekri;
|
||||
|
||||
if (!kekri->key)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT, CMS_R_NO_KEY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
wrap_nid = OBJ_obj2nid(kekri->keyEncryptionAlgorithm->algorithm);
|
||||
if (aes_wrap_keylen(wrap_nid) != kekri->keylen)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT,
|
||||
CMS_R_INVALID_KEY_LENGTH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* If encrypted key length is invalid don't bother */
|
||||
|
||||
if (kekri->encryptedKey->length < 16)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT,
|
||||
CMS_R_INVALID_ENCRYPTED_KEY_LENGTH);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (AES_set_decrypt_key(kekri->key, kekri->keylen << 3, &actx))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT,
|
||||
CMS_R_ERROR_SETTING_KEY);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ukey = OPENSSL_malloc(kekri->encryptedKey->length - 8);
|
||||
|
||||
if (!ukey)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT,
|
||||
ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ukeylen = AES_unwrap_key(&actx, NULL, ukey,
|
||||
kekri->encryptedKey->data,
|
||||
kekri->encryptedKey->length);
|
||||
|
||||
if (ukeylen <= 0)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT,
|
||||
CMS_R_UNWRAP_ERROR);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ec->key = ukey;
|
||||
ec->keylen = ukeylen;
|
||||
|
||||
r = 1;
|
||||
|
||||
err:
|
||||
|
||||
if (!r && ukey)
|
||||
OPENSSL_free(ukey);
|
||||
OPENSSL_cleanse(&actx, sizeof(actx));
|
||||
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
int CMS_RecipientInfo_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri)
|
||||
{
|
||||
switch(ri->type)
|
||||
{
|
||||
case CMS_RECIPINFO_TRANS:
|
||||
return cms_RecipientInfo_ktri_decrypt(cms, ri);
|
||||
|
||||
case CMS_RECIPINFO_KEK:
|
||||
return cms_RecipientInfo_kekri_decrypt(cms, ri);
|
||||
|
||||
default:
|
||||
CMSerr(CMS_F_CMS_RECIPIENTINFO_DECRYPT,
|
||||
CMS_R_UNSUPPORTED_RECPIENTINFO_TYPE);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
BIO *cms_EnvelopedData_init_bio(CMS_ContentInfo *cms)
|
||||
{
|
||||
CMS_EncryptedContentInfo *ec;
|
||||
STACK_OF(CMS_RecipientInfo) *rinfos;
|
||||
CMS_RecipientInfo *ri;
|
||||
int i, r, ok = 0;
|
||||
BIO *ret;
|
||||
|
||||
/* Get BIO first to set up key */
|
||||
|
||||
ec = cms->d.envelopedData->encryptedContentInfo;
|
||||
ret = cms_EncryptedContent_init_bio(ec);
|
||||
|
||||
/* If error or no cipher end of processing */
|
||||
|
||||
if (!ret || !ec->cipher)
|
||||
return ret;
|
||||
|
||||
/* Now encrypt content key according to each RecipientInfo type */
|
||||
|
||||
rinfos = cms->d.envelopedData->recipientInfos;
|
||||
|
||||
for (i = 0; i < sk_CMS_RecipientInfo_num(rinfos); i++)
|
||||
{
|
||||
ri = sk_CMS_RecipientInfo_value(rinfos, i);
|
||||
|
||||
switch (ri->type)
|
||||
{
|
||||
case CMS_RECIPINFO_TRANS:
|
||||
r = cms_RecipientInfo_ktri_encrypt(cms, ri);
|
||||
break;
|
||||
|
||||
case CMS_RECIPINFO_KEK:
|
||||
r = cms_RecipientInfo_kekri_encrypt(cms, ri);
|
||||
break;
|
||||
|
||||
default:
|
||||
CMSerr(CMS_F_CMS_ENVELOPEDDATA_INIT_BIO,
|
||||
CMS_R_UNSUPPORTED_RECIPIENT_TYPE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (r <= 0)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ENVELOPEDDATA_INIT_BIO,
|
||||
CMS_R_ERROR_SETTING_RECIPIENTINFO);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
ok = 1;
|
||||
|
||||
err:
|
||||
ec->cipher = NULL;
|
||||
if (ec->key)
|
||||
{
|
||||
OPENSSL_cleanse(ec->key, ec->keylen);
|
||||
OPENSSL_free(ec->key);
|
||||
ec->key = NULL;
|
||||
ec->keylen = 0;
|
||||
}
|
||||
if (ok)
|
||||
return ret;
|
||||
BIO_free(ret);
|
||||
return NULL;
|
||||
|
||||
}
|
236
crypto/cms/cms_err.c
Normal file
236
crypto/cms/cms_err.c
Normal file
@ -0,0 +1,236 @@
|
||||
/* crypto/cms/cms_err.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-2008 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
/* NOTE: this file was auto generated by the mkerr.pl script: any changes
|
||||
* made to it will be overwritten when the script next updates this file,
|
||||
* only reason strings will be preserved.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/cms.h>
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
|
||||
#define ERR_FUNC(func) ERR_PACK(ERR_LIB_CMS,func,0)
|
||||
#define ERR_REASON(reason) ERR_PACK(ERR_LIB_CMS,0,reason)
|
||||
|
||||
static ERR_STRING_DATA CMS_str_functs[]=
|
||||
{
|
||||
{ERR_FUNC(CMS_F_CHECK_CONTENT), "CHECK_CONTENT"},
|
||||
{ERR_FUNC(CMS_F_CMS_ADD0_CERT), "CMS_add0_cert"},
|
||||
{ERR_FUNC(CMS_F_CMS_ADD0_RECIPIENT_KEY), "CMS_add0_recipient_key"},
|
||||
{ERR_FUNC(CMS_F_CMS_ADD1_RECEIPTREQUEST), "CMS_add1_ReceiptRequest"},
|
||||
{ERR_FUNC(CMS_F_CMS_ADD1_RECIPIENT_CERT), "CMS_add1_recipient_cert"},
|
||||
{ERR_FUNC(CMS_F_CMS_ADD1_SIGNER), "CMS_add1_signer"},
|
||||
{ERR_FUNC(CMS_F_CMS_ADD1_SIGNINGTIME), "CMS_ADD1_SIGNINGTIME"},
|
||||
{ERR_FUNC(CMS_F_CMS_COMPRESS), "CMS_compress"},
|
||||
{ERR_FUNC(CMS_F_CMS_COMPRESSEDDATA_CREATE), "cms_CompressedData_create"},
|
||||
{ERR_FUNC(CMS_F_CMS_COMPRESSEDDATA_INIT_BIO), "cms_CompressedData_init_bio"},
|
||||
{ERR_FUNC(CMS_F_CMS_COPY_CONTENT), "CMS_COPY_CONTENT"},
|
||||
{ERR_FUNC(CMS_F_CMS_COPY_MESSAGEDIGEST), "CMS_COPY_MESSAGEDIGEST"},
|
||||
{ERR_FUNC(CMS_F_CMS_DATA), "CMS_data"},
|
||||
{ERR_FUNC(CMS_F_CMS_DATAFINAL), "CMS_dataFinal"},
|
||||
{ERR_FUNC(CMS_F_CMS_DATAINIT), "CMS_dataInit"},
|
||||
{ERR_FUNC(CMS_F_CMS_DECRYPT), "CMS_decrypt"},
|
||||
{ERR_FUNC(CMS_F_CMS_DECRYPT_SET1_KEY), "CMS_decrypt_set1_key"},
|
||||
{ERR_FUNC(CMS_F_CMS_DECRYPT_SET1_PKEY), "CMS_decrypt_set1_pkey"},
|
||||
{ERR_FUNC(CMS_F_CMS_DIGESTALGORITHM_FIND_CTX), "cms_DigestAlgorithm_find_ctx"},
|
||||
{ERR_FUNC(CMS_F_CMS_DIGESTALGORITHM_INIT_BIO), "cms_DigestAlgorithm_init_bio"},
|
||||
{ERR_FUNC(CMS_F_CMS_DIGESTEDDATA_DO_FINAL), "cms_DigestedData_do_final"},
|
||||
{ERR_FUNC(CMS_F_CMS_DIGEST_VERIFY), "CMS_digest_verify"},
|
||||
{ERR_FUNC(CMS_F_CMS_ENCODE_RECEIPT), "cms_encode_Receipt"},
|
||||
{ERR_FUNC(CMS_F_CMS_ENCRYPT), "CMS_encrypt"},
|
||||
{ERR_FUNC(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO), "cms_EncryptedContent_init_bio"},
|
||||
{ERR_FUNC(CMS_F_CMS_ENCRYPTEDDATA_DECRYPT), "CMS_EncryptedData_decrypt"},
|
||||
{ERR_FUNC(CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT), "CMS_EncryptedData_encrypt"},
|
||||
{ERR_FUNC(CMS_F_CMS_ENCRYPTEDDATA_SET1_KEY), "CMS_EncryptedData_set1_key"},
|
||||
{ERR_FUNC(CMS_F_CMS_ENVELOPEDDATA_CREATE), "CMS_EnvelopedData_create"},
|
||||
{ERR_FUNC(CMS_F_CMS_ENVELOPEDDATA_INIT_BIO), "cms_EnvelopedData_init_bio"},
|
||||
{ERR_FUNC(CMS_F_CMS_ENVELOPED_DATA_INIT), "CMS_ENVELOPED_DATA_INIT"},
|
||||
{ERR_FUNC(CMS_F_CMS_FINAL), "CMS_final"},
|
||||
{ERR_FUNC(CMS_F_CMS_GET0_CERTIFICATE_CHOICES), "CMS_GET0_CERTIFICATE_CHOICES"},
|
||||
{ERR_FUNC(CMS_F_CMS_GET0_CONTENT), "CMS_get0_content"},
|
||||
{ERR_FUNC(CMS_F_CMS_GET0_ECONTENT_TYPE), "CMS_GET0_ECONTENT_TYPE"},
|
||||
{ERR_FUNC(CMS_F_CMS_GET0_ENVELOPED), "CMS_GET0_ENVELOPED"},
|
||||
{ERR_FUNC(CMS_F_CMS_GET0_REVOCATION_CHOICES), "CMS_GET0_REVOCATION_CHOICES"},
|
||||
{ERR_FUNC(CMS_F_CMS_GET0_SIGNED), "CMS_GET0_SIGNED"},
|
||||
{ERR_FUNC(CMS_F_CMS_MSGSIGDIGEST_ADD1), "cms_msgSigDigest_add1"},
|
||||
{ERR_FUNC(CMS_F_CMS_RECEIPTREQUEST_CREATE0), "CMS_ReceiptRequest_create0"},
|
||||
{ERR_FUNC(CMS_F_CMS_RECEIPT_VERIFY), "cms_Receipt_verify"},
|
||||
{ERR_FUNC(CMS_F_CMS_RECIPIENTINFO_DECRYPT), "CMS_RecipientInfo_decrypt"},
|
||||
{ERR_FUNC(CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT), "CMS_RECIPIENTINFO_KEKRI_DECRYPT"},
|
||||
{ERR_FUNC(CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT), "CMS_RECIPIENTINFO_KEKRI_ENCRYPT"},
|
||||
{ERR_FUNC(CMS_F_CMS_RECIPIENTINFO_KEKRI_GET0_ID), "CMS_RecipientInfo_kekri_get0_id"},
|
||||
{ERR_FUNC(CMS_F_CMS_RECIPIENTINFO_KEKRI_ID_CMP), "CMS_RecipientInfo_kekri_id_cmp"},
|
||||
{ERR_FUNC(CMS_F_CMS_RECIPIENTINFO_KTRI_CERT_CMP), "CMS_RecipientInfo_ktri_cert_cmp"},
|
||||
{ERR_FUNC(CMS_F_CMS_RECIPIENTINFO_KTRI_DECRYPT), "CMS_RECIPIENTINFO_KTRI_DECRYPT"},
|
||||
{ERR_FUNC(CMS_F_CMS_RECIPIENTINFO_KTRI_ENCRYPT), "CMS_RECIPIENTINFO_KTRI_ENCRYPT"},
|
||||
{ERR_FUNC(CMS_F_CMS_RECIPIENTINFO_KTRI_GET0_ALGS), "CMS_RecipientInfo_ktri_get0_algs"},
|
||||
{ERR_FUNC(CMS_F_CMS_RECIPIENTINFO_KTRI_GET0_SIGNER_ID), "CMS_RecipientInfo_ktri_get0_signer_id"},
|
||||
{ERR_FUNC(CMS_F_CMS_RECIPIENTINFO_SET0_KEY), "CMS_RecipientInfo_set0_key"},
|
||||
{ERR_FUNC(CMS_F_CMS_RECIPIENTINFO_SET0_PKEY), "CMS_RecipientInfo_set0_pkey"},
|
||||
{ERR_FUNC(CMS_F_CMS_SET1_SIGNERIDENTIFIER), "cms_set1_SignerIdentifier"},
|
||||
{ERR_FUNC(CMS_F_CMS_SET_DETACHED), "CMS_set_detached"},
|
||||
{ERR_FUNC(CMS_F_CMS_SIGN), "CMS_sign"},
|
||||
{ERR_FUNC(CMS_F_CMS_SIGNED_DATA_INIT), "CMS_SIGNED_DATA_INIT"},
|
||||
{ERR_FUNC(CMS_F_CMS_SIGNERINFO_CONTENT_SIGN), "CMS_SIGNERINFO_CONTENT_SIGN"},
|
||||
{ERR_FUNC(CMS_F_CMS_SIGNERINFO_SIGN), "CMS_SignerInfo_sign"},
|
||||
{ERR_FUNC(CMS_F_CMS_SIGNERINFO_VERIFY), "CMS_SignerInfo_verify"},
|
||||
{ERR_FUNC(CMS_F_CMS_SIGNERINFO_VERIFY_CERT), "CMS_SIGNERINFO_VERIFY_CERT"},
|
||||
{ERR_FUNC(CMS_F_CMS_SIGNERINFO_VERIFY_CONTENT), "CMS_SignerInfo_verify_content"},
|
||||
{ERR_FUNC(CMS_F_CMS_SIGN_RECEIPT), "CMS_sign_receipt"},
|
||||
{ERR_FUNC(CMS_F_CMS_STREAM), "CMS_STREAM"},
|
||||
{ERR_FUNC(CMS_F_CMS_UNCOMPRESS), "CMS_uncompress"},
|
||||
{ERR_FUNC(CMS_F_CMS_VERIFY), "CMS_verify"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
static ERR_STRING_DATA CMS_str_reasons[]=
|
||||
{
|
||||
{ERR_REASON(CMS_R_ADD_SIGNER_ERROR) ,"add signer error"},
|
||||
{ERR_REASON(CMS_R_CERTIFICATE_ALREADY_PRESENT),"certificate already present"},
|
||||
{ERR_REASON(CMS_R_CERTIFICATE_HAS_NO_KEYID),"certificate has no keyid"},
|
||||
{ERR_REASON(CMS_R_CERTIFICATE_VERIFY_ERROR),"certificate verify error"},
|
||||
{ERR_REASON(CMS_R_CIPHER_INITIALISATION_ERROR),"cipher initialisation error"},
|
||||
{ERR_REASON(CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR),"cipher parameter initialisation error"},
|
||||
{ERR_REASON(CMS_R_CMS_DATAFINAL_ERROR) ,"cms datafinal error"},
|
||||
{ERR_REASON(CMS_R_CMS_LIB) ,"cms lib"},
|
||||
{ERR_REASON(CMS_R_CONTENTIDENTIFIER_MISMATCH),"contentidentifier mismatch"},
|
||||
{ERR_REASON(CMS_R_CONTENT_NOT_FOUND) ,"content not found"},
|
||||
{ERR_REASON(CMS_R_CONTENT_TYPE_MISMATCH) ,"content type mismatch"},
|
||||
{ERR_REASON(CMS_R_CONTENT_TYPE_NOT_COMPRESSED_DATA),"content type not compressed data"},
|
||||
{ERR_REASON(CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA),"content type not enveloped data"},
|
||||
{ERR_REASON(CMS_R_CONTENT_TYPE_NOT_SIGNED_DATA),"content type not signed data"},
|
||||
{ERR_REASON(CMS_R_CONTENT_VERIFY_ERROR) ,"content verify error"},
|
||||
{ERR_REASON(CMS_R_CTRL_ERROR) ,"ctrl error"},
|
||||
{ERR_REASON(CMS_R_CTRL_FAILURE) ,"ctrl failure"},
|
||||
{ERR_REASON(CMS_R_DECRYPT_ERROR) ,"decrypt error"},
|
||||
{ERR_REASON(CMS_R_DIGEST_ERROR) ,"digest error"},
|
||||
{ERR_REASON(CMS_R_ERROR_GETTING_PUBLIC_KEY),"error getting public key"},
|
||||
{ERR_REASON(CMS_R_ERROR_READING_MESSAGEDIGEST_ATTRIBUTE),"error reading messagedigest attribute"},
|
||||
{ERR_REASON(CMS_R_ERROR_SETTING_KEY) ,"error setting key"},
|
||||
{ERR_REASON(CMS_R_ERROR_SETTING_RECIPIENTINFO),"error setting recipientinfo"},
|
||||
{ERR_REASON(CMS_R_INVALID_ENCRYPTED_KEY_LENGTH),"invalid encrypted key length"},
|
||||
{ERR_REASON(CMS_R_INVALID_KEY_LENGTH) ,"invalid key length"},
|
||||
{ERR_REASON(CMS_R_MD_BIO_INIT_ERROR) ,"md bio init error"},
|
||||
{ERR_REASON(CMS_R_MESSAGEDIGEST_ATTRIBUTE_WRONG_LENGTH),"messagedigest attribute wrong length"},
|
||||
{ERR_REASON(CMS_R_MESSAGEDIGEST_WRONG_LENGTH),"messagedigest wrong length"},
|
||||
{ERR_REASON(CMS_R_MSGSIGDIGEST_ERROR) ,"msgsigdigest error"},
|
||||
{ERR_REASON(CMS_R_MSGSIGDIGEST_VERIFICATION_FAILURE),"msgsigdigest verification failure"},
|
||||
{ERR_REASON(CMS_R_MSGSIGDIGEST_WRONG_LENGTH),"msgsigdigest wrong length"},
|
||||
{ERR_REASON(CMS_R_NEED_ONE_SIGNER) ,"need one signer"},
|
||||
{ERR_REASON(CMS_R_NOT_A_SIGNED_RECEIPT) ,"not a signed receipt"},
|
||||
{ERR_REASON(CMS_R_NOT_ENCRYPTED_DATA) ,"not encrypted data"},
|
||||
{ERR_REASON(CMS_R_NOT_KEK) ,"not kek"},
|
||||
{ERR_REASON(CMS_R_NOT_KEY_TRANSPORT) ,"not key transport"},
|
||||
{ERR_REASON(CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE),"not supported for this key type"},
|
||||
{ERR_REASON(CMS_R_NO_CIPHER) ,"no cipher"},
|
||||
{ERR_REASON(CMS_R_NO_CONTENT) ,"no content"},
|
||||
{ERR_REASON(CMS_R_NO_CONTENT_TYPE) ,"no content type"},
|
||||
{ERR_REASON(CMS_R_NO_DEFAULT_DIGEST) ,"no default digest"},
|
||||
{ERR_REASON(CMS_R_NO_DIGEST_SET) ,"no digest set"},
|
||||
{ERR_REASON(CMS_R_NO_KEY) ,"no key"},
|
||||
{ERR_REASON(CMS_R_NO_KEY_OR_CERT) ,"no key or cert"},
|
||||
{ERR_REASON(CMS_R_NO_MATCHING_DIGEST) ,"no matching digest"},
|
||||
{ERR_REASON(CMS_R_NO_MATCHING_RECIPIENT) ,"no matching recipient"},
|
||||
{ERR_REASON(CMS_R_NO_MATCHING_SIGNATURE) ,"no matching signature"},
|
||||
{ERR_REASON(CMS_R_NO_MSGSIGDIGEST) ,"no msgsigdigest"},
|
||||
{ERR_REASON(CMS_R_NO_PRIVATE_KEY) ,"no private key"},
|
||||
{ERR_REASON(CMS_R_NO_PUBLIC_KEY) ,"no public key"},
|
||||
{ERR_REASON(CMS_R_NO_RECEIPT_REQUEST) ,"no receipt request"},
|
||||
{ERR_REASON(CMS_R_NO_SIGNERS) ,"no signers"},
|
||||
{ERR_REASON(CMS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE),"private key does not match certificate"},
|
||||
{ERR_REASON(CMS_R_RECEIPT_DECODE_ERROR) ,"receipt decode error"},
|
||||
{ERR_REASON(CMS_R_RECIPIENT_ERROR) ,"recipient error"},
|
||||
{ERR_REASON(CMS_R_SIGNER_CERTIFICATE_NOT_FOUND),"signer certificate not found"},
|
||||
{ERR_REASON(CMS_R_SIGNFINAL_ERROR) ,"signfinal error"},
|
||||
{ERR_REASON(CMS_R_SMIME_TEXT_ERROR) ,"smime text error"},
|
||||
{ERR_REASON(CMS_R_STORE_INIT_ERROR) ,"store init error"},
|
||||
{ERR_REASON(CMS_R_TYPE_NOT_COMPRESSED_DATA),"type not compressed data"},
|
||||
{ERR_REASON(CMS_R_TYPE_NOT_DATA) ,"type not data"},
|
||||
{ERR_REASON(CMS_R_TYPE_NOT_DIGESTED_DATA),"type not digested data"},
|
||||
{ERR_REASON(CMS_R_TYPE_NOT_ENCRYPTED_DATA),"type not encrypted data"},
|
||||
{ERR_REASON(CMS_R_TYPE_NOT_ENVELOPED_DATA),"type not enveloped data"},
|
||||
{ERR_REASON(CMS_R_UNABLE_TO_FINALIZE_CONTEXT),"unable to finalize context"},
|
||||
{ERR_REASON(CMS_R_UNKNOWN_CIPHER) ,"unknown cipher"},
|
||||
{ERR_REASON(CMS_R_UNKNOWN_DIGEST_ALGORIHM),"unknown digest algorihm"},
|
||||
{ERR_REASON(CMS_R_UNKNOWN_ID) ,"unknown id"},
|
||||
{ERR_REASON(CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM),"unsupported compression algorithm"},
|
||||
{ERR_REASON(CMS_R_UNSUPPORTED_CONTENT_TYPE),"unsupported content type"},
|
||||
{ERR_REASON(CMS_R_UNSUPPORTED_KEK_ALGORITHM),"unsupported kek algorithm"},
|
||||
{ERR_REASON(CMS_R_UNSUPPORTED_RECIPIENT_TYPE),"unsupported recipient type"},
|
||||
{ERR_REASON(CMS_R_UNSUPPORTED_RECPIENTINFO_TYPE),"unsupported recpientinfo type"},
|
||||
{ERR_REASON(CMS_R_UNSUPPORTED_TYPE) ,"unsupported type"},
|
||||
{ERR_REASON(CMS_R_UNWRAP_ERROR) ,"unwrap error"},
|
||||
{ERR_REASON(CMS_R_VERIFICATION_FAILURE) ,"verification failure"},
|
||||
{ERR_REASON(CMS_R_WRAP_ERROR) ,"wrap error"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
void ERR_load_CMS_strings(void)
|
||||
{
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
|
||||
if (ERR_func_error_string(CMS_str_functs[0].error) == NULL)
|
||||
{
|
||||
ERR_load_strings(0,CMS_str_functs);
|
||||
ERR_load_strings(0,CMS_str_reasons);
|
||||
}
|
||||
#endif
|
||||
}
|
420
crypto/cms/cms_ess.c
Normal file
420
crypto/cms/cms_ess.c
Normal file
@ -0,0 +1,420 @@
|
||||
/* crypto/cms/cms_ess.c */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2008 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/cms.h>
|
||||
#include "cms_lcl.h"
|
||||
|
||||
DECLARE_ASN1_ITEM(CMS_ReceiptRequest)
|
||||
DECLARE_ASN1_ITEM(CMS_Receipt)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const(CMS_ReceiptRequest)
|
||||
|
||||
/* ESS services: for now just Signed Receipt related */
|
||||
|
||||
int CMS_get1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest **prr)
|
||||
{
|
||||
ASN1_STRING *str;
|
||||
CMS_ReceiptRequest *rr = NULL;
|
||||
if (prr)
|
||||
*prr = NULL;
|
||||
str = CMS_signed_get0_data_by_OBJ(si,
|
||||
OBJ_nid2obj(NID_id_smime_aa_receiptRequest),
|
||||
-3, V_ASN1_SEQUENCE);
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
rr = ASN1_item_unpack(str, ASN1_ITEM_rptr(CMS_ReceiptRequest));
|
||||
if (!rr)
|
||||
return -1;
|
||||
if (prr)
|
||||
*prr = rr;
|
||||
else
|
||||
CMS_ReceiptRequest_free(rr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
CMS_ReceiptRequest *CMS_ReceiptRequest_create0(unsigned char *id, int idlen,
|
||||
int allorfirst,
|
||||
STACK_OF(GENERAL_NAMES) *receiptList,
|
||||
STACK_OF(GENERAL_NAMES) *receiptsTo)
|
||||
{
|
||||
CMS_ReceiptRequest *rr = NULL;
|
||||
|
||||
rr = CMS_ReceiptRequest_new();
|
||||
if (!rr)
|
||||
goto merr;
|
||||
if (id)
|
||||
ASN1_STRING_set0(rr->signedContentIdentifier, id, idlen);
|
||||
else
|
||||
{
|
||||
if (!ASN1_STRING_set(rr->signedContentIdentifier, NULL, 32))
|
||||
goto merr;
|
||||
if (RAND_pseudo_bytes(rr->signedContentIdentifier->data, 32)
|
||||
<= 0)
|
||||
goto err;
|
||||
}
|
||||
|
||||
sk_GENERAL_NAMES_pop_free(rr->receiptsTo, GENERAL_NAMES_free);
|
||||
rr->receiptsTo = receiptsTo;
|
||||
|
||||
if (receiptList)
|
||||
{
|
||||
rr->receiptsFrom->type = 1;
|
||||
rr->receiptsFrom->d.receiptList = receiptList;
|
||||
}
|
||||
else
|
||||
{
|
||||
rr->receiptsFrom->type = 0;
|
||||
rr->receiptsFrom->d.allOrFirstTier = allorfirst;
|
||||
}
|
||||
|
||||
return rr;
|
||||
|
||||
merr:
|
||||
CMSerr(CMS_F_CMS_RECEIPTREQUEST_CREATE0, ERR_R_MALLOC_FAILURE);
|
||||
|
||||
err:
|
||||
if (rr)
|
||||
CMS_ReceiptRequest_free(rr);
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
int CMS_add1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest *rr)
|
||||
{
|
||||
unsigned char *rrder = NULL;
|
||||
int rrderlen, r = 0;
|
||||
|
||||
rrderlen = i2d_CMS_ReceiptRequest(rr, &rrder);
|
||||
if (rrderlen < 0)
|
||||
goto merr;
|
||||
|
||||
if (!CMS_signed_add1_attr_by_NID(si, NID_id_smime_aa_receiptRequest,
|
||||
V_ASN1_SEQUENCE, rrder, rrderlen))
|
||||
goto merr;
|
||||
|
||||
r = 1;
|
||||
|
||||
merr:
|
||||
if (!r)
|
||||
CMSerr(CMS_F_CMS_ADD1_RECEIPTREQUEST, ERR_R_MALLOC_FAILURE);
|
||||
|
||||
if (rrder)
|
||||
OPENSSL_free(rrder);
|
||||
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
void CMS_ReceiptRequest_get0_values(CMS_ReceiptRequest *rr,
|
||||
ASN1_STRING **pcid,
|
||||
int *pallorfirst,
|
||||
STACK_OF(GENERAL_NAMES) **plist,
|
||||
STACK_OF(GENERAL_NAMES) **prto)
|
||||
{
|
||||
if (pcid)
|
||||
*pcid = rr->signedContentIdentifier;
|
||||
if (rr->receiptsFrom->type == 0)
|
||||
{
|
||||
if (pallorfirst)
|
||||
*pallorfirst = (int)rr->receiptsFrom->d.allOrFirstTier;
|
||||
if (plist)
|
||||
*plist = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pallorfirst)
|
||||
*pallorfirst = -1;
|
||||
if (plist)
|
||||
*plist = rr->receiptsFrom->d.receiptList;
|
||||
}
|
||||
if (prto)
|
||||
*prto = rr->receiptsTo;
|
||||
}
|
||||
|
||||
/* Digest a SignerInfo structure for msgSigDigest attribute processing */
|
||||
|
||||
static int cms_msgSigDigest(CMS_SignerInfo *si,
|
||||
unsigned char *dig, unsigned int *diglen)
|
||||
{
|
||||
const EVP_MD *md;
|
||||
md = EVP_get_digestbyobj(si->digestAlgorithm->algorithm);
|
||||
if (md == NULL)
|
||||
return 0;
|
||||
if (!ASN1_item_digest(ASN1_ITEM_rptr(CMS_Attributes_Verify), md,
|
||||
si->signedAttrs, dig, diglen))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Add a msgSigDigest attribute to a SignerInfo */
|
||||
|
||||
int cms_msgSigDigest_add1(CMS_SignerInfo *dest, CMS_SignerInfo *src)
|
||||
{
|
||||
unsigned char dig[EVP_MAX_MD_SIZE];
|
||||
unsigned int diglen;
|
||||
if (!cms_msgSigDigest(src, dig, &diglen))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_MSGSIGDIGEST_ADD1, CMS_R_MSGSIGDIGEST_ERROR);
|
||||
return 0;
|
||||
}
|
||||
if (!CMS_signed_add1_attr_by_NID(dest, NID_id_smime_aa_msgSigDigest,
|
||||
V_ASN1_OCTET_STRING, dig, diglen))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_MSGSIGDIGEST_ADD1, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Verify signed receipt after it has already passed normal CMS verify */
|
||||
|
||||
int cms_Receipt_verify(CMS_ContentInfo *cms, CMS_ContentInfo *req_cms)
|
||||
{
|
||||
int r = 0, i;
|
||||
CMS_ReceiptRequest *rr = NULL;
|
||||
CMS_Receipt *rct = NULL;
|
||||
STACK_OF(CMS_SignerInfo) *sis, *osis;
|
||||
CMS_SignerInfo *si, *osi = NULL;
|
||||
ASN1_OCTET_STRING *msig, **pcont;
|
||||
ASN1_OBJECT *octype;
|
||||
unsigned char dig[EVP_MAX_MD_SIZE];
|
||||
unsigned int diglen;
|
||||
|
||||
/* Get SignerInfos, also checks SignedData content type */
|
||||
osis = CMS_get0_SignerInfos(req_cms);
|
||||
sis = CMS_get0_SignerInfos(cms);
|
||||
if (!osis || !sis)
|
||||
goto err;
|
||||
|
||||
if (sk_CMS_SignerInfo_num(sis) != 1)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECEIPT_VERIFY, CMS_R_NEED_ONE_SIGNER);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Check receipt content type */
|
||||
if (OBJ_obj2nid(CMS_get0_eContentType(cms)) != NID_id_smime_ct_receipt)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECEIPT_VERIFY, CMS_R_NOT_A_SIGNED_RECEIPT);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Extract and decode receipt content */
|
||||
pcont = CMS_get0_content(cms);
|
||||
if (!pcont || !*pcont)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECEIPT_VERIFY, CMS_R_NO_CONTENT);
|
||||
goto err;
|
||||
}
|
||||
|
||||
rct = ASN1_item_unpack(*pcont, ASN1_ITEM_rptr(CMS_Receipt));
|
||||
|
||||
if (!rct)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECEIPT_VERIFY, CMS_R_RECEIPT_DECODE_ERROR);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Locate original request */
|
||||
|
||||
for (i = 0; i < sk_CMS_SignerInfo_num(osis); i++)
|
||||
{
|
||||
osi = sk_CMS_SignerInfo_value(osis, i);
|
||||
if (!ASN1_STRING_cmp(osi->signature,
|
||||
rct->originatorSignatureValue))
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == sk_CMS_SignerInfo_num(osis))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECEIPT_VERIFY, CMS_R_NO_MATCHING_SIGNATURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
si = sk_CMS_SignerInfo_value(sis, 0);
|
||||
|
||||
/* Get msgSigDigest value and compare */
|
||||
|
||||
msig = CMS_signed_get0_data_by_OBJ(si,
|
||||
OBJ_nid2obj(NID_id_smime_aa_msgSigDigest),
|
||||
-3, V_ASN1_OCTET_STRING);
|
||||
|
||||
if (!msig)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECEIPT_VERIFY, CMS_R_NO_MSGSIGDIGEST);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!cms_msgSigDigest(osi, dig, &diglen))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECEIPT_VERIFY, CMS_R_MSGSIGDIGEST_ERROR);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (diglen != (unsigned int)msig->length)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECEIPT_VERIFY,
|
||||
CMS_R_MSGSIGDIGEST_WRONG_LENGTH);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (memcmp(dig, msig->data, diglen))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECEIPT_VERIFY,
|
||||
CMS_R_MSGSIGDIGEST_VERIFICATION_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Compare content types */
|
||||
|
||||
octype = CMS_signed_get0_data_by_OBJ(osi,
|
||||
OBJ_nid2obj(NID_pkcs9_contentType),
|
||||
-3, V_ASN1_OBJECT);
|
||||
if (!octype)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECEIPT_VERIFY, CMS_R_NO_CONTENT_TYPE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Compare details in receipt request */
|
||||
|
||||
if (OBJ_cmp(octype, rct->contentType))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECEIPT_VERIFY, CMS_R_CONTENT_TYPE_MISMATCH);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Get original receipt request details */
|
||||
|
||||
if (!CMS_get1_ReceiptRequest(osi, &rr))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECEIPT_VERIFY, CMS_R_NO_RECEIPT_REQUEST);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (ASN1_STRING_cmp(rr->signedContentIdentifier,
|
||||
rct->signedContentIdentifier))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_RECEIPT_VERIFY,
|
||||
CMS_R_CONTENTIDENTIFIER_MISMATCH);
|
||||
goto err;
|
||||
}
|
||||
|
||||
r = 1;
|
||||
|
||||
err:
|
||||
if (rr)
|
||||
CMS_ReceiptRequest_free(rr);
|
||||
if (rct)
|
||||
M_ASN1_free_of(rct, CMS_Receipt);
|
||||
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
/* Encode a Receipt into an OCTET STRING read for including into content of
|
||||
* a SignedData ContentInfo.
|
||||
*/
|
||||
|
||||
ASN1_OCTET_STRING *cms_encode_Receipt(CMS_SignerInfo *si)
|
||||
{
|
||||
CMS_Receipt rct;
|
||||
CMS_ReceiptRequest *rr = NULL;
|
||||
ASN1_OBJECT *ctype;
|
||||
ASN1_OCTET_STRING *os = NULL;
|
||||
|
||||
/* Get original receipt request */
|
||||
|
||||
/* Get original receipt request details */
|
||||
|
||||
if (!CMS_get1_ReceiptRequest(si, &rr))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ENCODE_RECEIPT, CMS_R_NO_RECEIPT_REQUEST);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Get original content type */
|
||||
|
||||
ctype = CMS_signed_get0_data_by_OBJ(si,
|
||||
OBJ_nid2obj(NID_pkcs9_contentType),
|
||||
-3, V_ASN1_OBJECT);
|
||||
if (!ctype)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ENCODE_RECEIPT, CMS_R_NO_CONTENT_TYPE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
rct.version = 1;
|
||||
rct.contentType = ctype;
|
||||
rct.signedContentIdentifier = rr->signedContentIdentifier;
|
||||
rct.originatorSignatureValue = si->signature;
|
||||
|
||||
os = ASN1_item_pack(&rct, ASN1_ITEM_rptr(CMS_Receipt), NULL);
|
||||
|
||||
err:
|
||||
if (rr)
|
||||
CMS_ReceiptRequest_free(rr);
|
||||
|
||||
return os;
|
||||
|
||||
}
|
||||
|
||||
|
140
crypto/cms/cms_io.c
Normal file
140
crypto/cms/cms_io.c
Normal file
@ -0,0 +1,140 @@
|
||||
/* crypto/cms/cms_io.c */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2008 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/pem.h>
|
||||
#include "cms.h"
|
||||
#include "cms_lcl.h"
|
||||
|
||||
CMS_ContentInfo *d2i_CMS_bio(BIO *bp, CMS_ContentInfo **cms)
|
||||
{
|
||||
return ASN1_item_d2i_bio(ASN1_ITEM_rptr(CMS_ContentInfo), bp, cms);
|
||||
}
|
||||
|
||||
int i2d_CMS_bio(BIO *bp, CMS_ContentInfo *cms)
|
||||
{
|
||||
return ASN1_item_i2d_bio(ASN1_ITEM_rptr(CMS_ContentInfo), bp, cms);
|
||||
}
|
||||
|
||||
IMPLEMENT_PEM_rw_const(CMS, CMS_ContentInfo, PEM_STRING_CMS, CMS_ContentInfo)
|
||||
|
||||
/* Callback for int_smime_write_ASN1 */
|
||||
|
||||
static int cms_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
|
||||
const ASN1_ITEM *it)
|
||||
{
|
||||
CMS_ContentInfo *cms = (CMS_ContentInfo *)val;
|
||||
BIO *tmpbio, *cmsbio;
|
||||
int r = 0;
|
||||
|
||||
if (!(flags & SMIME_DETACHED))
|
||||
{
|
||||
SMIME_crlf_copy(data, out, flags);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Let CMS code prepend any needed BIOs */
|
||||
|
||||
cmsbio = CMS_dataInit(cms, out);
|
||||
|
||||
if (!cmsbio)
|
||||
return 0;
|
||||
|
||||
/* Copy data across, passing through filter BIOs for processing */
|
||||
SMIME_crlf_copy(data, cmsbio, flags);
|
||||
|
||||
/* Finalize structure */
|
||||
if (CMS_dataFinal(cms, cmsbio) <= 0)
|
||||
goto err;
|
||||
|
||||
r = 1;
|
||||
|
||||
err:
|
||||
|
||||
/* Now remove any digests prepended to the BIO */
|
||||
|
||||
while (cmsbio != out)
|
||||
{
|
||||
tmpbio = BIO_pop(cmsbio);
|
||||
BIO_free(cmsbio);
|
||||
cmsbio = tmpbio;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags)
|
||||
{
|
||||
STACK_OF(X509_ALGOR) *mdalgs;
|
||||
int ctype_nid = OBJ_obj2nid(cms->contentType);
|
||||
int econt_nid = OBJ_obj2nid(CMS_get0_eContentType(cms));
|
||||
if (ctype_nid == NID_pkcs7_signed)
|
||||
mdalgs = cms->d.signedData->digestAlgorithms;
|
||||
else
|
||||
mdalgs = NULL;
|
||||
|
||||
return int_smime_write_ASN1(bio, (ASN1_VALUE *)cms, data, flags,
|
||||
ctype_nid, econt_nid, mdalgs,
|
||||
cms_output_data,
|
||||
ASN1_ITEM_rptr(CMS_ContentInfo));
|
||||
}
|
||||
|
||||
CMS_ContentInfo *SMIME_read_CMS(BIO *bio, BIO **bcont)
|
||||
{
|
||||
return (CMS_ContentInfo *)SMIME_read_ASN1(bio, bcont,
|
||||
ASN1_ITEM_rptr(CMS_ContentInfo));
|
||||
}
|
460
crypto/cms/cms_lcl.h
Normal file
460
crypto/cms/cms_lcl.h
Normal file
@ -0,0 +1,460 @@
|
||||
/* crypto/cms/cms_lcl.h */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2008 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
#ifndef HEADER_CMS_LCL_H
|
||||
#define HEADER_CMS_LCL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <openssl/x509.h>
|
||||
|
||||
/* Cryptographic message syntax (CMS) structures: taken
|
||||
* from RFC3852
|
||||
*/
|
||||
|
||||
/* Forward references */
|
||||
|
||||
typedef struct CMS_IssuerAndSerialNumber_st CMS_IssuerAndSerialNumber;
|
||||
typedef struct CMS_EncapsulatedContentInfo_st CMS_EncapsulatedContentInfo;
|
||||
typedef struct CMS_SignerIdentifier_st CMS_SignerIdentifier;
|
||||
typedef struct CMS_SignedData_st CMS_SignedData;
|
||||
typedef struct CMS_OtherRevocationInfoFormat_st CMS_OtherRevocationInfoFormat;
|
||||
typedef struct CMS_OriginatorInfo_st CMS_OriginatorInfo;
|
||||
typedef struct CMS_EncryptedContentInfo_st CMS_EncryptedContentInfo;
|
||||
typedef struct CMS_EnvelopedData_st CMS_EnvelopedData;
|
||||
typedef struct CMS_DigestedData_st CMS_DigestedData;
|
||||
typedef struct CMS_EncryptedData_st CMS_EncryptedData;
|
||||
typedef struct CMS_AuthenticatedData_st CMS_AuthenticatedData;
|
||||
typedef struct CMS_CompressedData_st CMS_CompressedData;
|
||||
typedef struct CMS_OtherCertificateFormat_st CMS_OtherCertificateFormat;
|
||||
typedef struct CMS_KeyTransRecipientInfo_st CMS_KeyTransRecipientInfo;
|
||||
typedef struct CMS_OriginatorPublicKey_st CMS_OriginatorPublicKey;
|
||||
typedef struct CMS_OriginatorIdentifierOrKey_st CMS_OriginatorIdentifierOrKey;
|
||||
typedef struct CMS_KeyAgreeRecipientInfo_st CMS_KeyAgreeRecipientInfo;
|
||||
typedef struct CMS_OtherKeyAttribute_st CMS_OtherKeyAttribute;
|
||||
typedef struct CMS_RecipientKeyIdentifier_st CMS_RecipientKeyIdentifier;
|
||||
typedef struct CMS_KeyAgreeRecipientIdentifier_st CMS_KeyAgreeRecipientIdentifier;
|
||||
typedef struct CMS_RecipientEncryptedKey_st CMS_RecipientEncryptedKey;
|
||||
typedef struct CMS_KEKIdentifier_st CMS_KEKIdentifier;
|
||||
typedef struct CMS_KEKRecipientInfo_st CMS_KEKRecipientInfo;
|
||||
typedef struct CMS_PasswordRecipientInfo_st CMS_PasswordRecipientInfo;
|
||||
typedef struct CMS_OtherRecipientInfo_st CMS_OtherRecipientInfo;
|
||||
typedef struct CMS_ReceiptsFrom_st CMS_ReceiptsFrom;
|
||||
|
||||
struct CMS_ContentInfo_st
|
||||
{
|
||||
ASN1_OBJECT *contentType;
|
||||
union {
|
||||
ASN1_OCTET_STRING *data;
|
||||
CMS_SignedData *signedData;
|
||||
CMS_EnvelopedData *envelopedData;
|
||||
CMS_DigestedData *digestedData;
|
||||
CMS_EncryptedData *encryptedData;
|
||||
CMS_AuthenticatedData *authenticatedData;
|
||||
CMS_CompressedData *compressedData;
|
||||
ASN1_TYPE *other;
|
||||
/* Other types ... */
|
||||
void *otherData;
|
||||
} d;
|
||||
};
|
||||
|
||||
struct CMS_SignedData_st
|
||||
{
|
||||
long version;
|
||||
STACK_OF(X509_ALGOR) *digestAlgorithms;
|
||||
CMS_EncapsulatedContentInfo *encapContentInfo;
|
||||
STACK_OF(CMS_CertificateChoices) *certificates;
|
||||
STACK_OF(CMS_RevocationInfoChoice) *crls;
|
||||
STACK_OF(CMS_SignerInfo) *signerInfos;
|
||||
};
|
||||
|
||||
struct CMS_EncapsulatedContentInfo_st
|
||||
{
|
||||
ASN1_OBJECT *eContentType;
|
||||
ASN1_OCTET_STRING *eContent;
|
||||
/* Set to 1 if incomplete structure only part set up */
|
||||
int partial;
|
||||
};
|
||||
|
||||
struct CMS_SignerInfo_st
|
||||
{
|
||||
long version;
|
||||
CMS_SignerIdentifier *sid;
|
||||
X509_ALGOR *digestAlgorithm;
|
||||
STACK_OF(X509_ATTRIBUTE) *signedAttrs;
|
||||
X509_ALGOR *signatureAlgorithm;
|
||||
ASN1_OCTET_STRING *signature;
|
||||
STACK_OF(X509_ATTRIBUTE) *unsignedAttrs;
|
||||
/* Signing certificate and key */
|
||||
X509 *signer;
|
||||
EVP_PKEY *pkey;
|
||||
};
|
||||
|
||||
struct CMS_SignerIdentifier_st
|
||||
{
|
||||
int type;
|
||||
union {
|
||||
CMS_IssuerAndSerialNumber *issuerAndSerialNumber;
|
||||
ASN1_OCTET_STRING *subjectKeyIdentifier;
|
||||
} d;
|
||||
};
|
||||
|
||||
struct CMS_EnvelopedData_st
|
||||
{
|
||||
long version;
|
||||
CMS_OriginatorInfo *originatorInfo;
|
||||
STACK_OF(CMS_RecipientInfo) *recipientInfos;
|
||||
CMS_EncryptedContentInfo *encryptedContentInfo;
|
||||
STACK_OF(X509_ATTRIBUTE) *unprotectedAttrs;
|
||||
};
|
||||
|
||||
struct CMS_OriginatorInfo_st
|
||||
{
|
||||
STACK_OF(CMS_CertificateChoices) *certificates;
|
||||
STACK_OF(CMS_RevocationInfoChoice) *crls;
|
||||
};
|
||||
|
||||
struct CMS_EncryptedContentInfo_st
|
||||
{
|
||||
ASN1_OBJECT *contentType;
|
||||
X509_ALGOR *contentEncryptionAlgorithm;
|
||||
ASN1_OCTET_STRING *encryptedContent;
|
||||
/* Content encryption algorithm and key */
|
||||
const EVP_CIPHER *cipher;
|
||||
unsigned char *key;
|
||||
size_t keylen;
|
||||
};
|
||||
|
||||
struct CMS_RecipientInfo_st
|
||||
{
|
||||
int type;
|
||||
union {
|
||||
CMS_KeyTransRecipientInfo *ktri;
|
||||
CMS_KeyAgreeRecipientInfo *kari;
|
||||
CMS_KEKRecipientInfo *kekri;
|
||||
CMS_PasswordRecipientInfo *pwri;
|
||||
CMS_OtherRecipientInfo *ori;
|
||||
} d;
|
||||
};
|
||||
|
||||
typedef CMS_SignerIdentifier CMS_RecipientIdentifier;
|
||||
|
||||
struct CMS_KeyTransRecipientInfo_st
|
||||
{
|
||||
long version;
|
||||
CMS_RecipientIdentifier *rid;
|
||||
X509_ALGOR *keyEncryptionAlgorithm;
|
||||
ASN1_OCTET_STRING *encryptedKey;
|
||||
/* Recipient Key and cert */
|
||||
X509 *recip;
|
||||
EVP_PKEY *pkey;
|
||||
};
|
||||
|
||||
struct CMS_KeyAgreeRecipientInfo_st
|
||||
{
|
||||
long version;
|
||||
CMS_OriginatorIdentifierOrKey *originator;
|
||||
ASN1_OCTET_STRING *ukm;
|
||||
X509_ALGOR *keyEncryptionAlgorithm;
|
||||
STACK_OF(CMS_RecipientEncryptedKey) *recipientEncryptedKeys;
|
||||
};
|
||||
|
||||
struct CMS_OriginatorIdentifierOrKey_st
|
||||
{
|
||||
int type;
|
||||
union {
|
||||
CMS_IssuerAndSerialNumber *issuerAndSerialNumber;
|
||||
ASN1_OCTET_STRING *subjectKeyIdentifier;
|
||||
CMS_OriginatorPublicKey *originatorKey;
|
||||
} d;
|
||||
};
|
||||
|
||||
struct CMS_OriginatorPublicKey_st
|
||||
{
|
||||
X509_ALGOR *algorithm;
|
||||
ASN1_BIT_STRING *publicKey;
|
||||
};
|
||||
|
||||
struct CMS_RecipientEncryptedKey_st
|
||||
{
|
||||
CMS_KeyAgreeRecipientIdentifier *rid;
|
||||
ASN1_OCTET_STRING *encryptedKey;
|
||||
};
|
||||
|
||||
struct CMS_KeyAgreeRecipientIdentifier_st
|
||||
{
|
||||
int type;
|
||||
union {
|
||||
CMS_IssuerAndSerialNumber *issuerAndSerialNumber;
|
||||
CMS_RecipientKeyIdentifier *rKeyId;
|
||||
} d;
|
||||
};
|
||||
|
||||
struct CMS_RecipientKeyIdentifier_st
|
||||
{
|
||||
ASN1_OCTET_STRING *subjectKeyIdentifier;
|
||||
ASN1_GENERALIZEDTIME *date;
|
||||
CMS_OtherKeyAttribute *other;
|
||||
};
|
||||
|
||||
struct CMS_KEKRecipientInfo_st
|
||||
{
|
||||
long version;
|
||||
CMS_KEKIdentifier *kekid;
|
||||
X509_ALGOR *keyEncryptionAlgorithm;
|
||||
ASN1_OCTET_STRING *encryptedKey;
|
||||
/* Extra info: symmetric key to use */
|
||||
unsigned char *key;
|
||||
size_t keylen;
|
||||
};
|
||||
|
||||
struct CMS_KEKIdentifier_st
|
||||
{
|
||||
ASN1_OCTET_STRING *keyIdentifier;
|
||||
ASN1_GENERALIZEDTIME *date;
|
||||
CMS_OtherKeyAttribute *other;
|
||||
};
|
||||
|
||||
struct CMS_PasswordRecipientInfo_st
|
||||
{
|
||||
long version;
|
||||
X509_ALGOR *keyDerivationAlgorithm;
|
||||
X509_ALGOR *keyEncryptionAlgorithm;
|
||||
ASN1_OCTET_STRING *encryptedKey;
|
||||
};
|
||||
|
||||
struct CMS_OtherRecipientInfo_st
|
||||
{
|
||||
ASN1_OBJECT *oriType;
|
||||
ASN1_TYPE *oriValue;
|
||||
};
|
||||
|
||||
struct CMS_DigestedData_st
|
||||
{
|
||||
long version;
|
||||
X509_ALGOR *digestAlgorithm;
|
||||
CMS_EncapsulatedContentInfo *encapContentInfo;
|
||||
ASN1_OCTET_STRING *digest;
|
||||
};
|
||||
|
||||
struct CMS_EncryptedData_st
|
||||
{
|
||||
long version;
|
||||
CMS_EncryptedContentInfo *encryptedContentInfo;
|
||||
STACK_OF(X509_ATTRIBUTE) *unprotectedAttrs;
|
||||
};
|
||||
|
||||
struct CMS_AuthenticatedData_st
|
||||
{
|
||||
long version;
|
||||
CMS_OriginatorInfo *originatorInfo;
|
||||
STACK_OF(CMS_RecipientInfo) *recipientInfos;
|
||||
X509_ALGOR *macAlgorithm;
|
||||
X509_ALGOR *digestAlgorithm;
|
||||
CMS_EncapsulatedContentInfo *encapContentInfo;
|
||||
STACK_OF(X509_ATTRIBUTE) *authAttrs;
|
||||
ASN1_OCTET_STRING *mac;
|
||||
STACK_OF(X509_ATTRIBUTE) *unauthAttrs;
|
||||
};
|
||||
|
||||
struct CMS_CompressedData_st
|
||||
{
|
||||
long version;
|
||||
X509_ALGOR *compressionAlgorithm;
|
||||
STACK_OF(CMS_RecipientInfo) *recipientInfos;
|
||||
CMS_EncapsulatedContentInfo *encapContentInfo;
|
||||
};
|
||||
|
||||
struct CMS_RevocationInfoChoice_st
|
||||
{
|
||||
int type;
|
||||
union {
|
||||
X509_CRL *crl;
|
||||
CMS_OtherRevocationInfoFormat *other;
|
||||
} d;
|
||||
};
|
||||
|
||||
#define CMS_REVCHOICE_CRL 0
|
||||
#define CMS_REVCHOICE_OTHER 1
|
||||
|
||||
struct CMS_OtherRevocationInfoFormat_st
|
||||
{
|
||||
ASN1_OBJECT *otherRevInfoFormat;
|
||||
ASN1_TYPE *otherRevInfo;
|
||||
};
|
||||
|
||||
struct CMS_CertificateChoices
|
||||
{
|
||||
int type;
|
||||
union {
|
||||
X509 *certificate;
|
||||
ASN1_STRING *extendedCertificate; /* Obsolete */
|
||||
ASN1_STRING *v1AttrCert; /* Left encoded for now */
|
||||
ASN1_STRING *v2AttrCert; /* Left encoded for now */
|
||||
CMS_OtherCertificateFormat *other;
|
||||
} d;
|
||||
};
|
||||
|
||||
#define CMS_CERTCHOICE_CERT 0
|
||||
#define CMS_CERTCHOICE_EXCERT 1
|
||||
#define CMS_CERTCHOICE_V1ACERT 2
|
||||
#define CMS_CERTCHOICE_V2ACERT 3
|
||||
#define CMS_CERTCHOICE_OTHER 4
|
||||
|
||||
struct CMS_OtherCertificateFormat_st
|
||||
{
|
||||
ASN1_OBJECT *otherCertFormat;
|
||||
ASN1_TYPE *otherCert;
|
||||
};
|
||||
|
||||
/* This is also defined in pkcs7.h but we duplicate it
|
||||
* to allow the CMS code to be independent of PKCS#7
|
||||
*/
|
||||
|
||||
struct CMS_IssuerAndSerialNumber_st
|
||||
{
|
||||
X509_NAME *issuer;
|
||||
ASN1_INTEGER *serialNumber;
|
||||
};
|
||||
|
||||
struct CMS_OtherKeyAttribute_st
|
||||
{
|
||||
ASN1_OBJECT *keyAttrId;
|
||||
ASN1_TYPE *keyAttr;
|
||||
};
|
||||
|
||||
/* ESS structures */
|
||||
|
||||
#ifdef HEADER_X509V3_H
|
||||
|
||||
struct CMS_ReceiptRequest_st
|
||||
{
|
||||
ASN1_OCTET_STRING *signedContentIdentifier;
|
||||
CMS_ReceiptsFrom *receiptsFrom;
|
||||
STACK_OF(GENERAL_NAMES) *receiptsTo;
|
||||
};
|
||||
|
||||
|
||||
struct CMS_ReceiptsFrom_st
|
||||
{
|
||||
int type;
|
||||
union
|
||||
{
|
||||
long allOrFirstTier;
|
||||
STACK_OF(GENERAL_NAMES) *receiptList;
|
||||
} d;
|
||||
};
|
||||
#endif
|
||||
|
||||
struct CMS_Receipt_st
|
||||
{
|
||||
long version;
|
||||
ASN1_OBJECT *contentType;
|
||||
ASN1_OCTET_STRING *signedContentIdentifier;
|
||||
ASN1_OCTET_STRING *originatorSignatureValue;
|
||||
};
|
||||
|
||||
DECLARE_ASN1_ITEM(CMS_SignerInfo)
|
||||
DECLARE_ASN1_ITEM(CMS_IssuerAndSerialNumber)
|
||||
DECLARE_ASN1_ITEM(CMS_Attributes_Sign)
|
||||
DECLARE_ASN1_ITEM(CMS_Attributes_Verify)
|
||||
DECLARE_ASN1_ALLOC_FUNCTIONS(CMS_IssuerAndSerialNumber)
|
||||
|
||||
#define CMS_SIGNERINFO_ISSUER_SERIAL 0
|
||||
#define CMS_SIGNERINFO_KEYIDENTIFIER 1
|
||||
|
||||
#define CMS_RECIPINFO_ISSUER_SERIAL 0
|
||||
#define CMS_RECIPINFO_KEYIDENTIFIER 1
|
||||
|
||||
BIO *cms_content_bio(CMS_ContentInfo *cms);
|
||||
|
||||
CMS_ContentInfo *cms_Data_create(void);
|
||||
|
||||
CMS_ContentInfo *cms_DigestedData_create(const EVP_MD *md);
|
||||
BIO *cms_DigestedData_init_bio(CMS_ContentInfo *cms);
|
||||
int cms_DigestedData_do_final(CMS_ContentInfo *cms, BIO *chain, int verify);
|
||||
|
||||
BIO *cms_SignedData_init_bio(CMS_ContentInfo *cms);
|
||||
int cms_SignedData_final(CMS_ContentInfo *cms, BIO *chain);
|
||||
int cms_set1_SignerIdentifier(CMS_SignerIdentifier *sid, X509 *cert, int type);
|
||||
int cms_SignerIdentifier_get0_signer_id(CMS_SignerIdentifier *sid,
|
||||
ASN1_OCTET_STRING **keyid,
|
||||
X509_NAME **issuer, ASN1_INTEGER **sno);
|
||||
int cms_SignerIdentifier_cert_cmp(CMS_SignerIdentifier *sid, X509 *cert);
|
||||
|
||||
CMS_ContentInfo *cms_CompressedData_create(int comp_nid);
|
||||
BIO *cms_CompressedData_init_bio(CMS_ContentInfo *cms);
|
||||
|
||||
void cms_DigestAlgorithm_set(X509_ALGOR *alg, const EVP_MD *md);
|
||||
BIO *cms_DigestAlgorithm_init_bio(X509_ALGOR *digestAlgorithm);
|
||||
int cms_DigestAlgorithm_find_ctx(EVP_MD_CTX *mctx, BIO *chain,
|
||||
X509_ALGOR *mdalg);
|
||||
|
||||
BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec);
|
||||
BIO *cms_EncryptedData_init_bio(CMS_ContentInfo *cms);
|
||||
int cms_EncryptedContent_init(CMS_EncryptedContentInfo *ec,
|
||||
const EVP_CIPHER *cipher,
|
||||
const unsigned char *key, size_t keylen);
|
||||
|
||||
int cms_Receipt_verify(CMS_ContentInfo *cms, CMS_ContentInfo *req_cms);
|
||||
int cms_msgSigDigest_add1(CMS_SignerInfo *dest, CMS_SignerInfo *src);
|
||||
ASN1_OCTET_STRING *cms_encode_Receipt(CMS_SignerInfo *si);
|
||||
|
||||
BIO *cms_EnvelopedData_init_bio(CMS_ContentInfo *cms);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
623
crypto/cms/cms_lib.c
Normal file
623
crypto/cms/cms_lib.c
Normal file
@ -0,0 +1,623 @@
|
||||
/* crypto/cms/cms_lib.c */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2008 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/asn1.h>
|
||||
#include "cms.h"
|
||||
#include "cms_lcl.h"
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const(CMS_ContentInfo)
|
||||
|
||||
DECLARE_ASN1_ITEM(CMS_CertificateChoices)
|
||||
DECLARE_ASN1_ITEM(CMS_RevocationInfoChoice)
|
||||
DECLARE_STACK_OF(CMS_CertificateChoices)
|
||||
DECLARE_STACK_OF(CMS_RevocationInfoChoice)
|
||||
|
||||
const ASN1_OBJECT *CMS_get0_type(CMS_ContentInfo *cms)
|
||||
{
|
||||
return cms->contentType;
|
||||
}
|
||||
|
||||
CMS_ContentInfo *cms_Data_create(void)
|
||||
{
|
||||
CMS_ContentInfo *cms;
|
||||
cms = CMS_ContentInfo_new();
|
||||
if (cms)
|
||||
{
|
||||
cms->contentType = OBJ_nid2obj(NID_pkcs7_data);
|
||||
/* Never detached */
|
||||
CMS_set_detached(cms, 0);
|
||||
}
|
||||
return cms;
|
||||
}
|
||||
|
||||
BIO *cms_content_bio(CMS_ContentInfo *cms)
|
||||
{
|
||||
ASN1_OCTET_STRING **pos = CMS_get0_content(cms);
|
||||
if (!pos)
|
||||
return NULL;
|
||||
/* If content detached data goes nowhere: create NULL BIO */
|
||||
if (!*pos)
|
||||
return BIO_new(BIO_s_null());
|
||||
/* If content not detached and created return memory BIO
|
||||
*/
|
||||
if (!*pos || ((*pos)->flags == ASN1_STRING_FLAG_CONT))
|
||||
return BIO_new(BIO_s_mem());
|
||||
/* Else content was read in: return read only BIO for it */
|
||||
return BIO_new_mem_buf((*pos)->data, (*pos)->length);
|
||||
}
|
||||
|
||||
BIO *CMS_dataInit(CMS_ContentInfo *cms, BIO *icont)
|
||||
{
|
||||
BIO *cmsbio, *cont;
|
||||
if (icont)
|
||||
cont = icont;
|
||||
else
|
||||
cont = cms_content_bio(cms);
|
||||
if (!cont)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_DATAINIT, CMS_R_NO_CONTENT);
|
||||
return NULL;
|
||||
}
|
||||
switch (OBJ_obj2nid(cms->contentType))
|
||||
{
|
||||
|
||||
case NID_pkcs7_data:
|
||||
return cont;
|
||||
|
||||
case NID_pkcs7_signed:
|
||||
cmsbio = cms_SignedData_init_bio(cms);
|
||||
break;
|
||||
|
||||
case NID_pkcs7_digest:
|
||||
cmsbio = cms_DigestedData_init_bio(cms);
|
||||
break;
|
||||
#ifdef ZLIB
|
||||
case NID_id_smime_ct_compressedData:
|
||||
cmsbio = cms_CompressedData_init_bio(cms);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case NID_pkcs7_encrypted:
|
||||
cmsbio = cms_EncryptedData_init_bio(cms);
|
||||
break;
|
||||
|
||||
case NID_pkcs7_enveloped:
|
||||
cmsbio = cms_EnvelopedData_init_bio(cms);
|
||||
break;
|
||||
|
||||
default:
|
||||
CMSerr(CMS_F_CMS_DATAINIT, CMS_R_UNSUPPORTED_TYPE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (cmsbio)
|
||||
return BIO_push(cmsbio, cont);
|
||||
|
||||
if (!icont)
|
||||
BIO_free(cont);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
int CMS_dataFinal(CMS_ContentInfo *cms, BIO *cmsbio)
|
||||
{
|
||||
ASN1_OCTET_STRING **pos = CMS_get0_content(cms);
|
||||
if (!pos)
|
||||
return 0;
|
||||
/* If ebmedded content find memory BIO and set content */
|
||||
if (*pos && ((*pos)->flags & ASN1_STRING_FLAG_CONT))
|
||||
{
|
||||
BIO *mbio;
|
||||
unsigned char *cont;
|
||||
long contlen;
|
||||
mbio = BIO_find_type(cmsbio, BIO_TYPE_MEM);
|
||||
if (!mbio)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_DATAFINAL, CMS_R_CONTENT_NOT_FOUND);
|
||||
return 0;
|
||||
}
|
||||
contlen = BIO_get_mem_data(mbio, &cont);
|
||||
/* Set bio as read only so its content can't be clobbered */
|
||||
BIO_set_flags(mbio, BIO_FLAGS_MEM_RDONLY);
|
||||
BIO_set_mem_eof_return(mbio, 0);
|
||||
ASN1_STRING_set0(*pos, cont, contlen);
|
||||
(*pos)->flags &= ~ASN1_STRING_FLAG_CONT;
|
||||
}
|
||||
|
||||
switch (OBJ_obj2nid(cms->contentType))
|
||||
{
|
||||
|
||||
case NID_pkcs7_data:
|
||||
case NID_pkcs7_enveloped:
|
||||
case NID_pkcs7_encrypted:
|
||||
case NID_id_smime_ct_compressedData:
|
||||
/* Nothing to do */
|
||||
return 1;
|
||||
|
||||
case NID_pkcs7_signed:
|
||||
return cms_SignedData_final(cms, cmsbio);
|
||||
|
||||
case NID_pkcs7_digest:
|
||||
return cms_DigestedData_do_final(cms, cmsbio, 0);
|
||||
|
||||
default:
|
||||
CMSerr(CMS_F_CMS_DATAFINAL, CMS_R_UNSUPPORTED_TYPE);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return an OCTET STRING pointer to content. This allows it to
|
||||
* be accessed or set later.
|
||||
*/
|
||||
|
||||
ASN1_OCTET_STRING **CMS_get0_content(CMS_ContentInfo *cms)
|
||||
{
|
||||
switch (OBJ_obj2nid(cms->contentType))
|
||||
{
|
||||
|
||||
case NID_pkcs7_data:
|
||||
return &cms->d.data;
|
||||
|
||||
case NID_pkcs7_signed:
|
||||
return &cms->d.signedData->encapContentInfo->eContent;
|
||||
|
||||
case NID_pkcs7_enveloped:
|
||||
return &cms->d.envelopedData->encryptedContentInfo->encryptedContent;
|
||||
|
||||
case NID_pkcs7_digest:
|
||||
return &cms->d.digestedData->encapContentInfo->eContent;
|
||||
|
||||
case NID_pkcs7_encrypted:
|
||||
return &cms->d.encryptedData->encryptedContentInfo->encryptedContent;
|
||||
|
||||
case NID_id_smime_ct_authData:
|
||||
return &cms->d.authenticatedData->encapContentInfo->eContent;
|
||||
|
||||
case NID_id_smime_ct_compressedData:
|
||||
return &cms->d.compressedData->encapContentInfo->eContent;
|
||||
|
||||
default:
|
||||
if (cms->d.other->type == V_ASN1_OCTET_STRING)
|
||||
return &cms->d.other->value.octet_string;
|
||||
CMSerr(CMS_F_CMS_GET0_CONTENT, CMS_R_UNSUPPORTED_CONTENT_TYPE);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* Return an ASN1_OBJECT pointer to content type. This allows it to
|
||||
* be accessed or set later.
|
||||
*/
|
||||
|
||||
static ASN1_OBJECT **cms_get0_econtent_type(CMS_ContentInfo *cms)
|
||||
{
|
||||
switch (OBJ_obj2nid(cms->contentType))
|
||||
{
|
||||
|
||||
case NID_pkcs7_signed:
|
||||
return &cms->d.signedData->encapContentInfo->eContentType;
|
||||
|
||||
case NID_pkcs7_enveloped:
|
||||
return &cms->d.envelopedData->encryptedContentInfo->contentType;
|
||||
|
||||
case NID_pkcs7_digest:
|
||||
return &cms->d.digestedData->encapContentInfo->eContentType;
|
||||
|
||||
case NID_pkcs7_encrypted:
|
||||
return &cms->d.encryptedData->encryptedContentInfo->contentType;
|
||||
|
||||
case NID_id_smime_ct_authData:
|
||||
return &cms->d.authenticatedData->encapContentInfo->eContentType;
|
||||
|
||||
case NID_id_smime_ct_compressedData:
|
||||
return &cms->d.compressedData->encapContentInfo->eContentType;
|
||||
|
||||
default:
|
||||
CMSerr(CMS_F_CMS_GET0_ECONTENT_TYPE,
|
||||
CMS_R_UNSUPPORTED_CONTENT_TYPE);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
const ASN1_OBJECT *CMS_get0_eContentType(CMS_ContentInfo *cms)
|
||||
{
|
||||
ASN1_OBJECT **petype;
|
||||
petype = cms_get0_econtent_type(cms);
|
||||
if (petype)
|
||||
return *petype;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int CMS_set1_eContentType(CMS_ContentInfo *cms, const ASN1_OBJECT *oid)
|
||||
{
|
||||
ASN1_OBJECT **petype, *etype;
|
||||
petype = cms_get0_econtent_type(cms);
|
||||
if (!petype)
|
||||
return 0;
|
||||
if (!oid)
|
||||
return 1;
|
||||
etype = OBJ_dup(oid);
|
||||
if (!etype)
|
||||
return 0;
|
||||
ASN1_OBJECT_free(*petype);
|
||||
*petype = etype;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CMS_is_detached(CMS_ContentInfo *cms)
|
||||
{
|
||||
ASN1_OCTET_STRING **pos;
|
||||
pos = CMS_get0_content(cms);
|
||||
if (!pos)
|
||||
return -1;
|
||||
if (*pos)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CMS_set_detached(CMS_ContentInfo *cms, int detached)
|
||||
{
|
||||
ASN1_OCTET_STRING **pos;
|
||||
pos = CMS_get0_content(cms);
|
||||
if (!pos)
|
||||
return 0;
|
||||
if (detached)
|
||||
{
|
||||
if (*pos)
|
||||
{
|
||||
ASN1_OCTET_STRING_free(*pos);
|
||||
*pos = NULL;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (!*pos)
|
||||
*pos = ASN1_OCTET_STRING_new();
|
||||
if (*pos)
|
||||
{
|
||||
/* NB: special flag to show content is created and not
|
||||
* read in.
|
||||
*/
|
||||
(*pos)->flags |= ASN1_STRING_FLAG_CONT;
|
||||
return 1;
|
||||
}
|
||||
CMSerr(CMS_F_CMS_SET_DETACHED, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set up an X509_ALGOR DigestAlgorithmIdentifier from an EVP_MD */
|
||||
|
||||
void cms_DigestAlgorithm_set(X509_ALGOR *alg, const EVP_MD *md)
|
||||
{
|
||||
int param_type;
|
||||
|
||||
switch (EVP_MD_type(md))
|
||||
{
|
||||
case NID_sha1:
|
||||
case NID_sha224:
|
||||
case NID_sha256:
|
||||
case NID_sha384:
|
||||
case NID_sha512:
|
||||
param_type = V_ASN1_UNDEF;
|
||||
break;
|
||||
|
||||
default:
|
||||
param_type = V_ASN1_NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
X509_ALGOR_set0(alg, OBJ_nid2obj(EVP_MD_type(md)), param_type, NULL);
|
||||
|
||||
}
|
||||
|
||||
/* Create a digest BIO from an X509_ALGOR structure */
|
||||
|
||||
BIO *cms_DigestAlgorithm_init_bio(X509_ALGOR *digestAlgorithm)
|
||||
{
|
||||
BIO *mdbio = NULL;
|
||||
ASN1_OBJECT *digestoid;
|
||||
const EVP_MD *digest;
|
||||
X509_ALGOR_get0(&digestoid, NULL, NULL, digestAlgorithm);
|
||||
digest = EVP_get_digestbyobj(digestoid);
|
||||
if (!digest)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_DIGESTALGORITHM_INIT_BIO,
|
||||
CMS_R_UNKNOWN_DIGEST_ALGORIHM);
|
||||
goto err;
|
||||
}
|
||||
mdbio = BIO_new(BIO_f_md());
|
||||
if (!mdbio || !BIO_set_md(mdbio, digest))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_DIGESTALGORITHM_INIT_BIO,
|
||||
CMS_R_MD_BIO_INIT_ERROR);
|
||||
goto err;
|
||||
}
|
||||
return mdbio;
|
||||
err:
|
||||
if (mdbio)
|
||||
BIO_free(mdbio);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Locate a message digest content from a BIO chain based on SignerInfo */
|
||||
|
||||
int cms_DigestAlgorithm_find_ctx(EVP_MD_CTX *mctx, BIO *chain,
|
||||
X509_ALGOR *mdalg)
|
||||
{
|
||||
int nid;
|
||||
ASN1_OBJECT *mdoid;
|
||||
X509_ALGOR_get0(&mdoid, NULL, NULL, mdalg);
|
||||
nid = OBJ_obj2nid(mdoid);
|
||||
/* Look for digest type to match signature */
|
||||
for (;;)
|
||||
{
|
||||
EVP_MD_CTX *mtmp;
|
||||
chain = BIO_find_type(chain, BIO_TYPE_MD);
|
||||
if (chain == NULL)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_DIGESTALGORITHM_FIND_CTX,
|
||||
CMS_R_NO_MATCHING_DIGEST);
|
||||
return 0;
|
||||
}
|
||||
BIO_get_md_ctx(chain, &mtmp);
|
||||
if (EVP_MD_CTX_type(mtmp) == nid)
|
||||
{
|
||||
EVP_MD_CTX_copy_ex(mctx, mtmp);
|
||||
return 1;
|
||||
}
|
||||
chain = BIO_next(chain);
|
||||
}
|
||||
}
|
||||
|
||||
static STACK_OF(CMS_CertificateChoices) **cms_get0_certificate_choices(CMS_ContentInfo *cms)
|
||||
{
|
||||
switch (OBJ_obj2nid(cms->contentType))
|
||||
{
|
||||
|
||||
case NID_pkcs7_signed:
|
||||
return &cms->d.signedData->certificates;
|
||||
|
||||
case NID_pkcs7_enveloped:
|
||||
return &cms->d.envelopedData->originatorInfo->certificates;
|
||||
|
||||
default:
|
||||
CMSerr(CMS_F_CMS_GET0_CERTIFICATE_CHOICES,
|
||||
CMS_R_UNSUPPORTED_CONTENT_TYPE);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
CMS_CertificateChoices *CMS_add0_CertificateChoices(CMS_ContentInfo *cms)
|
||||
{
|
||||
STACK_OF(CMS_CertificateChoices) **pcerts;
|
||||
CMS_CertificateChoices *cch;
|
||||
pcerts = cms_get0_certificate_choices(cms);
|
||||
if (!pcerts)
|
||||
return NULL;
|
||||
if (!*pcerts)
|
||||
*pcerts = sk_CMS_CertificateChoices_new_null();
|
||||
if (!*pcerts)
|
||||
return NULL;
|
||||
cch = M_ASN1_new_of(CMS_CertificateChoices);
|
||||
if (!cch)
|
||||
return NULL;
|
||||
if (!sk_CMS_CertificateChoices_push(*pcerts, cch))
|
||||
{
|
||||
M_ASN1_free_of(cch, CMS_CertificateChoices);
|
||||
return NULL;
|
||||
}
|
||||
return cch;
|
||||
}
|
||||
|
||||
int CMS_add0_cert(CMS_ContentInfo *cms, X509 *cert)
|
||||
{
|
||||
CMS_CertificateChoices *cch;
|
||||
STACK_OF(CMS_CertificateChoices) **pcerts;
|
||||
int i;
|
||||
pcerts = cms_get0_certificate_choices(cms);
|
||||
if (!pcerts)
|
||||
return 0;
|
||||
if (!pcerts)
|
||||
return 0;
|
||||
for (i = 0; i < sk_CMS_CertificateChoices_num(*pcerts); i++)
|
||||
{
|
||||
cch = sk_CMS_CertificateChoices_value(*pcerts, i);
|
||||
if (cch->type == CMS_CERTCHOICE_CERT)
|
||||
{
|
||||
if (!X509_cmp(cch->d.certificate, cert))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ADD0_CERT,
|
||||
CMS_R_CERTIFICATE_ALREADY_PRESENT);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
cch = CMS_add0_CertificateChoices(cms);
|
||||
if (!cch)
|
||||
return 0;
|
||||
cch->type = CMS_CERTCHOICE_CERT;
|
||||
cch->d.certificate = cert;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CMS_add1_cert(CMS_ContentInfo *cms, X509 *cert)
|
||||
{
|
||||
int r;
|
||||
r = CMS_add0_cert(cms, cert);
|
||||
if (r > 0)
|
||||
CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
|
||||
return r;
|
||||
}
|
||||
|
||||
static STACK_OF(CMS_RevocationInfoChoice) **cms_get0_revocation_choices(CMS_ContentInfo *cms)
|
||||
{
|
||||
switch (OBJ_obj2nid(cms->contentType))
|
||||
{
|
||||
|
||||
case NID_pkcs7_signed:
|
||||
return &cms->d.signedData->crls;
|
||||
|
||||
case NID_pkcs7_enveloped:
|
||||
return &cms->d.envelopedData->originatorInfo->crls;
|
||||
|
||||
default:
|
||||
CMSerr(CMS_F_CMS_GET0_REVOCATION_CHOICES,
|
||||
CMS_R_UNSUPPORTED_CONTENT_TYPE);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
CMS_RevocationInfoChoice *CMS_add0_RevocationInfoChoice(CMS_ContentInfo *cms)
|
||||
{
|
||||
STACK_OF(CMS_RevocationInfoChoice) **pcrls;
|
||||
CMS_RevocationInfoChoice *rch;
|
||||
pcrls = cms_get0_revocation_choices(cms);
|
||||
if (!pcrls)
|
||||
return NULL;
|
||||
if (!*pcrls)
|
||||
*pcrls = sk_CMS_RevocationInfoChoice_new_null();
|
||||
if (!*pcrls)
|
||||
return NULL;
|
||||
rch = M_ASN1_new_of(CMS_RevocationInfoChoice);
|
||||
if (!rch)
|
||||
return NULL;
|
||||
if (!sk_CMS_RevocationInfoChoice_push(*pcrls, rch))
|
||||
{
|
||||
M_ASN1_free_of(rch, CMS_RevocationInfoChoice);
|
||||
return NULL;
|
||||
}
|
||||
return rch;
|
||||
}
|
||||
|
||||
int CMS_add0_crl(CMS_ContentInfo *cms, X509_CRL *crl)
|
||||
{
|
||||
CMS_RevocationInfoChoice *rch;
|
||||
rch = CMS_add0_RevocationInfoChoice(cms);
|
||||
if (!rch)
|
||||
return 0;
|
||||
rch->type = CMS_REVCHOICE_CRL;
|
||||
rch->d.crl = crl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
STACK_OF(X509) *CMS_get1_certs(CMS_ContentInfo *cms)
|
||||
{
|
||||
STACK_OF(X509) *certs = NULL;
|
||||
CMS_CertificateChoices *cch;
|
||||
STACK_OF(CMS_CertificateChoices) **pcerts;
|
||||
int i;
|
||||
pcerts = cms_get0_certificate_choices(cms);
|
||||
if (!pcerts)
|
||||
return NULL;
|
||||
for (i = 0; i < sk_CMS_CertificateChoices_num(*pcerts); i++)
|
||||
{
|
||||
cch = sk_CMS_CertificateChoices_value(*pcerts, i);
|
||||
if (cch->type == 0)
|
||||
{
|
||||
if (!certs)
|
||||
{
|
||||
certs = sk_X509_new_null();
|
||||
if (!certs)
|
||||
return NULL;
|
||||
}
|
||||
if (!sk_X509_push(certs, cch->d.certificate))
|
||||
{
|
||||
sk_X509_pop_free(certs, X509_free);
|
||||
return NULL;
|
||||
}
|
||||
CRYPTO_add(&cch->d.certificate->references,
|
||||
1, CRYPTO_LOCK_X509);
|
||||
}
|
||||
}
|
||||
return certs;
|
||||
|
||||
}
|
||||
|
||||
STACK_OF(X509_CRL) *CMS_get1_crls(CMS_ContentInfo *cms)
|
||||
{
|
||||
STACK_OF(X509_CRL) *crls = NULL;
|
||||
STACK_OF(CMS_RevocationInfoChoice) **pcrls;
|
||||
CMS_RevocationInfoChoice *rch;
|
||||
int i;
|
||||
pcrls = cms_get0_revocation_choices(cms);
|
||||
if (!pcrls)
|
||||
return NULL;
|
||||
for (i = 0; i < sk_CMS_RevocationInfoChoice_num(*pcrls); i++)
|
||||
{
|
||||
rch = sk_CMS_RevocationInfoChoice_value(*pcrls, i);
|
||||
if (rch->type == 0)
|
||||
{
|
||||
if (!crls)
|
||||
{
|
||||
crls = sk_X509_CRL_new_null();
|
||||
if (!crls)
|
||||
return NULL;
|
||||
}
|
||||
if (!sk_X509_CRL_push(crls, rch->d.crl))
|
||||
{
|
||||
sk_X509_CRL_pop_free(crls, X509_CRL_free);
|
||||
return NULL;
|
||||
}
|
||||
CRYPTO_add(&rch->d.crl->references,
|
||||
1, CRYPTO_LOCK_X509_CRL);
|
||||
}
|
||||
}
|
||||
return crls;
|
||||
}
|
1014
crypto/cms/cms_sd.c
Normal file
1014
crypto/cms/cms_sd.c
Normal file
File diff suppressed because it is too large
Load Diff
806
crypto/cms/cms_smime.c
Normal file
806
crypto/cms/cms_smime.c
Normal file
@ -0,0 +1,806 @@
|
||||
/* crypto/cms/cms_smime.c */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2008 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/cms.h>
|
||||
#include "cms_lcl.h"
|
||||
|
||||
static int cms_copy_content(BIO *out, BIO *in, unsigned int flags)
|
||||
{
|
||||
unsigned char buf[4096];
|
||||
int r = 0, i;
|
||||
BIO *tmpout = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
tmpout = BIO_new(BIO_s_null());
|
||||
else if (flags & CMS_TEXT)
|
||||
tmpout = BIO_new(BIO_s_mem());
|
||||
else
|
||||
tmpout = out;
|
||||
|
||||
if(!tmpout)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_COPY_CONTENT,ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Read all content through chain to process digest, decrypt etc */
|
||||
for (;;)
|
||||
{
|
||||
i=BIO_read(in,buf,sizeof(buf));
|
||||
if (i <= 0)
|
||||
{
|
||||
if (BIO_method_type(in) == BIO_TYPE_CIPHER)
|
||||
{
|
||||
if (!BIO_get_cipher_status(in))
|
||||
goto err;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (tmpout)
|
||||
BIO_write(tmpout, buf, i);
|
||||
}
|
||||
|
||||
if(flags & CMS_TEXT)
|
||||
{
|
||||
if(!SMIME_text(tmpout, out))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_COPY_CONTENT,CMS_R_SMIME_TEXT_ERROR);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
r = 1;
|
||||
|
||||
err:
|
||||
if (tmpout && (tmpout != out))
|
||||
BIO_free(tmpout);
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
static int check_content(CMS_ContentInfo *cms)
|
||||
{
|
||||
ASN1_OCTET_STRING **pos = CMS_get0_content(cms);
|
||||
if (!pos || !*pos)
|
||||
{
|
||||
CMSerr(CMS_F_CHECK_CONTENT, CMS_R_NO_CONTENT);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void do_free_upto(BIO *f, BIO *upto)
|
||||
{
|
||||
if (upto)
|
||||
{
|
||||
BIO *tbio;
|
||||
do
|
||||
{
|
||||
tbio = BIO_pop(f);
|
||||
BIO_free(f);
|
||||
f = tbio;
|
||||
}
|
||||
while (f != upto);
|
||||
}
|
||||
else
|
||||
BIO_free_all(f);
|
||||
}
|
||||
|
||||
int CMS_data(CMS_ContentInfo *cms, BIO *out, unsigned int flags)
|
||||
{
|
||||
BIO *cont;
|
||||
int r;
|
||||
if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_data)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_DATA, CMS_R_TYPE_NOT_DATA);
|
||||
return 0;
|
||||
}
|
||||
cont = CMS_dataInit(cms, NULL);
|
||||
if (!cont)
|
||||
return 0;
|
||||
r = cms_copy_content(out, cont, flags);
|
||||
BIO_free_all(cont);
|
||||
return r;
|
||||
}
|
||||
|
||||
CMS_ContentInfo *CMS_data_create(BIO *in, unsigned int flags)
|
||||
{
|
||||
CMS_ContentInfo *cms;
|
||||
cms = cms_Data_create();
|
||||
if (!cms)
|
||||
return NULL;
|
||||
|
||||
if (CMS_final(cms, in, NULL, flags))
|
||||
return cms;
|
||||
|
||||
CMS_ContentInfo_free(cms);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int CMS_digest_verify(CMS_ContentInfo *cms, BIO *dcont, BIO *out,
|
||||
unsigned int flags)
|
||||
{
|
||||
BIO *cont;
|
||||
int r;
|
||||
if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_digest)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_DIGEST_VERIFY, CMS_R_TYPE_NOT_DIGESTED_DATA);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!dcont && !check_content(cms))
|
||||
return 0;
|
||||
|
||||
cont = CMS_dataInit(cms, dcont);
|
||||
if (!cont)
|
||||
return 0;
|
||||
r = cms_copy_content(out, cont, flags);
|
||||
if (r)
|
||||
r = cms_DigestedData_do_final(cms, cont, 1);
|
||||
do_free_upto(cont, dcont);
|
||||
return r;
|
||||
}
|
||||
|
||||
CMS_ContentInfo *CMS_digest_create(BIO *in, const EVP_MD *md,
|
||||
unsigned int flags)
|
||||
{
|
||||
CMS_ContentInfo *cms;
|
||||
if (!md)
|
||||
md = EVP_sha1();
|
||||
cms = cms_DigestedData_create(md);
|
||||
if (!cms)
|
||||
return NULL;
|
||||
|
||||
if(!(flags & CMS_DETACHED))
|
||||
{
|
||||
flags &= ~CMS_STREAM;
|
||||
CMS_set_detached(cms, 0);
|
||||
}
|
||||
|
||||
if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags))
|
||||
return cms;
|
||||
|
||||
CMS_ContentInfo_free(cms);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int CMS_EncryptedData_decrypt(CMS_ContentInfo *cms,
|
||||
const unsigned char *key, size_t keylen,
|
||||
BIO *dcont, BIO *out, unsigned int flags)
|
||||
{
|
||||
BIO *cont;
|
||||
int r;
|
||||
if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_encrypted)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ENCRYPTEDDATA_DECRYPT,
|
||||
CMS_R_TYPE_NOT_ENCRYPTED_DATA);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!dcont && !check_content(cms))
|
||||
return 0;
|
||||
|
||||
if (CMS_EncryptedData_set1_key(cms, NULL, key, keylen) <= 0)
|
||||
return 0;
|
||||
cont = CMS_dataInit(cms, dcont);
|
||||
if (!cont)
|
||||
return 0;
|
||||
r = cms_copy_content(out, cont, flags);
|
||||
do_free_upto(cont, dcont);
|
||||
return r;
|
||||
}
|
||||
|
||||
CMS_ContentInfo *CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher,
|
||||
const unsigned char *key, size_t keylen,
|
||||
unsigned int flags)
|
||||
{
|
||||
CMS_ContentInfo *cms;
|
||||
if (!cipher)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT, CMS_R_NO_CIPHER);
|
||||
return NULL;
|
||||
}
|
||||
cms = CMS_ContentInfo_new();
|
||||
if (!cms)
|
||||
return NULL;
|
||||
if (!CMS_EncryptedData_set1_key(cms, cipher, key, keylen))
|
||||
return NULL;
|
||||
|
||||
if(!(flags & CMS_DETACHED))
|
||||
{
|
||||
flags &= ~CMS_STREAM;
|
||||
CMS_set_detached(cms, 0);
|
||||
}
|
||||
|
||||
if ((flags & (CMS_STREAM|CMS_PARTIAL))
|
||||
|| CMS_final(cms, in, NULL, flags))
|
||||
return cms;
|
||||
|
||||
CMS_ContentInfo_free(cms);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int cms_signerinfo_verify_cert(CMS_SignerInfo *si,
|
||||
X509_STORE *store,
|
||||
STACK_OF(X509) *certs,
|
||||
STACK_OF(X509_CRL) *crls,
|
||||
unsigned int flags)
|
||||
{
|
||||
X509_STORE_CTX ctx;
|
||||
X509 *signer;
|
||||
int i, j, r = 0;
|
||||
CMS_SignerInfo_get0_algs(si, NULL, &signer, NULL, NULL);
|
||||
if (!X509_STORE_CTX_init(&ctx, store, signer, certs))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CERT,
|
||||
CMS_R_STORE_INIT_ERROR);
|
||||
goto err;
|
||||
}
|
||||
X509_STORE_CTX_set_purpose(&ctx, X509_PURPOSE_SMIME_SIGN);
|
||||
if (crls)
|
||||
X509_STORE_CTX_set0_crls(&ctx, crls);
|
||||
|
||||
i = X509_verify_cert(&ctx);
|
||||
if (i <= 0)
|
||||
{
|
||||
j = X509_STORE_CTX_get_error(&ctx);
|
||||
CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CERT,
|
||||
CMS_R_CERTIFICATE_VERIFY_ERROR);
|
||||
ERR_add_error_data(2, "Verify error:",
|
||||
X509_verify_cert_error_string(j));
|
||||
goto err;
|
||||
}
|
||||
r = 1;
|
||||
err:
|
||||
X509_STORE_CTX_cleanup(&ctx);
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs,
|
||||
X509_STORE *store, BIO *dcont, BIO *out, unsigned int flags)
|
||||
{
|
||||
CMS_SignerInfo *si;
|
||||
STACK_OF(CMS_SignerInfo) *sinfos;
|
||||
STACK_OF(X509) *cms_certs = NULL;
|
||||
STACK_OF(X509_CRL) *crls = NULL;
|
||||
X509 *signer;
|
||||
int i, scount = 0, ret = 0;
|
||||
BIO *cmsbio = NULL, *tmpin = NULL;
|
||||
|
||||
if (!dcont && !check_content(cms))
|
||||
return 0;
|
||||
|
||||
/* Attempt to find all signer certificates */
|
||||
|
||||
sinfos = CMS_get0_SignerInfos(cms);
|
||||
|
||||
if (sk_CMS_SignerInfo_num(sinfos) <= 0)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_VERIFY, CMS_R_NO_SIGNERS);
|
||||
goto err;
|
||||
}
|
||||
|
||||
for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++)
|
||||
{
|
||||
si = sk_CMS_SignerInfo_value(sinfos, i);
|
||||
CMS_SignerInfo_get0_algs(si, NULL, &signer, NULL, NULL);
|
||||
if (signer)
|
||||
scount++;
|
||||
}
|
||||
|
||||
if (scount != sk_CMS_SignerInfo_num(sinfos))
|
||||
scount += CMS_set1_signers_certs(cms, certs, flags);
|
||||
|
||||
if (scount != sk_CMS_SignerInfo_num(sinfos))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_VERIFY, CMS_R_SIGNER_CERTIFICATE_NOT_FOUND);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Attempt to verify all signers certs */
|
||||
|
||||
if (!(flags & CMS_NO_SIGNER_CERT_VERIFY))
|
||||
{
|
||||
cms_certs = CMS_get1_certs(cms);
|
||||
if (!(flags & CMS_NOCRL))
|
||||
crls = CMS_get1_crls(cms);
|
||||
for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++)
|
||||
{
|
||||
si = sk_CMS_SignerInfo_value(sinfos, i);
|
||||
if (!cms_signerinfo_verify_cert(si, store,
|
||||
cms_certs, crls, flags))
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
/* Attempt to verify all SignerInfo signed attribute signatures */
|
||||
|
||||
if (!(flags & CMS_NO_ATTR_VERIFY))
|
||||
{
|
||||
for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++)
|
||||
{
|
||||
si = sk_CMS_SignerInfo_value(sinfos, i);
|
||||
if (CMS_signed_get_attr_count(si) < 0)
|
||||
continue;
|
||||
if (CMS_SignerInfo_verify(si) <= 0)
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
/* Performance optimization: if the content is a memory BIO then
|
||||
* store its contents in a temporary read only memory BIO. This
|
||||
* avoids potentially large numbers of slow copies of data which will
|
||||
* occur when reading from a read write memory BIO when signatures
|
||||
* are calculated.
|
||||
*/
|
||||
|
||||
if (dcont && (BIO_method_type(dcont) == BIO_TYPE_MEM))
|
||||
{
|
||||
char *ptr;
|
||||
long len;
|
||||
len = BIO_get_mem_data(dcont, &ptr);
|
||||
tmpin = BIO_new_mem_buf(ptr, len);
|
||||
if (tmpin == NULL)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_VERIFY,ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
tmpin = dcont;
|
||||
|
||||
|
||||
cmsbio=CMS_dataInit(cms, tmpin);
|
||||
if (!cmsbio)
|
||||
goto err;
|
||||
|
||||
if (!cms_copy_content(out, cmsbio, flags))
|
||||
goto err;
|
||||
|
||||
if (!(flags & CMS_NO_CONTENT_VERIFY))
|
||||
{
|
||||
for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++)
|
||||
{
|
||||
si = sk_CMS_SignerInfo_value(sinfos, i);
|
||||
if (!CMS_SignerInfo_verify_content(si, cmsbio))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_VERIFY,
|
||||
CMS_R_CONTENT_VERIFY_ERROR);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
|
||||
if (dcont && (tmpin == dcont))
|
||||
do_free_upto(cmsbio, dcont);
|
||||
else
|
||||
BIO_free_all(cmsbio);
|
||||
|
||||
if (cms_certs)
|
||||
sk_X509_pop_free(cms_certs, X509_free);
|
||||
if (crls)
|
||||
sk_X509_CRL_pop_free(crls, X509_CRL_free);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CMS_verify_receipt(CMS_ContentInfo *rcms, CMS_ContentInfo *ocms,
|
||||
STACK_OF(X509) *certs,
|
||||
X509_STORE *store, unsigned int flags)
|
||||
{
|
||||
int r;
|
||||
r = CMS_verify(rcms, certs, store, NULL, NULL, flags);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
return cms_Receipt_verify(rcms, ocms);
|
||||
}
|
||||
|
||||
CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
|
||||
BIO *data, unsigned int flags)
|
||||
{
|
||||
CMS_ContentInfo *cms;
|
||||
int i;
|
||||
|
||||
cms = CMS_ContentInfo_new();
|
||||
if (!cms || !CMS_SignedData_init(cms))
|
||||
goto merr;
|
||||
|
||||
if (pkey && !CMS_add1_signer(cms, signcert, pkey, NULL, flags))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_SIGN, CMS_R_ADD_SIGNER_ERROR);
|
||||
goto err;
|
||||
}
|
||||
|
||||
for (i = 0; i < sk_X509_num(certs); i++)
|
||||
{
|
||||
X509 *x = sk_X509_value(certs, i);
|
||||
if (!CMS_add1_cert(cms, x))
|
||||
goto merr;
|
||||
}
|
||||
|
||||
if(!(flags & CMS_DETACHED))
|
||||
{
|
||||
flags &= ~CMS_STREAM;
|
||||
CMS_set_detached(cms, 0);
|
||||
}
|
||||
|
||||
if ((flags & (CMS_STREAM|CMS_PARTIAL))
|
||||
|| CMS_final(cms, data, NULL, flags))
|
||||
return cms;
|
||||
else
|
||||
goto err;
|
||||
|
||||
merr:
|
||||
CMSerr(CMS_F_CMS_SIGN, ERR_R_MALLOC_FAILURE);
|
||||
|
||||
err:
|
||||
if (cms)
|
||||
CMS_ContentInfo_free(cms);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si,
|
||||
X509 *signcert, EVP_PKEY *pkey,
|
||||
STACK_OF(X509) *certs,
|
||||
unsigned int flags)
|
||||
{
|
||||
CMS_SignerInfo *rct_si;
|
||||
CMS_ContentInfo *cms = NULL;
|
||||
ASN1_OCTET_STRING **pos, *os;
|
||||
BIO *rct_cont = NULL;
|
||||
int r = 0;
|
||||
|
||||
flags &= ~CMS_STREAM;
|
||||
/* Not really detached but avoids content being allocated */
|
||||
flags |= CMS_PARTIAL|CMS_BINARY|CMS_DETACHED;
|
||||
if (!pkey || !signcert)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_SIGN_RECEIPT, CMS_R_NO_KEY_OR_CERT);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Initialize signed data */
|
||||
|
||||
cms = CMS_sign(NULL, NULL, certs, NULL, flags);
|
||||
if (!cms)
|
||||
goto err;
|
||||
|
||||
/* Set inner content type to signed receipt */
|
||||
if (!CMS_set1_eContentType(cms, OBJ_nid2obj(NID_id_smime_ct_receipt)))
|
||||
goto err;
|
||||
|
||||
rct_si = CMS_add1_signer(cms, signcert, pkey, NULL, flags);
|
||||
if (!rct_si)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_SIGN_RECEIPT, CMS_R_ADD_SIGNER_ERROR);
|
||||
goto err;
|
||||
}
|
||||
|
||||
os = cms_encode_Receipt(si);
|
||||
|
||||
if (!os)
|
||||
goto err;
|
||||
|
||||
/* Set content to digest */
|
||||
rct_cont = BIO_new_mem_buf(os->data, os->length);
|
||||
if (!rct_cont)
|
||||
goto err;
|
||||
|
||||
/* Add msgSigDigest attribute */
|
||||
|
||||
if (!cms_msgSigDigest_add1(rct_si, si))
|
||||
goto err;
|
||||
|
||||
/* Finalize structure */
|
||||
if (!CMS_final(cms, rct_cont, NULL, flags))
|
||||
goto err;
|
||||
|
||||
/* Set embedded content */
|
||||
pos = CMS_get0_content(cms);
|
||||
*pos = os;
|
||||
|
||||
r = 1;
|
||||
|
||||
err:
|
||||
if (rct_cont)
|
||||
BIO_free(rct_cont);
|
||||
if (r)
|
||||
return cms;
|
||||
CMS_ContentInfo_free(cms);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *data,
|
||||
const EVP_CIPHER *cipher, unsigned int flags)
|
||||
{
|
||||
CMS_ContentInfo *cms;
|
||||
int i;
|
||||
X509 *recip;
|
||||
cms = CMS_EnvelopedData_create(cipher);
|
||||
if (!cms)
|
||||
goto merr;
|
||||
for (i = 0; i < sk_X509_num(certs); i++)
|
||||
{
|
||||
recip = sk_X509_value(certs, i);
|
||||
if (!CMS_add1_recipient_cert(cms, recip, flags))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_ENCRYPT, CMS_R_RECIPIENT_ERROR);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if(!(flags & CMS_DETACHED))
|
||||
{
|
||||
flags &= ~CMS_STREAM;
|
||||
CMS_set_detached(cms, 0);
|
||||
}
|
||||
|
||||
if ((flags & (CMS_STREAM|CMS_PARTIAL))
|
||||
|| CMS_final(cms, data, NULL, flags))
|
||||
return cms;
|
||||
else
|
||||
goto err;
|
||||
|
||||
merr:
|
||||
CMSerr(CMS_F_CMS_ENCRYPT, ERR_R_MALLOC_FAILURE);
|
||||
err:
|
||||
if (cms)
|
||||
CMS_ContentInfo_free(cms);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert)
|
||||
{
|
||||
STACK_OF(CMS_RecipientInfo) *ris;
|
||||
CMS_RecipientInfo *ri;
|
||||
int i, r;
|
||||
ris = CMS_get0_RecipientInfos(cms);
|
||||
for (i = 0; i < sk_CMS_RecipientInfo_num(ris); i++)
|
||||
{
|
||||
ri = sk_CMS_RecipientInfo_value(ris, i);
|
||||
if (CMS_RecipientInfo_type(ri) != CMS_RECIPINFO_TRANS)
|
||||
continue;
|
||||
/* If we have a cert try matching RecipientInfo
|
||||
* otherwise try them all.
|
||||
*/
|
||||
if (!cert || (CMS_RecipientInfo_ktri_cert_cmp(ri, cert) == 0))
|
||||
{
|
||||
CMS_RecipientInfo_set0_pkey(ri, pk);
|
||||
r = CMS_RecipientInfo_decrypt(cms, ri);
|
||||
CMS_RecipientInfo_set0_pkey(ri, NULL);
|
||||
if (r > 0)
|
||||
return 1;
|
||||
if (cert)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_DECRYPT_SET1_PKEY,
|
||||
CMS_R_DECRYPT_ERROR);
|
||||
return 0;
|
||||
}
|
||||
ERR_clear_error();
|
||||
}
|
||||
}
|
||||
|
||||
CMSerr(CMS_F_CMS_DECRYPT_SET1_PKEY, CMS_R_NO_MATCHING_RECIPIENT);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int CMS_decrypt_set1_key(CMS_ContentInfo *cms,
|
||||
unsigned char *key, size_t keylen,
|
||||
unsigned char *id, size_t idlen)
|
||||
{
|
||||
STACK_OF(CMS_RecipientInfo) *ris;
|
||||
CMS_RecipientInfo *ri;
|
||||
int i, r;
|
||||
ris = CMS_get0_RecipientInfos(cms);
|
||||
for (i = 0; i < sk_CMS_RecipientInfo_num(ris); i++)
|
||||
{
|
||||
ri = sk_CMS_RecipientInfo_value(ris, i);
|
||||
if (CMS_RecipientInfo_type(ri) != CMS_RECIPINFO_KEK)
|
||||
continue;
|
||||
|
||||
/* If we have an id try matching RecipientInfo
|
||||
* otherwise try them all.
|
||||
*/
|
||||
if (!id || (CMS_RecipientInfo_kekri_id_cmp(ri, id, idlen) == 0))
|
||||
{
|
||||
CMS_RecipientInfo_set0_key(ri, key, keylen);
|
||||
r = CMS_RecipientInfo_decrypt(cms, ri);
|
||||
CMS_RecipientInfo_set0_key(ri, NULL, 0);
|
||||
if (r > 0)
|
||||
return 1;
|
||||
if (id)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_DECRYPT_SET1_KEY,
|
||||
CMS_R_DECRYPT_ERROR);
|
||||
return 0;
|
||||
}
|
||||
ERR_clear_error();
|
||||
}
|
||||
}
|
||||
|
||||
CMSerr(CMS_F_CMS_DECRYPT_SET1_KEY, CMS_R_NO_MATCHING_RECIPIENT);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert,
|
||||
BIO *dcont, BIO *out,
|
||||
unsigned int flags)
|
||||
{
|
||||
int r;
|
||||
BIO *cont;
|
||||
if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_enveloped)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_DECRYPT, CMS_R_TYPE_NOT_ENVELOPED_DATA);
|
||||
return 0;
|
||||
}
|
||||
if (!dcont && !check_content(cms))
|
||||
return 0;
|
||||
if (pk && !CMS_decrypt_set1_pkey(cms, pk, cert))
|
||||
return 0;
|
||||
|
||||
cont = CMS_dataInit(cms, dcont);
|
||||
if (!cont)
|
||||
return 0;
|
||||
r = cms_copy_content(out, cont, flags);
|
||||
do_free_upto(cont, dcont);
|
||||
return r;
|
||||
}
|
||||
|
||||
int CMS_final(CMS_ContentInfo *cms, BIO *data, BIO *dcont, unsigned int flags)
|
||||
{
|
||||
BIO *cmsbio;
|
||||
int ret = 0;
|
||||
if (!(cmsbio = CMS_dataInit(cms, dcont)))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_FINAL,ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SMIME_crlf_copy(data, cmsbio, flags);
|
||||
|
||||
(void)BIO_flush(cmsbio);
|
||||
|
||||
|
||||
if (!CMS_dataFinal(cms, cmsbio))
|
||||
{
|
||||
CMSerr(CMS_F_CMS_FINAL,CMS_R_CMS_DATAFINAL_ERROR);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
do_free_upto(cmsbio, dcont);
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
#ifdef ZLIB
|
||||
|
||||
int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out,
|
||||
unsigned int flags)
|
||||
{
|
||||
BIO *cont;
|
||||
int r;
|
||||
if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_id_smime_ct_compressedData)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_UNCOMPRESS,
|
||||
CMS_R_TYPE_NOT_COMPRESSED_DATA);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!dcont && !check_content(cms))
|
||||
return 0;
|
||||
|
||||
cont = CMS_dataInit(cms, dcont);
|
||||
if (!cont)
|
||||
return 0;
|
||||
r = cms_copy_content(out, cont, flags);
|
||||
do_free_upto(cont, dcont);
|
||||
return r;
|
||||
}
|
||||
|
||||
CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags)
|
||||
{
|
||||
CMS_ContentInfo *cms;
|
||||
if (comp_nid <= 0)
|
||||
comp_nid = NID_zlib_compression;
|
||||
cms = cms_CompressedData_create(comp_nid);
|
||||
if (!cms)
|
||||
return NULL;
|
||||
|
||||
if(!(flags & CMS_DETACHED))
|
||||
{
|
||||
flags &= ~CMS_STREAM;
|
||||
CMS_set_detached(cms, 0);
|
||||
}
|
||||
|
||||
if (CMS_final(cms, in, NULL, flags))
|
||||
return cms;
|
||||
|
||||
CMS_ContentInfo_free(cms);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out,
|
||||
unsigned int flags)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_UNCOMPRESS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags)
|
||||
{
|
||||
CMSerr(CMS_F_CMS_COMPRESS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
@ -105,6 +105,7 @@ typedef int (*deflateEnd_ft)(z_streamp strm);
|
||||
typedef int (*deflate_ft)(z_streamp strm, int flush);
|
||||
typedef int (*deflateInit__ft)(z_streamp strm, int level,
|
||||
const char * version, int stream_size);
|
||||
typedef const char * (*zError__ft)(int err);
|
||||
static compress_ft p_compress=NULL;
|
||||
static inflateEnd_ft p_inflateEnd=NULL;
|
||||
static inflate_ft p_inflate=NULL;
|
||||
@ -112,6 +113,7 @@ static inflateInit__ft p_inflateInit_=NULL;
|
||||
static deflateEnd_ft p_deflateEnd=NULL;
|
||||
static deflate_ft p_deflate=NULL;
|
||||
static deflateInit__ft p_deflateInit_=NULL;
|
||||
static zError__ft p_zError=NULL;
|
||||
|
||||
static int zlib_loaded = 0; /* only attempt to init func pts once */
|
||||
static DSO *zlib_dso = NULL;
|
||||
@ -123,6 +125,7 @@ static DSO *zlib_dso = NULL;
|
||||
#define deflateEnd p_deflateEnd
|
||||
#define deflate p_deflate
|
||||
#define deflateInit_ p_deflateInit_
|
||||
#define zError p_zError
|
||||
#endif /* ZLIB_SHARED */
|
||||
|
||||
struct zlib_state
|
||||
@ -373,10 +376,13 @@ COMP_METHOD *COMP_zlib(void)
|
||||
p_deflateInit_
|
||||
= (deflateInit__ft) DSO_bind_func(zlib_dso,
|
||||
"deflateInit_");
|
||||
p_zError
|
||||
= (zError__ft) DSO_bind_func(zlib_dso,
|
||||
"zError");
|
||||
|
||||
if (p_compress && p_inflateEnd && p_inflate
|
||||
&& p_inflateInit_ && p_deflateEnd
|
||||
&& p_deflate && p_deflateInit_)
|
||||
&& p_deflate && p_deflateInit_ && p_zError)
|
||||
zlib_loaded++;
|
||||
}
|
||||
}
|
||||
@ -410,3 +416,386 @@ err:
|
||||
return(meth);
|
||||
}
|
||||
|
||||
void COMP_zlib_cleanup(void)
|
||||
{
|
||||
#ifdef ZLIB_SHARED
|
||||
if (zlib_dso)
|
||||
DSO_free(zlib_dso);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ZLIB
|
||||
|
||||
/* Zlib based compression/decompression filter BIO */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned char *ibuf; /* Input buffer */
|
||||
int ibufsize; /* Buffer size */
|
||||
z_stream zin; /* Input decompress context */
|
||||
unsigned char *obuf; /* Output buffer */
|
||||
int obufsize; /* Output buffer size */
|
||||
unsigned char *optr; /* Position in output buffer */
|
||||
int ocount; /* Amount of data in output buffer */
|
||||
int odone; /* deflate EOF */
|
||||
int comp_level; /* Compression level to use */
|
||||
z_stream zout; /* Output compression context */
|
||||
} BIO_ZLIB_CTX;
|
||||
|
||||
#define ZLIB_DEFAULT_BUFSIZE 1024
|
||||
|
||||
static int bio_zlib_new(BIO *bi);
|
||||
static int bio_zlib_free(BIO *bi);
|
||||
static int bio_zlib_read(BIO *b, char *out, int outl);
|
||||
static int bio_zlib_write(BIO *b, const char *in, int inl);
|
||||
static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr);
|
||||
static long bio_zlib_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp);
|
||||
|
||||
static BIO_METHOD bio_meth_zlib =
|
||||
{
|
||||
BIO_TYPE_COMP,
|
||||
"zlib",
|
||||
bio_zlib_write,
|
||||
bio_zlib_read,
|
||||
NULL,
|
||||
NULL,
|
||||
bio_zlib_ctrl,
|
||||
bio_zlib_new,
|
||||
bio_zlib_free,
|
||||
bio_zlib_callback_ctrl
|
||||
};
|
||||
|
||||
BIO_METHOD *BIO_f_zlib(void)
|
||||
{
|
||||
return &bio_meth_zlib;
|
||||
}
|
||||
|
||||
|
||||
static int bio_zlib_new(BIO *bi)
|
||||
{
|
||||
BIO_ZLIB_CTX *ctx;
|
||||
#ifdef ZLIB_SHARED
|
||||
(void)COMP_zlib();
|
||||
if (!zlib_loaded)
|
||||
{
|
||||
COMPerr(COMP_F_BIO_ZLIB_NEW, COMP_R_ZLIB_NOT_SUPPORTED);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
ctx = OPENSSL_malloc(sizeof(BIO_ZLIB_CTX));
|
||||
if(!ctx)
|
||||
{
|
||||
COMPerr(COMP_F_BIO_ZLIB_NEW, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
ctx->ibuf = NULL;
|
||||
ctx->obuf = NULL;
|
||||
ctx->ibufsize = ZLIB_DEFAULT_BUFSIZE;
|
||||
ctx->obufsize = ZLIB_DEFAULT_BUFSIZE;
|
||||
ctx->zin.zalloc = Z_NULL;
|
||||
ctx->zin.zfree = Z_NULL;
|
||||
ctx->zin.next_in = NULL;
|
||||
ctx->zin.avail_in = 0;
|
||||
ctx->zin.next_out = NULL;
|
||||
ctx->zin.avail_out = 0;
|
||||
ctx->zout.zalloc = Z_NULL;
|
||||
ctx->zout.zfree = Z_NULL;
|
||||
ctx->zout.next_in = NULL;
|
||||
ctx->zout.avail_in = 0;
|
||||
ctx->zout.next_out = NULL;
|
||||
ctx->zout.avail_out = 0;
|
||||
ctx->odone = 0;
|
||||
ctx->comp_level = Z_DEFAULT_COMPRESSION;
|
||||
bi->init = 1;
|
||||
bi->ptr = (char *)ctx;
|
||||
bi->flags = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int bio_zlib_free(BIO *bi)
|
||||
{
|
||||
BIO_ZLIB_CTX *ctx;
|
||||
if(!bi) return 0;
|
||||
ctx = (BIO_ZLIB_CTX *)bi->ptr;
|
||||
if(ctx->ibuf)
|
||||
{
|
||||
/* Destroy decompress context */
|
||||
inflateEnd(&ctx->zin);
|
||||
OPENSSL_free(ctx->ibuf);
|
||||
}
|
||||
if(ctx->obuf)
|
||||
{
|
||||
/* Destroy compress context */
|
||||
deflateEnd(&ctx->zout);
|
||||
OPENSSL_free(ctx->obuf);
|
||||
}
|
||||
OPENSSL_free(ctx);
|
||||
bi->ptr = NULL;
|
||||
bi->init = 0;
|
||||
bi->flags = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int bio_zlib_read(BIO *b, char *out, int outl)
|
||||
{
|
||||
BIO_ZLIB_CTX *ctx;
|
||||
int ret;
|
||||
z_stream *zin;
|
||||
if(!out || !outl) return 0;
|
||||
ctx = (BIO_ZLIB_CTX *)b->ptr;
|
||||
zin = &ctx->zin;
|
||||
BIO_clear_retry_flags(b);
|
||||
if(!ctx->ibuf)
|
||||
{
|
||||
ctx->ibuf = OPENSSL_malloc(ctx->ibufsize);
|
||||
if(!ctx->ibuf)
|
||||
{
|
||||
COMPerr(COMP_F_BIO_ZLIB_READ, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
inflateInit(zin);
|
||||
zin->next_in = ctx->ibuf;
|
||||
zin->avail_in = 0;
|
||||
}
|
||||
|
||||
/* Copy output data directly to supplied buffer */
|
||||
zin->next_out = (unsigned char *)out;
|
||||
zin->avail_out = (unsigned int)outl;
|
||||
for(;;)
|
||||
{
|
||||
/* Decompress while data available */
|
||||
while(zin->avail_in)
|
||||
{
|
||||
ret = inflate(zin, 0);
|
||||
if((ret != Z_OK) && (ret != Z_STREAM_END))
|
||||
{
|
||||
COMPerr(COMP_F_BIO_ZLIB_READ,
|
||||
COMP_R_ZLIB_INFLATE_ERROR);
|
||||
ERR_add_error_data(2, "zlib error:",
|
||||
zError(ret));
|
||||
return 0;
|
||||
}
|
||||
/* If EOF or we've read everything then return */
|
||||
if((ret == Z_STREAM_END) || !zin->avail_out)
|
||||
return outl - zin->avail_out;
|
||||
}
|
||||
|
||||
/* No data in input buffer try to read some in,
|
||||
* if an error then return the total data read.
|
||||
*/
|
||||
ret = BIO_read(b->next_bio, ctx->ibuf, ctx->ibufsize);
|
||||
if(ret <= 0)
|
||||
{
|
||||
/* Total data read */
|
||||
int tot = outl - zin->avail_out;
|
||||
BIO_copy_next_retry(b);
|
||||
if(ret < 0) return (tot > 0) ? tot : ret;
|
||||
return tot;
|
||||
}
|
||||
zin->avail_in = ret;
|
||||
zin->next_in = ctx->ibuf;
|
||||
}
|
||||
}
|
||||
|
||||
static int bio_zlib_write(BIO *b, const char *in, int inl)
|
||||
{
|
||||
BIO_ZLIB_CTX *ctx;
|
||||
int ret;
|
||||
z_stream *zout;
|
||||
if(!in || !inl) return 0;
|
||||
ctx = (BIO_ZLIB_CTX *)b->ptr;
|
||||
if(ctx->odone) return 0;
|
||||
zout = &ctx->zout;
|
||||
BIO_clear_retry_flags(b);
|
||||
if(!ctx->obuf)
|
||||
{
|
||||
ctx->obuf = OPENSSL_malloc(ctx->obufsize);
|
||||
/* Need error here */
|
||||
if(!ctx->obuf)
|
||||
{
|
||||
COMPerr(COMP_F_BIO_ZLIB_WRITE, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
ctx->optr = ctx->obuf;
|
||||
ctx->ocount = 0;
|
||||
deflateInit(zout, ctx->comp_level);
|
||||
zout->next_out = ctx->obuf;
|
||||
zout->avail_out = ctx->obufsize;
|
||||
}
|
||||
/* Obtain input data directly from supplied buffer */
|
||||
zout->next_in = (void *)in;
|
||||
zout->avail_in = inl;
|
||||
for(;;)
|
||||
{
|
||||
/* If data in output buffer write it first */
|
||||
while(ctx->ocount) {
|
||||
ret = BIO_write(b->next_bio, ctx->optr, ctx->ocount);
|
||||
if(ret <= 0)
|
||||
{
|
||||
/* Total data written */
|
||||
int tot = inl - zout->avail_in;
|
||||
BIO_copy_next_retry(b);
|
||||
if(ret < 0) return (tot > 0) ? tot : ret;
|
||||
return tot;
|
||||
}
|
||||
ctx->optr += ret;
|
||||
ctx->ocount -= ret;
|
||||
}
|
||||
|
||||
/* Have we consumed all supplied data? */
|
||||
if(!zout->avail_in)
|
||||
return inl;
|
||||
|
||||
/* Compress some more */
|
||||
|
||||
/* Reset buffer */
|
||||
ctx->optr = ctx->obuf;
|
||||
zout->next_out = ctx->obuf;
|
||||
zout->avail_out = ctx->obufsize;
|
||||
/* Compress some more */
|
||||
ret = deflate(zout, 0);
|
||||
if(ret != Z_OK)
|
||||
{
|
||||
COMPerr(COMP_F_BIO_ZLIB_WRITE,
|
||||
COMP_R_ZLIB_DEFLATE_ERROR);
|
||||
ERR_add_error_data(2, "zlib error:", zError(ret));
|
||||
return 0;
|
||||
}
|
||||
ctx->ocount = ctx->obufsize - zout->avail_out;
|
||||
}
|
||||
}
|
||||
|
||||
static int bio_zlib_flush(BIO *b)
|
||||
{
|
||||
BIO_ZLIB_CTX *ctx;
|
||||
int ret;
|
||||
z_stream *zout;
|
||||
ctx = (BIO_ZLIB_CTX *)b->ptr;
|
||||
/* If no data written or already flush show success */
|
||||
if(!ctx->obuf || (ctx->odone && !ctx->ocount)) return 1;
|
||||
zout = &ctx->zout;
|
||||
BIO_clear_retry_flags(b);
|
||||
/* No more input data */
|
||||
zout->next_in = NULL;
|
||||
zout->avail_in = 0;
|
||||
for(;;)
|
||||
{
|
||||
/* If data in output buffer write it first */
|
||||
while(ctx->ocount)
|
||||
{
|
||||
ret = BIO_write(b->next_bio, ctx->optr, ctx->ocount);
|
||||
if(ret <= 0)
|
||||
{
|
||||
BIO_copy_next_retry(b);
|
||||
return ret;
|
||||
}
|
||||
ctx->optr += ret;
|
||||
ctx->ocount -= ret;
|
||||
}
|
||||
if(ctx->odone) return 1;
|
||||
|
||||
/* Compress some more */
|
||||
|
||||
/* Reset buffer */
|
||||
ctx->optr = ctx->obuf;
|
||||
zout->next_out = ctx->obuf;
|
||||
zout->avail_out = ctx->obufsize;
|
||||
/* Compress some more */
|
||||
ret = deflate(zout, Z_FINISH);
|
||||
if(ret == Z_STREAM_END) ctx->odone = 1;
|
||||
else if(ret != Z_OK)
|
||||
{
|
||||
COMPerr(COMP_F_BIO_ZLIB_FLUSH,
|
||||
COMP_R_ZLIB_DEFLATE_ERROR);
|
||||
ERR_add_error_data(2, "zlib error:", zError(ret));
|
||||
return 0;
|
||||
}
|
||||
ctx->ocount = ctx->obufsize - zout->avail_out;
|
||||
}
|
||||
}
|
||||
|
||||
static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
{
|
||||
BIO_ZLIB_CTX *ctx;
|
||||
int ret, *ip;
|
||||
int ibs, obs;
|
||||
if(!b->next_bio) return 0;
|
||||
ctx = (BIO_ZLIB_CTX *)b->ptr;
|
||||
switch (cmd)
|
||||
{
|
||||
|
||||
case BIO_CTRL_RESET:
|
||||
ctx->ocount = 0;
|
||||
ctx->odone = 0;
|
||||
break;
|
||||
|
||||
case BIO_CTRL_FLUSH:
|
||||
ret = bio_zlib_flush(b);
|
||||
if (ret > 0)
|
||||
ret = BIO_flush(b->next_bio);
|
||||
break;
|
||||
|
||||
case BIO_C_SET_BUFF_SIZE:
|
||||
ibs = -1;
|
||||
obs = -1;
|
||||
if (ptr != NULL)
|
||||
{
|
||||
ip = ptr;
|
||||
if (*ip == 0)
|
||||
ibs = (int) num;
|
||||
else
|
||||
obs = (int) num;
|
||||
}
|
||||
else
|
||||
{
|
||||
ibs = (int)num;
|
||||
obs = ibs;
|
||||
}
|
||||
|
||||
if (ibs != -1)
|
||||
{
|
||||
if (ctx->ibuf)
|
||||
{
|
||||
OPENSSL_free(ctx->ibuf);
|
||||
ctx->ibuf = NULL;
|
||||
}
|
||||
ctx->ibufsize = ibs;
|
||||
}
|
||||
|
||||
if (obs != -1)
|
||||
{
|
||||
if (ctx->obuf)
|
||||
{
|
||||
OPENSSL_free(ctx->obuf);
|
||||
ctx->obuf = NULL;
|
||||
}
|
||||
ctx->obufsize = obs;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case BIO_C_DO_STATE_MACHINE:
|
||||
BIO_clear_retry_flags(b);
|
||||
ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
|
||||
BIO_copy_next_retry(b);
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static long bio_zlib_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
|
||||
{
|
||||
if(!b->next_bio)
|
||||
return 0;
|
||||
return
|
||||
BIO_callback_ctrl(b->next_bio, cmd, fp);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -47,6 +47,13 @@ int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
|
||||
unsigned char *in, int ilen);
|
||||
COMP_METHOD *COMP_rle(void );
|
||||
COMP_METHOD *COMP_zlib(void );
|
||||
void COMP_zlib_cleanup(void);
|
||||
|
||||
#ifdef HEADER_BIO_H
|
||||
#ifdef ZLIB
|
||||
BIO_METHOD *BIO_f_zlib(void);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
@ -57,8 +64,15 @@ void ERR_load_COMP_strings(void);
|
||||
/* Error codes for the COMP functions. */
|
||||
|
||||
/* Function codes. */
|
||||
#define COMP_F_BIO_ZLIB_FLUSH 99
|
||||
#define COMP_F_BIO_ZLIB_NEW 100
|
||||
#define COMP_F_BIO_ZLIB_READ 101
|
||||
#define COMP_F_BIO_ZLIB_WRITE 102
|
||||
|
||||
/* Reason codes. */
|
||||
#define COMP_R_ZLIB_DEFLATE_ERROR 99
|
||||
#define COMP_R_ZLIB_INFLATE_ERROR 100
|
||||
#define COMP_R_ZLIB_NOT_SUPPORTED 101
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* crypto/comp/comp_err.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
|
||||
* Copyright (c) 1999-2008 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -70,11 +70,18 @@
|
||||
|
||||
static ERR_STRING_DATA COMP_str_functs[]=
|
||||
{
|
||||
{ERR_FUNC(COMP_F_BIO_ZLIB_FLUSH), "BIO_ZLIB_FLUSH"},
|
||||
{ERR_FUNC(COMP_F_BIO_ZLIB_NEW), "BIO_ZLIB_NEW"},
|
||||
{ERR_FUNC(COMP_F_BIO_ZLIB_READ), "BIO_ZLIB_READ"},
|
||||
{ERR_FUNC(COMP_F_BIO_ZLIB_WRITE), "BIO_ZLIB_WRITE"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
static ERR_STRING_DATA COMP_str_reasons[]=
|
||||
{
|
||||
{ERR_REASON(COMP_R_ZLIB_DEFLATE_ERROR) ,"zlib deflate error"},
|
||||
{ERR_REASON(COMP_R_ZLIB_INFLATE_ERROR) ,"zlib inflate error"},
|
||||
{ERR_REASON(COMP_R_ZLIB_NOT_SUPPORTED) ,"zlib not supported"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
|
@ -195,9 +195,10 @@ void DES_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out,
|
||||
long length,DES_key_schedule *ks1,
|
||||
DES_key_schedule *ks2,DES_key_schedule *ks3,
|
||||
DES_cblock *ivec,int *num);
|
||||
|
||||
#if 0
|
||||
void DES_xwhite_in2out(const_DES_cblock *DES_key,const_DES_cblock *in_white,
|
||||
DES_cblock *out_white);
|
||||
#endif
|
||||
|
||||
int DES_enc_read(int fd,void *buf,int len,DES_key_schedule *sched,
|
||||
DES_cblock *iv);
|
||||
|
@ -169,11 +169,13 @@ void _ossl_old_des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
|
||||
(DES_key_schedule *)ks3, ivec, num);
|
||||
}
|
||||
|
||||
#if 0 /* broken code, preserved just in case anyone specifically looks for this */
|
||||
void _ossl_old_des_xwhite_in2out(_ossl_old_des_cblock (*des_key), _ossl_old_des_cblock (*in_white),
|
||||
_ossl_old_des_cblock (*out_white))
|
||||
{
|
||||
DES_xwhite_in2out(des_key, in_white, out_white);
|
||||
}
|
||||
#endif
|
||||
|
||||
int _ossl_old_des_enc_read(int fd,char *buf,int len,des_key_schedule sched,
|
||||
_ossl_old_des_cblock *iv)
|
||||
|
@ -364,9 +364,10 @@ void _ossl_old_des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
|
||||
void _ossl_old_des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
|
||||
long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2,
|
||||
_ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num);
|
||||
|
||||
#if 0
|
||||
void _ossl_old_des_xwhite_in2out(_ossl_old_des_cblock (*des_key), _ossl_old_des_cblock (*in_white),
|
||||
_ossl_old_des_cblock (*out_white));
|
||||
#endif
|
||||
|
||||
int _ossl_old_des_enc_read(int fd,char *buf,int len,_ossl_old_des_key_schedule sched,
|
||||
_ossl_old_des_cblock *iv);
|
||||
|
@ -63,7 +63,10 @@
|
||||
* 1.1 added norm_expand_bits
|
||||
* 1.0 First working version
|
||||
*/
|
||||
#ifdef OPENSSL_FIPS
|
||||
#include <openssl/fips.h>
|
||||
#endif
|
||||
|
||||
#include "des_locl.h"
|
||||
|
||||
OPENSSL_IMPLEMENT_GLOBAL(int,DES_check_key); /* defaults to false */
|
||||
|
@ -60,6 +60,7 @@
|
||||
|
||||
/* RSA's DESX */
|
||||
|
||||
#if 0 /* broken code, preserved just in case anyone specifically looks for this */
|
||||
static unsigned char desx_white_in2out[256]={
|
||||
0xBD,0x56,0xEA,0xF2,0xA2,0xF1,0xAC,0x2A,0xB0,0x93,0xD1,0x9C,0x1B,0x33,0xFD,0xD0,
|
||||
0x30,0x04,0xB6,0xDC,0x7D,0xDF,0x32,0x4B,0xF7,0xCB,0x45,0x9B,0x31,0xBB,0x21,0x5A,
|
||||
@ -98,7 +99,7 @@ void DES_xwhite_in2out(const_DES_cblock *des_key, const_DES_cblock *in_white,
|
||||
}
|
||||
|
||||
out0=out[0];
|
||||
out1=out[i];
|
||||
out1=out[i]; /* BUG: out-of-bounds read */
|
||||
for (i=0; i<8; i++)
|
||||
{
|
||||
out[i]=in[i]^desx_white_in2out[out0^out1];
|
||||
@ -106,6 +107,7 @@ void DES_xwhite_in2out(const_DES_cblock *des_key, const_DES_cblock *in_white,
|
||||
out1=(int)out[i&0x07];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void DES_xcbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, DES_key_schedule *schedule,
|
||||
|
@ -61,7 +61,10 @@
|
||||
#include <openssl/dsa.h>
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#ifdef OPENSSL_FIPS
|
||||
#include <openssl/fips.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* Override the default new methods */
|
||||
static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
|
||||
|
@ -64,7 +64,10 @@
|
||||
#include <openssl/dsa.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/asn1.h>
|
||||
#ifdef OPENSSL_FIPS
|
||||
#include <openssl/fips.h>
|
||||
#endif
|
||||
|
||||
|
||||
DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
|
||||
{
|
||||
|
@ -64,7 +64,10 @@
|
||||
#include <openssl/dsa.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/asn1.h>
|
||||
#ifdef OPENSSL_FIPS
|
||||
#include <openssl/fips.h>
|
||||
#endif
|
||||
|
||||
#include <openssl/asn1_mac.h>
|
||||
|
||||
int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
|
||||
|
@ -107,6 +107,9 @@ void ENGINE_load_builtin_engines(void)
|
||||
#if defined(__OpenBSD__) || defined(__FreeBSD__)
|
||||
ENGINE_load_cryptodev();
|
||||
#endif
|
||||
#if defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_NO_CAPIENG)
|
||||
ENGINE_load_capi();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* crypto/engine/eng_err.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
|
||||
* Copyright (c) 1999-2008 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -92,6 +92,7 @@ static ERR_STRING_DATA ENGINE_str_functs[]=
|
||||
{ERR_FUNC(ENGINE_F_ENGINE_LIST_REMOVE), "ENGINE_LIST_REMOVE"},
|
||||
{ERR_FUNC(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY), "ENGINE_load_private_key"},
|
||||
{ERR_FUNC(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY), "ENGINE_load_public_key"},
|
||||
{ERR_FUNC(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT), "ENGINE_load_ssl_client_cert"},
|
||||
{ERR_FUNC(ENGINE_F_ENGINE_NEW), "ENGINE_new"},
|
||||
{ERR_FUNC(ENGINE_F_ENGINE_REMOVE), "ENGINE_remove"},
|
||||
{ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_STRING), "ENGINE_set_default_string"},
|
||||
|
@ -170,6 +170,8 @@ struct engine_st
|
||||
ENGINE_LOAD_KEY_PTR load_privkey;
|
||||
ENGINE_LOAD_KEY_PTR load_pubkey;
|
||||
|
||||
ENGINE_SSL_CLIENT_CERT_PTR load_ssl_client_cert;
|
||||
|
||||
const ENGINE_CMD_DEFN *cmd_defns;
|
||||
int flags;
|
||||
/* reference count on the structure itself */
|
||||
|
@ -126,6 +126,9 @@ void ENGINE_load_padlock (void)
|
||||
#ifdef _MSC_VER
|
||||
# include <malloc.h>
|
||||
# define alloca _alloca
|
||||
#elif defined(NETWARE_CLIB) && defined(__GNUC__)
|
||||
void *alloca(size_t);
|
||||
# define alloca(s) __builtin_alloca(s)
|
||||
#else
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
@ -231,8 +234,8 @@ padlock_bind_fn(ENGINE *e, const char *id)
|
||||
return 1;
|
||||
}
|
||||
|
||||
IMPLEMENT_DYNAMIC_CHECK_FN ()
|
||||
IMPLEMENT_DYNAMIC_BIND_FN (padlock_bind_fn)
|
||||
IMPLEMENT_DYNAMIC_CHECK_FN()
|
||||
IMPLEMENT_DYNAMIC_BIND_FN(padlock_bind_fn)
|
||||
#endif /* DYNAMIC_ENGINE */
|
||||
|
||||
/* ===== Here comes the "real" engine ===== */
|
||||
|
@ -69,6 +69,13 @@ int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ENGINE_set_load_ssl_client_cert_function(ENGINE *e,
|
||||
ENGINE_SSL_CLIENT_CERT_PTR loadssl_f)
|
||||
{
|
||||
e->load_ssl_client_cert = loadssl_f;
|
||||
return 1;
|
||||
}
|
||||
|
||||
ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e)
|
||||
{
|
||||
return e->load_privkey;
|
||||
@ -79,6 +86,11 @@ ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e)
|
||||
return e->load_pubkey;
|
||||
}
|
||||
|
||||
ENGINE_SSL_CLIENT_CERT_PTR ENGINE_get_ssl_client_cert_function(const ENGINE *e)
|
||||
{
|
||||
return e->load_ssl_client_cert;
|
||||
}
|
||||
|
||||
/* API functions to load public/private keys */
|
||||
|
||||
EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
|
||||
@ -152,3 +164,33 @@ EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
|
||||
}
|
||||
return pkey;
|
||||
}
|
||||
|
||||
int ENGINE_load_ssl_client_cert(ENGINE *e, SSL *s,
|
||||
STACK_OF(X509_NAME) *ca_dn, X509 **pcert, EVP_PKEY **ppkey,
|
||||
STACK_OF(X509) **pother, UI_METHOD *ui_method, void *callback_data)
|
||||
{
|
||||
|
||||
if(e == NULL)
|
||||
{
|
||||
ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT,
|
||||
ERR_R_PASSED_NULL_PARAMETER);
|
||||
return 0;
|
||||
}
|
||||
CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
|
||||
if(e->funct_ref == 0)
|
||||
{
|
||||
CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
|
||||
ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT,
|
||||
ENGINE_R_NOT_INITIALISED);
|
||||
return 0;
|
||||
}
|
||||
CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
|
||||
if (!e->load_ssl_client_cert)
|
||||
{
|
||||
ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT,
|
||||
ENGINE_R_NO_LOAD_FUNCTION);
|
||||
return 0;
|
||||
}
|
||||
return e->load_ssl_client_cert(e, s, ca_dn, pcert, ppkey, pother,
|
||||
ui_method, callback_data);
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
|
||||
{
|
||||
fnd = OPENSSL_malloc(sizeof(ENGINE_PILE));
|
||||
if(!fnd) goto end;
|
||||
fnd->uptodate = 0;
|
||||
fnd->uptodate = 1;
|
||||
fnd->nid = *nids;
|
||||
fnd->sk = sk_ENGINE_new_null();
|
||||
if(!fnd->sk)
|
||||
@ -152,7 +152,7 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
|
||||
if(!sk_ENGINE_push(fnd->sk, e))
|
||||
goto end;
|
||||
/* "touch" this ENGINE_PILE */
|
||||
fnd->uptodate = 1;
|
||||
fnd->uptodate = 0;
|
||||
if(setdefault)
|
||||
{
|
||||
if(!engine_unlocked_init(e))
|
||||
@ -164,6 +164,7 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
|
||||
if(fnd->funct)
|
||||
engine_unlocked_finish(fnd->funct, 0);
|
||||
fnd->funct = e;
|
||||
fnd->uptodate = 1;
|
||||
}
|
||||
nids++;
|
||||
}
|
||||
@ -179,8 +180,7 @@ static void int_unregister_cb(ENGINE_PILE *pile, ENGINE *e)
|
||||
while((n = sk_ENGINE_find(pile->sk, e)) >= 0)
|
||||
{
|
||||
(void)sk_ENGINE_delete(pile->sk, n);
|
||||
/* "touch" this ENGINE_CIPHER */
|
||||
pile->uptodate = 1;
|
||||
pile->uptodate = 0;
|
||||
}
|
||||
if(pile->funct == e)
|
||||
{
|
||||
|
@ -93,6 +93,8 @@
|
||||
#include <openssl/err.h>
|
||||
#endif
|
||||
|
||||
#include <openssl/x509.h>
|
||||
|
||||
#include <openssl/ossl_typ.h>
|
||||
#include <openssl/symhacks.h>
|
||||
|
||||
@ -278,6 +280,9 @@ typedef int (*ENGINE_CTRL_FUNC_PTR)(ENGINE *, int, long, void *, void (*f)(void)
|
||||
/* Generic load_key function pointer */
|
||||
typedef EVP_PKEY * (*ENGINE_LOAD_KEY_PTR)(ENGINE *, const char *,
|
||||
UI_METHOD *ui_method, void *callback_data);
|
||||
typedef int (*ENGINE_SSL_CLIENT_CERT_PTR)(ENGINE *, SSL *ssl,
|
||||
STACK_OF(X509_NAME) *ca_dn, X509 **pcert, EVP_PKEY **pkey,
|
||||
STACK_OF(X509) **pother, UI_METHOD *ui_method, void *callback_data);
|
||||
/* These callback types are for an ENGINE's handler for cipher and digest logic.
|
||||
* These handlers have these prototypes;
|
||||
* int foo(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int nid);
|
||||
@ -334,6 +339,9 @@ void ENGINE_load_ubsec(void);
|
||||
void ENGINE_load_cryptodev(void);
|
||||
void ENGINE_load_padlock(void);
|
||||
void ENGINE_load_builtin_engines(void);
|
||||
#ifndef OPENSSL_NO_CAPIENG
|
||||
void ENGINE_load_capi(void);
|
||||
#endif
|
||||
|
||||
/* Get and set global flags (ENGINE_TABLE_FLAG_***) for the implementation
|
||||
* "registry" handling. */
|
||||
@ -459,6 +467,8 @@ int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
|
||||
int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f);
|
||||
int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f);
|
||||
int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f);
|
||||
int ENGINE_set_load_ssl_client_cert_function(ENGINE *e,
|
||||
ENGINE_SSL_CLIENT_CERT_PTR loadssl_f);
|
||||
int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);
|
||||
int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);
|
||||
int ENGINE_set_flags(ENGINE *e, int flags);
|
||||
@ -494,6 +504,7 @@ ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);
|
||||
ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e);
|
||||
ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e);
|
||||
ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e);
|
||||
ENGINE_SSL_CLIENT_CERT_PTR ENGINE_get_ssl_client_cert_function(const ENGINE *e);
|
||||
ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e);
|
||||
ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e);
|
||||
const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid);
|
||||
@ -529,6 +540,10 @@ EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
|
||||
UI_METHOD *ui_method, void *callback_data);
|
||||
EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
|
||||
UI_METHOD *ui_method, void *callback_data);
|
||||
int ENGINE_load_ssl_client_cert(ENGINE *e, SSL *s,
|
||||
STACK_OF(X509_NAME) *ca_dn, X509 **pcert, EVP_PKEY **ppkey,
|
||||
STACK_OF(X509) **pother,
|
||||
UI_METHOD *ui_method, void *callback_data);
|
||||
|
||||
/* This returns a pointer for the current ENGINE structure that
|
||||
* is (by default) performing any RSA operations. The value returned
|
||||
@ -723,6 +738,7 @@ void ERR_load_ENGINE_strings(void);
|
||||
#define ENGINE_F_ENGINE_LIST_REMOVE 121
|
||||
#define ENGINE_F_ENGINE_LOAD_PRIVATE_KEY 150
|
||||
#define ENGINE_F_ENGINE_LOAD_PUBLIC_KEY 151
|
||||
#define ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT 192
|
||||
#define ENGINE_F_ENGINE_NEW 122
|
||||
#define ENGINE_F_ENGINE_REMOVE 123
|
||||
#define ENGINE_F_ENGINE_SET_DEFAULT_STRING 189
|
||||
|
@ -141,6 +141,7 @@ typedef struct err_state_st
|
||||
#define ERR_LIB_ECDH 43
|
||||
#define ERR_LIB_STORE 44
|
||||
#define ERR_LIB_FIPS 45
|
||||
#define ERR_LIB_CMS 46
|
||||
|
||||
#define ERR_LIB_USER 128
|
||||
|
||||
@ -173,6 +174,7 @@ typedef struct err_state_st
|
||||
#define ECDHerr(f,r) ERR_PUT_error(ERR_LIB_ECDH,(f),(r),__FILE__,__LINE__)
|
||||
#define STOREerr(f,r) ERR_PUT_error(ERR_LIB_STORE,(f),(r),__FILE__,__LINE__)
|
||||
#define FIPSerr(f,r) ERR_PUT_error(ERR_LIB_FIPS,(f),(r),__FILE__,__LINE__)
|
||||
#define CMSerr(f,r) ERR_PUT_error(ERR_LIB_CMS,(f),(r),__FILE__,__LINE__)
|
||||
|
||||
/* Borland C seems too stupid to be able to shift and do longs in
|
||||
* the pre-processor :-( */
|
||||
|
@ -94,7 +94,13 @@
|
||||
#include <openssl/ui.h>
|
||||
#include <openssl/ocsp.h>
|
||||
#include <openssl/err.h>
|
||||
#ifdef OPENSSL_FIPS
|
||||
#include <openssl/fips.h>
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_CMS
|
||||
#include <openssl/cms.h>
|
||||
#endif
|
||||
|
||||
void ERR_load_crypto_strings(void)
|
||||
{
|
||||
@ -142,5 +148,8 @@ void ERR_load_crypto_strings(void)
|
||||
#ifdef OPENSSL_FIPS
|
||||
ERR_load_FIPS_strings();
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_CMS
|
||||
ERR_load_CMS_strings();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
@ -147,6 +147,7 @@ static ERR_STRING_DATA ERR_str_libraries[]=
|
||||
{ERR_PACK(ERR_LIB_ENGINE,0,0) ,"engine routines"},
|
||||
{ERR_PACK(ERR_LIB_OCSP,0,0) ,"OCSP routines"},
|
||||
{ERR_PACK(ERR_LIB_FIPS,0,0) ,"FIPS routines"},
|
||||
{ERR_PACK(ERR_LIB_CMS,0,0) ,"CMS routines"},
|
||||
{0,NULL},
|
||||
};
|
||||
|
||||
|
@ -32,10 +32,12 @@ L ECDSA crypto/ecdsa/ecdsa.h crypto/ecdsa/ecs_err.c
|
||||
L ECDH crypto/ecdh/ecdh.h crypto/ecdh/ech_err.c
|
||||
L STORE crypto/store/store.h crypto/store/str_err.c
|
||||
L FIPS fips/fips.h crypto/fips_err.h
|
||||
L CMS crypto/cms/cms.h crypto/cms/cms_err.c
|
||||
|
||||
# additional header files to be scanned for function names
|
||||
L NONE crypto/x509/x509_vfy.h NONE
|
||||
L NONE crypto/ec/ec_lcl.h NONE
|
||||
L NONE crypto/cms/cms_lcl.h NONE
|
||||
|
||||
|
||||
F RSAREF_F_RSA_BN2BIN
|
||||
|
@ -93,7 +93,7 @@ IMPLEMENT_BLOCK_CIPHER(camellia_256, ks, Camellia, EVP_CAMELLIA_KEY,
|
||||
EVP_CIPHER_get_asn1_iv,
|
||||
NULL)
|
||||
|
||||
#define IMPLEMENT_CAMELLIA_CFBR(ksize,cbits) IMPLEMENT_CFBR(camellia,Camellia,EVP_CAMELLIA_KEY,ks,ksize,cbits,16,0)
|
||||
#define IMPLEMENT_CAMELLIA_CFBR(ksize,cbits) IMPLEMENT_CFBR(camellia,Camellia,EVP_CAMELLIA_KEY,ks,ksize,cbits,16)
|
||||
|
||||
IMPLEMENT_CAMELLIA_CFBR(128,1)
|
||||
IMPLEMENT_CAMELLIA_CFBR(192,1)
|
||||
|
@ -64,7 +64,10 @@
|
||||
#include <openssl/dso.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#ifdef OPENSSL_FIPS
|
||||
#include <openssl/fips.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* Algorithm configuration module. */
|
||||
|
||||
|
@ -58,7 +58,10 @@
|
||||
|
||||
#include <openssl/idea.h>
|
||||
#include <openssl/crypto.h>
|
||||
#ifdef OPENSSL_FIPS
|
||||
#include <openssl/fips.h>
|
||||
#endif
|
||||
|
||||
#include "idea_lcl.h"
|
||||
|
||||
static IDEA_INT inverse(unsigned int xin);
|
||||
|
@ -62,7 +62,10 @@
|
||||
#include <openssl/md2.h>
|
||||
#include <openssl/opensslv.h>
|
||||
#include <openssl/crypto.h>
|
||||
#ifdef OPENSSL_FIPS
|
||||
#include <openssl/fips.h>
|
||||
#endif
|
||||
|
||||
#include <openssl/err.h>
|
||||
|
||||
const char MD2_version[]="MD2" OPENSSL_VERSION_PTEXT;
|
||||
|
@ -60,7 +60,10 @@
|
||||
#include "md4_locl.h"
|
||||
#include <openssl/opensslv.h>
|
||||
#include <openssl/err.h>
|
||||
#ifdef OPENSSL_FIPS
|
||||
#include <openssl/fips.h>
|
||||
#endif
|
||||
|
||||
|
||||
const char MD4_version[]="MD4" OPENSSL_VERSION_PTEXT;
|
||||
|
||||
|
@ -60,7 +60,10 @@
|
||||
#include "md5_locl.h"
|
||||
#include <openssl/opensslv.h>
|
||||
#include <openssl/err.h>
|
||||
#ifdef OPENSSL_FIPS
|
||||
#include <openssl/fips.h>
|
||||
#endif
|
||||
|
||||
|
||||
const char MD5_version[]="MD5" OPENSSL_VERSION_PTEXT;
|
||||
|
||||
|
@ -62,7 +62,10 @@
|
||||
#include <openssl/des.h>
|
||||
#include <openssl/mdc2.h>
|
||||
#include <openssl/err.h>
|
||||
#ifdef OPENSSL_FIPS
|
||||
#include <openssl/fips.h>
|
||||
#endif
|
||||
|
||||
|
||||
#undef c2l
|
||||
#define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -805,6 +805,14 @@
|
||||
#define NID_id_smime_ct_DVCSResponseData 211
|
||||
#define OBJ_id_smime_ct_DVCSResponseData OBJ_id_smime_ct,8L
|
||||
|
||||
#define SN_id_smime_ct_compressedData "id-smime-ct-compressedData"
|
||||
#define NID_id_smime_ct_compressedData 786
|
||||
#define OBJ_id_smime_ct_compressedData OBJ_id_smime_ct,9L
|
||||
|
||||
#define SN_id_ct_asciiTextWithCRLF "id-ct-asciiTextWithCRLF"
|
||||
#define NID_id_ct_asciiTextWithCRLF 787
|
||||
#define OBJ_id_ct_asciiTextWithCRLF OBJ_id_smime_ct,27L
|
||||
|
||||
#define SN_id_smime_aa_receiptRequest "id-smime-aa-receiptRequest"
|
||||
#define NID_id_smime_aa_receiptRequest 212
|
||||
#define OBJ_id_smime_aa_receiptRequest OBJ_id_smime_aa,1L
|
||||
@ -2352,7 +2360,7 @@
|
||||
#define SN_zlib_compression "ZLIB"
|
||||
#define LN_zlib_compression "zlib compression"
|
||||
#define NID_zlib_compression 125
|
||||
#define OBJ_zlib_compression 1L,1L,1L,1L,666L,2L
|
||||
#define OBJ_zlib_compression OBJ_id_smime_alg,8L
|
||||
|
||||
#define OBJ_csor 2L,16L,840L,1L,101L,3L
|
||||
|
||||
@ -2460,6 +2468,18 @@
|
||||
#define LN_des_ede3_cfb8 "des-ede3-cfb8"
|
||||
#define NID_des_ede3_cfb8 659
|
||||
|
||||
#define SN_id_aes128_wrap "id-aes128-wrap"
|
||||
#define NID_id_aes128_wrap 788
|
||||
#define OBJ_id_aes128_wrap OBJ_aes,5L
|
||||
|
||||
#define SN_id_aes192_wrap "id-aes192-wrap"
|
||||
#define NID_id_aes192_wrap 789
|
||||
#define OBJ_id_aes192_wrap OBJ_aes,25L
|
||||
|
||||
#define SN_id_aes256_wrap "id-aes256-wrap"
|
||||
#define NID_id_aes256_wrap 790
|
||||
#define OBJ_id_aes256_wrap OBJ_aes,45L
|
||||
|
||||
#define OBJ_nist_hashalgs OBJ_nistAlgorithms,2L
|
||||
|
||||
#define SN_sha256 "SHA256"
|
||||
|
@ -783,3 +783,8 @@ id_PasswordBasedMAC 782
|
||||
id_DHBasedMac 783
|
||||
id_it_suppLangTags 784
|
||||
caRepository 785
|
||||
id_smime_ct_compressedData 786
|
||||
id_ct_asciiTextWithCRLF 787
|
||||
id_aes128_wrap 788
|
||||
id_aes192_wrap 789
|
||||
id_aes256_wrap 790
|
||||
|
@ -245,6 +245,8 @@ id-smime-ct 5 : id-smime-ct-TDTInfo
|
||||
id-smime-ct 6 : id-smime-ct-contentInfo
|
||||
id-smime-ct 7 : id-smime-ct-DVCSRequestData
|
||||
id-smime-ct 8 : id-smime-ct-DVCSResponseData
|
||||
id-smime-ct 9 : id-smime-ct-compressedData
|
||||
id-smime-ct 27 : id-ct-asciiTextWithCRLF
|
||||
|
||||
# S/MIME Attributes
|
||||
id-smime-aa 1 : id-smime-aa-receiptRequest
|
||||
@ -778,7 +780,7 @@ mime-mhs-headings 2 : id-hex-multipart-message : id-hex-multipart-message
|
||||
!Cname rle-compression
|
||||
1 1 1 1 666 1 : RLE : run length compression
|
||||
!Cname zlib-compression
|
||||
1 1 1 1 666 2 : ZLIB : zlib compression
|
||||
id-smime-alg 8 : ZLIB : zlib compression
|
||||
|
||||
# AES aka Rijndael
|
||||
|
||||
@ -820,6 +822,10 @@ aes 44 : AES-256-CFB : aes-256-cfb
|
||||
: DES-EDE3-CFB1 : des-ede3-cfb1
|
||||
: DES-EDE3-CFB8 : des-ede3-cfb8
|
||||
|
||||
aes 5 : id-aes128-wrap
|
||||
aes 25 : id-aes192-wrap
|
||||
aes 45 : id-aes256-wrap
|
||||
|
||||
# OIDs for SHA224, SHA256, SHA385 and SHA512, according to x9.84.
|
||||
!Alias nist_hashalgs nistAlgorithms 2
|
||||
nist_hashalgs 1 : SHA256 : sha256
|
||||
|
@ -140,6 +140,8 @@ typedef struct X509_crl_st X509_CRL;
|
||||
typedef struct X509_name_st X509_NAME;
|
||||
typedef struct x509_store_st X509_STORE;
|
||||
typedef struct x509_store_ctx_st X509_STORE_CTX;
|
||||
typedef struct ssl_st SSL;
|
||||
typedef struct ssl_ctx_st SSL_CTX;
|
||||
|
||||
typedef struct v3_ext_ctx X509V3_CTX;
|
||||
typedef struct conf_st CONF;
|
||||
|
@ -133,6 +133,7 @@ extern "C" {
|
||||
#define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY"
|
||||
#define PEM_STRING_ECPARAMETERS "EC PARAMETERS"
|
||||
#define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY"
|
||||
#define PEM_STRING_CMS "CMS"
|
||||
|
||||
/* Note that this structure is initialised by PEM_SealInit and cleaned up
|
||||
by PEM_SealFinal (at least for now) */
|
||||
|
@ -1,143 +1,130 @@
|
||||
#!/usr/bin/env perl
|
||||
#!/usr/local/bin/perl
|
||||
|
||||
# require 'x86asm.pl';
|
||||
# &asm_init(<flavor>,"des-586.pl"[,$i386only]);
|
||||
# &function_begin("foo");
|
||||
# ...
|
||||
# &function_end("foo");
|
||||
# &asm_finish
|
||||
# &asm_init("cpp","des-586.pl");
|
||||
# XXX
|
||||
# XXX
|
||||
# main'asm_finish
|
||||
|
||||
# AUTOLOAD is this context has quite unpleasant side effect, namely
|
||||
# that typos in function calls effectively go to assembler output,
|
||||
# but on the pros side we don't have to implement one subroutine per
|
||||
# each opcode...
|
||||
sub ::AUTOLOAD
|
||||
{ my $opcode = $AUTOLOAD;
|
||||
sub main'asm_finish
|
||||
{
|
||||
&file_end();
|
||||
&asm_finish_cpp() if $cpp;
|
||||
print &asm_get_output();
|
||||
}
|
||||
|
||||
die "more than 2 arguments passed to $opcode" if ($#_>1);
|
||||
sub main'asm_init
|
||||
{
|
||||
($type,$fn,$i386)=@_;
|
||||
$filename=$fn;
|
||||
|
||||
$opcode =~ s/.*:://;
|
||||
if ($opcode =~ /^push/) { $stack+=4; }
|
||||
elsif ($opcode =~ /^pop/) { $stack-=4; }
|
||||
|
||||
&generic($opcode,@_) or die "undefined subroutine \&$AUTOLOAD";
|
||||
}
|
||||
|
||||
$out=();
|
||||
$i386=0;
|
||||
|
||||
sub ::emit
|
||||
{ my $opcode=shift;
|
||||
|
||||
if ($#_==-1) { push(@out,"\t$opcode\n"); }
|
||||
else { push(@out,"\t$opcode\t".join(',',@_)."\n"); }
|
||||
}
|
||||
|
||||
sub ::LB
|
||||
{ $_[0] =~ m/^e?([a-d])x$/o or die "$_[0] does not have a 'low byte'";
|
||||
$1."l";
|
||||
}
|
||||
sub ::HB
|
||||
{ $_[0] =~ m/^e?([a-d])x$/o or die "$_[0] does not have a 'high byte'";
|
||||
$1."h";
|
||||
}
|
||||
sub ::stack_push{ my $num=$_[0]*4; $stack+=$num; &sub("esp",$num); }
|
||||
sub ::stack_pop { my $num=$_[0]*4; $stack-=$num; &add("esp",$num); }
|
||||
sub ::blindpop { &pop($_[0]); $stack+=4; }
|
||||
sub ::wparam { &DWP($stack+4*$_[0],"esp"); }
|
||||
sub ::swtmp { &DWP(4*$_[0],"esp"); }
|
||||
|
||||
sub ::bswap
|
||||
{ if ($i386) # emulate bswap for i386
|
||||
{ &comment("bswap @_");
|
||||
&xchg(&HB(@_),&LB(@_));
|
||||
&ror (@_,16);
|
||||
&xchg(&HB(@_),&LB(@_));
|
||||
}
|
||||
else
|
||||
{ &generic("bswap",@_); }
|
||||
}
|
||||
# These are made-up opcodes introduced over the years essentially
|
||||
# by ignorance, just alias them to real ones...
|
||||
sub ::movb { &mov(@_); }
|
||||
sub ::xorb { &xor(@_); }
|
||||
sub ::rotl { &rol(@_); }
|
||||
sub ::rotr { &ror(@_); }
|
||||
sub ::exch { &xchg(@_); }
|
||||
sub ::halt { &hlt; }
|
||||
|
||||
sub ::function_begin
|
||||
{ &function_begin_B(@_);
|
||||
$stack=4;
|
||||
&push("ebp");
|
||||
&push("ebx");
|
||||
&push("esi");
|
||||
&push("edi");
|
||||
}
|
||||
|
||||
sub ::function_end
|
||||
{ &pop("edi");
|
||||
&pop("esi");
|
||||
&pop("ebx");
|
||||
&pop("ebp");
|
||||
&ret();
|
||||
$stack=0;
|
||||
&function_end_B(@_);
|
||||
}
|
||||
|
||||
sub ::function_end_A
|
||||
{ &pop("edi");
|
||||
&pop("esi");
|
||||
&pop("ebx");
|
||||
&pop("ebp");
|
||||
&ret();
|
||||
$stack+=16; # readjust esp as if we didn't pop anything
|
||||
}
|
||||
|
||||
sub ::asciz { foreach (@_) { &data_byte(unpack("C*",$_),0); } }
|
||||
|
||||
sub ::asm_finish
|
||||
{ &file_end();
|
||||
print @out;
|
||||
}
|
||||
|
||||
sub ::asm_init
|
||||
{ my ($type,$fn,$cpu)=@_;
|
||||
|
||||
$filename=$fn;
|
||||
$i386=$cpu;
|
||||
|
||||
$elf=$cpp=$coff=$aout=$win32=$netware=$mwerks=0;
|
||||
if (($type eq "elf"))
|
||||
{ $elf=1; require "x86unix.pl"; }
|
||||
elsif (($type eq "a\.out"))
|
||||
{ $aout=1; require "x86unix.pl"; }
|
||||
elsif (($type eq "coff" or $type eq "gaswin"))
|
||||
{ $coff=1; require "x86unix.pl"; }
|
||||
elsif (($type eq "win32n"))
|
||||
{ $win32=1; require "x86nasm.pl"; }
|
||||
elsif (($type eq "nw-nasm"))
|
||||
{ $netware=1; require "x86nasm.pl"; }
|
||||
elsif (($type eq "nw-mwasm"))
|
||||
{ $netware=1; $mwerks=1; require "x86nasm.pl"; }
|
||||
else
|
||||
{ print STDERR <<"EOF";
|
||||
$elf=$cpp=$coff=$aout=$win32=$netware=$mwerks=0;
|
||||
if ( ($type eq "elf"))
|
||||
{ $elf=1; require "x86unix.pl"; }
|
||||
elsif ( ($type eq "a.out"))
|
||||
{ $aout=1; require "x86unix.pl"; }
|
||||
elsif ( ($type eq "coff" or $type eq "gaswin"))
|
||||
{ $coff=1; require "x86unix.pl"; }
|
||||
elsif ( ($type eq "cpp"))
|
||||
{ $cpp=1; require "x86unix.pl"; }
|
||||
elsif ( ($type eq "win32"))
|
||||
{ $win32=1; require "x86ms.pl"; }
|
||||
elsif ( ($type eq "win32n"))
|
||||
{ $win32=1; require "x86nasm.pl"; }
|
||||
elsif ( ($type eq "nw-nasm"))
|
||||
{ $netware=1; require "x86nasm.pl"; }
|
||||
elsif ( ($type eq "nw-mwasm"))
|
||||
{ $netware=1; $mwerks=1; require "x86nasm.pl"; }
|
||||
else
|
||||
{
|
||||
print STDERR <<"EOF";
|
||||
Pick one target type from
|
||||
elf - Linux, FreeBSD, Solaris x86, etc.
|
||||
a.out - DJGPP, elder OpenBSD, etc.
|
||||
a.out - OpenBSD, DJGPP, etc.
|
||||
coff - GAS/COFF such as Win32 targets
|
||||
win32 - Windows 95/Windows NT
|
||||
win32n - Windows 95/Windows NT NASM format
|
||||
nw-nasm - NetWare NASM format
|
||||
nw-mwasm- NetWare Metrowerks Assembler
|
||||
EOF
|
||||
exit(1);
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$pic=0;
|
||||
for (@ARGV) { $pic=1 if (/\-[fK]PIC/i); }
|
||||
$pic=0;
|
||||
for (@ARGV) { $pic=1 if (/\-[fK]PIC/i); }
|
||||
|
||||
$filename =~ s/\.pl$//;
|
||||
&file($filename);
|
||||
}
|
||||
&asm_init_output();
|
||||
|
||||
&comment("Don't even think of reading this code");
|
||||
&comment("It was automatically generated by $filename");
|
||||
&comment("Which is a perl program used to generate the x86 assember for");
|
||||
&comment("any of ELF, a.out, COFF, Win32, ...");
|
||||
&comment("eric <eay\@cryptsoft.com>");
|
||||
&comment("");
|
||||
|
||||
$filename =~ s/\.pl$//;
|
||||
&file($filename);
|
||||
}
|
||||
|
||||
sub asm_finish_cpp
|
||||
{
|
||||
return unless $cpp;
|
||||
|
||||
local($tmp,$i);
|
||||
foreach $i (&get_labels())
|
||||
{
|
||||
$tmp.="#define $i _$i\n";
|
||||
}
|
||||
print <<"EOF";
|
||||
/* Run the C pre-processor over this file with one of the following defined
|
||||
* ELF - elf object files,
|
||||
* OUT - a.out object files,
|
||||
* BSDI - BSDI style a.out object files
|
||||
* SOL - Solaris style elf
|
||||
*/
|
||||
|
||||
#define TYPE(a,b) .type a,b
|
||||
#define SIZE(a,b) .size a,b
|
||||
|
||||
#if defined(OUT) || (defined(BSDI) && !defined(ELF))
|
||||
$tmp
|
||||
#endif
|
||||
|
||||
#ifdef OUT
|
||||
#define OK 1
|
||||
#define ALIGN 4
|
||||
#if defined(__CYGWIN__) || defined(__DJGPP__) || (__MINGW32__)
|
||||
#undef SIZE
|
||||
#undef TYPE
|
||||
#define SIZE(a,b)
|
||||
#define TYPE(a,b) .def a; .scl 2; .type 32; .endef
|
||||
#endif /* __CYGWIN || __DJGPP */
|
||||
#endif
|
||||
|
||||
#if defined(BSDI) && !defined(ELF)
|
||||
#define OK 1
|
||||
#define ALIGN 4
|
||||
#undef SIZE
|
||||
#undef TYPE
|
||||
#define SIZE(a,b)
|
||||
#define TYPE(a,b)
|
||||
#endif
|
||||
|
||||
#if defined(ELF) || defined(SOL)
|
||||
#define OK 1
|
||||
#define ALIGN 16
|
||||
#endif
|
||||
|
||||
#ifndef OK
|
||||
You need to define one of
|
||||
ELF - elf systems - linux-elf, NetBSD and DG-UX
|
||||
OUT - a.out systems - linux-a.out and FreeBSD
|
||||
SOL - solaris systems, which are elf with strange comment lines
|
||||
BSDI - a.out with a very primative version of as.
|
||||
#endif
|
||||
|
||||
/* Let the Assembler begin :-) */
|
||||
EOF
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -1,256 +1,455 @@
|
||||
#!/usr/bin/env perl
|
||||
#!/usr/local/bin/perl
|
||||
|
||||
package x86nasm;
|
||||
|
||||
*out=\@::out;
|
||||
$label="L000";
|
||||
$under=($main'netware)?'':'_';
|
||||
|
||||
$lprfx="\@L";
|
||||
$label="000";
|
||||
$under=($::netware)?'':'_';
|
||||
$initseg="";
|
||||
%lb=( 'eax', 'al',
|
||||
'ebx', 'bl',
|
||||
'ecx', 'cl',
|
||||
'edx', 'dl',
|
||||
'ax', 'al',
|
||||
'bx', 'bl',
|
||||
'cx', 'cl',
|
||||
'dx', 'dl',
|
||||
);
|
||||
|
||||
sub ::generic
|
||||
{ my $opcode=shift;
|
||||
my $tmp;
|
||||
%hb=( 'eax', 'ah',
|
||||
'ebx', 'bh',
|
||||
'ecx', 'ch',
|
||||
'edx', 'dh',
|
||||
'ax', 'ah',
|
||||
'bx', 'bh',
|
||||
'cx', 'ch',
|
||||
'dx', 'dh',
|
||||
);
|
||||
|
||||
if (!$::mwerks)
|
||||
{ if ($opcode =~ m/^j/o && $#_==0) # optimize jumps
|
||||
{ $_[0] = "NEAR $_[0]"; }
|
||||
elsif ($opcode eq "lea" && $#_==1)# wipe storage qualifier from lea
|
||||
{ $_[1] =~ s/^[^\[]*\[/\[/o; }
|
||||
}
|
||||
&::emit($opcode,@_);
|
||||
1;
|
||||
sub main'asm_init_output { @out=(); }
|
||||
sub main'asm_get_output { return(@out); }
|
||||
sub main'get_labels { return(@labels); }
|
||||
|
||||
sub main'external_label
|
||||
{
|
||||
push(@labels,@_);
|
||||
foreach (@_) {
|
||||
push(@out,".") if ($main'mwerks);
|
||||
push(@out, "extern\t${under}$_\n");
|
||||
}
|
||||
}
|
||||
#
|
||||
# opcodes not covered by ::generic above, mostly inconsistent namings...
|
||||
#
|
||||
sub ::movz { &::movzx(@_); }
|
||||
sub ::pushf { &::pushfd; }
|
||||
sub ::popf { &::popfd; }
|
||||
|
||||
sub ::call { &::emit("call",(&islabel($_[0]) or "$under$_[0]")); }
|
||||
sub ::call_ptr { &::emit("call",@_); }
|
||||
sub ::jmp_ptr { &::emit("jmp",@_); }
|
||||
sub main'LB
|
||||
{
|
||||
(defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
|
||||
return($lb{$_[0]});
|
||||
}
|
||||
|
||||
# chosen SSE instructions
|
||||
sub ::movq
|
||||
{ my($p1,$p2,$optimize)=@_;
|
||||
sub main'HB
|
||||
{
|
||||
(defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
|
||||
return($hb{$_[0]});
|
||||
}
|
||||
|
||||
if ($optimize && $p1=~/^mm[0-7]$/ && $p2=~/^mm[0-7]$/)
|
||||
# movq between mmx registers can sink Intel CPUs
|
||||
{ &::pshufw($p1,$p2,0xe4); }
|
||||
else
|
||||
{ &::emit("movq",@_); }
|
||||
}
|
||||
sub ::pshufw { &::emit("pshufw",@_); }
|
||||
sub main'BP
|
||||
{
|
||||
&get_mem("BYTE",@_);
|
||||
}
|
||||
|
||||
sub main'DWP
|
||||
{
|
||||
&get_mem("DWORD",@_);
|
||||
}
|
||||
|
||||
sub main'QWP
|
||||
{
|
||||
&get_mem("",@_);
|
||||
}
|
||||
|
||||
sub main'BC
|
||||
{
|
||||
return (($main'mwerks)?"":"BYTE ")."@_";
|
||||
}
|
||||
|
||||
sub main'DWC
|
||||
{
|
||||
return (($main'mwerks)?"":"DWORD ")."@_";
|
||||
}
|
||||
|
||||
sub main'stack_push
|
||||
{
|
||||
my($num)=@_;
|
||||
$stack+=$num*4;
|
||||
&main'sub("esp",$num*4);
|
||||
}
|
||||
|
||||
sub main'stack_pop
|
||||
{
|
||||
my($num)=@_;
|
||||
$stack-=$num*4;
|
||||
&main'add("esp",$num*4);
|
||||
}
|
||||
|
||||
sub get_mem
|
||||
{ my($size,$addr,$reg1,$reg2,$idx)=@_;
|
||||
my($post,$ret);
|
||||
{
|
||||
my($size,$addr,$reg1,$reg2,$idx)=@_;
|
||||
my($t,$post);
|
||||
my($ret)=$size;
|
||||
if ($ret ne "")
|
||||
{
|
||||
$ret .= " PTR" if ($main'mwerks);
|
||||
$ret .= " ";
|
||||
}
|
||||
$ret .= "[";
|
||||
$addr =~ s/^\s+//;
|
||||
if ($addr =~ /^(.+)\+(.+)$/)
|
||||
{
|
||||
$reg2=&conv($1);
|
||||
$addr="$under$2";
|
||||
}
|
||||
elsif ($addr =~ /^[_a-z][_a-z0-9]*$/i)
|
||||
{
|
||||
$addr="$under$addr";
|
||||
}
|
||||
|
||||
if ($size ne "")
|
||||
{ $ret .= "$size";
|
||||
$ret .= " PTR" if ($::mwerks);
|
||||
$ret .= " ";
|
||||
}
|
||||
$ret .= "[";
|
||||
if ($addr =~ /^.+\-.+$/) { $addr="($addr)"; }
|
||||
|
||||
$addr =~ s/^\s+//;
|
||||
# prepend global references with optional underscore
|
||||
$addr =~ s/^([^\+\-0-9][^\+\-]*)/islabel($1) or "$under$1"/ige;
|
||||
# put address arithmetic expression in parenthesis
|
||||
$addr="($addr)" if ($addr =~ /^.+[\-\+].+$/);
|
||||
$reg1="$regs{$reg1}" if defined($regs{$reg1});
|
||||
$reg2="$regs{$reg2}" if defined($regs{$reg2});
|
||||
if (($addr ne "") && ($addr ne 0))
|
||||
{
|
||||
if ($addr !~ /^-/)
|
||||
{ $ret.="${addr}+"; }
|
||||
else { $post=$addr; }
|
||||
}
|
||||
if ($reg2 ne "")
|
||||
{
|
||||
$t="";
|
||||
$t="*$idx" if ($idx != 0);
|
||||
$reg1="+".$reg1 if ("$reg1$post" ne "");
|
||||
$ret.="$reg2$t$reg1$post]";
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret.="$reg1$post]"
|
||||
}
|
||||
$ret =~ s/\+\]/]/; # in case $addr was the only argument
|
||||
return($ret);
|
||||
}
|
||||
|
||||
if (($addr ne "") && ($addr ne 0))
|
||||
{ if ($addr !~ /^-/) { $ret .= "$addr+"; }
|
||||
else { $post=$addr; }
|
||||
}
|
||||
sub main'mov { &out2("mov",@_); }
|
||||
sub main'movb { &out2("mov",@_); }
|
||||
sub main'and { &out2("and",@_); }
|
||||
sub main'or { &out2("or",@_); }
|
||||
sub main'shl { &out2("shl",@_); }
|
||||
sub main'shr { &out2("shr",@_); }
|
||||
sub main'xor { &out2("xor",@_); }
|
||||
sub main'xorb { &out2("xor",@_); }
|
||||
sub main'add { &out2("add",@_); }
|
||||
sub main'adc { &out2("adc",@_); }
|
||||
sub main'sub { &out2("sub",@_); }
|
||||
sub main'sbb { &out2("sbb",@_); }
|
||||
sub main'rotl { &out2("rol",@_); }
|
||||
sub main'rotr { &out2("ror",@_); }
|
||||
sub main'exch { &out2("xchg",@_); }
|
||||
sub main'cmp { &out2("cmp",@_); }
|
||||
sub main'lea { &out2("lea",@_); }
|
||||
sub main'mul { &out1("mul",@_); }
|
||||
sub main'imul { &out2("imul",@_); }
|
||||
sub main'div { &out1("div",@_); }
|
||||
sub main'dec { &out1("dec",@_); }
|
||||
sub main'inc { &out1("inc",@_); }
|
||||
sub main'jmp { &out1("jmp",@_); }
|
||||
sub main'jmp_ptr { &out1p("jmp",@_); }
|
||||
|
||||
if ($reg2 ne "")
|
||||
{ $idx!=0 or $idx=1;
|
||||
$ret .= "$reg2*$idx";
|
||||
$ret .= "+$reg1" if ($reg1 ne "");
|
||||
}
|
||||
else
|
||||
{ $ret .= "$reg1"; }
|
||||
# This is a bit of a kludge: declare all branches as NEAR.
|
||||
$near=($main'mwerks)?'':'NEAR';
|
||||
sub main'je { &out1("je $near",@_); }
|
||||
sub main'jle { &out1("jle $near",@_); }
|
||||
sub main'jz { &out1("jz $near",@_); }
|
||||
sub main'jge { &out1("jge $near",@_); }
|
||||
sub main'jl { &out1("jl $near",@_); }
|
||||
sub main'ja { &out1("ja $near",@_); }
|
||||
sub main'jae { &out1("jae $near",@_); }
|
||||
sub main'jb { &out1("jb $near",@_); }
|
||||
sub main'jbe { &out1("jbe $near",@_); }
|
||||
sub main'jc { &out1("jc $near",@_); }
|
||||
sub main'jnc { &out1("jnc $near",@_); }
|
||||
sub main'jnz { &out1("jnz $near",@_); }
|
||||
sub main'jne { &out1("jne $near",@_); }
|
||||
sub main'jno { &out1("jno $near",@_); }
|
||||
|
||||
$ret .= "$post]";
|
||||
$ret =~ s/\+\]/]/; # in case $addr was the only argument
|
||||
sub main'push { &out1("push",@_); $stack+=4; }
|
||||
sub main'pop { &out1("pop",@_); $stack-=4; }
|
||||
sub main'pushf { &out0("pushfd"); $stack+=4; }
|
||||
sub main'popf { &out0("popfd"); $stack-=4; }
|
||||
sub main'bswap { &out1("bswap",@_); &using486(); }
|
||||
sub main'not { &out1("not",@_); }
|
||||
sub main'call { &out1("call",($_[0]=~/^\@L/?'':$under).$_[0]); }
|
||||
sub main'call_ptr { &out1p("call",@_); }
|
||||
sub main'ret { &out0("ret"); }
|
||||
sub main'nop { &out0("nop"); }
|
||||
sub main'test { &out2("test",@_); }
|
||||
sub main'bt { &out2("bt",@_); }
|
||||
sub main'leave { &out0("leave"); }
|
||||
sub main'cpuid { &out0("cpuid"); }
|
||||
sub main'rdtsc { &out0("rdtsc"); }
|
||||
sub main'halt { &out0("hlt"); }
|
||||
sub main'movz { &out2("movzx",@_); }
|
||||
sub main'neg { &out1("neg",@_); }
|
||||
sub main'cld { &out0("cld"); }
|
||||
|
||||
$ret;
|
||||
}
|
||||
sub ::BP { &get_mem("BYTE",@_); }
|
||||
sub ::DWP { &get_mem("DWORD",@_); }
|
||||
sub ::QWP { &get_mem("",@_); }
|
||||
sub ::BC { (($::mwerks)?"":"BYTE ")."@_"; }
|
||||
sub ::DWC { (($::mwerks)?"":"DWORD ")."@_"; }
|
||||
# SSE2
|
||||
sub main'emms { &out0("emms"); }
|
||||
sub main'movd { &out2("movd",@_); }
|
||||
sub main'movq { &out2("movq",@_); }
|
||||
sub main'movdqu { &out2("movdqu",@_); }
|
||||
sub main'movdqa { &out2("movdqa",@_); }
|
||||
sub main'movdq2q{ &out2("movdq2q",@_); }
|
||||
sub main'movq2dq{ &out2("movq2dq",@_); }
|
||||
sub main'paddq { &out2("paddq",@_); }
|
||||
sub main'pmuludq{ &out2("pmuludq",@_); }
|
||||
sub main'psrlq { &out2("psrlq",@_); }
|
||||
sub main'psllq { &out2("psllq",@_); }
|
||||
sub main'pxor { &out2("pxor",@_); }
|
||||
sub main'por { &out2("por",@_); }
|
||||
sub main'pand { &out2("pand",@_); }
|
||||
|
||||
sub ::file
|
||||
{ if ($::mwerks) { push(@out,".section\t.text\n"); }
|
||||
else
|
||||
{ my $tmp=<<___;
|
||||
sub out2
|
||||
{
|
||||
my($name,$p1,$p2)=@_;
|
||||
my($l,$t);
|
||||
|
||||
push(@out,"\t$name\t");
|
||||
if (!$main'mwerks and $name eq "lea")
|
||||
{
|
||||
$p1 =~ s/^[^\[]*\[/\[/;
|
||||
$p2 =~ s/^[^\[]*\[/\[/;
|
||||
}
|
||||
$t=&conv($p1).",";
|
||||
$l=length($t);
|
||||
push(@out,$t);
|
||||
$l=4-($l+9)/8;
|
||||
push(@out,"\t" x $l);
|
||||
push(@out,&conv($p2));
|
||||
push(@out,"\n");
|
||||
}
|
||||
|
||||
sub out0
|
||||
{
|
||||
my($name)=@_;
|
||||
|
||||
push(@out,"\t$name\n");
|
||||
}
|
||||
|
||||
sub out1
|
||||
{
|
||||
my($name,$p1)=@_;
|
||||
my($l,$t);
|
||||
push(@out,"\t$name\t".&conv($p1)."\n");
|
||||
}
|
||||
|
||||
sub conv
|
||||
{
|
||||
my($p)=@_;
|
||||
$p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
|
||||
return $p;
|
||||
}
|
||||
|
||||
sub using486
|
||||
{
|
||||
return if $using486;
|
||||
$using486++;
|
||||
grep(s/\.386/\.486/,@out);
|
||||
}
|
||||
|
||||
sub main'file
|
||||
{
|
||||
if ($main'mwerks) { push(@out,".section\t.text\n"); }
|
||||
else {
|
||||
local $tmp=<<___;
|
||||
%ifdef __omf__
|
||||
section code use32 class=code align=64
|
||||
section code use32 class=code
|
||||
%else
|
||||
section .text code align=64
|
||||
section .text
|
||||
%endif
|
||||
___
|
||||
push(@out,$tmp);
|
||||
}
|
||||
}
|
||||
push(@out,$tmp);
|
||||
}
|
||||
}
|
||||
|
||||
sub ::function_begin_B
|
||||
{ my $func=$under.shift;
|
||||
my $tmp=<<___;
|
||||
global $func
|
||||
align 16
|
||||
$func:
|
||||
___
|
||||
push(@out,$tmp);
|
||||
$::stack=4;
|
||||
}
|
||||
sub ::function_end_B
|
||||
{ my $i;
|
||||
foreach $i (%label) { undef $label{$i} if ($label{$i} =~ /^$prfx/); }
|
||||
$::stack=0;
|
||||
}
|
||||
sub main'function_begin
|
||||
{
|
||||
my($func,$extra)=@_;
|
||||
|
||||
sub ::file_end
|
||||
{ # try to detect if SSE2 or MMX extensions were used on Win32...
|
||||
if ($::win32 && grep {/\b[x]?mm[0-7]\b|OPENSSL_ia32cap_P\b/i} @out)
|
||||
{ # $1<<10 sets a reserved bit to signal that variable
|
||||
# was initialized already...
|
||||
my $code=<<___;
|
||||
align 16
|
||||
${lprfx}OPENSSL_ia32cap_init:
|
||||
lea edx,[${under}OPENSSL_ia32cap_P]
|
||||
cmp DWORD [edx],0
|
||||
jne NEAR ${lprfx}nocpuid
|
||||
mov DWORD [edx],1<<10
|
||||
pushfd
|
||||
pop eax
|
||||
mov ecx,eax
|
||||
xor eax,1<<21
|
||||
push eax
|
||||
popfd
|
||||
pushfd
|
||||
pop eax
|
||||
xor eax,ecx
|
||||
bt eax,21
|
||||
jnc NEAR ${lprfx}nocpuid
|
||||
push(@labels,$func);
|
||||
push(@out,".") if ($main'mwerks);
|
||||
my($tmp)=<<"EOF";
|
||||
global $under$func
|
||||
$under$func:
|
||||
push ebp
|
||||
push edi
|
||||
push ebx
|
||||
mov edi,edx
|
||||
xor eax,eax
|
||||
cpuid
|
||||
xor eax,eax
|
||||
cmp ebx,'Genu'
|
||||
setne al
|
||||
mov ebp,eax
|
||||
cmp edx,'ineI'
|
||||
setne al
|
||||
or ebp,eax
|
||||
cmp eax,'ntel'
|
||||
setne al
|
||||
or ebp,eax
|
||||
mov eax,1
|
||||
cpuid
|
||||
cmp ebp,0
|
||||
jne ${lprfx}notP4
|
||||
and ah,15
|
||||
cmp ah,15
|
||||
jne ${lprfx}notP4
|
||||
or edx,1<<20
|
||||
${lprfx}notP4:
|
||||
bt edx,28
|
||||
jnc ${lprfx}done
|
||||
shr ebx,16
|
||||
cmp bl,1
|
||||
ja ${lprfx}done
|
||||
and edx,0xefffffff
|
||||
${lprfx}done:
|
||||
or edx,1<<10
|
||||
mov DWORD [edi],edx
|
||||
pop ebx
|
||||
push esi
|
||||
push edi
|
||||
EOF
|
||||
push(@out,$tmp);
|
||||
$stack=20;
|
||||
}
|
||||
|
||||
sub main'function_begin_B
|
||||
{
|
||||
my($func,$extra)=@_;
|
||||
push(@out,".") if ($main'mwerks);
|
||||
my($tmp)=<<"EOF";
|
||||
global $under$func
|
||||
$under$func:
|
||||
EOF
|
||||
push(@out,$tmp);
|
||||
$stack=4;
|
||||
}
|
||||
|
||||
sub main'function_end
|
||||
{
|
||||
my($func)=@_;
|
||||
|
||||
my($tmp)=<<"EOF";
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebx
|
||||
pop ebp
|
||||
${lprfx}nocpuid:
|
||||
ret
|
||||
segment .CRT\$XCU data align=4
|
||||
dd ${lprfx}OPENSSL_ia32cap_init
|
||||
EOF
|
||||
push(@out,$tmp);
|
||||
$stack=0;
|
||||
%label=();
|
||||
}
|
||||
|
||||
sub main'function_end_B
|
||||
{
|
||||
$stack=0;
|
||||
%label=();
|
||||
}
|
||||
|
||||
sub main'function_end_A
|
||||
{
|
||||
my($func)=@_;
|
||||
|
||||
my($tmp)=<<"EOF";
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebx
|
||||
pop ebp
|
||||
ret
|
||||
EOF
|
||||
push(@out,$tmp);
|
||||
}
|
||||
|
||||
sub main'file_end
|
||||
{
|
||||
}
|
||||
|
||||
sub main'wparam
|
||||
{
|
||||
my($num)=@_;
|
||||
|
||||
return(&main'DWP($stack+$num*4,"esp","",0));
|
||||
}
|
||||
|
||||
sub main'swtmp
|
||||
{
|
||||
return(&main'DWP($_[0]*4,"esp","",0));
|
||||
}
|
||||
|
||||
# Should use swtmp, which is above esp. Linix can trash the stack above esp
|
||||
#sub main'wtmp
|
||||
# {
|
||||
# my($num)=@_;
|
||||
#
|
||||
# return(&main'DWP(-(($num+1)*4),"esp","",0));
|
||||
# }
|
||||
|
||||
sub main'comment
|
||||
{
|
||||
foreach (@_)
|
||||
{
|
||||
push(@out,"\t; $_\n");
|
||||
}
|
||||
}
|
||||
|
||||
sub main'public_label
|
||||
{
|
||||
$label{$_[0]}="${under}${_[0]}" if (!defined($label{$_[0]}));
|
||||
push(@out,".") if ($main'mwerks);
|
||||
push(@out,"global\t$label{$_[0]}\n");
|
||||
}
|
||||
|
||||
sub main'label
|
||||
{
|
||||
if (!defined($label{$_[0]}))
|
||||
{
|
||||
$label{$_[0]}="\@${label}${_[0]}";
|
||||
$label++;
|
||||
}
|
||||
return($label{$_[0]});
|
||||
}
|
||||
|
||||
sub main'set_label
|
||||
{
|
||||
if (!defined($label{$_[0]}))
|
||||
{
|
||||
$label{$_[0]}="\@${label}${_[0]}";
|
||||
$label++;
|
||||
}
|
||||
if ($_[1]!=0 && $_[1]>1)
|
||||
{
|
||||
main'align($_[1]);
|
||||
}
|
||||
push(@out,"$label{$_[0]}:\n");
|
||||
}
|
||||
|
||||
sub main'data_byte
|
||||
{
|
||||
push(@out,(($main'mwerks)?".byte\t":"DB\t").join(',',@_)."\n");
|
||||
}
|
||||
|
||||
sub main'data_word
|
||||
{
|
||||
push(@out,(($main'mwerks)?".long\t":"DD\t").join(',',@_)."\n");
|
||||
}
|
||||
|
||||
sub main'align
|
||||
{
|
||||
push(@out,".") if ($main'mwerks);
|
||||
push(@out,"align\t$_[0]\n");
|
||||
}
|
||||
|
||||
sub out1p
|
||||
{
|
||||
my($name,$p1)=@_;
|
||||
my($l,$t);
|
||||
|
||||
push(@out,"\t$name\t".&conv($p1)."\n");
|
||||
}
|
||||
|
||||
sub main'picmeup
|
||||
{
|
||||
local($dst,$sym)=@_;
|
||||
&main'lea($dst,&main'DWP($sym));
|
||||
}
|
||||
|
||||
sub main'blindpop { &out1("pop",@_); }
|
||||
|
||||
sub main'initseg
|
||||
{
|
||||
local($f)=@_;
|
||||
if ($main'win32)
|
||||
{
|
||||
local($tmp)=<<___;
|
||||
segment .CRT\$XCU data
|
||||
extern $under$f
|
||||
DD $under$f
|
||||
___
|
||||
my $data=<<___;
|
||||
segment .bss
|
||||
common ${under}OPENSSL_ia32cap_P 4
|
||||
___
|
||||
|
||||
#<not needed in OpenSSL context>#push (@out,$code);
|
||||
|
||||
# comment out OPENSSL_ia32cap_P declarations
|
||||
grep {s/(^extern\s+${under}OPENSSL_ia32cap_P)/\;$1/} @out;
|
||||
push (@out,$data)
|
||||
}
|
||||
push (@out,$initseg) if ($initseg);
|
||||
}
|
||||
|
||||
sub ::comment { foreach (@_) { push(@out,"\t; $_\n"); } }
|
||||
|
||||
sub islabel # see is argument is known label
|
||||
{ my $i;
|
||||
foreach $i (%label) { return $label{$i} if ($label{$i} eq $_[0]); }
|
||||
undef;
|
||||
}
|
||||
|
||||
sub ::external_label
|
||||
{ push(@labels,@_);
|
||||
foreach (@_)
|
||||
{ push(@out,".") if ($::mwerks);
|
||||
push(@out, "extern\t${under}$_\n");
|
||||
}
|
||||
}
|
||||
|
||||
sub ::public_label
|
||||
{ $label{$_[0]}="${under}${_[0]}" if (!defined($label{$_[0]}));
|
||||
push(@out,"global\t$label{$_[0]}\n");
|
||||
}
|
||||
|
||||
sub ::label
|
||||
{ if (!defined($label{$_[0]}))
|
||||
{ $label{$_[0]}="${lprfx}${label}${_[0]}"; $label++; }
|
||||
$label{$_[0]};
|
||||
}
|
||||
|
||||
sub ::set_label
|
||||
{ my $label=&::label($_[0]);
|
||||
&::align($_[1]) if ($_[1]>1);
|
||||
push(@out,"$label{$_[0]}:\n");
|
||||
}
|
||||
|
||||
sub ::data_byte
|
||||
{ push(@out,(($::mwerks)?".byte\t":"db\t").join(',',@_)."\n"); }
|
||||
|
||||
sub ::data_word
|
||||
{ push(@out,(($::mwerks)?".long\t":"dd\t").join(',',@_)."\n"); }
|
||||
|
||||
sub ::align
|
||||
{ push(@out,".") if ($::mwerks); push(@out,"align\t$_[0]\n"); }
|
||||
|
||||
sub ::picmeup
|
||||
{ my($dst,$sym)=@_;
|
||||
&::lea($dst,&::DWP($sym));
|
||||
}
|
||||
|
||||
sub ::initseg
|
||||
{ my($f)=$under.shift;
|
||||
if ($::win32)
|
||||
{ $initseg=<<___;
|
||||
segment .CRT\$XCU data align=4
|
||||
extern $f
|
||||
dd $f
|
||||
___
|
||||
}
|
||||
}
|
||||
push(@out,$tmp);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -1,152 +1,500 @@
|
||||
#!/usr/bin/env perl
|
||||
#!/usr/local/bin/perl
|
||||
|
||||
package x86unix; # GAS actually...
|
||||
|
||||
*out=\@::out;
|
||||
|
||||
$label="L000";
|
||||
$const="";
|
||||
$constl=0;
|
||||
|
||||
$align=($::aout)?"4":"16";
|
||||
$under=($::aout or $::coff)?"_":"";
|
||||
$dot=($::aout)?"":".";
|
||||
$com_start="#" if ($::aout or $::coff);
|
||||
$align=($main'aout)?"4":"16";
|
||||
$under=($main'aout or $main'coff)?"_":"";
|
||||
$dot=($main'aout)?"":".";
|
||||
$com_start="#" if ($main'aout or $main'coff);
|
||||
|
||||
sub opsize()
|
||||
{ my $reg=shift;
|
||||
if ($reg =~ m/^%e/o) { "l"; }
|
||||
elsif ($reg =~ m/^%[a-d][hl]$/o) { "b"; }
|
||||
elsif ($reg =~ m/^%[xm]/o) { undef; }
|
||||
else { "w"; }
|
||||
}
|
||||
sub main'asm_init_output { @out=(); }
|
||||
sub main'asm_get_output { return(@out); }
|
||||
sub main'get_labels { return(@labels); }
|
||||
sub main'external_label { push(@labels,@_); }
|
||||
|
||||
# swap arguments;
|
||||
# expand opcode with size suffix;
|
||||
# prefix numeric constants with $;
|
||||
sub ::generic
|
||||
{ my($opcode,$dst,$src)=@_;
|
||||
my($tmp,$suffix,@arg);
|
||||
|
||||
if (defined($src))
|
||||
{ $src =~ s/^(e?[a-dsixphl]{2})$/%$1/o;
|
||||
$src =~ s/^(x?mm[0-7])$/%$1/o;
|
||||
$src =~ s/^(\-?[0-9]+)$/\$$1/o;
|
||||
$src =~ s/^(\-?0x[0-9a-f]+)$/\$$1/o;
|
||||
push(@arg,$src);
|
||||
}
|
||||
if (defined($dst))
|
||||
{ $dst =~ s/^(\*?)(e?[a-dsixphl]{2})$/$1%$2/o;
|
||||
$dst =~ s/^(x?mm[0-7])$/%$1/o;
|
||||
$dst =~ s/^(\-?[0-9]+)$/\$$1/o if(!defined($src));
|
||||
$dst =~ s/^(\-?0x[0-9a-f]+)$/\$$1/o if(!defined($src));
|
||||
push(@arg,$dst);
|
||||
}
|
||||
|
||||
if ($dst =~ m/^%/o) { $suffix=&opsize($dst); }
|
||||
elsif ($src =~ m/^%/o) { $suffix=&opsize($src); }
|
||||
else { $suffix="l"; }
|
||||
undef $suffix if ($dst =~ m/^%[xm]/o || $src =~ m/^%[xm]/o);
|
||||
|
||||
if ($#_==0) { &::emit($opcode); }
|
||||
elsif ($opcode =~ m/^j/o && $#_==1) { &::emit($opcode,@arg); }
|
||||
elsif ($opcode eq "call" && $#_==1) { &::emit($opcode,@arg); }
|
||||
elsif ($opcode =~ m/^set/&& $#_==1) { &::emit($opcode,@arg); }
|
||||
else { &::emit($opcode.$suffix,@arg);}
|
||||
|
||||
1;
|
||||
}
|
||||
#
|
||||
# opcodes not covered by ::generic above, mostly inconsistent namings...
|
||||
#
|
||||
sub ::movz { &::movzb(@_); }
|
||||
sub ::pushf { &::pushfl; }
|
||||
sub ::popf { &::popfl; }
|
||||
sub ::cpuid { &::emit(".byte\t0x0f,0xa2"); }
|
||||
sub ::rdtsc { &::emit(".byte\t0x0f,0x31"); }
|
||||
|
||||
sub ::call { &::emit("call",(&islabel($_[0]) or "$under$_[0]")); }
|
||||
sub ::call_ptr { &::generic("call","*$_[0]"); }
|
||||
sub ::jmp_ptr { &::generic("jmp","*$_[0]"); }
|
||||
|
||||
*::bswap = sub { &::emit("bswap","%$_[0]"); } if (!$::i386);
|
||||
|
||||
# chosen SSE instructions
|
||||
sub ::movq
|
||||
{ my($p1,$p2,$optimize)=@_;
|
||||
if ($optimize && $p1=~/^mm[0-7]$/ && $p2=~/^mm[0-7]$/)
|
||||
# movq between mmx registers can sink Intel CPUs
|
||||
{ &::pshufw($p1,$p2,0xe4); }
|
||||
else
|
||||
{ &::generic("movq",@_); }
|
||||
}
|
||||
sub ::pshufw
|
||||
{ my($dst,$src,$magic)=@_;
|
||||
&::emit("pshufw","\$$magic","%$src","%$dst");
|
||||
}
|
||||
|
||||
sub ::DWP
|
||||
{ my($addr,$reg1,$reg2,$idx)=@_;
|
||||
my $ret="";
|
||||
|
||||
$addr =~ s/^\s+//;
|
||||
# prepend global references with optional underscore
|
||||
$addr =~ s/^([^\+\-0-9][^\+\-]*)/islabel($1) or "$under$1"/ige;
|
||||
|
||||
$reg1 = "%$reg1" if ($reg1);
|
||||
$reg2 = "%$reg2" if ($reg2);
|
||||
|
||||
$ret .= $addr if (($addr ne "") && ($addr ne 0));
|
||||
|
||||
if ($reg2)
|
||||
{ $idx!= 0 or $idx=1;
|
||||
$ret .= "($reg1,$reg2,$idx)";
|
||||
}
|
||||
elsif ($reg1)
|
||||
{ $ret .= "($reg1)"; }
|
||||
|
||||
$ret;
|
||||
}
|
||||
sub ::QWP { &::DWP(@_); }
|
||||
sub ::BP { &::DWP(@_); }
|
||||
sub ::BC { @_; }
|
||||
sub ::DWC { @_; }
|
||||
|
||||
sub ::file
|
||||
{ push(@out,".file\t\"$_[0].s\"\n"); }
|
||||
|
||||
sub ::function_begin_B
|
||||
{ my($func,$extra)=@_;
|
||||
my $tmp;
|
||||
|
||||
&::external_label($func);
|
||||
$func=$under.$func;
|
||||
|
||||
push(@out,".text\n.globl\t$func\n");
|
||||
if ($::coff)
|
||||
{ push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
|
||||
elsif ($::aout and !$::pic)
|
||||
{ }
|
||||
else
|
||||
{ push(@out,".type $func,\@function\n"); }
|
||||
push(@out,".align\t$align\n");
|
||||
push(@out,"$func:\n");
|
||||
$::stack=4;
|
||||
}
|
||||
|
||||
sub ::function_end_B
|
||||
{ my($func)=@_;
|
||||
|
||||
$func=$under.$func;
|
||||
push(@out,"${dot}L_${func}_end:\n");
|
||||
if ($::elf)
|
||||
{ push(@out,".size\t$func,${dot}L_${func}_end-$func\n"); }
|
||||
$::stack=0;
|
||||
%label=();
|
||||
}
|
||||
|
||||
sub ::comment
|
||||
if ($main'cpp)
|
||||
{
|
||||
if (!defined($com_start) or $::elf)
|
||||
{ # Regarding $::elf above...
|
||||
$align="ALIGN";
|
||||
$under="";
|
||||
$com_start='/*';
|
||||
$com_end='*/';
|
||||
}
|
||||
|
||||
%lb=( 'eax', '%al',
|
||||
'ebx', '%bl',
|
||||
'ecx', '%cl',
|
||||
'edx', '%dl',
|
||||
'ax', '%al',
|
||||
'bx', '%bl',
|
||||
'cx', '%cl',
|
||||
'dx', '%dl',
|
||||
);
|
||||
|
||||
%hb=( 'eax', '%ah',
|
||||
'ebx', '%bh',
|
||||
'ecx', '%ch',
|
||||
'edx', '%dh',
|
||||
'ax', '%ah',
|
||||
'bx', '%bh',
|
||||
'cx', '%ch',
|
||||
'dx', '%dh',
|
||||
);
|
||||
|
||||
%regs=( 'eax', '%eax',
|
||||
'ebx', '%ebx',
|
||||
'ecx', '%ecx',
|
||||
'edx', '%edx',
|
||||
'esi', '%esi',
|
||||
'edi', '%edi',
|
||||
'ebp', '%ebp',
|
||||
'esp', '%esp',
|
||||
|
||||
'mm0', '%mm0',
|
||||
'mm1', '%mm1',
|
||||
'mm2', '%mm2',
|
||||
'mm3', '%mm3',
|
||||
'mm4', '%mm4',
|
||||
'mm5', '%mm5',
|
||||
'mm6', '%mm6',
|
||||
'mm7', '%mm7',
|
||||
|
||||
'xmm0', '%xmm0',
|
||||
'xmm1', '%xmm1',
|
||||
'xmm2', '%xmm2',
|
||||
'xmm3', '%xmm3',
|
||||
'xmm4', '%xmm4',
|
||||
'xmm5', '%xmm5',
|
||||
'xmm6', '%xmm6',
|
||||
'xmm7', '%xmm7',
|
||||
);
|
||||
|
||||
%reg_val=(
|
||||
'eax', 0x00,
|
||||
'ebx', 0x03,
|
||||
'ecx', 0x01,
|
||||
'edx', 0x02,
|
||||
'esi', 0x06,
|
||||
'edi', 0x07,
|
||||
'ebp', 0x05,
|
||||
'esp', 0x04,
|
||||
);
|
||||
|
||||
sub main'LB
|
||||
{
|
||||
(defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
|
||||
return($lb{$_[0]});
|
||||
}
|
||||
|
||||
sub main'HB
|
||||
{
|
||||
(defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
|
||||
return($hb{$_[0]});
|
||||
}
|
||||
|
||||
sub main'DWP
|
||||
{
|
||||
local($addr,$reg1,$reg2,$idx)=@_;
|
||||
|
||||
$ret="";
|
||||
$addr =~ s/(^|[+ \t])([A-Za-z_]+[A-Za-z0-9_]+)($|[+ \t])/$1$under$2$3/;
|
||||
$reg1="$regs{$reg1}" if defined($regs{$reg1});
|
||||
$reg2="$regs{$reg2}" if defined($regs{$reg2});
|
||||
$ret.=$addr if ($addr ne "") && ($addr ne 0);
|
||||
if ($reg2 ne "")
|
||||
{
|
||||
if($idx ne "" && $idx != 0)
|
||||
{ $ret.="($reg1,$reg2,$idx)"; }
|
||||
else
|
||||
{ $ret.="($reg1,$reg2)"; }
|
||||
}
|
||||
elsif ($reg1 ne "")
|
||||
{ $ret.="($reg1)" }
|
||||
return($ret);
|
||||
}
|
||||
|
||||
sub main'QWP
|
||||
{
|
||||
return(&main'DWP(@_));
|
||||
}
|
||||
|
||||
sub main'BP
|
||||
{
|
||||
return(&main'DWP(@_));
|
||||
}
|
||||
|
||||
sub main'BC
|
||||
{
|
||||
return @_;
|
||||
}
|
||||
|
||||
sub main'DWC
|
||||
{
|
||||
return @_;
|
||||
}
|
||||
|
||||
#sub main'BP
|
||||
# {
|
||||
# local($addr,$reg1,$reg2,$idx)=@_;
|
||||
#
|
||||
# $ret="";
|
||||
#
|
||||
# $addr =~ s/(^|[+ \t])([A-Za-z_]+)($|[+ \t])/$1$under$2$3/;
|
||||
# $reg1="$regs{$reg1}" if defined($regs{$reg1});
|
||||
# $reg2="$regs{$reg2}" if defined($regs{$reg2});
|
||||
# $ret.=$addr if ($addr ne "") && ($addr ne 0);
|
||||
# if ($reg2 ne "")
|
||||
# { $ret.="($reg1,$reg2,$idx)"; }
|
||||
# else
|
||||
# { $ret.="($reg1)" }
|
||||
# return($ret);
|
||||
# }
|
||||
|
||||
sub main'mov { &out2("movl",@_); }
|
||||
sub main'movb { &out2("movb",@_); }
|
||||
sub main'and { &out2("andl",@_); }
|
||||
sub main'or { &out2("orl",@_); }
|
||||
sub main'shl { &out2("sall",@_); }
|
||||
sub main'shr { &out2("shrl",@_); }
|
||||
sub main'xor { &out2("xorl",@_); }
|
||||
sub main'xorb { &out2("xorb",@_); }
|
||||
sub main'add { &out2($_[0]=~/%[a-d][lh]/?"addb":"addl",@_); }
|
||||
sub main'adc { &out2("adcl",@_); }
|
||||
sub main'sub { &out2("subl",@_); }
|
||||
sub main'sbb { &out2("sbbl",@_); }
|
||||
sub main'rotl { &out2("roll",@_); }
|
||||
sub main'rotr { &out2("rorl",@_); }
|
||||
sub main'exch { &out2($_[0]=~/%[a-d][lh]/?"xchgb":"xchgl",@_); }
|
||||
sub main'cmp { &out2("cmpl",@_); }
|
||||
sub main'lea { &out2("leal",@_); }
|
||||
sub main'mul { &out1("mull",@_); }
|
||||
sub main'imul { &out2("imull",@_); }
|
||||
sub main'div { &out1("divl",@_); }
|
||||
sub main'jmp { &out1("jmp",@_); }
|
||||
sub main'jmp_ptr { &out1p("jmp",@_); }
|
||||
sub main'je { &out1("je",@_); }
|
||||
sub main'jle { &out1("jle",@_); }
|
||||
sub main'jne { &out1("jne",@_); }
|
||||
sub main'jnz { &out1("jnz",@_); }
|
||||
sub main'jz { &out1("jz",@_); }
|
||||
sub main'jge { &out1("jge",@_); }
|
||||
sub main'jl { &out1("jl",@_); }
|
||||
sub main'ja { &out1("ja",@_); }
|
||||
sub main'jae { &out1("jae",@_); }
|
||||
sub main'jb { &out1("jb",@_); }
|
||||
sub main'jbe { &out1("jbe",@_); }
|
||||
sub main'jc { &out1("jc",@_); }
|
||||
sub main'jnc { &out1("jnc",@_); }
|
||||
sub main'jno { &out1("jno",@_); }
|
||||
sub main'dec { &out1("decl",@_); }
|
||||
sub main'inc { &out1($_[0]=~/%[a-d][hl]/?"incb":"incl",@_); }
|
||||
sub main'push { &out1("pushl",@_); $stack+=4; }
|
||||
sub main'pop { &out1("popl",@_); $stack-=4; }
|
||||
sub main'pushf { &out0("pushfl"); $stack+=4; }
|
||||
sub main'popf { &out0("popfl"); $stack-=4; }
|
||||
sub main'not { &out1("notl",@_); }
|
||||
sub main'call { my $pre=$under;
|
||||
foreach $i (%label)
|
||||
{ if ($label{$i} eq $_[0]) { $pre=''; last; } }
|
||||
&out1("call",$pre.$_[0]);
|
||||
}
|
||||
sub main'call_ptr { &out1p("call",@_); }
|
||||
sub main'ret { &out0("ret"); }
|
||||
sub main'nop { &out0("nop"); }
|
||||
sub main'test { &out2("testl",@_); }
|
||||
sub main'bt { &out2("btl",@_); }
|
||||
sub main'leave { &out0("leave"); }
|
||||
sub main'cpuid { &out0(".byte\t0x0f,0xa2"); }
|
||||
sub main'rdtsc { &out0(".byte\t0x0f,0x31"); }
|
||||
sub main'halt { &out0("hlt"); }
|
||||
sub main'movz { &out2("movzbl",@_); }
|
||||
sub main'neg { &out1("negl",@_); }
|
||||
sub main'cld { &out0("cld"); }
|
||||
|
||||
# SSE2
|
||||
sub main'emms { &out0("emms"); }
|
||||
sub main'movd { &out2("movd",@_); }
|
||||
sub main'movdqu { &out2("movdqu",@_); }
|
||||
sub main'movdqa { &out2("movdqa",@_); }
|
||||
sub main'movdq2q{ &out2("movdq2q",@_); }
|
||||
sub main'movq2dq{ &out2("movq2dq",@_); }
|
||||
sub main'paddq { &out2("paddq",@_); }
|
||||
sub main'pmuludq{ &out2("pmuludq",@_); }
|
||||
sub main'psrlq { &out2("psrlq",@_); }
|
||||
sub main'psllq { &out2("psllq",@_); }
|
||||
sub main'pxor { &out2("pxor",@_); }
|
||||
sub main'por { &out2("por",@_); }
|
||||
sub main'pand { &out2("pand",@_); }
|
||||
sub main'movq {
|
||||
local($p1,$p2,$optimize)=@_;
|
||||
if ($optimize && $p1=~/^mm[0-7]$/ && $p2=~/^mm[0-7]$/)
|
||||
# movq between mmx registers can sink Intel CPUs
|
||||
{ push(@out,"\tpshufw\t\$0xe4,%$p2,%$p1\n"); }
|
||||
else { &out2("movq",@_); }
|
||||
}
|
||||
|
||||
# The bswapl instruction is new for the 486. Emulate if i386.
|
||||
sub main'bswap
|
||||
{
|
||||
if ($main'i386)
|
||||
{
|
||||
&main'comment("bswapl @_");
|
||||
&main'exch(main'HB(@_),main'LB(@_));
|
||||
&main'rotr(@_,16);
|
||||
&main'exch(main'HB(@_),main'LB(@_));
|
||||
}
|
||||
else
|
||||
{
|
||||
&out1("bswapl",@_);
|
||||
}
|
||||
}
|
||||
|
||||
sub out2
|
||||
{
|
||||
local($name,$p1,$p2)=@_;
|
||||
local($l,$ll,$t);
|
||||
local(%special)=( "roll",0xD1C0,"rorl",0xD1C8,
|
||||
"rcll",0xD1D0,"rcrl",0xD1D8,
|
||||
"shll",0xD1E0,"shrl",0xD1E8,
|
||||
"sarl",0xD1F8);
|
||||
|
||||
if ((defined($special{$name})) && defined($regs{$p1}) && ($p2 == 1))
|
||||
{
|
||||
$op=$special{$name}|$reg_val{$p1};
|
||||
$tmp1=sprintf(".byte %d\n",($op>>8)&0xff);
|
||||
$tmp2=sprintf(".byte %d\t",$op &0xff);
|
||||
push(@out,$tmp1);
|
||||
push(@out,$tmp2);
|
||||
|
||||
$p2=&conv($p2);
|
||||
$p1=&conv($p1);
|
||||
&main'comment("$name $p2 $p1");
|
||||
return;
|
||||
}
|
||||
|
||||
push(@out,"\t$name\t");
|
||||
$t=&conv($p2).",";
|
||||
$l=length($t);
|
||||
push(@out,$t);
|
||||
$ll=4-($l+9)/8;
|
||||
$tmp1=sprintf("\t" x $ll);
|
||||
push(@out,$tmp1);
|
||||
push(@out,&conv($p1)."\n");
|
||||
}
|
||||
|
||||
sub out1
|
||||
{
|
||||
local($name,$p1)=@_;
|
||||
local($l,$t);
|
||||
local(%special)=("bswapl",0x0FC8);
|
||||
|
||||
if ((defined($special{$name})) && defined($regs{$p1}))
|
||||
{
|
||||
$op=$special{$name}|$reg_val{$p1};
|
||||
$tmp1=sprintf(".byte %d\n",($op>>8)&0xff);
|
||||
$tmp2=sprintf(".byte %d\t",$op &0xff);
|
||||
push(@out,$tmp1);
|
||||
push(@out,$tmp2);
|
||||
|
||||
$p2=&conv($p2);
|
||||
$p1=&conv($p1);
|
||||
&main'comment("$name $p2 $p1");
|
||||
return;
|
||||
}
|
||||
|
||||
push(@out,"\t$name\t".&conv($p1)."\n");
|
||||
}
|
||||
|
||||
sub out1p
|
||||
{
|
||||
local($name,$p1)=@_;
|
||||
local($l,$t);
|
||||
|
||||
push(@out,"\t$name\t*".&conv($p1)."\n");
|
||||
}
|
||||
|
||||
sub out0
|
||||
{
|
||||
push(@out,"\t$_[0]\n");
|
||||
}
|
||||
|
||||
sub conv
|
||||
{
|
||||
local($p)=@_;
|
||||
|
||||
# $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
|
||||
|
||||
$p=$regs{$p} if (defined($regs{$p}));
|
||||
|
||||
$p =~ s/^(-{0,1}[0-9A-Fa-f]+)$/\$$1/;
|
||||
$p =~ s/^(0x[0-9A-Fa-f]+)$/\$$1/;
|
||||
return $p;
|
||||
}
|
||||
|
||||
sub main'file
|
||||
{
|
||||
local($file)=@_;
|
||||
|
||||
local($tmp)=<<"EOF";
|
||||
.file "$file.s"
|
||||
EOF
|
||||
push(@out,$tmp);
|
||||
}
|
||||
|
||||
sub main'function_begin
|
||||
{
|
||||
local($func)=@_;
|
||||
|
||||
&main'external_label($func);
|
||||
$func=$under.$func;
|
||||
|
||||
local($tmp)=<<"EOF";
|
||||
.text
|
||||
.globl $func
|
||||
EOF
|
||||
push(@out,$tmp);
|
||||
if ($main'cpp)
|
||||
{ $tmp=push(@out,"TYPE($func,\@function)\n"); }
|
||||
elsif ($main'coff)
|
||||
{ $tmp=push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
|
||||
elsif ($main'aout and !$main'pic)
|
||||
{ }
|
||||
else { $tmp=push(@out,".type\t$func,\@function\n"); }
|
||||
push(@out,".align\t$align\n");
|
||||
push(@out,"$func:\n");
|
||||
$tmp=<<"EOF";
|
||||
pushl %ebp
|
||||
pushl %ebx
|
||||
pushl %esi
|
||||
pushl %edi
|
||||
|
||||
EOF
|
||||
push(@out,$tmp);
|
||||
$stack=20;
|
||||
}
|
||||
|
||||
sub main'function_begin_B
|
||||
{
|
||||
local($func,$extra)=@_;
|
||||
|
||||
&main'external_label($func);
|
||||
$func=$under.$func;
|
||||
|
||||
local($tmp)=<<"EOF";
|
||||
.text
|
||||
.globl $func
|
||||
EOF
|
||||
push(@out,$tmp);
|
||||
if ($main'cpp)
|
||||
{ push(@out,"TYPE($func,\@function)\n"); }
|
||||
elsif ($main'coff)
|
||||
{ $tmp=push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
|
||||
elsif ($main'aout and !$main'pic)
|
||||
{ }
|
||||
else { push(@out,".type $func,\@function\n"); }
|
||||
push(@out,".align\t$align\n");
|
||||
push(@out,"$func:\n");
|
||||
$stack=4;
|
||||
}
|
||||
|
||||
sub main'function_end
|
||||
{
|
||||
local($func)=@_;
|
||||
|
||||
$func=$under.$func;
|
||||
|
||||
local($tmp)=<<"EOF";
|
||||
popl %edi
|
||||
popl %esi
|
||||
popl %ebx
|
||||
popl %ebp
|
||||
ret
|
||||
${dot}L_${func}_end:
|
||||
EOF
|
||||
push(@out,$tmp);
|
||||
|
||||
if ($main'cpp)
|
||||
{ push(@out,"SIZE($func,${dot}L_${func}_end-$func)\n"); }
|
||||
elsif ($main'coff or $main'aout)
|
||||
{ }
|
||||
else { push(@out,".size\t$func,${dot}L_${func}_end-$func\n"); }
|
||||
push(@out,".ident \"$func\"\n");
|
||||
$stack=0;
|
||||
%label=();
|
||||
}
|
||||
|
||||
sub main'function_end_A
|
||||
{
|
||||
local($func)=@_;
|
||||
|
||||
local($tmp)=<<"EOF";
|
||||
popl %edi
|
||||
popl %esi
|
||||
popl %ebx
|
||||
popl %ebp
|
||||
ret
|
||||
EOF
|
||||
push(@out,$tmp);
|
||||
}
|
||||
|
||||
sub main'function_end_B
|
||||
{
|
||||
local($func)=@_;
|
||||
|
||||
$func=$under.$func;
|
||||
|
||||
push(@out,"${dot}L_${func}_end:\n");
|
||||
if ($main'cpp)
|
||||
{ push(@out,"SIZE($func,${dot}L_${func}_end-$func)\n"); }
|
||||
elsif ($main'coff or $main'aout)
|
||||
{ }
|
||||
else { push(@out,".size\t$func,${dot}L_${func}_end-$func\n"); }
|
||||
push(@out,".ident \"$func\"\n");
|
||||
$stack=0;
|
||||
%label=();
|
||||
}
|
||||
|
||||
sub main'wparam
|
||||
{
|
||||
local($num)=@_;
|
||||
|
||||
return(&main'DWP($stack+$num*4,"esp","",0));
|
||||
}
|
||||
|
||||
sub main'stack_push
|
||||
{
|
||||
local($num)=@_;
|
||||
$stack+=$num*4;
|
||||
&main'sub("esp",$num*4);
|
||||
}
|
||||
|
||||
sub main'stack_pop
|
||||
{
|
||||
local($num)=@_;
|
||||
$stack-=$num*4;
|
||||
&main'add("esp",$num*4);
|
||||
}
|
||||
|
||||
sub main'swtmp
|
||||
{
|
||||
return(&main'DWP($_[0]*4,"esp","",0));
|
||||
}
|
||||
|
||||
# Should use swtmp, which is above esp. Linix can trash the stack above esp
|
||||
#sub main'wtmp
|
||||
# {
|
||||
# local($num)=@_;
|
||||
#
|
||||
# return(&main'DWP(-($num+1)*4,"esp","",0));
|
||||
# }
|
||||
|
||||
sub main'comment
|
||||
{
|
||||
if (!defined($com_start) or $main'elf)
|
||||
{ # Regarding $main'elf above...
|
||||
# GNU and SVR4 as'es use different comment delimiters,
|
||||
push(@out,"\n"); # so we just skip ELF comments...
|
||||
return;
|
||||
@ -160,167 +508,218 @@ sub ::comment
|
||||
}
|
||||
}
|
||||
|
||||
sub islabel # see is argument is a known label
|
||||
{ my $i;
|
||||
foreach $i (%label) { return $label{$i} if ($label{$i} eq $_[0]); }
|
||||
undef;
|
||||
}
|
||||
sub main'public_label
|
||||
{
|
||||
$label{$_[0]}="${under}${_[0]}" if (!defined($label{$_[0]}));
|
||||
push(@out,".globl\t$label{$_[0]}\n");
|
||||
}
|
||||
|
||||
sub ::external_label { push(@labels,@_); }
|
||||
sub main'label
|
||||
{
|
||||
if (!defined($label{$_[0]}))
|
||||
{
|
||||
$label{$_[0]}="${dot}${label}${_[0]}";
|
||||
$label++;
|
||||
}
|
||||
return($label{$_[0]});
|
||||
}
|
||||
|
||||
sub ::public_label
|
||||
{ $label{$_[0]}="${under}${_[0]}" if (!defined($label{$_[0]}));
|
||||
push(@out,".globl\t$label{$_[0]}\n");
|
||||
}
|
||||
sub main'set_label
|
||||
{
|
||||
if (!defined($label{$_[0]}))
|
||||
{
|
||||
$label{$_[0]}="${dot}${label}${_[0]}";
|
||||
$label++;
|
||||
}
|
||||
if ($_[1]!=0)
|
||||
{
|
||||
if ($_[1]>1) { main'align($_[1]); }
|
||||
else { push(@out,".align $align\n"); }
|
||||
}
|
||||
push(@out,"$label{$_[0]}:\n");
|
||||
}
|
||||
|
||||
sub ::label
|
||||
{ if (!defined($label{$_[0]}))
|
||||
{ $label{$_[0]}="${dot}${label}${_[0]}"; $label++; }
|
||||
$label{$_[0]};
|
||||
}
|
||||
sub main'file_end
|
||||
{
|
||||
# try to detect if SSE2 or MMX extensions were used on ELF platform...
|
||||
if ($main'elf && grep {/\b%[x]*mm[0-7]\b|OPENSSL_ia32cap_P\b/i} @out) {
|
||||
local($tmp);
|
||||
|
||||
sub ::set_label
|
||||
{ my $label=&::label($_[0]);
|
||||
&::align($_[1]) if ($_[1]>1);
|
||||
push(@out,"$label:\n");
|
||||
}
|
||||
push (@out,"\n.section\t.bss\n");
|
||||
push (@out,".comm\t${under}OPENSSL_ia32cap_P,4,4\n");
|
||||
|
||||
sub ::file_end
|
||||
{ # try to detect if SSE2 or MMX extensions were used on ELF platform...
|
||||
if ($::elf && grep {/\b%[x]?mm[0-7]\b|OPENSSL_ia32cap_P\b/i} @out) {
|
||||
return;
|
||||
}
|
||||
|
||||
push (@out,"\n.section\t.bss\n");
|
||||
push (@out,".comm\t${under}OPENSSL_ia32cap_P,4,4\n");
|
||||
if ($const ne "")
|
||||
{
|
||||
push(@out,".section .rodata\n");
|
||||
push(@out,$const);
|
||||
$const="";
|
||||
}
|
||||
}
|
||||
|
||||
return; # below is not needed in OpenSSL context
|
||||
sub main'data_byte
|
||||
{
|
||||
push(@out,"\t.byte\t".join(',',@_)."\n");
|
||||
}
|
||||
|
||||
push (@out,".section\t.init\n");
|
||||
&::picmeup("edx","OPENSSL_ia32cap_P");
|
||||
# $1<<10 sets a reserved bit to signal that variable
|
||||
# was initialized already...
|
||||
my $code=<<___;
|
||||
cmpl \$0,(%edx)
|
||||
jne 3f
|
||||
movl \$1<<10,(%edx)
|
||||
pushf
|
||||
popl %eax
|
||||
movl %eax,%ecx
|
||||
xorl \$1<<21,%eax
|
||||
pushl %eax
|
||||
popf
|
||||
pushf
|
||||
popl %eax
|
||||
xorl %ecx,%eax
|
||||
btl \$21,%eax
|
||||
jnc 3f
|
||||
pushl %ebp
|
||||
pushl %edi
|
||||
pushl %ebx
|
||||
movl %edx,%edi
|
||||
xor %eax,%eax
|
||||
.byte 0x0f,0xa2
|
||||
xorl %eax,%eax
|
||||
cmpl $1970169159,%ebx
|
||||
setne %al
|
||||
movl %eax,%ebp
|
||||
cmpl $1231384169,%edx
|
||||
setne %al
|
||||
orl %eax,%ebp
|
||||
cmpl $1818588270,%ecx
|
||||
setne %al
|
||||
orl %eax,%ebp
|
||||
movl $1,%eax
|
||||
.byte 0x0f,0xa2
|
||||
cmpl $0,%ebp
|
||||
jne 1f
|
||||
andb $15,%ah
|
||||
cmpb $15,%ah
|
||||
jne 1f
|
||||
orl $1048576,%edx
|
||||
1: btl $28,%edx
|
||||
jnc 2f
|
||||
shrl $16,%ebx
|
||||
cmpb $1,%bl
|
||||
ja 2f
|
||||
andl $4026531839,%edx
|
||||
2: orl \$1<<10,%edx
|
||||
movl %edx,0(%edi)
|
||||
popl %ebx
|
||||
popl %edi
|
||||
popl %ebp
|
||||
jmp 3f
|
||||
.align $align
|
||||
3:
|
||||
sub main'data_word
|
||||
{
|
||||
push(@out,"\t.long\t".join(',',@_)."\n");
|
||||
}
|
||||
|
||||
sub main'align
|
||||
{
|
||||
my $val=$_[0],$p2,$i;
|
||||
if ($main'aout) {
|
||||
for ($p2=0;$val!=0;$val>>=1) { $p2++; }
|
||||
$val=$p2-1;
|
||||
$val.=",0x90";
|
||||
}
|
||||
push(@out,".align\t$val\n");
|
||||
}
|
||||
|
||||
# debug output functions: puts, putx, printf
|
||||
|
||||
sub main'puts
|
||||
{
|
||||
&pushvars();
|
||||
&main'push('$Lstring' . ++$constl);
|
||||
&main'call('puts');
|
||||
$stack-=4;
|
||||
&main'add("esp",4);
|
||||
&popvars();
|
||||
|
||||
$const .= "Lstring$constl:\n\t.string \"@_[0]\"\n";
|
||||
}
|
||||
|
||||
sub main'putx
|
||||
{
|
||||
&pushvars();
|
||||
&main'push($_[0]);
|
||||
&main'push('$Lstring' . ++$constl);
|
||||
&main'call('printf');
|
||||
&main'add("esp",8);
|
||||
$stack-=8;
|
||||
&popvars();
|
||||
|
||||
$const .= "Lstring$constl:\n\t.string \"\%X\"\n";
|
||||
}
|
||||
|
||||
sub main'printf
|
||||
{
|
||||
$ostack = $stack;
|
||||
&pushvars();
|
||||
for ($i = @_ - 1; $i >= 0; $i--)
|
||||
{
|
||||
if ($i == 0) # change this to support %s format strings
|
||||
{
|
||||
&main'push('$Lstring' . ++$constl);
|
||||
$const .= "Lstring$constl:\n\t.string \"@_[$i]\"\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($_[$i] =~ /([0-9]*)\(%esp\)/)
|
||||
{
|
||||
&main'push(($1 + $stack - $ostack) . '(%esp)');
|
||||
}
|
||||
else
|
||||
{
|
||||
&main'push($_[$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
&main'call('printf');
|
||||
$stack-=4*@_;
|
||||
&main'add("esp",4*@_);
|
||||
&popvars();
|
||||
}
|
||||
|
||||
sub pushvars
|
||||
{
|
||||
&main'pushf();
|
||||
&main'push("edx");
|
||||
&main'push("ecx");
|
||||
&main'push("eax");
|
||||
}
|
||||
|
||||
sub popvars
|
||||
{
|
||||
&main'pop("eax");
|
||||
&main'pop("ecx");
|
||||
&main'pop("edx");
|
||||
&main'popf();
|
||||
}
|
||||
|
||||
sub main'picmeup
|
||||
{
|
||||
local($dst,$sym)=@_;
|
||||
if ($main'cpp)
|
||||
{
|
||||
local($tmp)=<<___;
|
||||
#if (defined(ELF) || defined(SOL)) && defined(PIC)
|
||||
call 1f
|
||||
1: popl $regs{$dst}
|
||||
addl \$_GLOBAL_OFFSET_TABLE_+[.-1b],$regs{$dst}
|
||||
movl $sym\@GOT($regs{$dst}),$regs{$dst}
|
||||
#else
|
||||
leal $sym,$regs{$dst}
|
||||
#endif
|
||||
___
|
||||
push (@out,$code);
|
||||
}
|
||||
}
|
||||
|
||||
sub ::data_byte { push(@out,".byte\t".join(',',@_)."\n"); }
|
||||
sub ::data_word { push(@out,".long\t".join(',',@_)."\n"); }
|
||||
|
||||
sub ::align
|
||||
{ my $val=$_[0],$p2,$i;
|
||||
if ($::aout)
|
||||
{ for ($p2=0;$val!=0;$val>>=1) { $p2++; }
|
||||
$val=$p2-1;
|
||||
$val.=",0x90";
|
||||
}
|
||||
push(@out,".align\t$val\n");
|
||||
}
|
||||
|
||||
sub ::picmeup
|
||||
{ my($dst,$sym,$base,$reflabel)=@_;
|
||||
|
||||
if ($::pic && ($::elf || $::aout))
|
||||
{ if (!defined($base))
|
||||
{ &::call(&::label("PIC_me_up"));
|
||||
&::set_label("PIC_me_up");
|
||||
&::blindpop($dst);
|
||||
&::add($dst,"\$${under}_GLOBAL_OFFSET_TABLE_+[.-".
|
||||
&::label("PIC_me_up") . "]");
|
||||
}
|
||||
push(@out,$tmp);
|
||||
}
|
||||
elsif ($main'pic && ($main'elf || $main'aout))
|
||||
{
|
||||
&main'call(&main'label("PIC_me_up"));
|
||||
&main'set_label("PIC_me_up");
|
||||
&main'blindpop($dst);
|
||||
&main'add($dst,"\$${under}_GLOBAL_OFFSET_TABLE_+[.-".
|
||||
&main'label("PIC_me_up") . "]");
|
||||
&main'mov($dst,&main'DWP($under.$sym."\@GOT",$dst));
|
||||
}
|
||||
else
|
||||
{ &::lea($dst,&::DWP("${under}_GLOBAL_OFFSET_TABLE_+[.-$reflabel]",
|
||||
$base));
|
||||
{
|
||||
&main'lea($dst,&main'DWP($sym));
|
||||
}
|
||||
}
|
||||
&::mov($dst,&::DWP($under.$sym."\@GOT",$dst));
|
||||
}
|
||||
else
|
||||
{ &::lea($dst,&::DWP($sym)); }
|
||||
}
|
||||
|
||||
sub ::initseg
|
||||
{ my($f)=@_;
|
||||
my($tmp,$ctor);
|
||||
sub main'blindpop { &out1("popl",@_); }
|
||||
|
||||
if ($::elf)
|
||||
{ $tmp=<<___;
|
||||
sub main'initseg
|
||||
{
|
||||
local($f)=@_;
|
||||
local($tmp);
|
||||
if ($main'elf)
|
||||
{
|
||||
$tmp=<<___;
|
||||
.section .init
|
||||
call $under$f
|
||||
jmp .Linitalign
|
||||
.align $align
|
||||
.Linitalign:
|
||||
___
|
||||
}
|
||||
elsif ($::coff)
|
||||
{ $tmp=<<___; # applies to both Cygwin and Mingw
|
||||
}
|
||||
elsif ($main'coff)
|
||||
{
|
||||
$tmp=<<___; # applies to both Cygwin and Mingw
|
||||
.section .ctors
|
||||
.long $under$f
|
||||
___
|
||||
}
|
||||
elsif ($::aout)
|
||||
{ $ctor="${under}_GLOBAL_\$I\$$f";
|
||||
$tmp=".text\n";
|
||||
$tmp.=".type $ctor,\@function\n" if ($::pic);
|
||||
$tmp.=<<___; # OpenBSD way...
|
||||
}
|
||||
elsif ($main'aout)
|
||||
{
|
||||
local($ctor)="${under}_GLOBAL_\$I\$$f";
|
||||
$tmp=".text\n";
|
||||
$tmp.=".type $ctor,\@function\n" if ($main'pic);
|
||||
$tmp.=<<___; # OpenBSD way...
|
||||
.globl $ctor
|
||||
.align 2
|
||||
$ctor:
|
||||
jmp $under$f
|
||||
___
|
||||
}
|
||||
push(@out,$tmp) if ($tmp);
|
||||
}
|
||||
}
|
||||
push(@out,$tmp) if ($tmp);
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -59,7 +59,10 @@
|
||||
#include <stdio.h>
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/pkcs12.h>
|
||||
#ifdef OPENSSL_FIPS
|
||||
#include <openssl/fips.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
static int pkcs12_add_bag(STACK_OF(PKCS12_SAFEBAG) **pbags, PKCS12_SAFEBAG *bag);
|
||||
|
@ -377,57 +377,6 @@ PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont)
|
||||
|
||||
}
|
||||
|
||||
/* Copy text from one BIO to another making the output CRLF at EOL */
|
||||
int SMIME_crlf_copy(BIO *in, BIO *out, int flags)
|
||||
{
|
||||
char eol;
|
||||
int len;
|
||||
char linebuf[MAX_SMLEN];
|
||||
if(flags & PKCS7_BINARY) {
|
||||
while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0)
|
||||
BIO_write(out, linebuf, len);
|
||||
return 1;
|
||||
}
|
||||
if(flags & PKCS7_TEXT)
|
||||
BIO_printf(out, "Content-Type: text/plain\r\n\r\n");
|
||||
while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) {
|
||||
eol = strip_eol(linebuf, &len);
|
||||
if (len)
|
||||
BIO_write(out, linebuf, len);
|
||||
if(eol) BIO_write(out, "\r\n", 2);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Strip off headers if they are text/plain */
|
||||
int SMIME_text(BIO *in, BIO *out)
|
||||
{
|
||||
char iobuf[4096];
|
||||
int len;
|
||||
STACK_OF(MIME_HEADER) *headers;
|
||||
MIME_HEADER *hdr;
|
||||
|
||||
if (!(headers = mime_parse_hdr(in))) {
|
||||
PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_MIME_PARSE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
|
||||
PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_MIME_NO_CONTENT_TYPE);
|
||||
sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
|
||||
return 0;
|
||||
}
|
||||
if (strcmp (hdr->value, "text/plain")) {
|
||||
PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_INVALID_MIME_TYPE);
|
||||
ERR_add_error_data(2, "type: ", hdr->value);
|
||||
sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
|
||||
return 0;
|
||||
}
|
||||
sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
|
||||
while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0)
|
||||
BIO_write(out, iobuf, len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Split a multipart/XXX message body into component parts: result is
|
||||
* canonical parts in a STACK of bios
|
||||
*/
|
||||
|
@ -126,7 +126,10 @@
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/err.h>
|
||||
#ifdef OPENSSL_FIPS
|
||||
#include <openssl/fips.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef BN_DEBUG
|
||||
# define PREDICT
|
||||
|
@ -61,7 +61,10 @@
|
||||
#include "cryptlib.h"
|
||||
#include "rand_lcl.h"
|
||||
#include <openssl/rand.h>
|
||||
#ifdef OPENSSL_FIPS
|
||||
#include <openssl/fips.h>
|
||||
#endif
|
||||
|
||||
#include <openssl/fips_rand.h>
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
#include <openssl/engine.h>
|
||||
|
@ -61,7 +61,10 @@
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/rand.h>
|
||||
#include "rand_lcl.h"
|
||||
#ifdef OPENSSL_FIPS
|
||||
#include <openssl/fips.h>
|
||||
#endif
|
||||
|
||||
#include <openssl/fips_rand.h>
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
#include <openssl/engine.h>
|
||||
|
@ -58,7 +58,10 @@
|
||||
|
||||
#include <openssl/rc2.h>
|
||||
#include <openssl/crypto.h>
|
||||
#ifdef OPENSSL_FIPS
|
||||
#include <openssl/fips.h>
|
||||
#endif
|
||||
|
||||
#include "rc2_locl.h"
|
||||
|
||||
static unsigned char key_table[256]={
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user