summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorschwarze <>2020-06-15 14:13:14 +0000
committerschwarze <>2020-06-15 14:13:14 +0000
commitbe1a496d70a47f3c5c3dda88e02d5297c3913e2a (patch)
treebc161df063488045bbf6766c8a9387db141fb561 /src
parentbb665705811d77d0aff1a5399bc12e8d86ae09e4 (diff)
downloadopenbsd-be1a496d70a47f3c5c3dda88e02d5297c3913e2a.tar.gz
openbsd-be1a496d70a47f3c5c3dda88e02d5297c3913e2a.tar.bz2
openbsd-be1a496d70a47f3c5c3dda88e02d5297c3913e2a.zip
Document PEM_def_callback(3).
Move pem_password_cb(3) to the file PEM_read(3) and rewrite its description from scratch for precision and conciseness. Plus some minor improvements in the vicinity. Tweaks and OK tb@.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/man/PEM_bytes_read_bio.336
-rw-r--r--src/lib/libcrypto/man/PEM_read.3146
-rw-r--r--src/lib/libcrypto/man/PEM_read_bio_PrivateKey.382
3 files changed, 158 insertions, 106 deletions
diff --git a/src/lib/libcrypto/man/PEM_bytes_read_bio.3 b/src/lib/libcrypto/man/PEM_bytes_read_bio.3
index d3a664ba74..d1148edfe0 100644
--- a/src/lib/libcrypto/man/PEM_bytes_read_bio.3
+++ b/src/lib/libcrypto/man/PEM_bytes_read_bio.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: PEM_bytes_read_bio.3,v 1.4 2020/06/12 18:16:13 schwarze Exp $ 1.\" $OpenBSD: PEM_bytes_read_bio.3,v 1.5 2020/06/15 14:13:14 schwarze Exp $
2.\" selective merge up to: 2.\" selective merge up to:
3.\" OpenSSL PEM_bytes_read_bio.pod 7671342e Feb 29 15:47:12 2016 -0600 3.\" OpenSSL PEM_bytes_read_bio.pod 7671342e Feb 29 15:47:12 2016 -0600
4.\" 4.\"
@@ -65,7 +65,7 @@
65.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 65.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
66.\" OF THE POSSIBILITY OF SUCH DAMAGE. 66.\" OF THE POSSIBILITY OF SUCH DAMAGE.
67.\" 67.\"
68.Dd $Mdocdate: June 12 2020 $ 68.Dd $Mdocdate: June 15 2020 $
69.Dt PEM_BYTES_READ_BIO 3 69.Dt PEM_BYTES_READ_BIO 3
70.Os 70.Os
71.Sh NAME 71.Sh NAME
@@ -79,31 +79,31 @@
79.Fa "long *plen" 79.Fa "long *plen"
80.Fa "char **pnm" 80.Fa "char **pnm"
81.Fa "const char *name" 81.Fa "const char *name"
82.Fa "BIO *bp" 82.Fa "BIO *in_bp"
83.Fa "pem_password_cb *cb" 83.Fa "pem_password_cb *cb"
84.Fa "void *u" 84.Fa "void *u"
85.Fc 85.Fc
86.Sh DESCRIPTION 86.Sh DESCRIPTION
87.Fn PEM_bytes_read_bio 87.Fn PEM_bytes_read_bio
88reads PEM-formatted (RFC 1421) data from the BIO 88reads and PEM decodes the first object of type
89.Fa bp
90for the data type given in
91.Fa name 89.Fa name
92(RSA PRIVATE KEY, CERTIFICATE, etc.). 90.Pq e.g. RSA PRIVATE KEY, CERTIFICATE, etc.\&
91from
92.Fa in_bp .
93If multiple PEM-encoded data structures are present in the same stream, 93If multiple PEM-encoded data structures are present in the same stream,
94.Fn PEM_bytes_read_bio 94it skips non-matching data types and continues reading.
95will skip non-matching data types and continue reading. 95Before reading each PEM object, lines not starting with
96Non-PEM data present in the stream may cause an error. 96.Qq "-----BEGIN "
97are also skipped; see
98.Xr PEM_read_bio 3
99for details of PEM parsing.
97.Pp 100.Pp
98The PEM header may indicate that the following data is encrypted; if so, 101The PEM header may indicate that the following data is encrypted; if so,
99the data will be decrypted, waiting on user input to supply a passphrase 102the data is decrypted, optionally using
100if needed.
101The password callback
102.Fa cb 103.Fa cb
103and rock 104and
104.Fa u 105.Fa u ,
105are used to obtain the decryption passphrase, if applicable. 106as described in
106For more details, see
107.Xr pem_password_cb 3 . 107.Xr pem_password_cb 3 .
108.Pp 108.Pp
109Some data types have compatibility aliases, such as a file containing 109Some data types have compatibility aliases, such as a file containing
@@ -175,6 +175,8 @@ Additional types of errors can result from
175.Xr PEM_ASN1_read 3 , 175.Xr PEM_ASN1_read 3 ,
176.Xr PEM_read 3 , 176.Xr PEM_read 3 ,
177.Xr PEM_read_bio_PrivateKey 3 177.Xr PEM_read_bio_PrivateKey 3
178.Sh STANDARDS
179RFC 1421: Privacy Enhancement for Internet Electronic Mail (PEM), Part I
178.Sh HISTORY 180.Sh HISTORY
179.Fn PEM_bytes_read_bio 181.Fn PEM_bytes_read_bio
180first appeared in OpenSSL 0.9.7 and has been available since 182first appeared in OpenSSL 0.9.7 and has been available since
diff --git a/src/lib/libcrypto/man/PEM_read.3 b/src/lib/libcrypto/man/PEM_read.3
index 1469ccd558..49cdd0f3c5 100644
--- a/src/lib/libcrypto/man/PEM_read.3
+++ b/src/lib/libcrypto/man/PEM_read.3
@@ -1,7 +1,24 @@
1.\" $OpenBSD: PEM_read.3,v 1.10 2020/06/12 11:37:42 schwarze Exp $ 1.\" $OpenBSD: PEM_read.3,v 1.11 2020/06/15 14:13:14 schwarze Exp $
2.\" OpenSSL 99d63d46 Oct 26 13:56:48 2016 -0400 2.\" full merge up to: OpenSSL 83cf7abf May 29 13:07:08 2018 +0100
3.\" 3.\"
4.\" This file was written by Viktor Dukhovni 4.\" This file is a derived work.
5.\" The changes are covered by the following Copyright and license:
6.\"
7.\" Copyright (c) 2020 Ingo Schwarze <schwarze@openbsd.org>
8.\"
9.\" Permission to use, copy, modify, and distribute this software for any
10.\" purpose with or without fee is hereby granted, provided that the above
11.\" copyright notice and this permission notice appear in all copies.
12.\"
13.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20.\"
21.\" The original file was written by Viktor Dukhovni
5.\" and by Rich Salz <rsalz@openssl.org>. 22.\" and by Rich Salz <rsalz@openssl.org>.
6.\" Copyright (c) 2016 The OpenSSL Project. All rights reserved. 23.\" Copyright (c) 2016 The OpenSSL Project. All rights reserved.
7.\" 24.\"
@@ -49,7 +66,7 @@
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 66.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE. 67.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\" 68.\"
52.Dd $Mdocdate: June 12 2020 $ 69.Dd $Mdocdate: June 15 2020 $
53.Dt PEM_READ 3 70.Dt PEM_READ 3
54.Os 71.Os
55.Sh NAME 72.Sh NAME
@@ -57,8 +74,10 @@
57.Nm PEM_write_bio , 74.Nm PEM_write_bio ,
58.Nm PEM_read , 75.Nm PEM_read ,
59.Nm PEM_read_bio , 76.Nm PEM_read_bio ,
77.Nm PEM_get_EVP_CIPHER_INFO ,
60.Nm PEM_do_header , 78.Nm PEM_do_header ,
61.Nm PEM_get_EVP_CIPHER_INFO 79.Nm PEM_def_callback ,
80.Nm pem_password_cb
62.Nd PEM encoding routines 81.Nd PEM encoding routines
63.Sh SYNOPSIS 82.Sh SYNOPSIS
64.In openssl/pem.h 83.In openssl/pem.h
@@ -107,6 +126,20 @@
107.Fa "pem_password_cb *cb" 126.Fa "pem_password_cb *cb"
108.Fa "void *u" 127.Fa "void *u"
109.Fc 128.Fc
129.Ft int
130.Fo PEM_def_callback
131.Fa "char *password"
132.Fa "int size"
133.Fa "int verify"
134.Fa "void *u"
135.Fc
136.Ft typedef int
137.Fo pem_password_cb
138.Fa "char *password"
139.Fa "int size"
140.Fa "int verify"
141.Fa "void *u"
142.Fc
110.Sh DESCRIPTION 143.Sh DESCRIPTION
111These functions read and write PEM-encoded objects, using the PEM type 144These functions read and write PEM-encoded objects, using the PEM type
112.Fa name , 145.Fa name ,
@@ -224,34 +257,83 @@ unknown or some internal error happens, 0 is returned.
224can then be used to decrypt the data if the header indicates encryption. 257can then be used to decrypt the data if the header indicates encryption.
225The 258The
226.Fa cinfo 259.Fa cinfo
227argument is a pointer to the structure initialized by the previous call 260argument is a pointer to the structure initialized by a preceding call
228to 261to
229.Fn PEM_get_EVP_CIPHER_INFO . 262.Fn PEM_get_EVP_CIPHER_INFO .
263If that structure indicates the absence of encryption,
264.Fn PEM_do_header
265returns sucessfully without taking any action.
230The 266The
231.Fa data 267.Fa data
232and 268and
233.Fa len 269.Fa len
234arguments are those returned by the previous call to 270arguments are used both to pass in the encrypted data that was
271returned in the same arguments from the preceding call to
235.Fn PEM_read 272.Fn PEM_read
236or 273or
237.Fn PEM_read_bio . 274.Fn PEM_read_bio
275and to pass out the decrypted data.
276.Pp
277The callback function
278.Fa cb
279is used to obtain the encryption
280.Fa password ;
281if
282.Fa cb
283is
284.Dv NULL ,
285.Fn PEM_def_callback
286is used instead.
238The 287The
288.Fa password
289buffer needs to be at least
290.Fa size
291bytes long.
292.Fn PEM_def_callback
293silently truncates the NUL-terminated byte string
294.Fa u
295to at most
296.Fa num
297bytes and copies it into
298.Fa password
299without a terminating NUL byte.
300If
301.Fa u
302is
303.Dv NULL ,
304.Fn PEM_def_callback
305instead prompts the user for the password with echoing turned off
306by calling
307.Xr EVP_read_pw_string_min 3
308internally.
309In this case, the
310.Fa size
311is silently reduced to at most
312.Dv BUFSIZ
313and at most
314.Fa size No \- 1
315bytes are accepted from the user and copied into the byte string buffer
316.Fa password .
317A callback function
239.Fa cb 318.Fa cb
240and 319supplied by the application may use
241.Fa u 320.Fa u
242arguments make it possible to override the default password prompt 321for a different purpose than
243function as described in 322.Fn PEM_def_callback
244.Xr PEM_read_PrivateKey 3 . 323does, e.g., as auxiliary data to use while acquiring the password.
245On successful completion, the 324For example, a GUI application might pass a window handle.
246.Fa data 325If the
247is decrypted in place, and 326.Fa verify
248.Fa len 327flag is non-zero, the user is prompted twice for the password to
249is updated to indicate the plaintext length. 328make typos less likely and it is checked that both inputs agree.
329This flag is not set by
330.Fn PEM_do_header
331nor by other read functions.
250.Pp 332.Pp
251If the data is a priori known to not be encrypted, then neither 333If the data is a priori known to not be encrypted, then neither
252.Fn PEM_do_header
253nor
254.Fn PEM_get_EVP_CIPHER_INFO 334.Fn PEM_get_EVP_CIPHER_INFO
335nor
336.Fn PEM_do_header
255need to be called. 337need to be called.
256.Sh RETURN VALUES 338.Sh RETURN VALUES
257.Fn PEM_read 339.Fn PEM_read
@@ -276,6 +358,28 @@ return 1 on success or 0 on failure.
276The 358The
277.Fa data 359.Fa data
278is likely meaningless if these functions fail. 360is likely meaningless if these functions fail.
361.Pp
362.Fn PEM_def_callback
363returns the number of bytes stored into
364.Fa buf
365or a negative value on failure, and
366.Fa cb
367is expected to behave in the same way.
368If
369.Fa u
370is
371.Dv NULL ,
372.Fn PEM_def_callback
373fails if
374.Fa num
375is less than 5
376or if an error occurs trying to prompt the user for the password.
377Otherwise, it fails when
378.Fa num
379is negative.
380The details of the circumstances that cause
381.Fa cb
382to fail may differ.
279.Sh SEE ALSO 383.Sh SEE ALSO
280.Xr crypto 3 , 384.Xr crypto 3 ,
281.Xr d2i_PKCS8PrivateKey_bio 3 , 385.Xr d2i_PKCS8PrivateKey_bio 3 ,
@@ -299,3 +403,7 @@ and
299first appeared in SSLeay 0.6.0. 403first appeared in SSLeay 0.6.0.
300These functions have been available since 404These functions have been available since
301.Ox 2.4 . 405.Ox 2.4 .
406.Pp
407.Fn PEM_def_callback
408first appeared in OpenSSL 0.9.7 and has been available since
409.Ox 3.2 .
diff --git a/src/lib/libcrypto/man/PEM_read_bio_PrivateKey.3 b/src/lib/libcrypto/man/PEM_read_bio_PrivateKey.3
index 3799baa040..cc58640b1c 100644
--- a/src/lib/libcrypto/man/PEM_read_bio_PrivateKey.3
+++ b/src/lib/libcrypto/man/PEM_read_bio_PrivateKey.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: PEM_read_bio_PrivateKey.3,v 1.17 2020/06/12 11:37:42 schwarze Exp $ 1.\" $OpenBSD: PEM_read_bio_PrivateKey.3,v 1.18 2020/06/15 14:13:14 schwarze Exp $
2.\" full merge up to: 2.\" full merge up to:
3.\" OpenSSL man3/PEM_read_bio_PrivateKey.pod 18bad535 Apr 9 15:13:55 2019 +0100 3.\" OpenSSL man3/PEM_read_bio_PrivateKey.pod 18bad535 Apr 9 15:13:55 2019 +0100
4.\" OpenSSL man3/PEM_read_CMS.pod 83cf7abf May 29 13:07:08 2018 +0100 4.\" OpenSSL man3/PEM_read_CMS.pod 83cf7abf May 29 13:07:08 2018 +0100
@@ -51,11 +51,10 @@
51.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 51.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52.\" OF THE POSSIBILITY OF SUCH DAMAGE. 52.\" OF THE POSSIBILITY OF SUCH DAMAGE.
53.\" 53.\"
54.Dd $Mdocdate: June 12 2020 $ 54.Dd $Mdocdate: June 15 2020 $
55.Dt PEM_READ_BIO_PRIVATEKEY 3 55.Dt PEM_READ_BIO_PRIVATEKEY 3
56.Os 56.Os
57.Sh NAME 57.Sh NAME
58.Nm pem_password_cb ,
59.Nm PEM_read_bio_PrivateKey , 58.Nm PEM_read_bio_PrivateKey ,
60.Nm PEM_read_PrivateKey , 59.Nm PEM_read_PrivateKey ,
61.Nm PEM_write_bio_PrivateKey , 60.Nm PEM_write_bio_PrivateKey ,
@@ -149,13 +148,6 @@
149.Nd PEM routines 148.Nd PEM routines
150.Sh SYNOPSIS 149.Sh SYNOPSIS
151.In openssl/pem.h 150.In openssl/pem.h
152.Ft typedef int
153.Fo pem_password_cb
154.Fa "char *buf"
155.Fa "int size"
156.Fa "int rwflag"
157.Fa "void *u"
158.Fc
159.Ft EVP_PKEY * 151.Ft EVP_PKEY *
160.Fo PEM_read_bio_PrivateKey 152.Fo PEM_read_bio_PrivateKey
161.Fa "BIO *bp" 153.Fa "BIO *bp"
@@ -754,7 +746,9 @@
754.Sh DESCRIPTION 746.Sh DESCRIPTION
755The PEM functions read or write structures in PEM format. 747The PEM functions read or write structures in PEM format.
756In this sense PEM format is simply base64-encoded data surrounded by 748In this sense PEM format is simply base64-encoded data surrounded by
757header lines. 749header lines; see
750.Xr PEM_read 3
751for more details.
758.Pp 752.Pp
759For more details about the meaning of arguments see the 753For more details about the meaning of arguments see the
760.Sx PEM function arguments 754.Sx PEM function arguments
@@ -1050,10 +1044,14 @@ If this parameter is set to
1050.Dv NULL , 1044.Dv NULL ,
1051then the private key is written in unencrypted form. 1045then the private key is written in unencrypted form.
1052.Pp 1046.Pp
1053The 1047The optional arguments
1048.Fa u
1049and
1054.Fa cb 1050.Fa cb
1055argument is the callback to use when querying for the passphrase used 1051are a passphrase used for encrypting a PEM structure
1056for encrypted PEM structures (normally only private keys). 1052or a callback to obtain the passphrase; see
1053.Xr pem_password_cb 3
1054for details.
1057.Pp 1055.Pp
1058For the PEM write routines, if the 1056For the PEM write routines, if the
1059.Fa kstr 1057.Fa kstr
@@ -1066,62 +1064,6 @@ bytes at
1066are used as the passphrase and 1064are used as the passphrase and
1067.Fa cb 1065.Fa cb
1068is ignored. 1066is ignored.
1069.Pp
1070If the
1071.Fa cb
1072parameter is set to
1073.Dv NULL
1074and the
1075.Fa u
1076parameter is not
1077.Dv NULL ,
1078then the
1079.Fa u
1080parameter is interpreted as a null terminated string to use as the
1081passphrase.
1082If both
1083.Fa cb
1084and
1085.Fa u
1086are
1087.Dv NULL ,
1088then the default callback routine is used, which will typically
1089prompt for the passphrase on the current terminal with echoing
1090turned off.
1091.Pp
1092The default passphrase callback is sometimes inappropriate (for example
1093in a GUI application) so an alternative can be supplied.
1094The callback routine has the following form:
1095.Bd -filled -offset inset
1096.Ft int
1097.Fo cb
1098.Fa "char *buf"
1099.Fa "int size"
1100.Fa "int rwflag"
1101.Fa "void *u"
1102.Fc
1103.Ed
1104.Pp
1105.Fa buf
1106is the buffer to write the passphrase to.
1107.Fa size
1108is the maximum length of the passphrase, i.e. the size of
1109.Fa buf .
1110.Fa rwflag
1111is a flag which is set to 0 when reading and 1 when writing.
1112A typical routine will ask the user to verify the passphrase (for
1113example by prompting for it twice) if
1114.Fa rwflag
1115is 1.
1116The
1117.Fa u
1118parameter has the same value as the
1119.Fa u
1120parameter passed to the PEM routine.
1121It allows arbitrary data to be passed to the callback by the application
1122(for example a window handle in a GUI application).
1123The callback must return the number of characters in the passphrase
1124or -1 if an error occurred.
1125.Ss PEM encryption format 1067.Ss PEM encryption format
1126This old 1068This old
1127.Sy PrivateKey 1069.Sy PrivateKey