History log of /openbsd-current/usr.bin/openssl/ca.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.59 23-Jun-2024 tb

openssl ca: avoid double free for spkac files without default section

ok jsing


Revision tags: OPENBSD_7_5_BASE
# 1.58 04-Feb-2024 tb

Zap a useless comment followed by a stray semicolon

Noticed by Christian Andersen


# 1.57 13-Nov-2023 tb

Kill last user of ASN1_time_parse() in the tree

ASN1_time_parse() was useful while OpenSSL didn't have something sort of
equivalent, but now they do. Let's retire ASN1_time_parse() to internal.
This will require some patching in ports, but shrug.

ok beck


Revision tags: OPENBSD_7_4_BASE
# 1.56 02-Jul-2023 tb

Teach openssl ca about Ed25519 certificates

This adds a few logic curlies to end up setting the EVP_MD to EVP_md_null()
as required by the API. This way ASN1_item_sign() now knows how to behave.

"ok = (rv == 2);" beck


Revision tags: OPENBSD_7_3_BASE
# 1.55 06-Mar-2023 tb

Rename struct ${app}_config to plain cfg

All the structs are static and we need to reach into them many times.
Having a shorter name is more concise and results in less visual clutter.
It also avoids many overlong lines and we will be able to get rid of some
unfortunate line wrapping down the road.

Discussed with jsing


# 1.54 11-Nov-2022 joshua

Remove the legacy interactive mode from openssl(1).

This removes the legacy interactive mode from openssl(1) since it is
rarely used, complicates the code, and has also been removed from
OpenSSL in version 3.x.x.

ok tb@ jsing@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.53 03-Feb-2022 tb

Use X509_*get0_pubkey() wherever possible to simplify and clean up
the code. Also add error checking where possible.

ok jsing


# 1.52 21-Nov-2021 tb

Tweak for opaque EVP_MD: use EVP_MD_type(dgst) instead of dgst->type.


# 1.51 23-Oct-2021 tb

Stop reaching into structs that will become opaque in ca.c

"just commit it" beck


# 1.50 22-Oct-2021 tb

Stop setting enc.modified manually. It's no longer needed.


Revision tags: OPENBSD_7_0_BASE
# 1.49 05-Sep-2021 inoguchi

Remove unused variable tmptm in do_body of openssl(1) ca


# 1.48 05-Sep-2021 inoguchi

Using serial number instead as subject if it is empty in openssl(1) ca

This allows multiple entries without a subject even if unique_subject == yes.
Referred to OpenSSL commit 5af88441 and arranged for our codebase.

ok tb@


# 1.47 05-Sep-2021 inoguchi

Check extensions before setting version to v3

Referred to OpenSSL commit 4881d849 and arranged for our codebase.

comment and ok from tb@


# 1.46 05-Sep-2021 inoguchi

Use accessor method rather than direct X509 structure access

Referred to OpenSSL commit a8d8e06b and arranged for our codebase.

comment and ok from tb@


# 1.45 02-Sep-2021 inoguchi

Use defined constants


# 1.44 02-Sep-2021 inoguchi

Move subject check process after the subject edit process

Referred to OpenSSL commit 2cedf794 and arranged for our codebase.

ok tb@


# 1.43 30-Aug-2021 inoguchi

Clean up end of do_body in openssl(1) ca

suggested from tb@


# 1.42 30-Aug-2021 inoguchi

Remove NULL check before free in openssl(1) ca

ok tb@


# 1.41 28-Aug-2021 inoguchi

Check X509_get_notAfter return value in openssl(1) ca.c


# 1.40 28-Aug-2021 inoguchi

Use strndup instead of malloc, memcpy and NULL termination in openssl(1) ca.c

suggested from tb@ for do_updatedb(),
and applied the same for do_body() and do_revoke().


# 1.39 28-Aug-2021 inoguchi

Remove ASN1_TIME_new and use NULL for X509_gmtime_adj, free tmptm in err path

comments from tb@


# 1.38 28-Aug-2021 inoguchi

Unwrap lines in openssl(1) ca.c

suggested from tb@


# 1.37 28-Aug-2021 inoguchi

Avoid leak with X509_REVOKED variable in openssl(1) ca.c

pointed out by tb@


# 1.36 28-Aug-2021 inoguchi

Checking the return value in openssl(1) ca.c

Some functions are used without verifying the return value in openssl(1) ca.
This diff adds checking for the function return value.
With this diff, I changed return value of the write_new_certificate from void
to int to return the condition to the caller.

ok and comments from tb@


# 1.35 24-Jul-2021 inoguchi

Compare strcmp and strcasecmp return value with zero


# 1.34 20-Jul-2021 inoguchi

Check pointer variable if it is NULL in ca.c

missed with r1.32


# 1.33 15-Jul-2021 inoguchi

Wrap over 80 long lines in ca.c


# 1.32 15-Jul-2021 inoguchi

Explicitly check pointer variable if it is NULL or not in ca.c


# 1.31 15-Jul-2021 inoguchi

Remove space between '*' and pointer variable in ca.c


# 1.30 15-Jul-2021 inoguchi

Use 'serial' rather than 'ser' in ca.c

input from jsing@


# 1.29 15-Jul-2021 inoguchi

Convert openssl(1) ca option handling

New option handling for openssl(1) ca.
This diff is just replacing with new option handling, no functional change.
I'm using the word DN or RDN in description as manual uses them, rather than
replacing with "Distinguished Name" or "Relative Distinguished Name".

I would like to add another fixes below by follow-up diffs.
- remove space between '*' and pointer variable
- wrap 80+ long lines
- explicitly check pointer variable if it is NULL or not

comments and ok from jsing@


Revision tags: OPENBSD_6_9_BASE
# 1.28 16-Dec-2020 tb

Remove a redundant memset call.


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.58 04-Feb-2024 tb

Zap a useless comment followed by a stray semicolon

Noticed by Christian Andersen


# 1.57 13-Nov-2023 tb

Kill last user of ASN1_time_parse() in the tree

ASN1_time_parse() was useful while OpenSSL didn't have something sort of
equivalent, but now they do. Let's retire ASN1_time_parse() to internal.
This will require some patching in ports, but shrug.

ok beck


Revision tags: OPENBSD_7_4_BASE
# 1.56 02-Jul-2023 tb

Teach openssl ca about Ed25519 certificates

This adds a few logic curlies to end up setting the EVP_MD to EVP_md_null()
as required by the API. This way ASN1_item_sign() now knows how to behave.

"ok = (rv == 2);" beck


Revision tags: OPENBSD_7_3_BASE
# 1.55 06-Mar-2023 tb

Rename struct ${app}_config to plain cfg

All the structs are static and we need to reach into them many times.
Having a shorter name is more concise and results in less visual clutter.
It also avoids many overlong lines and we will be able to get rid of some
unfortunate line wrapping down the road.

Discussed with jsing


# 1.54 11-Nov-2022 joshua

Remove the legacy interactive mode from openssl(1).

This removes the legacy interactive mode from openssl(1) since it is
rarely used, complicates the code, and has also been removed from
OpenSSL in version 3.x.x.

ok tb@ jsing@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.53 03-Feb-2022 tb

Use X509_*get0_pubkey() wherever possible to simplify and clean up
the code. Also add error checking where possible.

ok jsing


# 1.52 21-Nov-2021 tb

Tweak for opaque EVP_MD: use EVP_MD_type(dgst) instead of dgst->type.


# 1.51 23-Oct-2021 tb

Stop reaching into structs that will become opaque in ca.c

"just commit it" beck


# 1.50 22-Oct-2021 tb

Stop setting enc.modified manually. It's no longer needed.


Revision tags: OPENBSD_7_0_BASE
# 1.49 05-Sep-2021 inoguchi

Remove unused variable tmptm in do_body of openssl(1) ca


# 1.48 05-Sep-2021 inoguchi

Using serial number instead as subject if it is empty in openssl(1) ca

This allows multiple entries without a subject even if unique_subject == yes.
Referred to OpenSSL commit 5af88441 and arranged for our codebase.

ok tb@


# 1.47 05-Sep-2021 inoguchi

Check extensions before setting version to v3

Referred to OpenSSL commit 4881d849 and arranged for our codebase.

comment and ok from tb@


# 1.46 05-Sep-2021 inoguchi

Use accessor method rather than direct X509 structure access

Referred to OpenSSL commit a8d8e06b and arranged for our codebase.

comment and ok from tb@


# 1.45 02-Sep-2021 inoguchi

Use defined constants


# 1.44 02-Sep-2021 inoguchi

Move subject check process after the subject edit process

Referred to OpenSSL commit 2cedf794 and arranged for our codebase.

ok tb@


# 1.43 30-Aug-2021 inoguchi

Clean up end of do_body in openssl(1) ca

suggested from tb@


# 1.42 30-Aug-2021 inoguchi

Remove NULL check before free in openssl(1) ca

ok tb@


