| 
									
										
										
										
											2008-11-06 02:39:08 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2023-09-07 16:59:15 +08:00
										 |  |  |  * Copyright 2000-2023 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-12-06 20:00:26 +08:00
										 |  |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							| 
									
										
										
										
											2016-05-18 02:18:30 +08:00
										 |  |  |  * this file except in compliance with the License.  You can obtain a copy | 
					
						
							|  |  |  |  * in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  |  * https://www.openssl.org/source/license.html
 | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-10-26 20:05:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-16 20:37:36 +08:00
										 |  |  | #include <openssl/opensslconf.h>
 | 
					
						
							| 
									
										
										
										
											2000-10-26 20:05:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-05 05:52:22 +08:00
										 |  |  | #include "apps.h"
 | 
					
						
							|  |  |  | #include "progs.h"
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <openssl/err.h>
 | 
					
						
							|  |  |  | #include <openssl/pem.h>
 | 
					
						
							|  |  |  | #include <openssl/rsa.h>
 | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-05 05:52:22 +08:00
										 |  |  | #define RSA_SIGN        1
 | 
					
						
							|  |  |  | #define RSA_VERIFY      2
 | 
					
						
							|  |  |  | #define RSA_ENCRYPT     3
 | 
					
						
							|  |  |  | #define RSA_DECRYPT     4
 | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-05 05:52:22 +08:00
										 |  |  | #define KEY_PRIVKEY     1
 | 
					
						
							|  |  |  | #define KEY_PUBKEY      2
 | 
					
						
							|  |  |  | #define KEY_CERT        3
 | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  | typedef enum OPTION_choice { | 
					
						
							| 
									
										
										
										
											2021-05-01 21:29:00 +08:00
										 |  |  |     OPT_COMMON, | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     OPT_ENGINE, OPT_IN, OPT_OUT, OPT_ASN1PARSE, OPT_HEXDUMP, | 
					
						
							| 
									
										
										
										
											2021-02-23 01:55:25 +08:00
										 |  |  |     OPT_RSA_RAW, OPT_OAEP, OPT_PKCS, OPT_X931, | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     OPT_SIGN, OPT_VERIFY, OPT_REV, OPT_ENCRYPT, OPT_DECRYPT, | 
					
						
							| 
									
										
										
										
											2017-07-05 22:58:48 +08:00
										 |  |  |     OPT_PUBIN, OPT_CERTIN, OPT_INKEY, OPT_PASSIN, OPT_KEYFORM, | 
					
						
							| 
									
										
										
										
											2020-02-25 12:29:30 +08:00
										 |  |  |     OPT_R_ENUM, OPT_PROV_ENUM | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  | } OPTION_CHOICE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-13 21:07:50 +08:00
										 |  |  | const OPTIONS rsautl_options[] = { | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  |     OPT_SECTION("General"), | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     {"help", OPT_HELP, '-', "Display this summary"}, | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  |     {"sign", OPT_SIGN, '-', "Sign with private key"}, | 
					
						
							|  |  |  |     {"verify", OPT_VERIFY, '-', "Verify with public key"}, | 
					
						
							|  |  |  |     {"encrypt", OPT_ENCRYPT, '-', "Encrypt with public key"}, | 
					
						
							|  |  |  |     {"decrypt", OPT_DECRYPT, '-', "Decrypt with private key"}, | 
					
						
							| 
									
										
										
										
											2020-03-05 05:52:22 +08:00
										 |  |  | #ifndef OPENSSL_NO_ENGINE
 | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  |     {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"}, | 
					
						
							| 
									
										
										
										
											2020-03-05 05:52:22 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     OPT_SECTION("Input"), | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     {"in", OPT_IN, '<', "Input file"}, | 
					
						
							| 
									
										
										
										
											2022-08-27 02:40:48 +08:00
										 |  |  |     {"inkey", OPT_INKEY, 's', "Input key, by default an RSA private key"}, | 
					
						
							| 
									
										
										
										
											2020-05-06 19:51:50 +08:00
										 |  |  |     {"keyform", OPT_KEYFORM, 'E', "Private key format (ENGINE, other values ignored)"}, | 
					
						
							| 
									
										
										
										
											2022-08-27 02:40:48 +08:00
										 |  |  |     {"pubin", OPT_PUBIN, '-', "Input key is an RSA public pkey"}, | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     {"certin", OPT_CERTIN, '-', "Input is a cert carrying an RSA public key"}, | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  |     {"rev", OPT_REV, '-', "Reverse the order of the input buffer"}, | 
					
						
							|  |  |  |     {"passin", OPT_PASSIN, 's', "Input file pass phrase source"}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     OPT_SECTION("Output"), | 
					
						
							|  |  |  |     {"out", OPT_OUT, '>', "Output file"}, | 
					
						
							| 
									
										
										
										
											2019-02-19 20:34:32 +08:00
										 |  |  |     {"raw", OPT_RSA_RAW, '-', "Use no padding"}, | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     {"pkcs", OPT_PKCS, '-', "Use PKCS#1 v1.5 padding (default)"}, | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  |     {"x931", OPT_X931, '-', "Use ANSI X9.31 padding"}, | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     {"oaep", OPT_OAEP, '-', "Use PKCS#1 OAEP"}, | 
					
						
							| 
									
										
										
										
											2016-02-19 01:23:27 +08:00
										 |  |  |     {"asn1parse", OPT_ASN1PARSE, '-', | 
					
						
							|  |  |  |      "Run output through asn1parse; useful with -verify"}, | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     {"hexdump", OPT_HEXDUMP, '-', "Hex dump output"}, | 
					
						
							| 
									
										
										
										
											2019-11-08 04:08:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-05 22:58:48 +08:00
										 |  |  |     OPT_R_OPTIONS, | 
					
						
							| 
									
										
										
										
											2020-02-25 12:29:30 +08:00
										 |  |  |     OPT_PROV_OPTIONS, | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     {NULL} | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  | int rsautl_main(int argc, char **argv) | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     BIO *in = NULL, *out = NULL; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     ENGINE *e = NULL; | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |     EVP_PKEY *pkey = NULL; | 
					
						
							| 
									
										
										
										
											2020-10-04 22:34:31 +08:00
										 |  |  |     EVP_PKEY_CTX *ctx = NULL; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     X509 *x; | 
					
						
							| 
									
										
										
										
											2015-04-26 03:41:29 +08:00
										 |  |  |     char *infile = NULL, *outfile = NULL, *keyfile = NULL; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     char *passinarg = NULL, *passin = NULL, *prog; | 
					
						
							|  |  |  |     char rsa_mode = RSA_VERIFY, key_type = KEY_PRIVKEY; | 
					
						
							|  |  |  |     unsigned char *rsa_in = NULL, *rsa_out = NULL, pad = RSA_PKCS1_PADDING; | 
					
						
							| 
									
										
										
										
											2020-10-04 22:34:31 +08:00
										 |  |  |     size_t rsa_inlen, rsa_outlen = 0; | 
					
						
							| 
									
										
										
										
											2021-04-30 22:57:53 +08:00
										 |  |  |     int keyformat = FORMAT_UNDEF, keysize, ret = 1, rv; | 
					
						
							| 
									
										
										
										
											2020-10-04 22:34:31 +08:00
										 |  |  |     int hexdump = 0, asn1parse = 0, need_priv = 0, rev = 0; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     OPTION_CHOICE o; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     prog = opt_init(argc, argv, rsautl_options); | 
					
						
							|  |  |  |     while ((o = opt_next()) != OPT_EOF) { | 
					
						
							|  |  |  |         switch (o) { | 
					
						
							|  |  |  |         case OPT_EOF: | 
					
						
							|  |  |  |         case OPT_ERR: | 
					
						
							|  |  |  |  opthelp: | 
					
						
							|  |  |  |             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); | 
					
						
							|  |  |  |             goto end; | 
					
						
							|  |  |  |         case OPT_HELP: | 
					
						
							|  |  |  |             opt_help(rsautl_options); | 
					
						
							|  |  |  |             ret = 0; | 
					
						
							|  |  |  |             goto end; | 
					
						
							|  |  |  |         case OPT_KEYFORM: | 
					
						
							| 
									
										
										
										
											2020-05-06 19:51:50 +08:00
										 |  |  |             if (!opt_format(opt_arg(), OPT_FMT_ANY, &keyformat)) | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |                 goto opthelp; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case OPT_IN: | 
					
						
							|  |  |  |             infile = opt_arg(); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case OPT_OUT: | 
					
						
							|  |  |  |             outfile = opt_arg(); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case OPT_ENGINE: | 
					
						
							| 
									
										
										
										
											2015-04-26 03:41:29 +08:00
										 |  |  |             e = setup_engine(opt_arg(), 0); | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case OPT_ASN1PARSE: | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |             asn1parse = 1; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case OPT_HEXDUMP: | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |             hexdump = 1; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |             break; | 
					
						
							| 
									
										
										
										
											2019-02-19 20:34:32 +08:00
										 |  |  |         case OPT_RSA_RAW: | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |             pad = RSA_NO_PADDING; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case OPT_OAEP: | 
					
						
							| 
									
										
										
										
											2000-09-06 19:49:43 +08:00
										 |  |  |             pad = RSA_PKCS1_OAEP_PADDING; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case OPT_PKCS: | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |             pad = RSA_PKCS1_PADDING; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case OPT_X931: | 
					
						
							| 
									
										
										
										
											2005-05-29 04:44:02 +08:00
										 |  |  |             pad = RSA_X931_PADDING; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case OPT_SIGN: | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |             rsa_mode = RSA_SIGN; | 
					
						
							|  |  |  |             need_priv = 1; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case OPT_VERIFY: | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |             rsa_mode = RSA_VERIFY; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case OPT_REV: | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |             rev = 1; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case OPT_ENCRYPT: | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |             rsa_mode = RSA_ENCRYPT; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case OPT_DECRYPT: | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |             rsa_mode = RSA_DECRYPT; | 
					
						
							|  |  |  |             need_priv = 1; | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |             break; | 
					
						
							|  |  |  |         case OPT_PUBIN: | 
					
						
							|  |  |  |             key_type = KEY_PUBKEY; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case OPT_CERTIN: | 
					
						
							|  |  |  |             key_type = KEY_CERT; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case OPT_INKEY: | 
					
						
							|  |  |  |             keyfile = opt_arg(); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case OPT_PASSIN: | 
					
						
							|  |  |  |             passinarg = opt_arg(); | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2017-07-05 22:58:48 +08:00
										 |  |  |         case OPT_R_CASES: | 
					
						
							|  |  |  |             if (!opt_rand(o)) | 
					
						
							|  |  |  |                 goto end; | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2020-02-25 12:29:30 +08:00
										 |  |  |         case OPT_PROV_CASES: | 
					
						
							|  |  |  |             if (!opt_provider(o)) | 
					
						
							|  |  |  |                 goto end; | 
					
						
							|  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-11-29 05:12:58 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* No extra arguments. */ | 
					
						
							| 
									
										
										
										
											2021-08-27 21:33:18 +08:00
										 |  |  |     if (!opt_check_rest_arg(NULL)) | 
					
						
							| 
									
										
										
										
											2016-02-15 03:45:02 +08:00
										 |  |  |         goto opthelp; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-03 18:53:51 +08:00
										 |  |  |     if (!app_RAND_load()) | 
					
						
							|  |  |  |         goto end; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-06 06:30:38 +08:00
										 |  |  |     if (need_priv && (key_type != KEY_PRIVKEY)) { | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |         BIO_printf(bio_err, "A private key is needed for this operation\n"); | 
					
						
							|  |  |  |         goto end; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-04-26 03:41:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     if (!app_passwd(passinarg, NULL, &passin, NULL)) { | 
					
						
							| 
									
										
										
										
											2003-09-21 10:20:02 +08:00
										 |  |  |         BIO_printf(bio_err, "Error getting password\n"); | 
					
						
							|  |  |  |         goto end; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2000-10-29 06:40:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |     switch (key_type) { | 
					
						
							|  |  |  |     case KEY_PRIVKEY: | 
					
						
							| 
									
										
										
										
											2020-09-17 07:39:00 +08:00
										 |  |  |         pkey = load_key(keyfile, keyformat, 0, passin, e, "private key"); | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |     case KEY_PUBKEY: | 
					
						
							| 
									
										
										
										
											2020-09-17 07:39:00 +08:00
										 |  |  |         pkey = load_pubkey(keyfile, keyformat, 0, NULL, e, "public key"); | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |     case KEY_CERT: | 
					
						
							| 
									
										
										
										
											2021-04-30 22:57:53 +08:00
										 |  |  |         x = load_cert(keyfile, FORMAT_UNDEF, "Certificate"); | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |         if (x) { | 
					
						
							|  |  |  |             pkey = X509_get_pubkey(x); | 
					
						
							|  |  |  |             X509_free(x); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 01:24:02 +08:00
										 |  |  |     if (pkey == NULL) | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |         return 1; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-04 18:49:06 +08:00
										 |  |  |     in = bio_open_default(infile, 'r', FORMAT_BINARY); | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     if (in == NULL) | 
					
						
							|  |  |  |         goto end; | 
					
						
							| 
									
										
										
										
											2015-09-04 18:49:06 +08:00
										 |  |  |     out = bio_open_default(outfile, 'w', FORMAT_BINARY); | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |     if (out == NULL) | 
					
						
							|  |  |  |         goto end; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
											
												Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
											
										 
											2021-05-21 22:58:08 +08:00
										 |  |  |     keysize = EVP_PKEY_get_size(pkey); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-01 05:48:31 +08:00
										 |  |  |     rsa_in = app_malloc(keysize * 2, "hold rsa key"); | 
					
						
							|  |  |  |     rsa_out = app_malloc(keysize, "output rsa key"); | 
					
						
							| 
									
										
										
										
											2020-10-04 22:34:31 +08:00
										 |  |  |     rsa_outlen = keysize; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |     /* Read the input data */ | 
					
						
							| 
									
										
										
										
											2020-10-04 22:34:31 +08:00
										 |  |  |     rv = BIO_read(in, rsa_in, keysize * 2); | 
					
						
							|  |  |  |     if (rv < 0) { | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |         BIO_printf(bio_err, "Error reading input Data\n"); | 
					
						
							| 
									
										
											  
											
												Big apps cleanup (option-parsing, etc)
This is merges the old "rsalz-monolith" branch over to master.  The biggest
change is that option parsing switch from cascasding 'else if strcmp("-foo")'
to a utility routine and somethin akin to getopt.  Also, an error in the
command line no longer prints the full summary; use -help (or --help :)
for that.  There have been many other changes and code-cleanup, see
bullet list below.
Special thanks to Matt for the long and detailed code review.
TEMPORARY:
        For now, comment out CRYPTO_mem_leaks() at end of main
Tickets closed:
        RT3515: Use 3DES in pkcs12 if built with no-rc2
        RT1766: s_client -reconnect and -starttls broke
        RT2932: Catch write errors
        RT2604: port should be 'unsigned short'
        RT2983: total_bytes undeclared #ifdef RENEG
        RT1523: Add -nocert to fix output in x509 app
        RT3508: Remove unused variable introduced by b09eb24
        RT3511: doc fix; req default serial is random
        RT1325,2973: Add more extensions to c_rehash
        RT2119,3407: Updated to dgst.pod
        RT2379: Additional typo fix
        RT2693: Extra include of string.h
        RT2880: HFS is case-insensitive filenames
        RT3246: req command prints version number wrong
Other changes; incompatibilities marked with *:
        Add SCSV support
        Add -misalign to speed command
        Make dhparam, dsaparam, ecparam, x509 output C in proper style
        Make some internal ocsp.c functions void
        Only display cert usages with -help in verify
        Use global bio_err, remove "BIO*err" parameter from functions
        For filenames, - always means stdin (or stdout as appropriate)
        Add aliases for -des/aes "wrap" ciphers.
        *Remove support for IISSGC (server gated crypto)
        *The undocumented OCSP -header flag is now "-header name=value"
        *Documented the OCSP -header flag
Reviewed-by: Matt Caswell <matt@openssl.org>
											
										 
											2015-04-25 03:26:15 +08:00
										 |  |  |         goto end; | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-10-04 22:34:31 +08:00
										 |  |  |     rsa_inlen = rv; | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |     if (rev) { | 
					
						
							| 
									
										
										
										
											2020-10-04 22:34:31 +08:00
										 |  |  |         size_t i; | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |         unsigned char ctmp; | 
					
						
							| 
									
										
										
										
											2020-10-04 22:34:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |         for (i = 0; i < rsa_inlen / 2; i++) { | 
					
						
							|  |  |  |             ctmp = rsa_in[i]; | 
					
						
							|  |  |  |             rsa_in[i] = rsa_in[rsa_inlen - 1 - i]; | 
					
						
							|  |  |  |             rsa_in[rsa_inlen - 1 - i] = ctmp; | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-04 22:34:31 +08:00
										 |  |  |     if ((ctx = EVP_PKEY_CTX_new_from_pkey(NULL, pkey, NULL)) == NULL) | 
					
						
							|  |  |  |         goto end; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (rsa_mode) { | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |     case RSA_VERIFY: | 
					
						
							| 
									
										
										
										
											2022-12-02 16:31:02 +08:00
										 |  |  |         rv = EVP_PKEY_verify_recover_init(ctx) > 0 | 
					
						
							|  |  |  |             && EVP_PKEY_CTX_set_rsa_padding(ctx, pad) > 0 | 
					
						
							| 
									
										
										
										
											2020-10-04 22:34:31 +08:00
										 |  |  |             && EVP_PKEY_verify_recover(ctx, rsa_out, &rsa_outlen, | 
					
						
							| 
									
										
										
										
											2022-12-02 16:31:02 +08:00
										 |  |  |                                        rsa_in, rsa_inlen) > 0; | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case RSA_SIGN: | 
					
						
							| 
									
										
										
										
											2022-12-02 16:31:02 +08:00
										 |  |  |         rv = EVP_PKEY_sign_init(ctx) > 0 | 
					
						
							|  |  |  |             && EVP_PKEY_CTX_set_rsa_padding(ctx, pad) > 0 | 
					
						
							|  |  |  |             && EVP_PKEY_sign(ctx, rsa_out, &rsa_outlen, rsa_in, rsa_inlen) > 0; | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case RSA_ENCRYPT: | 
					
						
							| 
									
										
										
										
											2022-12-02 16:31:02 +08:00
										 |  |  |         rv = EVP_PKEY_encrypt_init(ctx) > 0 | 
					
						
							|  |  |  |             && EVP_PKEY_CTX_set_rsa_padding(ctx, pad) > 0 | 
					
						
							|  |  |  |             && EVP_PKEY_encrypt(ctx, rsa_out, &rsa_outlen, rsa_in, rsa_inlen) > 0; | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case RSA_DECRYPT: | 
					
						
							| 
									
										
										
										
											2022-12-02 16:31:02 +08:00
										 |  |  |         rv = EVP_PKEY_decrypt_init(ctx) > 0 | 
					
						
							|  |  |  |             && EVP_PKEY_CTX_set_rsa_padding(ctx, pad) > 0 | 
					
						
							|  |  |  |             && EVP_PKEY_decrypt(ctx, rsa_out, &rsa_outlen, rsa_in, rsa_inlen) > 0; | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-04 22:34:31 +08:00
										 |  |  |     if (!rv) { | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |         BIO_printf(bio_err, "RSA operation error\n"); | 
					
						
							|  |  |  |         ERR_print_errors(bio_err); | 
					
						
							|  |  |  |         goto end; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     ret = 0; | 
					
						
							|  |  |  |     if (asn1parse) { | 
					
						
							|  |  |  |         if (!ASN1_parse_dump(out, rsa_out, rsa_outlen, 1, -1)) { | 
					
						
							|  |  |  |             ERR_print_errors(bio_err); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-06-13 01:24:02 +08:00
										 |  |  |     } else if (hexdump) { | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |         BIO_dump(out, (char *)rsa_out, rsa_outlen); | 
					
						
							| 
									
										
										
										
											2017-06-13 01:24:02 +08:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |         BIO_write(out, rsa_out, rsa_outlen); | 
					
						
							| 
									
										
										
										
											2017-06-13 01:24:02 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |  end: | 
					
						
							| 
									
										
										
										
											2020-10-04 22:34:31 +08:00
										 |  |  |     EVP_PKEY_CTX_free(ctx); | 
					
						
							|  |  |  |     EVP_PKEY_free(pkey); | 
					
						
							| 
									
										
										
										
											2016-09-29 05:39:18 +08:00
										 |  |  |     release_engine(e); | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |     BIO_free(in); | 
					
						
							| 
									
										
										
											
												On VMS, stdout may very well lead to a file that is written to in a
record-oriented fashion.  That means that every write() will write a
separate record, which will be read separately by the programs trying
to read from it.  This can be very confusing.
The solution is to put a BIO filter in the way that will buffer text
until a linefeed is reached, and then write everything a line at a
time, so every record written will be an actual line, not chunks of
lines and not (usually doesn't happen, but I've seen it once) several
lines in one record.  Voila, BIO_f_linebuffer() is born.
Since we're so close to release time, I'm making this VMS-only for
now, just to make sure no code is needlessly broken by this.  After
the release, this BIO method will be enabled on all other platforms as
well.
											
										 
											2000-09-20 21:55:50 +08:00
										 |  |  |     BIO_free_all(out); | 
					
						
							| 
									
										
										
										
											2015-05-01 22:02:07 +08:00
										 |  |  |     OPENSSL_free(rsa_in); | 
					
						
							|  |  |  |     OPENSSL_free(rsa_out); | 
					
						
							|  |  |  |     OPENSSL_free(passin); | 
					
						
							| 
									
										
										
										
											2000-09-04 07:13:48 +08:00
										 |  |  |     return ret; | 
					
						
							|  |  |  | } |