diff options
| author | schwarze <> | 2016-11-28 17:55:26 +0000 |
|---|---|---|
| committer | schwarze <> | 2016-11-28 17:55:26 +0000 |
| commit | 629d2ef1fa4054b43d8a16a1839ff096d8f396d2 (patch) | |
| tree | 8e26a9f4693cca6a55334d58208c3dbc7bb87e6b /src | |
| parent | 450d0bc447519e3f7f1faf230ed55c0237dd3676 (diff) | |
| download | openbsd-629d2ef1fa4054b43d8a16a1839ff096d8f396d2.tar.gz openbsd-629d2ef1fa4054b43d8a16a1839ff096d8f396d2.tar.bz2 openbsd-629d2ef1fa4054b43d8a16a1839ff096d8f396d2.zip | |
import from OpenSSL with minor tweaks
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/man/Makefile | 3 | ||||
| -rw-r--r-- | src/lib/libcrypto/man/PEM_read.3 | 282 |
2 files changed, 284 insertions, 1 deletions
diff --git a/src/lib/libcrypto/man/Makefile b/src/lib/libcrypto/man/Makefile index fc9f62bd06..3275d0784c 100644 --- a/src/lib/libcrypto/man/Makefile +++ b/src/lib/libcrypto/man/Makefile | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.57 2016/11/28 16:33:48 schwarze Exp $ | 1 | # $OpenBSD: Makefile,v 1.58 2016/11/28 17:55:26 schwarze Exp $ |
| 2 | 2 | ||
| 3 | .include <bsd.own.mk> | 3 | .include <bsd.own.mk> |
| 4 | 4 | ||
| @@ -133,6 +133,7 @@ MAN= \ | |||
| 133 | OPENSSL_load_builtin_modules.3 \ | 133 | OPENSSL_load_builtin_modules.3 \ |
| 134 | OPENSSL_malloc.3 \ | 134 | OPENSSL_malloc.3 \ |
| 135 | OpenSSL_add_all_algorithms.3 \ | 135 | OpenSSL_add_all_algorithms.3 \ |
| 136 | PEM_read.3 \ | ||
| 136 | PEM_read_bio_PrivateKey.3 \ | 137 | PEM_read_bio_PrivateKey.3 \ |
| 137 | PEM_write_bio_PKCS7_stream.3 \ | 138 | PEM_write_bio_PKCS7_stream.3 \ |
| 138 | PKCS12_create.3 \ | 139 | PKCS12_create.3 \ |
diff --git a/src/lib/libcrypto/man/PEM_read.3 b/src/lib/libcrypto/man/PEM_read.3 new file mode 100644 index 0000000000..bca26f1ef6 --- /dev/null +++ b/src/lib/libcrypto/man/PEM_read.3 | |||
| @@ -0,0 +1,282 @@ | |||
| 1 | .\" $OpenBSD: PEM_read.3,v 1.1 2016/11/28 17:55:26 schwarze Exp $ | ||
| 2 | .\" OpenSSL 99d63d46 Oct 26 13:56:48 2016 -0400 | ||
| 3 | .\" | ||
| 4 | .\" This file was written by Viktor Dukhovni | ||
| 5 | .\" and by Rich Salz <rsalz@openssl.org>. | ||
| 6 | .\" Copyright (c) 2016 The OpenSSL Project. All rights reserved. | ||
| 7 | .\" | ||
| 8 | .\" Redistribution and use in source and binary forms, with or without | ||
| 9 | .\" modification, are permitted provided that the following conditions | ||
| 10 | .\" are met: | ||
| 11 | .\" | ||
| 12 | .\" 1. Redistributions of source code must retain the above copyright | ||
| 13 | .\" notice, this list of conditions and the following disclaimer. | ||
| 14 | .\" | ||
| 15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | .\" notice, this list of conditions and the following disclaimer in | ||
| 17 | .\" the documentation and/or other materials provided with the | ||
| 18 | .\" distribution. | ||
| 19 | .\" | ||
| 20 | .\" 3. All advertising materials mentioning features or use of this | ||
| 21 | .\" software must display the following acknowledgment: | ||
| 22 | .\" "This product includes software developed by the OpenSSL Project | ||
| 23 | .\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 24 | .\" | ||
| 25 | .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | .\" endorse or promote products derived from this software without | ||
| 27 | .\" prior written permission. For written permission, please contact | ||
| 28 | .\" openssl-core@openssl.org. | ||
| 29 | .\" | ||
| 30 | .\" 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | .\" nor may "OpenSSL" appear in their names without prior written | ||
| 32 | .\" permission of the OpenSSL Project. | ||
| 33 | .\" | ||
| 34 | .\" 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | .\" acknowledgment: | ||
| 36 | .\" "This product includes software developed by the OpenSSL Project | ||
| 37 | .\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 38 | .\" | ||
| 39 | .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | .\" OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | .\" | ||
| 52 | .Dd $Mdocdate: November 28 2016 $ | ||
| 53 | .Dt PEM_READ 3 | ||
| 54 | .Os | ||
| 55 | .Sh NAME | ||
| 56 | .Nm PEM_write , | ||
| 57 | .Nm PEM_write_bio , | ||
| 58 | .Nm PEM_read , | ||
| 59 | .Nm PEM_read_bio , | ||
| 60 | .Nm PEM_do_header , | ||
| 61 | .Nm PEM_get_EVP_CIPHER_INFO | ||
| 62 | .Nd PEM encoding routines | ||
| 63 | .Sh SYNOPSIS | ||
| 64 | .In openssl/pem.h | ||
| 65 | .Ft int | ||
| 66 | .Fo PEM_write | ||
| 67 | .Fa "FILE *fp" | ||
| 68 | .Fa "char *name" | ||
| 69 | .Fa "char *header" | ||
| 70 | .Fa "unsigned char *data" | ||
| 71 | .Fa "long len" | ||
| 72 | .Fc | ||
| 73 | .Ft int | ||
| 74 | .Fo PEM_write_bio | ||
| 75 | .Fa "BIO *bp" | ||
| 76 | .Fa "const char *name" | ||
| 77 | .Fa "char *header" | ||
| 78 | .Fa "unsigned char *data" | ||
| 79 | .Fa "long len" | ||
| 80 | .Fc | ||
| 81 | .Ft int | ||
| 82 | .Fo PEM_read | ||
| 83 | .Fa "FILE *fp" | ||
| 84 | .Fa "char **name" | ||
| 85 | .Fa "char **header" | ||
| 86 | .Fa "unsigned char **data" | ||
| 87 | .Fa "long *len" | ||
| 88 | .Fc | ||
| 89 | .Ft int | ||
| 90 | .Fo PEM_read_bio | ||
| 91 | .Fa "BIO *bp" | ||
| 92 | .Fa "char **name" | ||
| 93 | .Fa "char **header" | ||
| 94 | .Fa "unsigned char **data" | ||
| 95 | .Fa "long *len" | ||
| 96 | .Fc | ||
| 97 | .Ft int | ||
| 98 | .Fo PEM_get_EVP_CIPHER_INFO | ||
| 99 | .Fa "char *header" | ||
| 100 | .Fa "EVP_CIPHER_INFO *cinfo" | ||
| 101 | .Fc | ||
| 102 | .Ft int | ||
| 103 | .Fo PEM_do_header | ||
| 104 | .Fa "EVP_CIPHER_INFO *cinfo" | ||
| 105 | .Fa "unsigned char *data" | ||
| 106 | .Fa "long *len" | ||
| 107 | .Fa "pem_password_cb *cb" | ||
| 108 | .Fa "void *u" | ||
| 109 | .Fc | ||
| 110 | .Sh DESCRIPTION | ||
| 111 | These functions read and write PEM-encoded objects, using the PEM type | ||
| 112 | .Fa name , | ||
| 113 | any additional | ||
| 114 | .Fa header | ||
| 115 | information, and the raw | ||
| 116 | .Fa data | ||
| 117 | of length | ||
| 118 | .Fa len . | ||
| 119 | .Pp | ||
| 120 | PEM is the binary content encoding first defined in IETF RFC 1421. | ||
| 121 | The content is a series of base64-encoded lines, surrounded by | ||
| 122 | begin/end markers each on their own line. | ||
| 123 | For example: | ||
| 124 | .Bd -literal -offset indent | ||
| 125 | -----BEGIN PRIVATE KEY----- | ||
| 126 | MIICdg.... | ||
| 127 | \&... bhTQ== | ||
| 128 | -----END PRIVATE KEY----- | ||
| 129 | .Ed | ||
| 130 | .Pp | ||
| 131 | Optional header line(s) may appear after the begin line, and their | ||
| 132 | existence depends on the type of object being written or read. | ||
| 133 | .Pp | ||
| 134 | .Fn PEM_write | ||
| 135 | writes to the file | ||
| 136 | .Fa fp , | ||
| 137 | while | ||
| 138 | .Fn PEM_write_bio | ||
| 139 | writes to the BIO | ||
| 140 | .Fa bp . | ||
| 141 | The | ||
| 142 | .Fa name | ||
| 143 | is the name to use in the marker, the | ||
| 144 | .Fa header | ||
| 145 | is the header value or | ||
| 146 | .Dv NULL , | ||
| 147 | and | ||
| 148 | .Fa data | ||
| 149 | and | ||
| 150 | .Fa len | ||
| 151 | specify the data and its length. | ||
| 152 | .Pp | ||
| 153 | The final | ||
| 154 | .Fa data | ||
| 155 | buffer is typically an ASN.1 object which can be decoded with the | ||
| 156 | .Fn d2i_* | ||
| 157 | function appropriate to the type | ||
| 158 | .Fa name ; | ||
| 159 | see | ||
| 160 | .Xr d2i_X509 3 | ||
| 161 | for examples. | ||
| 162 | .Pp | ||
| 163 | .Fn PEM_read | ||
| 164 | reads from the file | ||
| 165 | .Fa fp , | ||
| 166 | while | ||
| 167 | .Fn PEM_read_bio | ||
| 168 | reads from the BIO | ||
| 169 | .Fa bp . | ||
| 170 | Both skip any non-PEM data that precedes the start of the next PEM | ||
| 171 | object. | ||
| 172 | When an object is successfully retrieved, the type name from the | ||
| 173 | "----BEGIN <type>-----" is returned via the | ||
| 174 | .Fa name | ||
| 175 | argument, any encapsulation headers are returned in | ||
| 176 | .Fa header , | ||
| 177 | and the base64-decoded content and its length are returned via | ||
| 178 | .Fa data | ||
| 179 | and | ||
| 180 | .Fa len , | ||
| 181 | respectively. | ||
| 182 | The | ||
| 183 | .Fa name , | ||
| 184 | .Fa header , | ||
| 185 | and | ||
| 186 | .Fa data | ||
| 187 | pointers should be freed by the caller when no longer needed. | ||
| 188 | .Pp | ||
| 189 | The remaining functions are deprecated because the underlying PEM | ||
| 190 | encryption format is obsolete and should be avoided. | ||
| 191 | It uses an encryption format with an OpenSSL-specific key-derivation | ||
| 192 | function, which employs MD5 with an iteration count of 1. | ||
| 193 | Instead, private keys should be stored in PKCS#8 form, with a strong | ||
| 194 | PKCS#5 v2.0 PBE, see | ||
| 195 | .Xr PEM_write_PrivateKey 3 | ||
| 196 | and | ||
| 197 | .Xr d2i_PKCS8PrivateKey_bio 3 . | ||
| 198 | .Pp | ||
| 199 | .Fn PEM_get_EVP_CIPHER_INFO | ||
| 200 | can be used to determine the | ||
| 201 | .Fa data | ||
| 202 | returned by | ||
| 203 | .Fn PEM_read | ||
| 204 | or | ||
| 205 | .Fn PEM_read_bio | ||
| 206 | is encrypted and to retrieve the associated cipher and IV. | ||
| 207 | The caller passes a pointer to a structure of type | ||
| 208 | .Vt EVP_CIPHER_INFO | ||
| 209 | via the | ||
| 210 | .Fa cinfo | ||
| 211 | argument and the | ||
| 212 | .Fa header | ||
| 213 | returned via | ||
| 214 | .Fn PEM_read | ||
| 215 | or | ||
| 216 | .Fn PEM_read_bio . | ||
| 217 | If the call is successful, 1 is returned and the cipher and IV are | ||
| 218 | stored at the address pointed to by | ||
| 219 | .Fa cinfo . | ||
| 220 | When the header is malformed or not supported or when the cipher is | ||
| 221 | unknown or some internal error happens, 0 is returned. | ||
| 222 | .Pp | ||
| 223 | .Fn PEM_do_header | ||
| 224 | can then be used to decrypt the data if the header indicates encryption. | ||
| 225 | The | ||
| 226 | .Fa cinfo | ||
| 227 | argument is a pointer to the structure initialized by the previous call | ||
| 228 | to | ||
| 229 | .Fn PEM_get_EVP_CIPHER_INFO . | ||
| 230 | The | ||
| 231 | .Fa data | ||
| 232 | and | ||
| 233 | .Fa len | ||
| 234 | arguments are those returned by the previous call to | ||
| 235 | .Fn PEM_read | ||
| 236 | or | ||
| 237 | .Fn PEM_read_bio . | ||
| 238 | The | ||
| 239 | .Fa cb | ||
| 240 | and | ||
| 241 | .Fa u | ||
| 242 | arguments make it possible to override the default password prompt | ||
| 243 | function as described in | ||
| 244 | .Xr PEM_read_PrivateKey 3 . | ||
| 245 | On successful completion, the | ||
| 246 | .Fa data | ||
| 247 | is decrypted in place, and | ||
| 248 | .Fa len | ||
| 249 | is updated to indicate the plaintext length. | ||
| 250 | .Pp | ||
| 251 | If the data is a priori known to not be encrypted, then neither | ||
| 252 | .Fn PEM_do_header | ||
| 253 | nor | ||
| 254 | .Fn PEM_get_EVP_CIPHER_INFO | ||
| 255 | need to be called. | ||
| 256 | .Sh RETURN VALUES | ||
| 257 | .Fn PEM_read | ||
| 258 | and | ||
| 259 | .Fn PEM_read_bio | ||
| 260 | return 1 on success or 0 on failure. | ||
| 261 | The latter includes the case when no more PEM objects remain in the | ||
| 262 | input file. | ||
| 263 | To distinguish end of file from more serious errors, the caller | ||
| 264 | must peek at the error stack and check for | ||
| 265 | .Dv PEM_R_NO_START_LINE , | ||
| 266 | which indicates that no more PEM objects were found. | ||
| 267 | See | ||
| 268 | .Xr ERR_peek_last_error 3 | ||
| 269 | and | ||
| 270 | .Xr ERR_GET_REASON 3 . | ||
| 271 | .Pp | ||
| 272 | .Fn PEM_get_EVP_CIPHER_INFO | ||
| 273 | and | ||
| 274 | .Fn PEM_do_header | ||
| 275 | return 1 on success or 0 on failure. | ||
| 276 | The | ||
| 277 | .Fa data | ||
| 278 | is likely meaningless if these functions fail. | ||
| 279 | .Sh SEE ALSO | ||
| 280 | .Xr d2i_PKCS8PrivateKey_bio 3 , | ||
| 281 | .Xr ERR_GET_LIB 3 , | ||
| 282 | .Xr ERR_peek_last_error 3 | ||