# 1.41 28-Aug-2021 inoguchi

Check X509_get_notAfter return value in openssl(1) ca.c


# 1.40 28-Aug-2021 inoguchi

Use strndup instead of malloc, memcpy and NULL termination in openssl(1) ca.c

suggested from tb@ for do_updatedb(),
and applied the same for do_body() and do_revoke().


# 1.39 28-Aug-2021 inoguchi

Remove ASN1_TIME_new and use NULL for X509_gmtime_adj, free tmptm in err path

comments from tb@


# 1.38 28-Aug-2021 inoguchi

Unwrap lines in openssl(1) ca.c

suggested from tb@


# 1.37 28-Aug-2021 inoguchi

Avoid leak with X509_REVOKED variable in openssl(1) ca.c

pointed out by tb@


# 1.36 28-Aug-2021 inoguchi

Checking the return value in openssl(1) ca.c

Some functions are used without verifying the return value in openssl(1) ca.
This diff adds checking for the function return value.
With this diff, I changed return value of the write_new_certificate from void
to int to return the condition to the caller.

ok and comments from tb@


# 1.35 24-Jul-2021 inoguchi

Compare strcmp and strcasecmp return value with zero


# 1.34 20-Jul-2021 inoguchi

Check pointer variable if it is NULL in ca.c

missed with r1.32


# 1.33 15-Jul-2021 inoguchi

Wrap over 80 long lines in ca.c


# 1.32 15-Jul-2021 inoguchi

Explicitly check pointer variable if it is NULL or not in ca.c


# 1.31 15-Jul-2021 inoguchi

Remove space between '*' and pointer variable in ca.c


# 1.30 15-Jul-2021 inoguchi

Use 'serial' rather than 'ser' in ca.c

input from jsing@


# 1.29 15-Jul-2021 inoguchi

Convert openssl(1) ca option handling

New option handling for openssl(1) ca.
This diff is just replacing with new option handling, no functional change.
I'm using the word DN or RDN in description as manual uses them, rather than
replacing with "Distinguished Name" or "Relative Distinguished Name".

I would like to add another fixes below by follow-up diffs.
- remove space between '*' and pointer variable
- wrap 80+ long lines
- explicitly check pointer variable if it is NULL or not

comments and ok from jsing@


Revision tags: OPENBSD_6_9_BASE
# 1.28 16-Dec-2020 tb

Remove a redundant memset call.


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.57 13-Nov-2023 tb

Kill last user of ASN1_time_parse() in the tree

ASN1_time_parse() was useful while OpenSSL didn't have something sort of
equivalent, but now they do. Let's retire ASN1_time_parse() to internal.
This will require some patching in ports, but shrug.

ok beck


Revision tags: OPENBSD_7_4_BASE
# 1.56 02-Jul-2023 tb

Teach openssl ca about Ed25519 certificates

This adds a few logic curlies to end up setting the EVP_MD to EVP_md_null()
as required by the API. This way ASN1_item_sign() now knows how to behave.

"ok = (rv == 2);" beck


Revision tags: OPENBSD_7_3_BASE
# 1.55 06-Mar-2023 tb

Rename struct ${app}_config to plain cfg

All the structs are static and we need to reach into them many times.
Having a shorter name is more concise and results in less visual clutter.
It also avoids many overlong lines and we will be able to get rid of some
unfortunate line wrapping down the road.

Discussed with jsing


# 1.54 11-Nov-2022 joshua

Remove the legacy interactive mode from openssl(1).

This removes the legacy interactive mode from openssl(1) since it is
rarely used, complicates the code, and has also been removed from
OpenSSL in version 3.x.x.

ok tb@ jsing@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.53 03-Feb-2022 tb

Use X509_*get0_pubkey() wherever possible to simplify and clean up
the code. Also add error checking where possible.

ok jsing


# 1.52 21-Nov-2021 tb

Tweak for opaque EVP_MD: use EVP_MD_type(dgst) instead of dgst->type.


# 1.51 23-Oct-2021 tb

Stop reaching into structs that will become opaque in ca.c

"just commit it" beck


# 1.50 22-Oct-2021 tb

Stop setting enc.modified manually. It's no longer needed.


Revision tags: OPENBSD_7_0_BASE
# 1.49 05-Sep-2021 inoguchi

Remove unused variable tmptm in do_body of openssl(1) ca


# 1.48 05-Sep-2021 inoguchi

Using serial number instead as subject if it is empty in openssl(1) ca

This allows multiple entries without a subject even if unique_subject == yes.
Referred to OpenSSL commit 5af88441 and arranged for our codebase.

ok tb@


# 1.47 05-Sep-2021 inoguchi

Check extensions before setting version to v3

Referred to OpenSSL commit 4881d849 and arranged for our codebase.

comment and ok from tb@


# 1.46 05-Sep-2021 inoguchi

Use accessor method rather than direct X509 structure access

Referred to OpenSSL commit a8d8e06b and arranged for our codebase.

comment and ok from tb@


# 1.45 02-Sep-2021 inoguchi

Use defined constants


# 1.44 02-Sep-2021 inoguchi

Move subject check process after the subject edit process

Referred to OpenSSL commit 2cedf794 and arranged for our codebase.

ok tb@


# 1.43 30-Aug-2021 inoguchi

Clean up end of do_body in openssl(1) ca

suggested from tb@


# 1.42 30-Aug-2021 inoguchi

Remove NULL check before free in openssl(1) ca

ok tb@


# 1.41 28-Aug-2021 inoguchi

Check X509_get_notAfter return value in openssl(1) ca.c


# 1.40 28-Aug-2021 inoguchi

Use strndup instead of malloc, memcpy and NULL termination in openssl(1) ca.c

suggested from tb@ for do_updatedb(),
and applied the same for do_body() and do_revoke().


# 1.39 28-Aug-2021 inoguchi

Remove ASN1_TIME_new and use NULL for X509_gmtime_adj, free tmptm in err path

comments from tb@


# 1.38 28-Aug-2021 inoguchi

Unwrap lines in openssl(1) ca.c

suggested from tb@


# 1.37 28-Aug-2021 inoguchi

Avoid leak with X509_REVOKED variable in openssl(1) ca.c

pointed out by tb@


# 1.36 28-Aug-2021 inoguchi

Checking the return value in openssl(1) ca.c

Some functions are used without verifying the return value in openssl(1) ca.
This diff adds checking for the function return value.
With this diff, I changed return value of the write_new_certificate from void
to int to return the condition to the caller.

ok and comments from tb@


# 1.35 24-Jul-2021 inoguchi

Compare strcmp and strcasecmp return value with zero


# 1.34 20-Jul-2021 inoguchi

Check pointer variable if it is NULL in ca.c

missed with r1.32


# 1.33 15-Jul-2021 inoguchi

Wrap over 80 long lines in ca.c


# 1.32 15-Jul-2021 inoguchi

Explicitly check pointer variable if it is NULL or not in ca.c


# 1.31 15-Jul-2021 inoguchi

Remove space between '*' and pointer variable in ca.c


# 1.30 15-Jul-2021 inoguchi

Use 'serial' rather than 'ser' in ca.c

input from jsing@


# 1.29 15-Jul-2021 inoguchi

Convert openssl(1) ca option handling

New option handling for openssl(1) ca.
This diff is just replacing with new option handling, no functional change.
I'm using the word DN or RDN in description as manual uses them, rather than
replacing with "Distinguished Name" or "Relative Distinguished Name".

I would like to add another fixes below by follow-up diffs.
- remove space between '*' and pointer variable
- wrap 80+ long lines
- explicitly check pointer variable if it is NULL or not

comments and ok from jsing@


Revision tags: OPENBSD_6_9_BASE
# 1.28 16-Dec-2020 tb

Remove a redundant memset call.


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.56 02-Jul-2023 tb

Teach openssl ca about Ed25519 certificates

This adds a few logic curlies to end up setting the EVP_MD to EVP_md_null()
as required by the API. This way ASN1_item_sign() now knows how to behave.

"ok = (rv == 2);" beck


Revision tags: OPENBSD_7_3_BASE
# 1.55 06-Mar-2023 tb

Rename struct ${app}_config to plain cfg

All the structs are static and we need to reach into them many times.
Having a shorter name is more concise and results in less visual clutter.
It also avoids many overlong lines and we will be able to get rid of some
unfortunate line wrapping down the road.

Discussed with jsing


# 1.54 11-Nov-2022 joshua

Remove the legacy interactive mode from openssl(1).

This removes the legacy interactive mode from openssl(1) since it is
rarely used, complicates the code, and has also been removed from
OpenSSL in version 3.x.x.

ok tb@ jsing@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.53 03-Feb-2022 tb

Use X509_*get0_pubkey() wherever possible to simplify and clean up
the code. Also add error checking where possible.

ok jsing


# 1.52 21-Nov-2021 tb

Tweak for opaque EVP_MD: use EVP_MD_type(dgst) instead of dgst->type.


