]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - secure/lib/libcrypto/man/man7/proxy-certificates.7
OpenSSL: Merge OpenSSL 1.1.1o
[FreeBSD/FreeBSD.git] / secure / lib / libcrypto / man / man7 / proxy-certificates.7
1 .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43)
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
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
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-
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 .    ds C`
42 .    ds C'
43 'br\}
44 .\"
45 .\" Escape single quotes in literal strings from groff's Unicode transform.
46 .ie \n(.g .ds Aq \(aq
47 .el       .ds Aq '
48 .\"
49 .\" If the F register is >0, we'll generate index entries on stderr for
50 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
51 .\" entries marked with X<> in POD.  Of course, you'll have to process the
52 .\" output yourself in some meaningful fashion.
53 .\"
54 .\" Avoid warning from groff about undefined register 'F'.
55 .de IX
56 ..
57 .nr rF 0
58 .if \n(.g .if rF .nr rF 1
59 .if (\n(rF:(\n(.g==0)) \{\
60 .    if \nF \{\
61 .        de IX
62 .        tm Index:\\$1\t\\n%\t"\\$2"
63 ..
64 .        if !\nF==2 \{\
65 .            nr % 0
66 .            nr F 2
67 .        \}
68 .    \}
69 .\}
70 .rr rF
71 .\"
72 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
73 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
74 .    \" fudge factors for nroff and troff
75 .if n \{\
76 .    ds #H 0
77 .    ds #V .8m
78 .    ds #F .3m
79 .    ds #[ \f1
80 .    ds #] \fP
81 .\}
82 .if t \{\
83 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
84 .    ds #V .6m
85 .    ds #F 0
86 .    ds #[ \&
87 .    ds #] \&
88 .\}
89 .    \" simple accents for nroff and troff
90 .if n \{\
91 .    ds ' \&
92 .    ds ` \&
93 .    ds ^ \&
94 .    ds , \&
95 .    ds ~ ~
96 .    ds /
97 .\}
98 .if t \{\
99 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
100 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
101 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
102 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
103 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
104 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
105 .\}
106 .    \" troff and (daisy-wheel) nroff accents
107 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
108 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
109 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
110 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
111 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
112 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
113 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
114 .ds ae a\h'-(\w'a'u*4/10)'e
115 .ds Ae A\h'-(\w'A'u*4/10)'E
116 .    \" corrections for vroff
117 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
118 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
119 .    \" for low resolution devices (crt and lpr)
120 .if \n(.H>23 .if \n(.V>19 \
121 \{\
122 .    ds : e
123 .    ds 8 ss
124 .    ds o a
125 .    ds d- d\h'-1'\(ga
126 .    ds D- D\h'-1'\(hy
127 .    ds th \o'bp'
128 .    ds Th \o'LP'
129 .    ds ae ae
130 .    ds Ae AE
131 .\}
132 .rm #[ #] #H #V #F C
133 .\" ========================================================================
134 .\"
135 .IX Title "PROXY-CERTIFICATES 7"
136 .TH PROXY-CERTIFICATES 7 "2022-05-03" "1.1.1o" "OpenSSL"
137 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
138 .\" way too many mistakes in technical documents.
139 .if n .ad l
140 .nh
141 .SH "NAME"
142 proxy\-certificates \- Proxy certificates in OpenSSL
143 .SH "DESCRIPTION"
144 .IX Header "DESCRIPTION"
145 Proxy certificates are defined in \s-1RFC 3820.\s0  They are used to
146 extend rights to some other entity (a computer process, typically, or
147 sometimes to the user itself).  This allows the entity to perform
148 operations on behalf of the owner of the \s-1EE\s0 (End Entity) certificate.
149 .PP
150 The requirements for a valid proxy certificate are:
151 .IP "\(bu" 4
152 They are issued by an End Entity, either a normal \s-1EE\s0 certificate, or
153 another proxy certificate.
154 .IP "\(bu" 4
155 They must not have the \fBsubjectAltName\fR or \fBissuerAltName\fR
156 extensions.
157 .IP "\(bu" 4
158 They must have the \fBproxyCertInfo\fR extension.
159 .IP "\(bu" 4
160 They must have the subject of their issuer, with one \fBcommonName\fR
161 added.
162 .SS "Enabling proxy certificate verification"
163 .IX Subsection "Enabling proxy certificate verification"
164 OpenSSL expects applications that want to use proxy certificates to be
165 specially aware of them, and make that explicit.  This is done by
166 setting an X509 verification flag:
167 .PP
168 .Vb 1
169 \&    X509_STORE_CTX_set_flags(ctx, X509_V_FLAG_ALLOW_PROXY_CERTS);
170 .Ve
171 .PP
172 or
173 .PP
174 .Vb 1
175 \&    X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_ALLOW_PROXY_CERTS);
176 .Ve
177 .PP
178 See \*(L"\s-1NOTES\*(R"\s0 for a discussion on this requirement.
179 .SS "Creating proxy certificates"
180 .IX Subsection "Creating proxy certificates"
181 Creating proxy certificates can be done using the \fBopenssl\-x509\fR\|(1)
182 command, with some extra extensions:
183 .PP
184 .Vb 3
185 \&    [ v3_proxy ]
186 \&    # A proxy certificate MUST NEVER be a CA certificate.
187 \&    basicConstraints=CA:FALSE
188 \&
189 \&    # Usual authority key ID
190 \&    authorityKeyIdentifier=keyid,issuer:always
191 \&
192 \&    # The extension which marks this certificate as a proxy
193 \&    proxyCertInfo=critical,language:id\-ppl\-anyLanguage,pathlen:1,policy:text:AB
194 .Ve
195 .PP
196 It's also possible to specify the proxy extension in a separate section:
197 .PP
198 .Vb 1
199 \&    proxyCertInfo=critical,@proxy_ext
200 \&
201 \&    [ proxy_ext ]
202 \&    language=id\-ppl\-anyLanguage
203 \&    pathlen=0
204 \&    policy=text:BC
205 .Ve
206 .PP
207 The policy value has a specific syntax, \fIsyntag\fR:\fIstring\fR, where the
208 \&\fIsyntag\fR determines what will be done with the string.  The following
209 \&\fIsyntag\fRs are recognised:
210 .IP "\fBtext\fR" 4
211 .IX Item "text"
212 indicates that the string is a byte sequence, without any encoding:
213 .Sp
214 .Vb 1
215 \&    policy=text:ra\*:ksmo\*:rga\*os
216 .Ve
217 .IP "\fBhex\fR" 4
218 .IX Item "hex"
219 indicates the string is encoded hexadecimal encoded binary data, with
220 colons between each byte (every second hex digit):
221 .Sp
222 .Vb 1
223 \&    policy=hex:72:E4:6B:73:6D:F6:72:67:E5:73
224 .Ve
225 .IP "\fBfile\fR" 4
226 .IX Item "file"
227 indicates that the text of the policy should be taken from a file.
228 The string is then a filename.  This is useful for policies that are
229 large (more than a few lines, e.g. \s-1XML\s0 documents).
230 .PP
231 \&\fI\s-1NOTE:\s0 The proxy policy value is what determines the rights granted
232 to the process during the proxy certificate.  It's up to the
233 application to interpret and combine these policies.\fR
234 .PP
235 With a proxy extension, creating a proxy certificate is a matter of
236 two commands:
237 .PP
238 .Vb 3
239 \&    openssl req \-new \-config proxy.cnf \e
240 \&        \-out proxy.req \-keyout proxy.key \e
241 \&        \-subj "/DC=org/DC=openssl/DC=users/CN=proxy 1"
242 \&
243 \&    openssl x509 \-req \-CAcreateserial \-in proxy.req \-out proxy.crt \e
244 \&        \-CA user.crt \-CAkey user.key \-days 7 \e
245 \&        \-extfile proxy.cnf \-extensions v3_proxy1
246 .Ve
247 .PP
248 You can also create a proxy certificate using another proxy
249 certificate as issuer (note: using a different configuration
250 section for the proxy extensions):
251 .PP
252 .Vb 3
253 \&    openssl req \-new \-config proxy.cnf \e
254 \&        \-out proxy2.req \-keyout proxy2.key \e
255 \&        \-subj "/DC=org/DC=openssl/DC=users/CN=proxy 1/CN=proxy 2"
256 \&
257 \&    openssl x509 \-req \-CAcreateserial \-in proxy2.req \-out proxy2.crt \e
258 \&        \-CA proxy.crt \-CAkey proxy.key \-days 7 \e
259 \&        \-extfile proxy.cnf \-extensions v3_proxy2
260 .Ve
261 .SS "Using proxy certs in applications"
262 .IX Subsection "Using proxy certs in applications"
263 To interpret proxy policies, the application would normally start with
264 some default rights (perhaps none at all), then compute the resulting
265 rights by checking the rights against the chain of proxy certificates,
266 user certificate and \s-1CA\s0 certificates.
267 .PP
268 The complicated part is figuring out how to pass data between your
269 application and the certificate validation procedure.
270 .PP
271 The following ingredients are needed for such processing:
272 .IP "\(bu" 4
273 a callback function that will be called for every certificate being
274 validated.  The callback is called several times for each certificate,
275 so you must be careful to do the proxy policy interpretation at the
276 right time.  You also need to fill in the defaults when the \s-1EE\s0
277 certificate is checked.
278 .IP "\(bu" 4
279 a data structure that is shared between your application code and the
280 callback.
281 .IP "\(bu" 4
282 a wrapper function that sets it all up.
283 .IP "\(bu" 4
284 an ex_data index function that creates an index into the generic
285 ex_data store that is attached to an X509 validation context.
286 .PP
287 The following skeleton code can be used as a starting point:
288 .PP
289 .Vb 4
290 \&    #include <string.h>
291 \&    #include <netdb.h>
292 \&    #include <openssl/x509.h>
293 \&    #include <openssl/x509v3.h>
294 \&
295 \&    #define total_rights 25
296 \&
297 \&    /*
298 \&     * In this example, I will use a view of granted rights as a bit
299 \&     * array, one bit for each possible right.
300 \&     */
301 \&    typedef struct your_rights {
302 \&        unsigned char rights[(total_rights + 7) / 8];
303 \&    } YOUR_RIGHTS;
304 \&
305 \&    /*
306 \&     * The following procedure will create an index for the ex_data
307 \&     * store in the X509 validation context the first time it\*(Aqs
308 \&     * called.  Subsequent calls will return the same index.
309 \&     */
310 \&    static int get_proxy_auth_ex_data_idx(X509_STORE_CTX *ctx)
311 \&    {
312 \&        static volatile int idx = \-1;
313 \&
314 \&        if (idx < 0) {
315 \&            X509_STORE_lock(X509_STORE_CTX_get0_store(ctx));
316 \&            if (idx < 0) {
317 \&                idx = X509_STORE_CTX_get_ex_new_index(0,
318 \&                                                      "for verify callback",
319 \&                                                      NULL,NULL,NULL);
320 \&            }
321 \&            X509_STORE_unlock(X509_STORE_CTX_get0_store(ctx));
322 \&        }
323 \&        return idx;
324 \&    }
325 \&
326 \&    /* Callback to be given to the X509 validation procedure.  */
327 \&    static int verify_callback(int ok, X509_STORE_CTX *ctx)
328 \&    {
329 \&        if (ok == 1) {
330 \&            /*
331 \&             * It\*(Aqs REALLY important you keep the proxy policy check
332 \&             * within this section.  It\*(Aqs important to know that when
333 \&             * ok is 1, the certificates are checked from top to
334 \&             * bottom.  You get the CA root first, followed by the
335 \&             * possible chain of intermediate CAs, followed by the EE
336 \&             * certificate, followed by the possible proxy
337 \&             * certificates. 
338 \&             */
339 \&            X509 *xs = X509_STORE_CTX_get_current_cert(ctx);
340 \&
341 \&            if (X509_get_extension_flags(xs) & EXFLAG_PROXY) {
342 \&                YOUR_RIGHTS *rights =
343 \&                    (YOUR_RIGHTS *)X509_STORE_CTX_get_ex_data(ctx,
344 \&                        get_proxy_auth_ex_data_idx(ctx));
345 \&                PROXY_CERT_INFO_EXTENSION *pci =
346 \&                    X509_get_ext_d2i(xs, NID_proxyCertInfo, NULL, NULL);
347 \&
348 \&                switch (OBJ_obj2nid(pci\->proxyPolicy\->policyLanguage)) {
349 \&                case NID_Independent:
350 \&                    /*
351 \&                     * Do whatever you need to grant explicit rights
352 \&                     * to this particular proxy certificate, usually
353 \&                     * by pulling them from some database.  If there
354 \&                     * are none to be found, clear all rights (making
355 \&                     * this and any subsequent proxy certificate void
356 \&                     * of any rights). 
357 \&                     */
358 \&                    memset(rights\->rights, 0, sizeof(rights\->rights));
359 \&                    break;
360 \&                case NID_id_ppl_inheritAll:
361 \&                    /*
362 \&                     * This is basically a NOP, we simply let the
363 \&                     * current rights stand as they are.
364 \&                     */
365 \&                    break;
366 \&                default:
367 \&                    /*
368 \&                     * This is usually the most complex section of
369 \&                     * code.  You really do whatever you want as long
370 \&                     * as you follow RFC 3820.  In the example we use
371 \&                     * here, the simplest thing to do is to build
372 \&                     * another, temporary bit array and fill it with
373 \&                     * the rights granted by the current proxy
374 \&                     * certificate, then use it as a mask on the
375 \&                     * accumulated rights bit array, and voila\*`, you
376 \&                     * now have a new accumulated rights bit array.
377 \&                     */
378 \&                    {
379 \&                        int i;
380 \&                        YOUR_RIGHTS tmp_rights;
381 \&                        memset(tmp_rights.rights, 0,
382 \&                               sizeof(tmp_rights.rights));
383 \&
384 \&                        /*
385 \&                         * process_rights() is supposed to be a
386 \&                         * procedure that takes a string and its
387 \&                         * length, interprets it and sets the bits
388 \&                         * in the YOUR_RIGHTS pointed at by the
389 \&                         * third argument.
390 \&                         */
391 \&                        process_rights((char *) pci\->proxyPolicy\->policy\->data,
392 \&                                       pci\->proxyPolicy\->policy\->length,
393 \&                                       &tmp_rights);
394 \&
395 \&                        for(i = 0; i < total_rights / 8; i++)
396 \&                            rights\->rights[i] &= tmp_rights.rights[i];
397 \&                    }
398 \&                    break;
399 \&                }
400 \&                PROXY_CERT_INFO_EXTENSION_free(pci);
401 \&            } else if (!(X509_get_extension_flags(xs) & EXFLAG_CA)) {
402 \&                /* We have an EE certificate, let\*(Aqs use it to set default! */
403 \&                YOUR_RIGHTS *rights =
404 \&                    (YOUR_RIGHTS *)X509_STORE_CTX_get_ex_data(ctx,
405 \&                        get_proxy_auth_ex_data_idx(ctx));
406 \&
407 \&                /*
408 \&                 * The following procedure finds out what rights the
409 \&                 * owner of the current certificate has, and sets them
410 \&                 * in the YOUR_RIGHTS structure pointed at by the
411 \&                 * second argument.
412 \&                 */
413 \&                set_default_rights(xs, rights);
414 \&            }
415 \&        }
416 \&        return ok;
417 \&    }
418 \&
419 \&    static int my_X509_verify_cert(X509_STORE_CTX *ctx,
420 \&                                   YOUR_RIGHTS *needed_rights)
421 \&    {
422 \&        int ok;
423 \&        int (*save_verify_cb)(int ok,X509_STORE_CTX *ctx) =
424 \&            X509_STORE_CTX_get_verify_cb(ctx);
425 \&        YOUR_RIGHTS rights;
426 \&
427 \&        X509_STORE_CTX_set_verify_cb(ctx, verify_callback);
428 \&        X509_STORE_CTX_set_ex_data(ctx, get_proxy_auth_ex_data_idx(ctx),
429 \&                                   &rights);
430 \&        X509_STORE_CTX_set_flags(ctx, X509_V_FLAG_ALLOW_PROXY_CERTS);
431 \&        ok = X509_verify_cert(ctx);
432 \&
433 \&        if (ok == 1) {
434 \&            ok = check_needed_rights(rights, needed_rights);
435 \&        }
436 \&
437 \&        X509_STORE_CTX_set_verify_cb(ctx, save_verify_cb);
438 \&
439 \&        return ok;
440 \&    }
441 .Ve
442 .PP
443 If you use \s-1SSL\s0 or \s-1TLS,\s0 you can easily set up a callback to have the
444 certificates checked properly, using the code above:
445 .PP
446 .Vb 2
447 \&    SSL_CTX_set_cert_verify_callback(s_ctx, my_X509_verify_cert,
448 \&                                     &needed_rights);
449 .Ve
450 .SH "NOTES"
451 .IX Header "NOTES"
452 To this date, it seems that proxy certificates have only been used in
453 environments that are aware of them, and no one seems to have
454 investigated how they can be used or misused outside of such an
455 environment.
456 .PP
457 For that reason, OpenSSL requires that applications aware of proxy
458 certificates must also make that explicit.
459 .PP
460 \&\fBsubjectAltName\fR and \fBissuerAltName\fR are forbidden in proxy
461 certificates, and this is enforced in OpenSSL.  The subject must be
462 the same as the issuer, with one commonName added on.
463 .SH "SEE ALSO"
464 .IX Header "SEE ALSO"
465 \&\fBX509_STORE_CTX_set_flags\fR\|(3),
466 \&\fBX509_STORE_CTX_set_verify_cb\fR\|(3),
467 \&\fBX509_VERIFY_PARAM_set_flags\fR\|(3),
468 \&\fBSSL_CTX_set_cert_verify_callback\fR\|(3),
469 \&\fBopenssl\-req\fR\|(1), \fBopenssl\-x509\fR\|(1),
470 \&\s-1RFC 3820\s0 <https://tools.ietf.org/html/rfc3820>
471 .SH "COPYRIGHT"
472 .IX Header "COPYRIGHT"
473 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
474 .PP
475 Licensed under the Apache License 2.0 (the \*(L"License\*(R").  You may not use
476 this file except in compliance with the License.  You can obtain a copy
477 in the file \s-1LICENSE\s0 in the source distribution or at
478 <https://www.openssl.org/source/license.html>.