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

NOTES

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

SEE ALSO

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