# 1.51 23-Oct-2021 tb

Stop reaching into structs that will become opaque in ca.c

"just commit it" beck


# 1.50 22-Oct-2021 tb

Stop setting enc.modified manually. It's no longer needed.


Revision tags: OPENBSD_7_0_BASE
# 1.49 05-Sep-2021 inoguchi

Remove unused variable tmptm in do_body of openssl(1) ca


# 1.48 05-Sep-2021 inoguchi

Using serial number instead as subject if it is empty in openssl(1) ca

This allows multiple entries without a subject even if unique_subject == yes.
Referred to OpenSSL commit 5af88441 and arranged for our codebase.

ok tb@


# 1.47 05-Sep-2021 inoguchi

Check extensions before setting version to v3

Referred to OpenSSL commit 4881d849 and arranged for our codebase.

comment and ok from tb@


# 1.46 05-Sep-2021 inoguchi

Use accessor method rather than direct X509 structure access

Referred to OpenSSL commit a8d8e06b and arranged for our codebase.

comment and ok from tb@


# 1.45 02-Sep-2021 inoguchi

Use defined constants


# 1.44 02-Sep-2021 inoguchi

Move subject check process after the subject edit process

Referred to OpenSSL commit 2cedf794 and arranged for our codebase.

ok tb@


# 1.43 30-Aug-2021 inoguchi

Clean up end of do_body in openssl(1) ca

suggested from tb@


# 1.42 30-Aug-2021 inoguchi

Remove NULL check before free in openssl(1) ca

ok tb@


# 1.41 28-Aug-2021 inoguchi

Check X509_get_notAfter return value in openssl(1) ca.c


# 1.40 28-Aug-2021 inoguchi

Use strndup instead of malloc, memcpy and NULL termination in openssl(1) ca.c

suggested from tb@ for do_updatedb(),
and applied the same for do_body() and do_revoke().


# 1.39 28-Aug-2021 inoguchi

Remove ASN1_TIME_new and use NULL for X509_gmtime_adj, free tmptm in err path

comments from tb@


# 1.38 28-Aug-2021 inoguchi

Unwrap lines in openssl(1) ca.c

suggested from tb@


# 1.37 28-Aug-2021 inoguchi

Avoid leak with X509_REVOKED variable in openssl(1) ca.c

pointed out by tb@


# 1.36 28-Aug-2021 inoguchi

Checking the return value in openssl(1) ca.c

Some functions are used without verifying the return value in openssl(1) ca.
This diff adds checking for the function return value.
With this diff, I changed return value of the write_new_certificate from void
to int to return the condition to the caller.

ok and comments from tb@


# 1.35 24-Jul-2021 inoguchi

Compare strcmp and strcasecmp return value with zero


# 1.34 20-Jul-2021 inoguchi

Check pointer variable if it is NULL in ca.c

missed with r1.32


# 1.33 15-Jul-2021 inoguchi

Wrap over 80 long lines in ca.c


# 1.32 15-Jul-2021 inoguchi

Explicitly check pointer variable if it is NULL or not in ca.c


# 1.31 15-Jul-2021 inoguchi

Remove space between '*' and pointer variable in ca.c


# 1.30 15-Jul-2021 inoguchi

Use 'serial' rather than 'ser' in ca.c

input from jsing@


# 1.29 15-Jul-2021 inoguchi

Convert openssl(1) ca option handling

New option handling for openssl(1) ca.
This diff is just replacing with new option handling, no functional change.
I'm using the word DN or RDN in description as manual uses them, rather than
replacing with "Distinguished Name" or "Relative Distinguished Name".

I would like to add another fixes below by follow-up diffs.
- remove space between '*' and pointer variable
- wrap 80+ long lines
- explicitly check pointer variable if it is NULL or not

comments and ok from jsing@


Revision tags: OPENBSD_6_9_BASE
# 1.28 16-Dec-2020 tb

Remove a redundant memset call.


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.55 06-Mar-2023 tb

Rename struct ${app}_config to plain cfg

All the structs are static and we need to reach into them many times.
Having a shorter name is more concise and results in less visual clutter.
It also avoids many overlong lines and we will be able to get rid of some
unfortunate line wrapping down the road.

Discussed with jsing


# 1.54 11-Nov-2022 joshua

Remove the legacy interactive mode from openssl(1).

This removes the legacy interactive mode from openssl(1) since it is
rarely used, complicates the code, and has also been removed from
OpenSSL in version 3.x.x.

ok tb@ jsing@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.53 03-Feb-2022 tb

Use X509_*get0_pubkey() wherever possible to simplify and clean up
the code. Also add error checking where possible.

ok jsing


# 1.52 21-Nov-2021 tb

Tweak for opaque EVP_MD: use EVP_MD_type(dgst) instead of dgst->type.


# 1.51 23-Oct-2021 tb

Stop reaching into structs that will become opaque in ca.c

"just commit it" beck


# 1.50 22-Oct-2021 tb

Stop setting enc.modified manually. It's no longer needed.


Revision tags: OPENBSD_7_0_BASE
# 1.49 05-Sep-2021 inoguchi

Remove unused variable tmptm in do_body of openssl(1) ca


# 1.48 05-Sep-2021 inoguchi

Using serial number instead as subject if it is empty in openssl(1) ca

This allows multiple entries without a subject even if unique_subject == yes.
Referred to OpenSSL commit 5af88441 and arranged for our codebase.

ok tb@


# 1.47 05-Sep-2021 inoguchi

Check extensions before setting version to v3

Referred to OpenSSL commit 4881d849 and arranged for our codebase.

comment and ok from tb@


# 1.46 05-Sep-2021 inoguchi

Use accessor method rather than direct X509 structure access

Referred to OpenSSL commit a8d8e06b and arranged for our codebase.

comment and ok from tb@


# 1.45 02-Sep-2021 inoguchi

Use defined constants


# 1.44 02-Sep-2021 inoguchi

Move subject check process after the subject edit process

Referred to OpenSSL commit 2cedf794 and arranged for our codebase.

ok tb@


# 1.43 30-Aug-2021 inoguchi

Clean up end of do_body in openssl(1) ca

suggested from tb@


# 1.42 30-Aug-2021 inoguchi

Remove NULL check before free in openssl(1) ca

ok tb@


# 1.41 28-Aug-2021 inoguchi

Check X509_get_notAfter return value in openssl(1) ca.c


# 1.40 28-Aug-2021 inoguchi

Use strndup instead of malloc, memcpy and NULL termination in openssl(1) ca.c

suggested from tb@ for do_updatedb(),
and applied the same for do_body() and do_revoke().


# 1.39 28-Aug-2021 inoguchi

Remove ASN1_TIME_new and use NULL for X509_gmtime_adj, free tmptm in err path

comments from tb@


# 1.38 28-Aug-2021 inoguchi

Unwrap lines in openssl(1) ca.c

suggested from tb@


# 1.37 28-Aug-2021 inoguchi

Avoid leak with X509_REVOKED variable in openssl(1) ca.c

pointed out by tb@


# 1.36 28-Aug-2021 inoguchi

Checking the return value in openssl(1) ca.c

Some functions are used without verifying the return value in openssl(1) ca.
This diff adds checking for the function return value.
With this diff, I changed return value of the write_new_certificate from void
to int to return the condition to the caller.

ok and comments from tb@


# 1.35 24-Jul-2021 inoguchi

Compare strcmp and strcasecmp return value with zero


# 1.34 20-Jul-2021 inoguchi

Check pointer variable if it is NULL in ca.c

missed with r1.32


# 1.33 15-Jul-2021 inoguchi

Wrap over 80 long lines in ca.c


# 1.32 15-Jul-2021 inoguchi

Explicitly check pointer variable if it is NULL or not in ca.c


# 1.31 15-Jul-2021 inoguchi

Remove space between '*' and pointer variable in ca.c


# 1.30 15-Jul-2021 inoguchi

Use 'serial' rather than 'ser' in ca.c

input from jsing@


# 1.29 15-Jul-2021 inoguchi

Convert openssl(1) ca option handling

New option handling for openssl(1) ca.
This diff is just replacing with new option handling, no functional change.
I'm using the word DN or RDN in description as manual uses them, rather than
replacing with "Distinguished Name" or "Relative Distinguished Name".

I would like to add another fixes below by follow-up diffs.
- remove space between '*' and pointer variable
- wrap 80+ long lines
- explicitly check pointer variable if it is NULL or not

comments and ok from jsing@


Revision tags: OPENBSD_6_9_BASE
# 1.28 16-Dec-2020 tb

Remove a redundant memset call.


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.54 11-Nov-2022 joshua

Remove the legacy interactive mode from openssl(1).

This removes the legacy interactive mode from openssl(1) since it is
rarely used, complicates the code, and has also been removed from
OpenSSL in version 3.x.x.

ok tb@ jsing@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.53 03-Feb-2022 tb

