summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschwarze <>2020-05-24 12:37:30 +0000
committerschwarze <>2020-05-24 12:37:30 +0000
commit3897abf3f7fbae4cfd94912a4a3ccdcbbfe8470a (patch)
tree8698d6c7b03954fcc8dd1a11b74381f4e02b8d67
parent8f3ed8b4747c31e8aafe844575024d46e2d682fa (diff)
downloadopenbsd-3897abf3f7fbae4cfd94912a4a3ccdcbbfe8470a.tar.gz
openbsd-3897abf3f7fbae4cfd94912a4a3ccdcbbfe8470a.tar.bz2
openbsd-3897abf3f7fbae4cfd94912a4a3ccdcbbfe8470a.zip
Minimally document PKCS7_dataInit(3).
No comment when shown around among LibreSSL devs except "very very strange function" from beck@ and "cannot say much about it" from tb@. If needed, this can be further polished in the tree, review is still welcome.
-rw-r--r--src/lib/libcrypto/man/Makefile3
-rw-r--r--src/lib/libcrypto/man/PKCS7_dataInit.3207
-rw-r--r--src/lib/libcrypto/man/PKCS7_new.35
-rw-r--r--src/lib/libcrypto/man/PKCS7_set_content.35
4 files changed, 215 insertions, 5 deletions
diff --git a/src/lib/libcrypto/man/Makefile b/src/lib/libcrypto/man/Makefile
index 1394012e9c..5468ba9869 100644
--- a/src/lib/libcrypto/man/Makefile
+++ b/src/lib/libcrypto/man/Makefile
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile,v 1.162 2020/05/20 11:40:26 schwarze Exp $ 1# $OpenBSD: Makefile,v 1.163 2020/05/24 12:37:30 schwarze Exp $
2 2
3.include <bsd.own.mk> 3.include <bsd.own.mk>
4 4
@@ -214,6 +214,7 @@ MAN= \
214 PKCS12_parse.3 \ 214 PKCS12_parse.3 \
215 PKCS12_SAFEBAG_new.3 \ 215 PKCS12_SAFEBAG_new.3 \
216 PKCS5_PBKDF2_HMAC.3 \ 216 PKCS5_PBKDF2_HMAC.3 \
217 PKCS7_dataInit.3 \
217 PKCS7_decrypt.3 \ 218 PKCS7_decrypt.3 \
218 PKCS7_encrypt.3 \ 219 PKCS7_encrypt.3 \
219 PKCS7_new.3 \ 220 PKCS7_new.3 \
diff --git a/src/lib/libcrypto/man/PKCS7_dataInit.3 b/src/lib/libcrypto/man/PKCS7_dataInit.3
new file mode 100644
index 0000000000..53090ff960
--- /dev/null
+++ b/src/lib/libcrypto/man/PKCS7_dataInit.3
@@ -0,0 +1,207 @@
1.\" $OpenBSD: PKCS7_dataInit.3,v 1.1 2020/05/24 12:37:30 schwarze Exp $
2.\"
3.\" Copyright (c) 2020 Ingo Schwarze <schwarze@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: May 24 2020 $
18.Dt PKCS7_DATAINIT 3
19.Os
20.Sh NAME
21.Nm PKCS7_dataInit
22.Nd construct a BIO chain for adding or retrieving content
23.Sh SYNOPSIS
24.In openssl/pkcs7.h
25.Ft BIO *
26.Fo PKCS7_dataInit
27.Fa "PKCS7 *p7"
28.Fa "BIO *indata"
29.Fc
30.Sh DESCRIPTION
31.Fn PKCS7_dataInit
32constructs a BIO chain in preparation for putting data into
33or retrieving data out of
34.Fa p7 .
35Depending on the
36.Fa contentType
37of
38.Fa p7 ,
39the created chain starts with:
40.Bl -tag -width Ds
41.It for Vt SignedData :
42one or more
43.Xr BIO_f_md 3
44message digest filters
45.It for Vt EnvelopedData :
46one
47.Xr BIO_f_cipher 3
48encryption filter
49.It for Vt SignedAndEnvelopedData :
50one or more
51.Xr BIO_f_md 3
52message digest filters followed by one
53.Xr BIO_f_cipher 3
54encryption filter
55.It for Vt DigestedData :
56one
57.Xr BIO_f_md 3
58message digest filter
59.It for arbitrary data :
60no filter BIO
61.El
62.Pp
63One additional BIO is appended to the end of the chain,
64depending on the first condition that holds in the following list:
65.Bl -tag -width Ds
66.It Fa indata
67if the
68.Fa indata
69argument is not
70.Dv NULL .
71This only makes sense while verifying a detached signature, in which case
72.Fa indata
73is expected to supply the content associated with the detached signature.
74.It Xr BIO_s_null 3
75if the
76.Fa contentType
77of
78.Fa p7
79is
80.Vt SignedData
81and it is configured to contain a detached signature.
82This only makes sense while creating the detached signature.
83.It Xr BIO_new_mem_buf 3
84when reading from a
85.Vt SignedData
86or
87.Vt DigestedData
88object.
89.Fn PKCS7_dataInit
90attaches the end of the chain to the nested content of
91.Fa p7 .
92.It Xr BIO_s_mem 3
93otherwise.
94This is the most common case while writing data to
95.Fa p7 .
96.Xr PKCS7_dataFinal 3
97can later be used to transfer the data from the memory BIO into
98.Fa p7 .
99.El
100.Ss Adding content
101Before calling
102.Fn PKCS7_dataInit
103in order to add content,
104.Xr PKCS7_new 3 ,
105.Xr PKCS7_set_type 3 ,
106and
107.Xr PKCS7_content_new 3
108are typically required to create
109.Fa p7 ,
110to choose its desired type, and to allocate the nested
111.Vt ContentInfo
112structure.
113.Pp
114After calling
115.Fn PKCS7_dataInit ,
116the desired data can be written into the returned
117.Vt BIO ,
118.Xr BIO_flush 3
119can be called on it,
120.Xr PKCS7_dataFinal 3
121can be used to transfer the processed data
122from the returned memory BIO to the
123.Fa p7
124structure, and the chain can finally be destroyed with
125.Xr BIO_free_all 3 .
126.Pp
127While
128.Fn PKCS7_dataInit
129does support the
130.Vt EnvelopedData
131and
132.Vt SignedAndEnvelopedData
133types, using it for these types is awkward and error prone because
134.Xr PKCS7_content_new 3
135does not support these two types.
136So in addition to creating
137.Fa p7
138itself and setting its type, the nested
139.Fa ContentInfo
140structure also needs to be constructed with
141.Xr PKCS7_new 3
142and
143.Xr PKCS7_set_type 3
144and manually inserted into the correct field
145of the respective sub-structure of
146.Fa p7 .
147.Ss Retrieving content
148.Fn PKCS7_dataInit
149can also be called on a fully populated object of type
150.Vt SignedData
151or
152.Vt DigestedData .
153After that,
154.Xr BIO_read 3
155can be used to retrieve data from it.
156In this use case, do not call
157.Xr PKCS7_dataFinal 3 ;
158simply proceed directly to
159.Xr BIO_free_all 3
160after reading the data.
161.Sh RETURN VALUES
162.Fn PKCS7_dataInit
163returns a BIO chain on success or
164.Dv NULL
165on failure.
166It fails if
167.Fa p7
168is
169.Dv NULL ,
170if the
171.Fa content
172field of
173.Fa p7
174is empty, if the
175.Fa contentType
176of
177.Fa p7
178is unsupported, if a cipher is required but none is configured, or
179if any required operation fails, for example due to lack of memory
180or for various other reasons.
181.Sh SEE ALSO
182.Xr BIO_new 3 ,
183.Xr BIO_read 3 ,
184.Xr PKCS7_content_new 3 ,
185.Xr PKCS7_dataFinal 3 ,
186.Xr PKCS7_new 3 ,
187.Xr PKCS7_set_type 3 ,
188.Xr PKCS7_sign 3
189.Sh HISTORY
190.Fn PKCS7_dataInit
191first appeared in SSLeay 0.8.1 and has been available since
192.Ox 2.4 .
193.Sh CAVEATS
194This function does not support
195.Vt EncryptedData .
196.Sh BUGS
197If
198.Fa p7
199is a fully populated structure containing
200.Vt EnvelopedData ,
201.Vt SignedAndEnvelopedData ,
202or arbitrary data,
203.Fn PKCS7_dataInit
204returns a BIO chain that ultimately reads from an empty memory BIO,
205so reading from it will instantly return an end-of-file indication
206rather than reading the actual data contained in
207.Fa p7 .
diff --git a/src/lib/libcrypto/man/PKCS7_new.3 b/src/lib/libcrypto/man/PKCS7_new.3
index 56a8b566ba..c0943e021a 100644
--- a/src/lib/libcrypto/man/PKCS7_new.3
+++ b/src/lib/libcrypto/man/PKCS7_new.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: PKCS7_new.3,v 1.8 2020/05/20 11:40:26 schwarze Exp $ 1.\" $OpenBSD: PKCS7_new.3,v 1.9 2020/05/24 12:37:30 schwarze Exp $
2.\" 2.\"
3.\" Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org> 3.\" Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
4.\" 4.\"
@@ -14,7 +14,7 @@
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\" 16.\"
17.Dd $Mdocdate: May 20 2020 $ 17.Dd $Mdocdate: May 24 2020 $
18.Dt PKCS7_NEW 3 18.Dt PKCS7_NEW 3
19.Os 19.Os
20.Sh NAME 20.Sh NAME
@@ -246,6 +246,7 @@ frees
246.Xr i2d_PKCS7_bio_stream 3 , 246.Xr i2d_PKCS7_bio_stream 3 ,
247.Xr PEM_read_PKCS7 3 , 247.Xr PEM_read_PKCS7 3 ,
248.Xr PEM_write_bio_PKCS7_stream 3 , 248.Xr PEM_write_bio_PKCS7_stream 3 ,
249.Xr PKCS7_dataInit 3 ,
249.Xr PKCS7_decrypt 3 , 250.Xr PKCS7_decrypt 3 ,
250.Xr PKCS7_encrypt 3 , 251.Xr PKCS7_encrypt 3 ,
251.Xr PKCS7_ISSUER_AND_SERIAL_digest 3 , 252.Xr PKCS7_ISSUER_AND_SERIAL_digest 3 ,
diff --git a/src/lib/libcrypto/man/PKCS7_set_content.3 b/src/lib/libcrypto/man/PKCS7_set_content.3
index 1f77a8042b..fa057341d5 100644
--- a/src/lib/libcrypto/man/PKCS7_set_content.3
+++ b/src/lib/libcrypto/man/PKCS7_set_content.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: PKCS7_set_content.3,v 1.1 2020/05/20 11:40:26 schwarze Exp $ 1.\" $OpenBSD: PKCS7_set_content.3,v 1.2 2020/05/24 12:37:30 schwarze Exp $
2.\" 2.\"
3.\" Copyright (c) 2020 Ingo Schwarze <schwarze@openbsd.org> 3.\" Copyright (c) 2020 Ingo Schwarze <schwarze@openbsd.org>
4.\" 4.\"
@@ -14,7 +14,7 @@
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\" 16.\"
17.Dd $Mdocdate: May 20 2020 $ 17.Dd $Mdocdate: May 24 2020 $
18.Dt PKCS7_SET_CONTENT 3 18.Dt PKCS7_SET_CONTENT 3
19.Os 19.Os
20.Sh NAME 20.Sh NAME
@@ -89,6 +89,7 @@ In case of failure,
89.Fa outer 89.Fa outer
90remains unchanged. 90remains unchanged.
91.Sh SEE ALSO 91.Sh SEE ALSO
92.Xr PKCS7_dataInit 3 ,
92.Xr PKCS7_new 3 , 93.Xr PKCS7_new 3 ,
93.Xr PKCS7_set_type 3 , 94.Xr PKCS7_set_type 3 ,
94.Xr PKCS7_sign 3 95.Xr PKCS7_sign 3