summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/doc/PEM_read_bio_PrivateKey.pod
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/doc/PEM_read_bio_PrivateKey.pod')
-rw-r--r--src/lib/libcrypto/doc/PEM_read_bio_PrivateKey.pod498
1 files changed, 0 insertions, 498 deletions
diff --git a/src/lib/libcrypto/doc/PEM_read_bio_PrivateKey.pod b/src/lib/libcrypto/doc/PEM_read_bio_PrivateKey.pod
deleted file mode 100644
index 6d87079a84..0000000000
--- a/src/lib/libcrypto/doc/PEM_read_bio_PrivateKey.pod
+++ /dev/null
@@ -1,498 +0,0 @@
1=pod
2
3=head1 NAME
4
5PEM, PEM_read_bio_PrivateKey, PEM_read_PrivateKey, PEM_write_bio_PrivateKey,
6PEM_write_PrivateKey, PEM_write_bio_PKCS8PrivateKey, PEM_write_PKCS8PrivateKey,
7PEM_write_bio_PKCS8PrivateKey_nid, PEM_write_PKCS8PrivateKey_nid,
8PEM_read_bio_PUBKEY, PEM_read_PUBKEY, PEM_write_bio_PUBKEY, PEM_write_PUBKEY,
9PEM_read_bio_RSAPrivateKey, PEM_read_RSAPrivateKey,
10PEM_write_bio_RSAPrivateKey, PEM_write_RSAPrivateKey,
11PEM_read_bio_RSAPublicKey, PEM_read_RSAPublicKey, PEM_write_bio_RSAPublicKey,
12PEM_write_RSAPublicKey, PEM_read_bio_RSA_PUBKEY, PEM_read_RSA_PUBKEY,
13PEM_write_bio_RSA_PUBKEY, PEM_write_RSA_PUBKEY, PEM_read_bio_DSAPrivateKey,
14PEM_read_DSAPrivateKey, PEM_write_bio_DSAPrivateKey, PEM_write_DSAPrivateKey,
15PEM_read_bio_DSA_PUBKEY, PEM_read_DSA_PUBKEY, PEM_write_bio_DSA_PUBKEY,
16PEM_write_DSA_PUBKEY, PEM_read_bio_DSAparams, PEM_read_DSAparams,
17PEM_write_bio_DSAparams, PEM_write_DSAparams, PEM_read_bio_DHparams,
18PEM_read_DHparams, PEM_write_bio_DHparams, PEM_write_DHparams,
19PEM_read_bio_X509, PEM_read_X509, PEM_write_bio_X509, PEM_write_X509,
20PEM_read_bio_X509_AUX, PEM_read_X509_AUX, PEM_write_bio_X509_AUX,
21PEM_write_X509_AUX, PEM_read_bio_X509_REQ, PEM_read_X509_REQ,
22PEM_write_bio_X509_REQ, PEM_write_X509_REQ, PEM_write_bio_X509_REQ_NEW,
23PEM_write_X509_REQ_NEW, PEM_read_bio_X509_CRL, PEM_read_X509_CRL,
24PEM_write_bio_X509_CRL, PEM_write_X509_CRL, PEM_read_bio_PKCS7, PEM_read_PKCS7,
25PEM_write_bio_PKCS7, PEM_write_PKCS7, PEM_read_bio_NETSCAPE_CERT_SEQUENCE,
26PEM_read_NETSCAPE_CERT_SEQUENCE, PEM_write_bio_NETSCAPE_CERT_SEQUENCE,
27PEM_write_NETSCAPE_CERT_SEQUENCE - PEM routines
28
29=head1 SYNOPSIS
30
31 #include <openssl/pem.h>
32
33 EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x,
34 pem_password_cb *cb, void *u);
35
36 EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x,
37 pem_password_cb *cb, void *u);
38
39 int PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
40 unsigned char *kstr, int klen,
41 pem_password_cb *cb, void *u);
42
43 int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
44 unsigned char *kstr, int klen,
45 pem_password_cb *cb, void *u);
46
47 int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
48 char *kstr, int klen,
49 pem_password_cb *cb, void *u);
50
51 int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
52 char *kstr, int klen,
53 pem_password_cb *cb, void *u);
54
55 int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
56 char *kstr, int klen,
57 pem_password_cb *cb, void *u);
58
59 int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
60 char *kstr, int klen,
61 pem_password_cb *cb, void *u);
62
63 EVP_PKEY *PEM_read_bio_PUBKEY(BIO *bp, EVP_PKEY **x,
64 pem_password_cb *cb, void *u);
65
66 EVP_PKEY *PEM_read_PUBKEY(FILE *fp, EVP_PKEY **x,
67 pem_password_cb *cb, void *u);
68
69 int PEM_write_bio_PUBKEY(BIO *bp, EVP_PKEY *x);
70 int PEM_write_PUBKEY(FILE *fp, EVP_PKEY *x);
71
72 RSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **x,
73 pem_password_cb *cb, void *u);
74
75 RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **x,
76 pem_password_cb *cb, void *u);
77
78 int PEM_write_bio_RSAPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER *enc,
79 unsigned char *kstr, int klen,
80 pem_password_cb *cb, void *u);
81
82 int PEM_write_RSAPrivateKey(FILE *fp, RSA *x, const EVP_CIPHER *enc,
83 unsigned char *kstr, int klen,
84 pem_password_cb *cb, void *u);
85
86 RSA *PEM_read_bio_RSAPublicKey(BIO *bp, RSA **x,
87 pem_password_cb *cb, void *u);
88
89 RSA *PEM_read_RSAPublicKey(FILE *fp, RSA **x,
90 pem_password_cb *cb, void *u);
91
92 int PEM_write_bio_RSAPublicKey(BIO *bp, RSA *x);
93
94 int PEM_write_RSAPublicKey(FILE *fp, RSA *x);
95
96 RSA *PEM_read_bio_RSA_PUBKEY(BIO *bp, RSA **x,
97 pem_password_cb *cb, void *u);
98
99 RSA *PEM_read_RSA_PUBKEY(FILE *fp, RSA **x,
100 pem_password_cb *cb, void *u);
101
102 int PEM_write_bio_RSA_PUBKEY(BIO *bp, RSA *x);
103
104 int PEM_write_RSA_PUBKEY(FILE *fp, RSA *x);
105
106 DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **x,
107 pem_password_cb *cb, void *u);
108
109 DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **x,
110 pem_password_cb *cb, void *u);
111
112 int PEM_write_bio_DSAPrivateKey(BIO *bp, DSA *x, const EVP_CIPHER *enc,
113 unsigned char *kstr, int klen,
114 pem_password_cb *cb, void *u);
115
116 int PEM_write_DSAPrivateKey(FILE *fp, DSA *x, const EVP_CIPHER *enc,
117 unsigned char *kstr, int klen,
118 pem_password_cb *cb, void *u);
119
120 DSA *PEM_read_bio_DSA_PUBKEY(BIO *bp, DSA **x,
121 pem_password_cb *cb, void *u);
122
123 DSA *PEM_read_DSA_PUBKEY(FILE *fp, DSA **x,
124 pem_password_cb *cb, void *u);
125
126 int PEM_write_bio_DSA_PUBKEY(BIO *bp, DSA *x);
127
128 int PEM_write_DSA_PUBKEY(FILE *fp, DSA *x);
129
130 DSA *PEM_read_bio_DSAparams(BIO *bp, DSA **x, pem_password_cb *cb, void *u);
131
132 DSA *PEM_read_DSAparams(FILE *fp, DSA **x, pem_password_cb *cb, void *u);
133
134 int PEM_write_bio_DSAparams(BIO *bp, DSA *x);
135
136 int PEM_write_DSAparams(FILE *fp, DSA *x);
137
138 DH *PEM_read_bio_DHparams(BIO *bp, DH **x, pem_password_cb *cb, void *u);
139
140 DH *PEM_read_DHparams(FILE *fp, DH **x, pem_password_cb *cb, void *u);
141
142 int PEM_write_bio_DHparams(BIO *bp, DH *x);
143
144 int PEM_write_DHparams(FILE *fp, DH *x);
145
146 X509 *PEM_read_bio_X509(BIO *bp, X509 **x, pem_password_cb *cb, void *u);
147
148 X509 *PEM_read_X509(FILE *fp, X509 **x, pem_password_cb *cb, void *u);
149
150 int PEM_write_bio_X509(BIO *bp, X509 *x);
151
152 int PEM_write_X509(FILE *fp, X509 *x);
153
154 X509 *PEM_read_bio_X509_AUX(BIO *bp, X509 **x, pem_password_cb *cb, void *u);
155
156 X509 *PEM_read_X509_AUX(FILE *fp, X509 **x, pem_password_cb *cb, void *u);
157
158 int PEM_write_bio_X509_AUX(BIO *bp, X509 *x);
159
160 int PEM_write_X509_AUX(FILE *fp, X509 *x);
161
162 X509_REQ *PEM_read_bio_X509_REQ(BIO *bp, X509_REQ **x,
163 pem_password_cb *cb, void *u);
164
165 X509_REQ *PEM_read_X509_REQ(FILE *fp, X509_REQ **x,
166 pem_password_cb *cb, void *u);
167
168 int PEM_write_bio_X509_REQ(BIO *bp, X509_REQ *x);
169
170 int PEM_write_X509_REQ(FILE *fp, X509_REQ *x);
171
172 int PEM_write_bio_X509_REQ_NEW(BIO *bp, X509_REQ *x);
173
174 int PEM_write_X509_REQ_NEW(FILE *fp, X509_REQ *x);
175
176 X509_CRL *PEM_read_bio_X509_CRL(BIO *bp, X509_CRL **x,
177 pem_password_cb *cb, void *u);
178 X509_CRL *PEM_read_X509_CRL(FILE *fp, X509_CRL **x,
179 pem_password_cb *cb, void *u);
180 int PEM_write_bio_X509_CRL(BIO *bp, X509_CRL *x);
181 int PEM_write_X509_CRL(FILE *fp, X509_CRL *x);
182
183 PKCS7 *PEM_read_bio_PKCS7(BIO *bp, PKCS7 **x, pem_password_cb *cb, void *u);
184
185 PKCS7 *PEM_read_PKCS7(FILE *fp, PKCS7 **x, pem_password_cb *cb, void *u);
186
187 int PEM_write_bio_PKCS7(BIO *bp, PKCS7 *x);
188
189 int PEM_write_PKCS7(FILE *fp, PKCS7 *x);
190
191 NETSCAPE_CERT_SEQUENCE *PEM_read_bio_NETSCAPE_CERT_SEQUENCE(BIO *bp,
192 NETSCAPE_CERT_SEQUENCE **x,
193 pem_password_cb *cb, void *u);
194
195 NETSCAPE_CERT_SEQUENCE *PEM_read_NETSCAPE_CERT_SEQUENCE(FILE *fp,
196 NETSCAPE_CERT_SEQUENCE **x,
197 pem_password_cb *cb, void *u);
198
199 int PEM_write_bio_NETSCAPE_CERT_SEQUENCE(BIO *bp, NETSCAPE_CERT_SEQUENCE *x);
200
201 int PEM_write_NETSCAPE_CERT_SEQUENCE(FILE *fp, NETSCAPE_CERT_SEQUENCE *x);
202
203=head1 DESCRIPTION
204
205The PEM functions read or write structures in PEM format. In
206this sense PEM format is simply base64 encoded data surrounded
207by header lines.
208
209For more details about the meaning of arguments see the
210B<PEM FUNCTION ARGUMENTS> section.
211
212Each operation has four functions associated with it. For
213clarity the term "B<foobar> functions" will be used to collectively
214refer to the PEM_read_bio_foobar(), PEM_read_foobar(),
215PEM_write_bio_foobar() and PEM_write_foobar() functions.
216
217The B<PrivateKey> functions read or write a private key in
218PEM format using an EVP_PKEY structure. The write routines use
219"traditional" private key format and can handle both RSA and DSA
220private keys. The read functions can additionally transparently
221handle PKCS#8 format encrypted and unencrypted keys too.
222
223PEM_write_bio_PKCS8PrivateKey() and PEM_write_PKCS8PrivateKey()
224write a private key in an EVP_PKEY structure in PKCS#8
225EncryptedPrivateKeyInfo format using PKCS#5 v2.0 password based encryption
226algorithms. The B<cipher> argument specifies the encryption algorithm to
227use: unlike all other PEM routines the encryption is applied at the
228PKCS#8 level and not in the PEM headers. If B<cipher> is NULL then no
229encryption is used and a PKCS#8 PrivateKeyInfo structure is used instead.
230
231PEM_write_bio_PKCS8PrivateKey_nid() and PEM_write_PKCS8PrivateKey_nid()
232also write out a private key as a PKCS#8 EncryptedPrivateKeyInfo however
233it uses PKCS#5 v1.5 or PKCS#12 encryption algorithms instead. The algorithm
234to use is specified in the B<nid> parameter and should be the NID of the
235corresponding OBJECT IDENTIFIER (see NOTES section).
236
237The B<PUBKEY> functions process a public key using an EVP_PKEY
238structure. The public key is encoded as a SubjectPublicKeyInfo
239structure.
240
241The B<RSAPrivateKey> functions process an RSA private key using an
242RSA structure. It handles the same formats as the B<PrivateKey>
243functions but an error occurs if the private key is not RSA.
244
245The B<RSAPublicKey> functions process an RSA public key using an
246RSA structure. The public key is encoded using a PKCS#1 RSAPublicKey
247structure.
248
249The B<RSA_PUBKEY> functions also process an RSA public key using
250an RSA structure. However the public key is encoded using a
251SubjectPublicKeyInfo structure and an error occurs if the public
252key is not RSA.
253
254The B<DSAPrivateKey> functions process a DSA private key using a
255DSA structure. It handles the same formats as the B<PrivateKey>
256functions but an error occurs if the private key is not DSA.
257
258The B<DSA_PUBKEY> functions process a DSA public key using
259a DSA structure. The public key is encoded using a
260SubjectPublicKeyInfo structure and an error occurs if the public
261key is not DSA.
262
263The B<DSAparams> functions process DSA parameters using a DSA
264structure. The parameters are encoded using a foobar structure.
265
266The B<DHparams> functions process DH parameters using a DH
267structure. The parameters are encoded using a PKCS#3 DHparameter
268structure.
269
270The B<X509> functions process an X509 certificate using an X509
271structure. They will also process a trusted X509 certificate but
272any trust settings are discarded.
273
274The B<X509_AUX> functions process a trusted X509 certificate using
275an X509 structure.
276
277The B<X509_REQ> and B<X509_REQ_NEW> functions process a PKCS#10
278certificate request using an X509_REQ structure. The B<X509_REQ>
279write functions use B<CERTIFICATE REQUEST> in the header whereas
280the B<X509_REQ_NEW> functions use B<NEW CERTIFICATE REQUEST>
281(as required by some CAs). The B<X509_REQ> read functions will
282handle either form so there are no B<X509_REQ_NEW> read functions.
283
284The B<X509_CRL> functions process an X509 CRL using an X509_CRL
285structure.
286
287The B<PKCS7> functions process a PKCS#7 ContentInfo using a PKCS7
288structure.
289
290The B<NETSCAPE_CERT_SEQUENCE> functions process a Netscape Certificate
291Sequence using a NETSCAPE_CERT_SEQUENCE structure.
292
293=head1 PEM FUNCTION ARGUMENTS
294
295The PEM functions have many common arguments.
296
297The B<bp> BIO parameter (if present) specifies the BIO to read from
298or write to.
299
300The B<fp> FILE parameter (if present) specifies the FILE pointer to
301read from or write to.
302
303The PEM read functions all take an argument B<TYPE **x> and return
304a B<TYPE *> pointer. Where B<TYPE> is whatever structure the function
305uses. If B<x> is NULL then the parameter is ignored. If B<x> is not
306NULL but B<*x> is NULL then the structure returned will be written
307to B<*x>. If neither B<x> nor B<*x> is NULL then an attempt is made
308to reuse the structure at B<*x> (but see BUGS and EXAMPLES sections).
309Irrespective of the value of B<x> a pointer to the structure is always
310returned (or NULL if an error occurred).
311
312The PEM functions which write private keys take an B<enc> parameter
313which specifies the encryption algorithm to use, encryption is done
314at the PEM level. If this parameter is set to NULL then the private
315key is written in unencrypted form.
316
317The B<cb> argument is the callback to use when querying for the pass
318phrase used for encrypted PEM structures (normally only private keys).
319
320For the PEM write routines if the B<kstr> parameter is not NULL then
321B<klen> bytes at B<kstr> are used as the passphrase and B<cb> is
322ignored.
323
324If the B<cb> parameters is set to NULL and the B<u> parameter is not
325NULL then the B<u> parameter is interpreted as a null terminated string
326to use as the passphrase. If both B<cb> and B<u> are NULL then the
327default callback routine is used which will typically prompt for the
328passphrase on the current terminal with echoing turned off.
329
330The default passphrase callback is sometimes inappropriate (for example
331in a GUI application) so an alternative can be supplied. The callback
332routine has the following form:
333
334 int cb(char *buf, int size, int rwflag, void *u);
335
336B<buf> is the buffer to write the passphrase to. B<size> is the maximum
337length of the passphrase (i.e. the size of buf). B<rwflag> is a flag
338which is set to 0 when reading and 1 when writing. A typical routine
339will ask the user to verify the passphrase (for example by prompting
340for it twice) if B<rwflag> is 1. The B<u> parameter has the same
341value as the B<u> parameter passed to the PEM routine. It allows
342arbitrary data to be passed to the callback by the application
343(for example a window handle in a GUI application). The callback
344B<must> return the number of characters in the passphrase or 0 if
345an error occurred.
346
347=head1 EXAMPLES
348
349Although the PEM routines take several arguments in almost all applications
350most of them are set to 0 or NULL.
351
352Read a certificate in PEM format from a BIO:
353
354 X509 *x;
355 x = PEM_read_bio_X509(bp, NULL, 0, NULL);
356 if (x == NULL) {
357 /* Error */
358 }
359
360Alternative method:
361
362 X509 *x = NULL;
363 if (!PEM_read_bio_X509(bp, &x, 0, NULL)) {
364 /* Error */
365 }
366
367Write a certificate to a BIO:
368
369 if (!PEM_write_bio_X509(bp, x)) {
370 /* Error */
371 }
372
373Write an unencrypted private key to a FILE pointer:
374
375 if (!PEM_write_PrivateKey(fp, key, NULL, NULL, 0, 0, NULL)) {
376 /* Error */
377 }
378
379Write a private key (using traditional format) to a BIO using
380triple DES encryption, the pass phrase is prompted for:
381
382 if (!PEM_write_bio_PrivateKey(bp, key, EVP_des_ede3_cbc(),
383 NULL, 0, 0, NULL)) {
384 /* Error */
385 }
386
387Write a private key (using PKCS#8 format) to a BIO using triple
388DES encryption, using the pass phrase "hello":
389
390 if (!PEM_write_bio_PKCS8PrivateKey(bp, key, EVP_des_ede3_cbc(),
391 NULL, 0, 0, "hello")) {
392 /* Error */
393 }
394
395Read a private key from a BIO using the pass phrase "hello":
396
397 key = PEM_read_bio_PrivateKey(bp, NULL, 0, "hello");
398 if (key == NULL) {
399 /* Error */
400 }
401
402Read a private key from a BIO using a pass phrase callback:
403
404 key = PEM_read_bio_PrivateKey(bp, NULL, pass_cb, "My Private Key");
405 if (key == NULL) {
406 /* Error */
407 }
408
409Skeleton pass phrase callback:
410
411 int
412 pass_cb(char *buf, int size, int rwflag, void *u)
413 {
414 int len;
415 char *tmp;
416
417 /* We'd probably do something else if 'rwflag' is 1 */
418 printf("Enter pass phrase for \"%s\"\n", u);
419
420 /* get pass phrase, length 'len' into 'tmp' */
421 tmp = "hello";
422 len = strlen(tmp);
423
424 if (len == 0)
425 return 0;
426 /* if too long, truncate */
427 if (len > size)
428 len = size;
429 memcpy(buf, tmp, len);
430 return len;
431 }
432
433=head1 NOTES
434
435The old B<PrivateKey> write routines are retained for compatibility.
436New applications should write private keys using the
437PEM_write_bio_PKCS8PrivateKey() or PEM_write_PKCS8PrivateKey() routines
438because they are more secure (they use an iteration count of 2048 whereas
439the traditional routines use a count of 1) unless compatibility with older
440versions of OpenSSL is important.
441
442The B<PrivateKey> read routines can be used in all applications because
443they handle all formats transparently.
444
445A frequent cause of problems is attempting to use the PEM routines like
446this:
447
448 X509 *x;
449 PEM_read_bio_X509(bp, &x, 0, NULL);
450
451this is a bug because an attempt will be made to reuse the data at B<x>
452which is an uninitialised pointer.
453
454=head1 PEM ENCRYPTION FORMAT
455
456This old B<PrivateKey> routines use a non standard technique for encryption.
457
458The private key (or other data) takes the following form:
459
460 -----BEGIN RSA PRIVATE KEY-----
461 Proc-Type: 4,ENCRYPTED
462 DEK-Info: DES-EDE3-CBC,3F17F5316E2BAC89
463
464 ...base64 encoded data...
465 -----END RSA PRIVATE KEY-----
466
467The line beginning DEK-Info contains two comma separated pieces of information:
468the encryption algorithm name as used by EVP_get_cipherbyname() and an 8
469byte B<salt> encoded as a set of hexadecimal digits.
470
471After this is the base64 encoded encrypted data.
472
473The encryption key is determined using EVP_bytestokey(), using B<salt> and an
474iteration count of 1. The IV used is the value of B<salt> and *not* the IV
475returned by EVP_bytestokey().
476
477=head1 BUGS
478
479The PEM read routines in some versions of OpenSSL will not correctly reuse
480an existing structure. Therefore the following:
481
482 PEM_read_bio_X509(bp, &x, 0, NULL);
483
484where B<x> already contains a valid certificate, may not work, whereas:
485
486 X509_free(x);
487 x = PEM_read_bio_X509(bp, NULL, 0, NULL);
488
489is guaranteed to work.
490
491=head1 RETURN CODES
492
493The read routines return either a pointer to the structure read or NULL
494if an error occurred.
495
496The write routines return 1 for success or 0 for failure.
497
498=cut