Use X509_*get0_pubkey() wherever possible to simplify and clean up
the code. Also add error checking where possible.

ok jsing


# 1.52 21-Nov-2021 tb

Tweak for opaque EVP_MD: use EVP_MD_type(dgst) instead of dgst->type.


# 1.51 23-Oct-2021 tb

Stop reaching into structs that will become opaque in ca.c

"just commit it" beck


# 1.50 22-Oct-2021 tb

Stop setting enc.modified manually. It's no longer needed.


Revision tags: OPENBSD_7_0_BASE
# 1.49 05-Sep-2021 inoguchi

Remove unused variable tmptm in do_body of openssl(1) ca


# 1.48 05-Sep-2021 inoguchi

Using serial number instead as subject if it is empty in openssl(1) ca

This allows multiple entries without a subject even if unique_subject == yes.
Referred to OpenSSL commit 5af88441 and arranged for our codebase.

ok tb@


# 1.47 05-Sep-2021 inoguchi

Check extensions before setting version to v3

Referred to OpenSSL commit 4881d849 and arranged for our codebase.

comment and ok from tb@


# 1.46 05-Sep-2021 inoguchi

Use accessor method rather than direct X509 structure access

Referred to OpenSSL commit a8d8e06b and arranged for our codebase.

comment and ok from tb@


# 1.45 02-Sep-2021 inoguchi

Use defined constants


# 1.44 02-Sep-2021 inoguchi

Move subject check process after the subject edit process

Referred to OpenSSL commit 2cedf794 and arranged for our codebase.

ok tb@


# 1.43 30-Aug-2021 inoguchi

Clean up end of do_body in openssl(1) ca

suggested from tb@


# 1.42 30-Aug-2021 inoguchi

Remove NULL check before free in openssl(1) ca

ok tb@


# 1.41 28-Aug-2021 inoguchi

Check X509_get_notAfter return value in openssl(1) ca.c


# 1.40 28-Aug-2021 inoguchi

Use strndup instead of malloc, memcpy and NULL termination in openssl(1) ca.c

suggested from tb@ for do_updatedb(),
and applied the same for do_body() and do_revoke().


# 1.39 28-Aug-2021 inoguchi

Remove ASN1_TIME_new and use NULL for X509_gmtime_adj, free tmptm in err path

comments from tb@


# 1.38 28-Aug-2021 inoguchi

Unwrap lines in openssl(1) ca.c

suggested from tb@


# 1.37 28-Aug-2021 inoguchi

Avoid leak with X509_REVOKED variable in openssl(1) ca.c

pointed out by tb@


# 1.36 28-Aug-2021 inoguchi

Checking the return value in openssl(1) ca.c

Some functions are used without verifying the return value in openssl(1) ca.
This diff adds checking for the function return value.
With this diff, I changed return value of the write_new_certificate from void
to int to return the condition to the caller.

ok and comments from tb@


# 1.35 24-Jul-2021 inoguchi

Compare strcmp and strcasecmp return value with zero


# 1.34 20-Jul-2021 inoguchi

Check pointer variable if it is NULL in ca.c

missed with r1.32


# 1.33 15-Jul-2021 inoguchi

Wrap over 80 long lines in ca.c


# 1.32 15-Jul-2021 inoguchi

Explicitly check pointer variable if it is NULL or not in ca.c


# 1.31 15-Jul-2021 inoguchi

Remove space between '*' and pointer variable in ca.c


# 1.30 15-Jul-2021 inoguchi

Use 'serial' rather than 'ser' in ca.c

input from jsing@


# 1.29 15-Jul-2021 inoguchi

Convert openssl(1) ca option handling

New option handling for openssl(1) ca.
This diff is just replacing with new option handling, no functional change.
I'm using the word DN or RDN in description as manual uses them, rather than
replacing with "Distinguished Name" or "Relative Distinguished Name".

I would like to add another fixes below by follow-up diffs.
- remove space between '*' and pointer variable
- wrap 80+ long lines
- explicitly check pointer variable if it is NULL or not

comments and ok from jsing@


Revision tags: OPENBSD_6_9_BASE
# 1.28 16-Dec-2020 tb

Remove a redundant memset call.


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.53 03-Feb-2022 tb

Use X509_*get0_pubkey() wherever possible to simplify and clean up
the code. Also add error checking where possible.

ok jsing


# 1.52 21-Nov-2021 tb

Tweak for opaque EVP_MD: use EVP_MD_type(dgst) instead of dgst->type.


# 1.51 23-Oct-2021 tb

Stop reaching into structs that will become opaque in ca.c

"just commit it" beck


# 1.50 22-Oct-2021 tb

Stop setting enc.modified manually. It's no longer needed.


Revision tags: OPENBSD_7_0_BASE
# 1.49 05-Sep-2021 inoguchi

Remove unused variable tmptm in do_body of openssl(1) ca


# 1.48 05-Sep-2021 inoguchi

Using serial number instead as subject if it is empty in openssl(1) ca

This allows multiple entries without a subject even if unique_subject == yes.
Referred to OpenSSL commit 5af88441 and arranged for our codebase.

ok tb@


# 1.47 05-Sep-2021 inoguchi

Check extensions before setting version to v3

Referred to OpenSSL commit 4881d849 and arranged for our codebase.

comment and ok from tb@


# 1.46 05-Sep-2021 inoguchi

Use accessor method rather than direct X509 structure access

Referred to OpenSSL commit a8d8e06b and arranged for our codebase.

comment and ok from tb@


# 1.45 02-Sep-2021 inoguchi

Use defined constants


# 1.44 02-Sep-2021 inoguchi

Move subject check process after the subject edit process

Referred to OpenSSL commit 2cedf794 and arranged for our codebase.

ok tb@


# 1.43 30-Aug-2021 inoguchi

Clean up end of do_body in openssl(1) ca

suggested from tb@


# 1.42 30-Aug-2021 inoguchi

Remove NULL check before free in openssl(1) ca

ok tb@


# 1.41 28-Aug-2021 inoguchi

Check X509_get_notAfter return value in openssl(1) ca.c


# 1.40 28-Aug-2021 inoguchi

Use strndup instead of malloc, memcpy and NULL termination in openssl(1) ca.c

suggested from tb@ for do_updatedb(),
and applied the same for do_body() and do_revoke().


# 1.39 28-Aug-2021 inoguchi

Remove ASN1_TIME_new and use NULL for X509_gmtime_adj, free tmptm in err path

comments from tb@


# 1.38 28-Aug-2021 inoguchi

Unwrap lines in openssl(1) ca.c

suggested from tb@


# 1.37 28-Aug-2021 inoguchi

Avoid leak with X509_REVOKED variable in openssl(1) ca.c

pointed out by tb@


# 1.36 28-Aug-2021 inoguchi

Checking the return value in openssl(1) ca.c

Some functions are used without verifying the return value in openssl(1) ca.
This diff adds checking for the function return value.
With this diff, I changed return value of the write_new_certificate from void
to int to return the condition to the caller.

ok and comments from tb@


# 1.35 24-Jul-2021 inoguchi

Compare strcmp and strcasecmp return value with zero


# 1.34 20-Jul-2021 inoguchi

Check pointer variable if it is NULL in ca.c

missed with r1.32


# 1.33 15-Jul-2021 inoguchi

Wrap over 80 long lines in ca.c


# 1.32 15-Jul-2021 inoguchi

Explicitly check pointer variable if it is NULL or not in ca.c


# 1.31 15-Jul-2021 inoguchi

Remove space between '*' and pointer variable in ca.c


# 1.30 15-Jul-2021 inoguchi

Use 'serial' rather than 'ser' in ca.c

input from jsing@


# 1.29 15-Jul-2021 inoguchi

Convert openssl(1) ca option handling

New option handling for openssl(1) ca.
This diff is just replacing with new option handling, no functional change.
I'm using the word DN or RDN in description as manual uses them, rather than
replacing with "Distinguished Name" or "Relative Distinguished Name".

I would like to add another fixes below by follow-up diffs.
- remove space between '*' and pointer variable
- wrap 80+ long lines
- explicitly check pointer variable if it is NULL or not

comments and ok from jsing@


Revision tags: OPENBSD_6_9_BASE
# 1.28 16-Dec-2020 tb

Remove a redundant memset call.


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.52 21-Nov-2021 tb

Tweak for opaque EVP_MD: use EVP_MD_type(dgst) instead of dgst->type.


# 1.51 23-Oct-2021 tb

Stop reaching into structs that will become opaque in ca.c

"just commit it" beck


# 1.50 22-Oct-2021 tb

Stop setting enc.modified manually. It's no longer needed.


Revision tags: OPENBSD_7_0_BASE
# 1.49 05-Sep-2021 inoguchi

Remove unused variable tmptm in do_body of openssl(1) ca


# 1.48 05-Sep-2021 inoguchi

Using serial number instead as subject if it is empty in openssl(1) ca

