1PROXY-CERTIFICATES(7ossl)           OpenSSL          PROXY-CERTIFICATES(7ossl)
2
3
4

NAME

6       proxy-certificates - Proxy certificates in OpenSSL
7

DESCRIPTION

9       Proxy certificates are defined in RFC 3820.  They are used to extend
10       rights to some other entity (a computer process, typically, or
11       sometimes to the user itself).  This allows the entity to perform
12       operations on behalf of the owner of the EE (End Entity) certificate.
13
14       The requirements for a valid proxy certificate are:
15
16       •   They are issued by an End Entity, either a normal EE certificate,
17           or another proxy certificate.
18
19       •   They must not have the subjectAltName or issuerAltName extensions.
20
21       •   They must have the proxyCertInfo extension.
22
23       •   They must have the subject of their issuer, with one commonName
24           added.
25
26   Enabling proxy certificate verification
27       OpenSSL expects applications that want to use proxy certificates to be
28       specially aware of them, and make that explicit.  This is done by
29       setting an X509 verification flag:
30
31           X509_STORE_CTX_set_flags(ctx, X509_V_FLAG_ALLOW_PROXY_CERTS);
32
33       or
34
35           X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_ALLOW_PROXY_CERTS);
36
37       See "NOTES" for a discussion on this requirement.
38
39   Creating proxy certificates
40       Creating proxy certificates can be done using the openssl-x509(1)
41       command, with some extra extensions:
42
43           [ proxy ]
44           # A proxy certificate MUST NEVER be a CA certificate.
45           basicConstraints = CA:FALSE
46           # Usual authority key ID
47           authorityKeyIdentifier = keyid,issuer:always
48           # The extension which marks this certificate as a proxy
49           proxyCertInfo = critical,language:id-ppl-anyLanguage,pathlen:1,policy:text:AB
50
51       It's also possible to specify the proxy extension in a separate
52       section:
53
54           proxyCertInfo = critical,@proxy_ext
55
56           [ proxy_ext ]
57           language = id-ppl-anyLanguage
58           pathlen = 0
59           policy = text:BC
60
61       The policy value has a specific syntax, syntag:string, where the syntag
62       determines what will be done with the string.  The following syntags
63       are recognised:
64
65       text
66           indicates that the string is a byte sequence, without any encoding:
67
68               policy=text:räksmörgås
69
70       hex indicates the string is encoded hexadecimal encoded binary data,
71           with colons between each byte (every second hex digit):
72
73               policy=hex:72:E4:6B:73:6D:F6:72:67:E5:73
74
75       file
76           indicates that the text of the policy should be taken from a file.
77           The string is then a filename.  This is useful for policies that
78           are more than a few lines, such as XML or other markup.
79
80       Note that the proxy policy value is what determines the rights granted
81       to the process during the proxy certificate, and it is up to the
82       application to interpret and combine these policies.>
83
84       With a proxy extension, creating a proxy certificate is a matter of two
85       commands:
86
87           openssl req -new -config proxy.cnf \
88               -out proxy.req -keyout proxy.key \
89               -subj "/DC=org/DC=openssl/DC=users/CN=proxy"
90
91           openssl x509 -req -CAcreateserial -in proxy.req -out proxy.crt \
92               -CA user.crt -CAkey user.key -days 7 \
93               -extfile proxy.cnf -extensions proxy
94
95       You can also create a proxy certificate using another proxy certificate
96       as issuer. Note that this example uses a different configuration
97       section for the proxy extensions:
98
99           openssl req -new -config proxy.cnf \
100               -out proxy2.req -keyout proxy2.key \
101               -subj "/DC=org/DC=openssl/DC=users/CN=proxy/CN=proxy 2"
102
103           openssl x509 -req -CAcreateserial -in proxy2.req -out proxy2.crt \
104               -CA proxy.crt -CAkey proxy.key -days 7 \
105               -extfile proxy.cnf -extensions proxy_2
106
107   Using proxy certs in applications
108       To interpret proxy policies, the application would normally start with
109       some default rights (perhaps none at all), then compute the resulting
110       rights by checking the rights against the chain of proxy certificates,
111       user certificate and CA certificates.
112
113       The complicated part is figuring out how to pass data between your
114       application and the certificate validation procedure.
115
116       The following ingredients are needed for such processing:
117
118       •   a callback function that will be called for every certificate being
119           validated.  The callback is called several times for each
120           certificate, so you must be careful to do the proxy policy
121           interpretation at the right time.  You also need to fill in the
122           defaults when the EE certificate is checked.
123
124       •   a data structure that is shared between your application code and
125           the callback.
126
127       •   a wrapper function that sets it all up.
128
129       •   an ex_data index function that creates an index into the generic
130           ex_data store that is attached to an X509 validation context.
131
132       The following skeleton code can be used as a starting point:
133
134           #include <string.h>
135           #include <netdb.h>
136           #include <openssl/x509.h>
137           #include <openssl/x509v3.h>
138
139           #define total_rights 25
140
141           /*
142            * In this example, I will use a view of granted rights as a bit
143            * array, one bit for each possible right.
144            */
145           typedef struct your_rights {
146               unsigned char rights[(total_rights + 7) / 8];
147           } YOUR_RIGHTS;
148
149           /*
150            * The following procedure will create an index for the ex_data
151            * store in the X509 validation context the first time it's
152            * called.  Subsequent calls will return the same index.
153            */
154           static int get_proxy_auth_ex_data_idx(X509_STORE_CTX *ctx)
155           {
156               static volatile int idx = -1;
157
158               if (idx < 0) {
159                   X509_STORE_lock(X509_STORE_CTX_get0_store(ctx));
160                   if (idx < 0) {
161                       idx = X509_STORE_CTX_get_ex_new_index(0,
162                                                             "for verify callback",
163                                                             NULL,NULL,NULL);
164                   }
165                   X509_STORE_unlock(X509_STORE_CTX_get0_store(ctx));
166               }
167               return idx;
168           }
169
170           /* Callback to be given to the X509 validation procedure.  */
171           static int verify_callback(int ok, X509_STORE_CTX *ctx)
172           {
173               if (ok == 1) {
174                   /*
175                    * It's REALLY important you keep the proxy policy check
176                    * within this section.  It's important to know that when
177                    * ok is 1, the certificates are checked from top to
178                    * bottom.  You get the CA root first, followed by the
179                    * possible chain of intermediate CAs, followed by the EE
180                    * certificate, followed by the possible proxy
181                    * certificates.
182                    */
183                   X509 *xs = X509_STORE_CTX_get_current_cert(ctx);
184
185                   if (X509_get_extension_flags(xs) & EXFLAG_PROXY) {
186                       YOUR_RIGHTS *rights =
187                           (YOUR_RIGHTS *)X509_STORE_CTX_get_ex_data(ctx,
188                               get_proxy_auth_ex_data_idx(ctx));
189                       PROXY_CERT_INFO_EXTENSION *pci =
190                           X509_get_ext_d2i(xs, NID_proxyCertInfo, NULL, NULL);
191
192                       switch (OBJ_obj2nid(pci->proxyPolicy->policyLanguage)) {
193                       case NID_Independent:
194                           /*
195                            * Do whatever you need to grant explicit rights
196                            * to this particular proxy certificate, usually
197                            * by pulling them from some database.  If there
198                            * are none to be found, clear all rights (making
199                            * this and any subsequent proxy certificate void
200                            * of any rights).
201                            */
202                           memset(rights->rights, 0, sizeof(rights->rights));
203                           break;
204                       case NID_id_ppl_inheritAll:
205                           /*
206                            * This is basically a NOP, we simply let the
207                            * current rights stand as they are.
208                            */
209                           break;
210                       default:
211                           /*
212                            * This is usually the most complex section of
213                            * code.  You really do whatever you want as long
214                            * as you follow RFC 3820.  In the example we use
215                            * here, the simplest thing to do is to build
216                            * another, temporary bit array and fill it with
217                            * the rights granted by the current proxy
218                            * certificate, then use it as a mask on the
219                            * accumulated rights bit array, and voilà, you
220                            * now have a new accumulated rights bit array.
221                            */
222                           {
223                               int i;
224                               YOUR_RIGHTS tmp_rights;
225                               memset(tmp_rights.rights, 0,
226                                      sizeof(tmp_rights.rights));
227
228                               /*
229                                * process_rights() is supposed to be a
230                                * procedure that takes a string and its
231                                * length, interprets it and sets the bits
232                                * in the YOUR_RIGHTS pointed at by the
233                                * third argument.
234                                */
235                               process_rights((char *) pci->proxyPolicy->policy->data,
236                                              pci->proxyPolicy->policy->length,
237                                              &tmp_rights);
238
239                               for(i = 0; i < total_rights / 8; i++)
240                                   rights->rights[i] &= tmp_rights.rights[i];
241                           }
242                           break;
243                       }
244                       PROXY_CERT_INFO_EXTENSION_free(pci);
245                   } else if (!(X509_get_extension_flags(xs) & EXFLAG_CA)) {
246                       /* We have an EE certificate, let's use it to set default! */
247                       YOUR_RIGHTS *rights =
248                           (YOUR_RIGHTS *)X509_STORE_CTX_get_ex_data(ctx,
249                               get_proxy_auth_ex_data_idx(ctx));
250
251                       /*
252                        * The following procedure finds out what rights the
253                        * owner of the current certificate has, and sets them
254                        * in the YOUR_RIGHTS structure pointed at by the
255                        * second argument.
256                        */
257                       set_default_rights(xs, rights);
258                   }
259               }
260               return ok;
261           }
262
263           static int my_X509_verify_cert(X509_STORE_CTX *ctx,
264                                          YOUR_RIGHTS *needed_rights)
265           {
266               int ok;
267               int (*save_verify_cb)(int ok,X509_STORE_CTX *ctx) =
268                   X509_STORE_CTX_get_verify_cb(ctx);
269               YOUR_RIGHTS rights;
270
271               X509_STORE_CTX_set_verify_cb(ctx, verify_callback);
272               X509_STORE_CTX_set_ex_data(ctx, get_proxy_auth_ex_data_idx(ctx),
273                                          &rights);
274               X509_STORE_CTX_set_flags(ctx, X509_V_FLAG_ALLOW_PROXY_CERTS);
275               ok = X509_verify_cert(ctx);
276
277               if (ok == 1) {
278                   ok = check_needed_rights(rights, needed_rights);
279               }
280
281               X509_STORE_CTX_set_verify_cb(ctx, save_verify_cb);
282
283               return ok;
284           }
285
286       If you use SSL or TLS, you can easily set up a callback to have the
287       certificates checked properly, using the code above:
288
289           SSL_CTX_set_cert_verify_callback(s_ctx, my_X509_verify_cert,
290                                            &needed_rights);
291

NOTES

293       To this date, it seems that proxy certificates have only been used in
294       environments that are aware of them, and no one seems to have
295       investigated how they can be used or misused outside of such an
296       environment.
297
298       For that reason, OpenSSL requires that applications aware of proxy
299       certificates must also make that explicit.
300
301       subjectAltName and issuerAltName are forbidden in proxy certificates,
302       and this is enforced in OpenSSL.  The subject must be the same as the
303       issuer, with one commonName added on.
304

SEE ALSO

306       X509_STORE_CTX_set_flags(3), X509_STORE_CTX_set_verify_cb(3),
307       X509_VERIFY_PARAM_set_flags(3), SSL_CTX_set_cert_verify_callback(3),
308       openssl-req(1), openssl-x509(1), RFC 3820
309       <https://tools.ietf.org/html/rfc3820>
310
312       Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
313
314       Licensed under the Apache License 2.0 (the "License").  You may not use
315       this file except in compliance with the License.  You can obtain a copy
316       in the file LICENSE in the source distribution or at
317       <https://www.openssl.org/source/license.html>.
318
319
320
3213.1.1                             2023-08-31         PROXY-CERTIFICATES(7ossl)
Impressum