d2i_X509.3 (206048) | d2i_X509.3 (215698) |
---|---|
1.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.37 | 1.\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.07) |
2.\" 3.\" Standard preamble: 4.\" ======================================================================== | 2.\" 3.\" Standard preamble: 4.\" ======================================================================== |
5.de Sh \" Subsection heading 6.br 7.if t .Sp 8.ne 5 9.PP 10\fB\\$1\fR 11.PP 12.. | |
13.de Sp \" Vertical space (when we can't use .PP) 14.if t .sp .5v 15.if n .sp 16.. 17.de Vb \" Begin verbatim text 18.ft CW 19.nf 20.ne \\$1 21.. 22.de Ve \" End verbatim text 23.ft R 24.fi 25.. 26.\" Set up some character translations and predefined strings. \*(-- will 27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left | 5.de Sp \" Vertical space (when we can't use .PP) 6.if t .sp .5v 7.if n .sp 8.. 9.de Vb \" Begin verbatim text 10.ft CW 11.nf 12.ne \\$1 13.. 14.de Ve \" End verbatim text 15.ft R 16.fi 17.. 18.\" Set up some character translations and predefined strings. \*(-- will 19.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left |
28.\" double quote, and \*(R" will give a right double quote. | will give a 29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to 30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' 31.\" expand to `' in nroff, nothing in troff, for use with C<>. 32.tr \(*W-|\(bv\*(Tr | 20.\" double quote, and \*(R" will give a right double quote. \*(C+ will 21.\" give a nicer C++. Capital omega is used to do unbreakable dashes and 22.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, 23.\" nothing in troff, for use with C<>. 24.tr \(*W- |
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' 34.ie n \{\ 35. ds -- \(*W- 36. ds PI pi 37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch 38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch 39. ds L" "" 40. ds R" "" 41. ds C` "" 42. ds C' "" 43'br\} 44.el\{\ 45. ds -- \|\(em\| 46. ds PI \(*p 47. ds L" `` 48. ds R" '' 49'br\} 50.\" | 25.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' 26.ie n \{\ 27. ds -- \(*W- 28. ds PI pi 29. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch 30. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch 31. ds L" "" 32. ds R" "" 33. ds C` "" 34. ds C' "" 35'br\} 36.el\{\ 37. ds -- \|\(em\| 38. ds PI \(*p 39. ds L" `` 40. ds R" '' 41'br\} 42.\" |
43.\" Escape single quotes in literal strings from groff's Unicode transform. 44.ie \n(.g .ds Aq \(aq 45.el .ds Aq ' 46.\" |
|
51.\" If the F register is turned on, we'll generate index entries on stderr for | 47.\" If the F register is turned on, we'll generate index entries on stderr for |
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index | 48.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
53.\" entries marked with X<> in POD. Of course, you'll have to process the 54.\" output yourself in some meaningful fashion. | 49.\" entries marked with X<> in POD. Of course, you'll have to process the 50.\" output yourself in some meaningful fashion. |
55.if \nF \{\ | 51.ie \nF \{\ |
56. de IX 57. tm Index:\\$1\t\\n%\t"\\$2" 58.. 59. nr % 0 60. rr F 61.\} | 52. de IX 53. tm Index:\\$1\t\\n%\t"\\$2" 54.. 55. nr % 0 56. rr F 57.\} |
58.el \{\ 59. de IX 60.. 61.\} |
|
62.\" | 62.\" |
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes 64.\" way too many mistakes in technical documents. 65.hy 0 66.if n .na 67.\" | |
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). 69.\" Fear. Run. Save yourself. No user-serviceable parts. 70. \" fudge factors for nroff and troff 71.if n \{\ 72. ds #H 0 73. ds #V .8m 74. ds #F .3m 75. ds #[ \f1 --- 48 unchanged lines hidden (view full) --- 124. ds Th \o'LP' 125. ds ae ae 126. ds Ae AE 127.\} 128.rm #[ #] #H #V #F C 129.\" ======================================================================== 130.\" 131.IX Title "d2i_X509 3" | 63.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). 64.\" Fear. Run. Save yourself. No user-serviceable parts. 65. \" fudge factors for nroff and troff 66.if n \{\ 67. ds #H 0 68. ds #V .8m 69. ds #F .3m 70. ds #[ \f1 --- 48 unchanged lines hidden (view full) --- 119. ds Th \o'LP' 120. ds ae ae 121. ds Ae AE 122.\} 123.rm #[ #] #H #V #F C 124.\" ======================================================================== 125.\" 126.IX Title "d2i_X509 3" |
132.TH d2i_X509 3 "2010-03-24" "0.9.8n" "OpenSSL" | 127.TH d2i_X509 3 "2010-11-16" "0.9.8p" "OpenSSL" 128.\" For nroff, turn off justification. Always turn off hyphenation; it makes 129.\" way too many mistakes in technical documents. 130.if n .ad l 131.nh |
133.SH "NAME" 134d2i_X509, i2d_X509, d2i_X509_bio, d2i_X509_fp, i2d_X509_bio, 135i2d_X509_fp \- X509 encode and decode functions 136.SH "SYNOPSIS" 137.IX Header "SYNOPSIS" 138.Vb 1 139\& #include <openssl/x509.h> | 132.SH "NAME" 133d2i_X509, i2d_X509, d2i_X509_bio, d2i_X509_fp, i2d_X509_bio, 134i2d_X509_fp \- X509 encode and decode functions 135.SH "SYNOPSIS" 136.IX Header "SYNOPSIS" 137.Vb 1 138\& #include <openssl/x509.h> |
140.Ve 141.PP 142.Vb 2 | 139\& |
143\& X509 *d2i_X509(X509 **px, const unsigned char **in, int len); 144\& int i2d_X509(X509 *x, unsigned char **out); | 140\& X509 *d2i_X509(X509 **px, const unsigned char **in, int len); 141\& int i2d_X509(X509 *x, unsigned char **out); |
145.Ve 146.PP 147.Vb 2 | 142\& |
148\& X509 *d2i_X509_bio(BIO *bp, X509 **x); 149\& X509 *d2i_X509_fp(FILE *fp, X509 **x); | 143\& X509 *d2i_X509_bio(BIO *bp, X509 **x); 144\& X509 *d2i_X509_fp(FILE *fp, X509 **x); |
150.Ve 151.PP 152.Vb 2 | 145\& |
153\& int i2d_X509_bio(BIO *bp, X509 *x); 154\& int i2d_X509_fp(FILE *fp, X509 *x); 155.Ve 156.SH "DESCRIPTION" 157.IX Header "DESCRIPTION" 158The X509 encode and decode routines encode and parse an 159\&\fBX509\fR structure, which represents an X509 certificate. 160.PP --- 5 unchanged lines hidden (view full) --- 166structure and an attempt is made to reuse it. If the call is 167successful \fB*in\fR is incremented to the byte following the 168parsed data. 169.PP 170\&\fIi2d_X509()\fR encodes the structure pointed to by \fBx\fR into \s-1DER\s0 format. 171If \fBout\fR is not \fB\s-1NULL\s0\fR is writes the \s-1DER\s0 encoded data to the buffer 172at \fB*out\fR, and increments it to point after the data just written. 173If the return value is negative an error occurred, otherwise it | 146\& int i2d_X509_bio(BIO *bp, X509 *x); 147\& int i2d_X509_fp(FILE *fp, X509 *x); 148.Ve 149.SH "DESCRIPTION" 150.IX Header "DESCRIPTION" 151The X509 encode and decode routines encode and parse an 152\&\fBX509\fR structure, which represents an X509 certificate. 153.PP --- 5 unchanged lines hidden (view full) --- 159structure and an attempt is made to reuse it. If the call is 160successful \fB*in\fR is incremented to the byte following the 161parsed data. 162.PP 163\&\fIi2d_X509()\fR encodes the structure pointed to by \fBx\fR into \s-1DER\s0 format. 164If \fBout\fR is not \fB\s-1NULL\s0\fR is writes the \s-1DER\s0 encoded data to the buffer 165at \fB*out\fR, and increments it to point after the data just written. 166If the return value is negative an error occurred, otherwise it |
174returns the length of the encoded data. | 167returns the length of the encoded data. |
175.PP 176For OpenSSL 0.9.7 and later if \fB*out\fR is \fB\s-1NULL\s0\fR memory will be 177allocated for a buffer and the encoded data written to it. In this 178case \fB*out\fR is not incremented and it points to the start of the 179data just written. 180.PP 181\&\fId2i_X509_bio()\fR is similar to \fId2i_X509()\fR except it attempts 182to parse data from \s-1BIO\s0 \fBbp\fR. --- 34 unchanged lines hidden (view full) --- 217another will processed after it. 218.SH "EXAMPLES" 219.IX Header "EXAMPLES" 220Allocate and encode the \s-1DER\s0 encoding of an X509 structure: 221.PP 222.Vb 2 223\& int len; 224\& unsigned char *buf, *p; | 168.PP 169For OpenSSL 0.9.7 and later if \fB*out\fR is \fB\s-1NULL\s0\fR memory will be 170allocated for a buffer and the encoded data written to it. In this 171case \fB*out\fR is not incremented and it points to the start of the 172data just written. 173.PP 174\&\fId2i_X509_bio()\fR is similar to \fId2i_X509()\fR except it attempts 175to parse data from \s-1BIO\s0 \fBbp\fR. --- 34 unchanged lines hidden (view full) --- 210another will processed after it. 211.SH "EXAMPLES" 212.IX Header "EXAMPLES" 213Allocate and encode the \s-1DER\s0 encoding of an X509 structure: 214.PP 215.Vb 2 216\& int len; 217\& unsigned char *buf, *p; |
225.Ve 226.PP 227.Vb 1 | 218\& |
228\& len = i2d_X509(x, NULL); | 219\& len = i2d_X509(x, NULL); |
229.Ve 230.PP 231.Vb 1 | 220\& |
232\& buf = OPENSSL_malloc(len); | 221\& buf = OPENSSL_malloc(len); |
233.Ve 234.PP 235.Vb 2 | 222\& |
236\& if (buf == NULL) 237\& /* error */ | 223\& if (buf == NULL) 224\& /* error */ |
238.Ve 239.PP 240.Vb 1 | 225\& |
241\& p = buf; | 226\& p = buf; |
242.Ve 243.PP 244.Vb 1 | 227\& |
245\& i2d_X509(x, &p); 246.Ve 247.PP 248If you are using OpenSSL 0.9.7 or later then this can be 249simplified to: 250.PP 251.Vb 2 252\& int len; 253\& unsigned char *buf; | 228\& i2d_X509(x, &p); 229.Ve 230.PP 231If you are using OpenSSL 0.9.7 or later then this can be 232simplified to: 233.PP 234.Vb 2 235\& int len; 236\& unsigned char *buf; |
254.Ve 255.PP 256.Vb 1 | 237\& |
257\& buf = NULL; | 238\& buf = NULL; |
258.Ve 259.PP 260.Vb 1 | 239\& |
261\& len = i2d_X509(x, &buf); | 240\& len = i2d_X509(x, &buf); |
262.Ve 263.PP 264.Vb 2 | 241\& |
265\& if (len < 0) 266\& /* error */ 267.Ve 268.PP 269Attempt to decode a buffer: 270.PP 271.Vb 1 272\& X509 *x; | 242\& if (len < 0) 243\& /* error */ 244.Ve 245.PP 246Attempt to decode a buffer: 247.PP 248.Vb 1 249\& X509 *x; |
273.Ve 274.PP 275.Vb 1 | 250\& |
276\& unsigned char *buf, *p; | 251\& unsigned char *buf, *p; |
277.Ve 278.PP 279.Vb 1 | 252\& |
280\& int len; | 253\& int len; |
281.Ve 282.PP 283.Vb 1 | 254\& |
284\& /* Something to setup buf and len */ | 255\& /* Something to setup buf and len */ |
285.Ve 286.PP 287.Vb 1 | 256\& |
288\& p = buf; | 257\& p = buf; |
289.Ve 290.PP 291.Vb 1 | 258\& |
292\& x = d2i_X509(NULL, &p, len); | 259\& x = d2i_X509(NULL, &p, len); |
293.Ve 294.PP 295.Vb 2 | 260\& |
296\& if (x == NULL) 297\& /* Some error */ 298.Ve 299.PP 300Alternative technique: 301.PP 302.Vb 1 303\& X509 *x; | 261\& if (x == NULL) 262\& /* Some error */ 263.Ve 264.PP 265Alternative technique: 266.PP 267.Vb 1 268\& X509 *x; |
304.Ve 305.PP 306.Vb 1 | 269\& |
307\& unsigned char *buf, *p; | 270\& unsigned char *buf, *p; |
308.Ve 309.PP 310.Vb 1 | 271\& |
311\& int len; | 272\& int len; |
312.Ve 313.PP 314.Vb 1 | 273\& |
315\& /* Something to setup buf and len */ | 274\& /* Something to setup buf and len */ |
316.Ve 317.PP 318.Vb 1 | 275\& |
319\& p = buf; | 276\& p = buf; |
320.Ve 321.PP 322.Vb 1 | 277\& |
323\& x = NULL; | 278\& x = NULL; |
324.Ve 325.PP 326.Vb 2 | 279\& |
327\& if(!d2i_X509(&x, &p, len)) 328\& /* Some error */ 329.Ve 330.SH "WARNINGS" 331.IX Header "WARNINGS" 332The use of temporary variable is mandatory. A common 333mistake is to attempt to use a buffer directly as follows: 334.PP 335.Vb 2 336\& int len; 337\& unsigned char *buf; | 280\& if(!d2i_X509(&x, &p, len)) 281\& /* Some error */ 282.Ve 283.SH "WARNINGS" 284.IX Header "WARNINGS" 285The use of temporary variable is mandatory. A common 286mistake is to attempt to use a buffer directly as follows: 287.PP 288.Vb 2 289\& int len; 290\& unsigned char *buf; |
338.Ve 339.PP 340.Vb 1 | 291\& |
341\& len = i2d_X509(x, NULL); | 292\& len = i2d_X509(x, NULL); |
342.Ve 343.PP 344.Vb 1 | 293\& |
345\& buf = OPENSSL_malloc(len); | 294\& buf = OPENSSL_malloc(len); |
346.Ve 347.PP 348.Vb 2 | 295\& |
349\& if (buf == NULL) 350\& /* error */ | 296\& if (buf == NULL) 297\& /* error */ |
351.Ve 352.PP 353.Vb 1 | 298\& |
354\& i2d_X509(x, &buf); | 299\& i2d_X509(x, &buf); |
355.Ve 356.PP 357.Vb 1 | 300\& |
358\& /* Other stuff ... */ | 301\& /* Other stuff ... */ |
359.Ve 360.PP 361.Vb 1 | 302\& |
362\& OPENSSL_free(buf); 363.Ve 364.PP 365This code will result in \fBbuf\fR apparently containing garbage because 366it was incremented after the call to point after the data just written. 367Also \fBbuf\fR will no longer contain the pointer allocated by \fB\f(BIOPENSSL_malloc()\fB\fR 368and the subsequent call to \fB\f(BIOPENSSL_free()\fB\fR may well crash. 369.PP 370The auto allocation feature (setting buf to \s-1NULL\s0) only works on OpenSSL 3710.9.7 and later. Attempts to use it on earlier versions will typically 372cause a segmentation violation. 373.PP 374Another trap to avoid is misuse of the \fBxp\fR argument to \fB\f(BId2i_X509()\fB\fR: 375.PP 376.Vb 1 377\& X509 *x; | 303\& OPENSSL_free(buf); 304.Ve 305.PP 306This code will result in \fBbuf\fR apparently containing garbage because 307it was incremented after the call to point after the data just written. 308Also \fBbuf\fR will no longer contain the pointer allocated by \fB\f(BIOPENSSL_malloc()\fB\fR 309and the subsequent call to \fB\f(BIOPENSSL_free()\fB\fR may well crash. 310.PP 311The auto allocation feature (setting buf to \s-1NULL\s0) only works on OpenSSL 3120.9.7 and later. Attempts to use it on earlier versions will typically 313cause a segmentation violation. 314.PP 315Another trap to avoid is misuse of the \fBxp\fR argument to \fB\f(BId2i_X509()\fB\fR: 316.PP 317.Vb 1 318\& X509 *x; |
378.Ve 379.PP 380.Vb 2 | 319\& |
381\& if (!d2i_X509(&x, &p, len)) 382\& /* Some error */ 383.Ve 384.PP 385This will probably crash somewhere in \fB\f(BId2i_X509()\fB\fR. The reason for this 386is that the variable \fBx\fR is uninitialized and an attempt will be made to 387interpret its (invalid) value as an \fBX509\fR structure, typically causing 388a segmentation violation. If \fBx\fR is set to \s-1NULL\s0 first then this will not --- 10 unchanged lines hidden (view full) --- 399then the encoded structure may contain invalid data or omit the 400fields entirely and will not be parsed by \fId2i_X509()\fR. This may be 401fixed in future so code should not assume that \fIi2d_X509()\fR will 402always succeed. 403.SH "RETURN VALUES" 404.IX Header "RETURN VALUES" 405\&\fId2i_X509()\fR, \fId2i_X509_bio()\fR and \fId2i_X509_fp()\fR return a valid \fBX509\fR structure 406or \fB\s-1NULL\s0\fR if an error occurs. The error code that can be obtained by | 320\& if (!d2i_X509(&x, &p, len)) 321\& /* Some error */ 322.Ve 323.PP 324This will probably crash somewhere in \fB\f(BId2i_X509()\fB\fR. The reason for this 325is that the variable \fBx\fR is uninitialized and an attempt will be made to 326interpret its (invalid) value as an \fBX509\fR structure, typically causing 327a segmentation violation. If \fBx\fR is set to \s-1NULL\s0 first then this will not --- 10 unchanged lines hidden (view full) --- 338then the encoded structure may contain invalid data or omit the 339fields entirely and will not be parsed by \fId2i_X509()\fR. This may be 340fixed in future so code should not assume that \fIi2d_X509()\fR will 341always succeed. 342.SH "RETURN VALUES" 343.IX Header "RETURN VALUES" 344\&\fId2i_X509()\fR, \fId2i_X509_bio()\fR and \fId2i_X509_fp()\fR return a valid \fBX509\fR structure 345or \fB\s-1NULL\s0\fR if an error occurs. The error code that can be obtained by |
407\&\fIERR_get_error\fR\|(3). | 346\&\fIERR_get_error\fR\|(3). |
408.PP 409\&\fIi2d_X509()\fR returns the number of bytes successfully encoded or a negative 410value if an error occurs. The error code can be obtained by | 347.PP 348\&\fIi2d_X509()\fR returns the number of bytes successfully encoded or a negative 349value if an error occurs. The error code can be obtained by |
411\&\fIERR_get_error\fR\|(3). | 350\&\fIERR_get_error\fR\|(3). |
412.PP 413\&\fIi2d_X509_bio()\fR and \fIi2d_X509_fp()\fR return 1 for success and 0 if an error | 351.PP 352\&\fIi2d_X509_bio()\fR and \fIi2d_X509_fp()\fR return 1 for success and 0 if an error |
414occurs The error code can be obtained by \fIERR_get_error\fR\|(3). | 353occurs The error code can be obtained by \fIERR_get_error\fR\|(3). |
415.SH "SEE ALSO" 416.IX Header "SEE ALSO" 417\&\fIERR_get_error\fR\|(3) 418.SH "HISTORY" 419.IX Header "HISTORY" 420d2i_X509, i2d_X509, d2i_X509_bio, d2i_X509_fp, i2d_X509_bio and i2d_X509_fp 421are available in all versions of SSLeay and OpenSSL. | 354.SH "SEE ALSO" 355.IX Header "SEE ALSO" 356\&\fIERR_get_error\fR\|(3) 357.SH "HISTORY" 358.IX Header "HISTORY" 359d2i_X509, i2d_X509, d2i_X509_bio, d2i_X509_fp, i2d_X509_bio and i2d_X509_fp 360are available in all versions of SSLeay and OpenSSL. |