This allows multiple entries without a subject even if unique_subject == yes.
Referred to OpenSSL commit 5af88441 and arranged for our codebase.

ok tb@


# 1.47 05-Sep-2021 inoguchi

Check extensions before setting version to v3

Referred to OpenSSL commit 4881d849 and arranged for our codebase.

comment and ok from tb@


# 1.46 05-Sep-2021 inoguchi

Use accessor method rather than direct X509 structure access

Referred to OpenSSL commit a8d8e06b and arranged for our codebase.

comment and ok from tb@


# 1.45 02-Sep-2021 inoguchi

Use defined constants


# 1.44 02-Sep-2021 inoguchi

Move subject check process after the subject edit process

Referred to OpenSSL commit 2cedf794 and arranged for our codebase.

ok tb@


# 1.43 30-Aug-2021 inoguchi

Clean up end of do_body in openssl(1) ca

suggested from tb@


# 1.42 30-Aug-2021 inoguchi

Remove NULL check before free in openssl(1) ca

ok tb@


# 1.41 28-Aug-2021 inoguchi

Check X509_get_notAfter return value in openssl(1) ca.c


# 1.40 28-Aug-2021 inoguchi

Use strndup instead of malloc, memcpy and NULL termination in openssl(1) ca.c

suggested from tb@ for do_updatedb(),
and applied the same for do_body() and do_revoke().


# 1.39 28-Aug-2021 inoguchi

Remove ASN1_TIME_new and use NULL for X509_gmtime_adj, free tmptm in err path

comments from tb@


# 1.38 28-Aug-2021 inoguchi

Unwrap lines in openssl(1) ca.c

suggested from tb@


# 1.37 28-Aug-2021 inoguchi

Avoid leak with X509_REVOKED variable in openssl(1) ca.c

pointed out by tb@


# 1.36 28-Aug-2021 inoguchi

Checking the return value in openssl(1) ca.c

Some functions are used without verifying the return value in openssl(1) ca.
This diff adds checking for the function return value.
With this diff, I changed return value of the write_new_certificate from void
to int to return the condition to the caller.

ok and comments from tb@


# 1.35 24-Jul-2021 inoguchi

Compare strcmp and strcasecmp return value with zero


# 1.34 20-Jul-2021 inoguchi

Check pointer variable if it is NULL in ca.c

missed with r1.32


# 1.33 15-Jul-2021 inoguchi

Wrap over 80 long lines in ca.c


# 1.32 15-Jul-2021 inoguchi

Explicitly check pointer variable if it is NULL or not in ca.c


# 1.31 15-Jul-2021 inoguchi

Remove space between '*' and pointer variable in ca.c


# 1.30 15-Jul-2021 inoguchi

Use 'serial' rather than 'ser' in ca.c

input from jsing@


# 1.29 15-Jul-2021 inoguchi

Convert openssl(1) ca option handling

New option handling for openssl(1) ca.
This diff is just replacing with new option handling, no functional change.
I'm using the word DN or RDN in description as manual uses them, rather than
replacing with "Distinguished Name" or "Relative Distinguished Name".

I would like to add another fixes below by follow-up diffs.
- remove space between '*' and pointer variable
- wrap 80+ long lines
- explicitly check pointer variable if it is NULL or not

comments and ok from jsing@


Revision tags: OPENBSD_6_9_BASE
# 1.28 16-Dec-2020 tb

Remove a redundant memset call.


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.51 23-Oct-2021 tb

Stop reaching into structs that will become opaque in ca.c

"just commit it" beck


# 1.50 22-Oct-2021 tb

Stop setting enc.modified manually. It's no longer needed.


Revision tags: OPENBSD_7_0_BASE
# 1.49 05-Sep-2021 inoguchi

Remove unused variable tmptm in do_body of openssl(1) ca


# 1.48 05-Sep-2021 inoguchi

Using serial number instead as subject if it is empty in openssl(1) ca

This allows multiple entries without a subject even if unique_subject == yes.
Referred to OpenSSL commit 5af88441 and arranged for our codebase.

ok tb@


# 1.47 05-Sep-2021 inoguchi

Check extensions before setting version to v3

Referred to OpenSSL commit 4881d849 and arranged for our codebase.

comment and ok from tb@


# 1.46 05-Sep-2021 inoguchi

Use accessor method rather than direct X509 structure access

Referred to OpenSSL commit a8d8e06b and arranged for our codebase.

comment and ok from tb@


# 1.45 02-Sep-2021 inoguchi

Use defined constants


# 1.44 02-Sep-2021 inoguchi

Move subject check process after the subject edit process

Referred to OpenSSL commit 2cedf794 and arranged for our codebase.

ok tb@


# 1.43 30-Aug-2021 inoguchi

Clean up end of do_body in openssl(1) ca

suggested from tb@


# 1.42 30-Aug-2021 inoguchi

Remove NULL check before free in openssl(1) ca

ok tb@


# 1.41 28-Aug-2021 inoguchi

Check X509_get_notAfter return value in openssl(1) ca.c


# 1.40 28-Aug-2021 inoguchi

Use strndup instead of malloc, memcpy and NULL termination in openssl(1) ca.c

suggested from tb@ for do_updatedb(),
and applied the same for do_body() and do_revoke().


# 1.39 28-Aug-2021 inoguchi

Remove ASN1_TIME_new and use NULL for X509_gmtime_adj, free tmptm in err path

comments from tb@


# 1.38 28-Aug-2021 inoguchi

Unwrap lines in openssl(1) ca.c

suggested from tb@


# 1.37 28-Aug-2021 inoguchi

Avoid leak with X509_REVOKED variable in openssl(1) ca.c

pointed out by tb@


# 1.36 28-Aug-2021 inoguchi

Checking the return value in openssl(1) ca.c

Some functions are used without verifying the return value in openssl(1) ca.
This diff adds checking for the function return value.
With this diff, I changed return value of the write_new_certificate from void
to int to return the condition to the caller.

ok and comments from tb@


# 1.35 24-Jul-2021 inoguchi

Compare strcmp and strcasecmp return value with zero


# 1.34 20-Jul-2021 inoguchi

Check pointer variable if it is NULL in ca.c

missed with r1.32


# 1.33 15-Jul-2021 inoguchi

Wrap over 80 long lines in ca.c


# 1.32 15-Jul-2021 inoguchi

Explicitly check pointer variable if it is NULL or not in ca.c


# 1.31 15-Jul-2021 inoguchi

Remove space between '*' and pointer variable in ca.c


# 1.30 15-Jul-2021 inoguchi

Use 'serial' rather than 'ser' in ca.c

input from jsing@


# 1.29 15-Jul-2021 inoguchi

Convert openssl(1) ca option handling

New option handling for openssl(1) ca.
This diff is just replacing with new option handling, no functional change.
I'm using the word DN or RDN in description as manual uses them, rather than
replacing with "Distinguished Name" or "Relative Distinguished Name".

I would like to add another fixes below by follow-up diffs.
- remove space between '*' and pointer variable
- wrap 80+ long lines
- explicitly check pointer variable if it is NULL or not

comments and ok from jsing@


Revision tags: OPENBSD_6_9_BASE
# 1.28 16-Dec-2020 tb

Remove a redundant memset call.


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.50 22-Oct-2021 tb

Stop setting enc.modified manually. It's no longer needed.


Revision tags: OPENBSD_7_0_BASE
# 1.49 05-Sep-2021 inoguchi

Remove unused variable tmptm in do_body of openssl(1) ca


# 1.48 05-Sep-2021 inoguchi

Using serial number instead as subject if it is empty in openssl(1) ca

This allows multiple entries without a subject even if unique_subject == yes.
Referred to OpenSSL commit 5af88441 and arranged for our codebase.

ok tb@


# 1.47 05-Sep-2021 inoguchi

Check extensions before setting version to v3

Referred to OpenSSL commit 4881d849 and arranged for our codebase.

comment and ok from tb@


# 1.46 05-Sep-2021 inoguchi

Use accessor method rather than direct X509 structure access

Referred to OpenSSL commit a8d8e06b and arranged for our codebase.

comment and ok from tb@


# 1.45 02-Sep-2021 inoguchi

Use defined constants


# 1.44 02-Sep-2021 inoguchi

Move subject check process after the subject edit process

Referred to OpenSSL commit 2cedf794 and arranged for our codebase.

ok tb@


# 1.43 30-Aug-2021 inoguchi

Clean up end of do_body in openssl(1) ca

suggested from tb@


# 1.42 30-Aug-2021 inoguchi

Remove NULL check before free in openssl(1) ca

ok tb@


# 1.41 28-Aug-2021 inoguchi

Check X509_get_notAfter return value in openssl(1) ca.c


# 1.40 28-Aug-2021 inoguchi

Use strndup instead of malloc, memcpy and NULL termination in openssl(1) ca.c

suggested from tb@ for do_updatedb(),
and applied the same for do_body() and do_revoke().


# 1.39 28-Aug-2021 inoguchi

Remove ASN1_TIME_new and use NULL for X509_gmtime_adj, free tmptm in err path

comments from tb@


# 1.38 28-Aug-2021 inoguchi

Unwrap lines in openssl(1) ca.c

suggested from tb@


# 1.37 28-Aug-2021 inoguchi

Avoid leak with X509_REVOKED variable in openssl(1) ca.c

pointed out by tb@


# 1.36 28-Aug-2021 inoguchi

Checking the return value in openssl(1) ca.c

Some functions are used without verifying the return value in openssl(1) ca.
This diff adds checking for the function return value.
With this diff, I changed return value of the write_new_certificate from void
to int to return the condition to the caller.

ok and comments from tb@


# 1.35 24-Jul-2021 inoguchi

Compare strcmp and strcasecmp return value with zero


# 1.34 20-Jul-2021 inoguchi

Check pointer variable if it is NULL in ca.c

missed with r1.32


# 1.33 15-Jul-2021 inoguchi

Wrap over 80 long lines in ca.c


# 1.32 15-Jul-2021 inoguchi

Explicitly check pointer variable if it is NULL or not in ca.c


# 1.31 15-Jul-2021 inoguchi

Remove space between '*' and pointer variable in ca.c


# 1.30 15-Jul-2021 inoguchi

Use 'serial' rather than 'ser' in ca.c

input from jsing@


# 1.29 15-Jul-2021 inoguchi

Convert openssl(1) ca option handling

New option handling for openssl(1) ca.
This diff is just replacing with new option handling, no functional change.
I'm using the word DN or RDN in description as manual uses them, rather than
replacing with "Distinguished Name" or "Relative Distinguished Name".

I would like to add another fixes below by follow-up diffs.
- remove space between '*' and pointer variable
- wrap 80+ long lines
- explicitly check pointer variable if it is NULL or not

comments and ok from jsing@


Revision tags: OPENBSD_6_9_BASE
# 1.28 16-Dec-2020 tb

Remove a redundant memset call.


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.49 05-Sep-2021 inoguchi

Remove unused variable tmptm in do_body of openssl(1) ca


# 1.48 05-Sep-2021 inoguchi

Using serial number instead as subject if it is empty in openssl(1) ca

This allows multiple entries without a subject even if unique_subject == yes.
Referred to OpenSSL commit 5af88441 and arranged for our codebase.

ok tb@


# 1.47 05-Sep-2021 inoguchi

Check extensions before setting version to v3

Referred to OpenSSL commit 4881d849 and arranged for our codebase.

comment and ok from tb@


# 1.46 05-Sep-2021 inoguchi

Use accessor method rather than direct X509 structure access

Referred to OpenSSL commit a8d8e06b and arranged for our codebase.

comment and ok from tb@


# 1.45 02-Sep-2021 inoguchi

Use defined constants


# 1.44 02-Sep-2021 inoguchi

Move subject check process after the subject edit process

Referred to OpenSSL commit 2cedf794 and arranged for our codebase.

ok tb@


# 1.43 30-Aug-2021 inoguchi

Clean up end of do_body in openssl(1) ca

suggested from tb@


# 1.42 30-Aug-2021 inoguchi

Remove NULL check before free in openssl(1) ca

ok tb@


# 1.41 28-Aug-2021 inoguchi

Check X509_get_notAfter return value in openssl(1) ca.c


# 1.40 28-Aug-2021 inoguchi

Use strndup instead of malloc, memcpy and NULL termination in openssl(1) ca.c

suggested from tb@ for do_updatedb(),
and applied the same for do_body() and do_revoke().


# 1.39 28-Aug-2021 inoguchi

Remove ASN1_TIME_new and use NULL for X509_gmtime_adj, free tmptm in err path

comments from tb@


# 1.38 28-Aug-2021 inoguchi

Unwrap lines in openssl(1) ca.c

suggested from tb@


# 1.37 28-Aug-2021 inoguchi

Avoid leak with X509_REVOKED variable in openssl(1) ca.c

pointed out by tb@


# 1.36 28-Aug-2021 inoguchi

Checking the return value in openssl(1) ca.c

Some functions are used without verifying the return value in openssl(1) ca.
This diff adds checking for the function return value.
With this diff, I changed return value of the write_new_certificate from void
to int to return the condition to the caller.

ok and comments from tb@


# 1.35 24-Jul-2021 inoguchi

Compare strcmp and strcasecmp return value with zero


# 1.34 20-Jul-2021 inoguchi

Check pointer variable if it is NULL in ca.c

missed with r1.32


# 1.33 15-Jul-2021 inoguchi

Wrap over 80 long lines in ca.c


# 1.32 15-Jul-2021 inoguchi

Explicitly check pointer variable if it is NULL or not in ca.c


# 1.31 15-Jul-2021 inoguchi

Remove space between '*' and pointer variable in ca.c


# 1.30 15-Jul-2021 inoguchi

Use 'serial' rather than 'ser' in ca.c

input from jsing@


# 1.29 15-Jul-2021 inoguchi

Convert openssl(1) ca option handling

New option handling for openssl(1) ca.
This diff is just replacing with new option handling, no functional change.
I'm using the word DN or RDN in description as manual uses them, rather than
replacing with "Distinguished Name" or "Relative Distinguished Name".

I would like to add another fixes below by follow-up diffs.
- remove space between '*' and pointer variable
- wrap 80+ long lines
- explicitly check pointer variable if it is NULL or not

comments and ok from jsing@


Revision tags: OPENBSD_6_9_BASE
# 1.28 16-Dec-2020 tb

Remove a redundant memset call.


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.45 02-Sep-2021 inoguchi

Use defined constants


# 1.44 02-Sep-2021 inoguchi

Move subject check process after the subject edit process

Referred to OpenSSL commit 2cedf794 and arranged for our codebase.

ok tb@


# 1.43 30-Aug-2021 inoguchi

Clean up end of do_body in openssl(1) ca

suggested from tb@


# 1.42 30-Aug-2021 inoguchi

Remove NULL check before free in openssl(1) ca

ok tb@


# 1.41 28-Aug-2021 inoguchi

Check X509_get_notAfter return value in openssl(1) ca.c


# 1.40 28-Aug-2021 inoguchi

Use strndup instead of malloc, memcpy and NULL termination in openssl(1) ca.c

suggested from tb@ for do_updatedb(),
and applied the same for do_body() and do_revoke().


# 1.39 28-Aug-2021 inoguchi

Remove ASN1_TIME_new and use NULL for X509_gmtime_adj, free tmptm in err path

comments from tb@


# 1.38 28-Aug-2021 inoguchi

Unwrap lines in openssl(1) ca.c

suggested from tb@


# 1.37 28-Aug-2021 inoguchi

Avoid leak with X509_REVOKED variable in openssl(1) ca.c

pointed out by tb@


# 1.36 28-Aug-2021 inoguchi

Checking the return value in openssl(1) ca.c

Some functions are used without verifying the return value in openssl(1) ca.
This diff adds checking for the function return value.
With this diff, I changed return value of the write_new_certificate from void
to int to return the condition to the caller.

ok and comments from tb@


# 1.35 24-Jul-2021 inoguchi

Compare strcmp and strcasecmp return value with zero


# 1.34 20-Jul-2021 inoguchi

Check pointer variable if it is NULL in ca.c

missed with r1.32


# 1.33 15-Jul-2021 inoguchi

Wrap over 80 long lines in ca.c


# 1.32 15-Jul-2021 inoguchi

Explicitly check pointer variable if it is NULL or not in ca.c


# 1.31 15-Jul-2021 inoguchi

Remove space between '*' and pointer variable in ca.c


# 1.30 15-Jul-2021 inoguchi

Use 'serial' rather than 'ser' in ca.c

input from jsing@


# 1.29 15-Jul-2021 inoguchi

Convert openssl(1) ca option handling

New option handling for openssl(1) ca.
This diff is just replacing with new option handling, no functional change.
I'm using the word DN or RDN in description as manual uses them, rather than
replacing with "Distinguished Name" or "Relative Distinguished Name".

I would like to add another fixes below by follow-up diffs.
- remove space between '*' and pointer variable
- wrap 80+ long lines
- explicitly check pointer variable if it is NULL or not

comments and ok from jsing@


Revision tags: OPENBSD_6_9_BASE
# 1.28 16-Dec-2020 tb

Remove a redundant memset call.


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.45 02-Sep-2021 inoguchi

Use defined constants


# 1.44 02-Sep-2021 inoguchi

Move subject check process after the subject edit process

Referred to OpenSSL commit 2cedf794 and arranged for our codebase.

ok tb@


# 1.43 30-Aug-2021 inoguchi

Clean up end of do_body in openssl(1) ca

suggested from tb@


# 1.42 30-Aug-2021 inoguchi

Remove NULL check before free in openssl(1) ca

ok tb@


# 1.41 28-Aug-2021 inoguchi

Check X509_get_notAfter return value in openssl(1) ca.c


# 1.40 28-Aug-2021 inoguchi

Use strndup instead of malloc, memcpy and NULL termination in openssl(1) ca.c

suggested from tb@ for do_updatedb(),
and applied the same for do_body() and do_revoke().


# 1.39 28-Aug-2021 inoguchi

Remove ASN1_TIME_new and use NULL for X509_gmtime_adj, free tmptm in err path

comments from tb@


# 1.38 28-Aug-2021 inoguchi

Unwrap lines in openssl(1) ca.c

suggested from tb@


# 1.37 28-Aug-2021 inoguchi

Avoid leak with X509_REVOKED variable in openssl(1) ca.c

pointed out by tb@


# 1.36 28-Aug-2021 inoguchi

Checking the return value in openssl(1) ca.c

Some functions are used without verifying the return value in openssl(1) ca.
This diff adds checking for the function return value.
With this diff, I changed return value of the write_new_certificate from void
to int to return the condition to the caller.

ok and comments from tb@


# 1.35 24-Jul-2021 inoguchi

Compare strcmp and strcasecmp return value with zero


# 1.34 20-Jul-2021 inoguchi

Check pointer variable if it is NULL in ca.c

missed with r1.32


# 1.33 15-Jul-2021 inoguchi

Wrap over 80 long lines in ca.c


# 1.32 15-Jul-2021 inoguchi

Explicitly check pointer variable if it is NULL or not in ca.c


# 1.31 15-Jul-2021 inoguchi

Remove space between '*' and pointer variable in ca.c


# 1.30 15-Jul-2021 inoguchi

Use 'serial' rather than 'ser' in ca.c

input from jsing@


# 1.29 15-Jul-2021 inoguchi

Convert openssl(1) ca option handling

New option handling for openssl(1) ca.
This diff is just replacing with new option handling, no functional change.
I'm using the word DN or RDN in description as manual uses them, rather than
replacing with "Distinguished Name" or "Relative Distinguished Name".

I would like to add another fixes below by follow-up diffs.
- remove space between '*' and pointer variable
- wrap 80+ long lines
- explicitly check pointer variable if it is NULL or not

comments and ok from jsing@


Revision tags: OPENBSD_6_9_BASE
# 1.28 16-Dec-2020 tb

Remove a redundant memset call.


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.43 30-Aug-2021 inoguchi

Clean up end of do_body in openssl(1) ca

suggested from tb@


# 1.42 30-Aug-2021 inoguchi

Remove NULL check before free in openssl(1) ca

ok tb@


# 1.41 28-Aug-2021 inoguchi

Check X509_get_notAfter return value in openssl(1) ca.c


# 1.40 28-Aug-2021 inoguchi

Use strndup instead of malloc, memcpy and NULL termination in openssl(1) ca.c

suggested from tb@ for do_updatedb(),
and applied the same for do_body() and do_revoke().


# 1.39 28-Aug-2021 inoguchi

Remove ASN1_TIME_new and use NULL for X509_gmtime_adj, free tmptm in err path

comments from tb@


# 1.38 28-Aug-2021 inoguchi

Unwrap lines in openssl(1) ca.c

suggested from tb@


# 1.37 28-Aug-2021 inoguchi

Avoid leak with X509_REVOKED variable in openssl(1) ca.c

pointed out by tb@


# 1.36 28-Aug-2021 inoguchi

Checking the return value in openssl(1) ca.c

Some functions are used without verifying the return value in openssl(1) ca.
This diff adds checking for the function return value.
With this diff, I changed return value of the write_new_certificate from void
to int to return the condition to the caller.

ok and comments from tb@


# 1.35 24-Jul-2021 inoguchi

Compare strcmp and strcasecmp return value with zero


# 1.34 20-Jul-2021 inoguchi

Check pointer variable if it is NULL in ca.c

missed with r1.32


# 1.33 15-Jul-2021 inoguchi

Wrap over 80 long lines in ca.c


# 1.32 15-Jul-2021 inoguchi

Explicitly check pointer variable if it is NULL or not in ca.c


# 1.31 15-Jul-2021 inoguchi

Remove space between '*' and pointer variable in ca.c


# 1.30 15-Jul-2021 inoguchi

Use 'serial' rather than 'ser' in ca.c

input from jsing@


# 1.29 15-Jul-2021 inoguchi

Convert openssl(1) ca option handling

New option handling for openssl(1) ca.
This diff is just replacing with new option handling, no functional change.
I'm using the word DN or RDN in description as manual uses them, rather than
replacing with "Distinguished Name" or "Relative Distinguished Name".

I would like to add another fixes below by follow-up diffs.
- remove space between '*' and pointer variable
- wrap 80+ long lines
- explicitly check pointer variable if it is NULL or not

comments and ok from jsing@


Revision tags: OPENBSD_6_9_BASE
# 1.28 16-Dec-2020 tb

Remove a redundant memset call.


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.41 28-Aug-2021 inoguchi

Check X509_get_notAfter return value in openssl(1) ca.c


# 1.40 28-Aug-2021 inoguchi

Use strndup instead of malloc, memcpy and NULL termination in openssl(1) ca.c

suggested from tb@ for do_updatedb(),
and applied the same for do_body() and do_revoke().


# 1.39 28-Aug-2021 inoguchi

Remove ASN1_TIME_new and use NULL for X509_gmtime_adj, free tmptm in err path

comments from tb@


# 1.38 28-Aug-2021 inoguchi

Unwrap lines in openssl(1) ca.c

suggested from tb@


# 1.37 28-Aug-2021 inoguchi

Avoid leak with X509_REVOKED variable in openssl(1) ca.c

pointed out by tb@


# 1.36 28-Aug-2021 inoguchi

Checking the return value in openssl(1) ca.c

Some functions are used without verifying the return value in openssl(1) ca.
This diff adds checking for the function return value.
With this diff, I changed return value of the write_new_certificate from void
to int to return the condition to the caller.

ok and comments from tb@


# 1.35 24-Jul-2021 inoguchi

Compare strcmp and strcasecmp return value with zero


# 1.34 20-Jul-2021 inoguchi

Check pointer variable if it is NULL in ca.c

missed with r1.32


# 1.33 15-Jul-2021 inoguchi

Wrap over 80 long lines in ca.c


# 1.32 15-Jul-2021 inoguchi

Explicitly check pointer variable if it is NULL or not in ca.c


# 1.31 15-Jul-2021 inoguchi

Remove space between '*' and pointer variable in ca.c


# 1.30 15-Jul-2021 inoguchi

Use 'serial' rather than 'ser' in ca.c

input from jsing@


# 1.29 15-Jul-2021 inoguchi

Convert openssl(1) ca option handling

New option handling for openssl(1) ca.
This diff is just replacing with new option handling, no functional change.
I'm using the word DN or RDN in description as manual uses them, rather than
replacing with "Distinguished Name" or "Relative Distinguished Name".

I would like to add another fixes below by follow-up diffs.
- remove space between '*' and pointer variable
- wrap 80+ long lines
- explicitly check pointer variable if it is NULL or not

comments and ok from jsing@


Revision tags: OPENBSD_6_9_BASE
# 1.28 16-Dec-2020 tb

Remove a redundant memset call.


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.35 24-Jul-2021 inoguchi

Compare strcmp and strcasecmp return value with zero


# 1.34 20-Jul-2021 inoguchi

Check pointer variable if it is NULL in ca.c

missed with r1.32


# 1.33 15-Jul-2021 inoguchi

Wrap over 80 long lines in ca.c


# 1.32 15-Jul-2021 inoguchi

Explicitly check pointer variable if it is NULL or not in ca.c


# 1.31 15-Jul-2021 inoguchi

Remove space between '*' and pointer variable in ca.c


# 1.30 15-Jul-2021 inoguchi

Use 'serial' rather than 'ser' in ca.c

input from jsing@


# 1.29 15-Jul-2021 inoguchi

Convert openssl(1) ca option handling

New option handling for openssl(1) ca.
This diff is just replacing with new option handling, no functional change.
I'm using the word DN or RDN in description as manual uses them, rather than
replacing with "Distinguished Name" or "Relative Distinguished Name".

I would like to add another fixes below by follow-up diffs.
- remove space between '*' and pointer variable
- wrap 80+ long lines
- explicitly check pointer variable if it is NULL or not

comments and ok from jsing@


Revision tags: OPENBSD_6_9_BASE
# 1.28 16-Dec-2020 tb

Remove a redundant memset call.


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.34 20-Jul-2021 inoguchi

Check pointer variable if it is NULL in ca.c

missed with r1.32


# 1.33 15-Jul-2021 inoguchi

Wrap over 80 long lines in ca.c


# 1.32 15-Jul-2021 inoguchi

Explicitly check pointer variable if it is NULL or not in ca.c


# 1.31 15-Jul-2021 inoguchi

Remove space between '*' and pointer variable in ca.c


# 1.30 15-Jul-2021 inoguchi

Use 'serial' rather than 'ser' in ca.c

input from jsing@


# 1.29 15-Jul-2021 inoguchi

Convert openssl(1) ca option handling

New option handling for openssl(1) ca.
This diff is just replacing with new option handling, no functional change.
I'm using the word DN or RDN in description as manual uses them, rather than
replacing with "Distinguished Name" or "Relative Distinguished Name".

I would like to add another fixes below by follow-up diffs.
- remove space between '*' and pointer variable
- wrap 80+ long lines
- explicitly check pointer variable if it is NULL or not

comments and ok from jsing@


Revision tags: OPENBSD_6_9_BASE
# 1.28 16-Dec-2020 tb

Remove a redundant memset call.


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.33 15-Jul-2021 inoguchi

Wrap over 80 long lines in ca.c


# 1.32 15-Jul-2021 inoguchi

Explicitly check pointer variable if it is NULL or not in ca.c


# 1.31 15-Jul-2021 inoguchi

Remove space between '*' and pointer variable in ca.c


# 1.30 15-Jul-2021 inoguchi

Use 'serial' rather than 'ser' in ca.c

input from jsing@


# 1.29 15-Jul-2021 inoguchi

Convert openssl(1) ca option handling

New option handling for openssl(1) ca.
This diff is just replacing with new option handling, no functional change.
I'm using the word DN or RDN in description as manual uses them, rather than
replacing with "Distinguished Name" or "Relative Distinguished Name".

I would like to add another fixes below by follow-up diffs.
- remove space between '*' and pointer variable
- wrap 80+ long lines
- explicitly check pointer variable if it is NULL or not

comments and ok from jsing@


Revision tags: OPENBSD_6_9_BASE
# 1.28 16-Dec-2020 tb

Remove a redundant memset call.


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.33 15-Jul-2021 inoguchi

Wrap over 80 long lines in ca.c


# 1.32 15-Jul-2021 inoguchi

Explicitly check pointer variable if it is NULL or not in ca.c


# 1.31 15-Jul-2021 inoguchi

Remove space between '*' and pointer variable in ca.c


# 1.30 15-Jul-2021 inoguchi

Use 'serial' rather than 'ser' in ca.c

input from jsing@


# 1.29 15-Jul-2021 inoguchi

Convert openssl(1) ca option handling

New option handling for openssl(1) ca.
This diff is just replacing with new option handling, no functional change.
I'm using the word DN or RDN in description as manual uses them, rather than
replacing with "Distinguished Name" or "Relative Distinguished Name".

I would like to add another fixes below by follow-up diffs.
- remove space between '*' and pointer variable
- wrap 80+ long lines
- explicitly check pointer variable if it is NULL or not

comments and ok from jsing@


Revision tags: OPENBSD_6_9_BASE
# 1.28 16-Dec-2020 tb

Remove a redundant memset call.


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.28 16-Dec-2020 tb

Remove a redundant memset call.


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.27 03-Jul-2019 deraadt

snprintf/vsnprintf return < 0 on error, rather than -1.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


# 1.26 07-Feb-2018 jsing

Indent labels with a single space so that diff prototypes are more useful.


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@


Revision tags: OPENBSD_6_2_BASE
# 1.25 08-May-2017 beck

simplify startdate/enddate validation
ok jsing@


# 1.24 04-May-2017 beck

Fix the ca command so that certs it generates have RFC5280 conformant time.
Problem noticed by Harald Dunkel <harald.dunkel@aixigo.de>


Revision tags: OPENBSD_6_1_BASE
# 1.23 20-Jan-2017 deraadt

rearrange pledge promises into the canonical order; easier to eyeball


# 1.22 31-Aug-2016 deraadt

We don't need any VMS access tricks.
ok beck tedu


# 1.21 30-Aug-2016 deraadt

buf[][] with strange use all over the place is ridiculous, especially
if buf[1] is never used.
ok guenther beck


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.20 24-Dec-2015 mmcc

more e-mail -> email


# 1.19 17-Oct-2015 doug

Exit if a pledge call fails in non-interactive mode.

ok semarie@


# 1.18 17-Oct-2015 semarie

add "tty" for several subcommands of openssl

it is needed in order to let libssl UI_* function plays with echo on/off when
asking for password on terminal.

passwd subcommand needs additionnal "wpath cpath" in order to let it calls
fopen("/dev/tty", "w") (O_WRONLY with O_CREAT | O_TRUNC).

problem reported by several
with and ok doug@


# 1.17 10-Oct-2015 doug

Initial support for pledges in openssl(1) commands.

openssl(1) has two mechanisms for operating: either a single execution
of one command (looking at argv[0] or argv[1]) or as an interactive
session than may execute any number of commands.

We already have a top level pledge that should cover all commands
and that's what interactive mode must continue using. However, we can
tighten up the pledges when only executing one command.

This is an initial stab at support and may contain regressions. Most
commands only need "stdio rpath wpath cpath". The pledges could be
further restricted by evaluating the situation after parsing options.

deraadt@ and beck@ are roughly fine with this approach.


# 1.16 21-Sep-2015 bcook

add a couple of missing NULL checks

noted by Bill Parker (dogbert2) on github


# 1.15 21-Sep-2015 bcook

remove vestigial bits of sha-0 and md2 from openssl(1)

Noted by kinichiro on github. We probably need a better way to indicate the
list of message digests that are allowed, as the current ones are nowhere near
exhaustive (sigh - guenther@)

OK guenther@ jmc@


# 1.14 12-Sep-2015 lteo

Nuke SSLEAY_CONF -- a backwards compatibility environment variable that
has been superseded by OPENSSL_CONF and discouraged from use for almost
16 years.

"Definately ok" jsing@
"burn it" deraadt@
"Kill it with fire" miod@
"KILL IT WITH FIRE!!! BURN!!!!" beck@


# 1.13 11-Sep-2015 beck

fix unchecked mallocs - coverity 130454 and 130455
ok jsing@


# 1.12 11-Sep-2015 bcook

Remove engine command and parameters from openssl(1).

We do not have any builtin or dynamic engines, meaning openssl(1) has
no way to use the engine command or parameters at all.

ok jsing@


# 1.11 10-Sep-2015 jsing

Correct spelling of OPENSSL_cleanse.


# 1.10 10-Sep-2015 lteo

Remove unused defines. No binary change.

ok deraadt@ miod@


# 1.9 22-Aug-2015 jsing

Remove all duplicate prototypes for *_main functions (these are already
provided by progs.h). Also, move the FUNCTION type (and flags) into
openssl.c since that is the only place of use. Lastly, remove pointless
'extern' from the prototypes and use char **argv instead of char *argv[]
(the former is used elsewhere).

ok deraadt@ doug@


Revision tags: OPENBSD_5_8_BASE
# 1.8 22-Jul-2015 jsing

Revert ca.c r1.7 - BN_to_ASN1_INTEGER() only allocates an ASN.1 integer
when it is not passed a reference to one. In this case, it is passed a
reference to an ASN.1 integer that is part of the X509 ASN.1 data
structure. Freeing this causes bad things to happen, since it is used and
then freed later on.

Found the hard way by kinichiro inoguchi.


# 1.7 19-Jul-2015 doug

Free memory when finished.

Fixes coverity 78835.

ok bcook@


# 1.6 19-Jul-2015 doug

Remove effectively unused variable.

Fixes Coverity issue 21693.

ok beck@ bcook@


Revision tags: OPENBSD_5_7_BASE
# 1.5 08-Feb-2015 doug

Delete commented out code from openssl(1) apps.

From OpenSSL commits:

6f91b017bbb7140f816721141ac156d1b828a6b3
75d0ebef2aef7a2c77b27575b8da898e22f3ccd5
a2b18e657ea1a932d125154f4e13ab2258796d90

ok miod@, jsing@


# 1.4 07-Feb-2015 bcook

Modify BSIZE to BUFLEN to avoid redefinition on HP-UX.

HP-UX defines BSIZE in its <sys/param.h>, and there is a route where its
getting included as a side-effect. I tracked back to at least from HP-UX 9.0
ca. 1993, up to the latest, so the user namespace is polluted.

from kinichiro <kinichiro.inoguchi@gmail.com>

ok miod@, jsing@


# 1.3 01-Sep-2014 doug

Enable -Wshadow in openssl(1) and fix a few shadow warnings.

ok jsing@


# 1.2 28-Aug-2014 jsing

openssl_setup() calls SSL_load_error_strings(), which happens to call
ERR_load_crypto_strings() - as such, we do not need to call the same
function from most of the applications.


# 1.1 26-Aug-2014 jsing

Move openssl(1) from /usr/sbin/openssl to /usr/bin/openssl, since it is not
a system/superuser binary. At the same time, move the source code from its
current lib/libssl/src/apps location to a more appropriate home under
usr.bin/openssl.

ok deraadt@ miod@