7 proxy-certificates - Proxy certificates in OpenSSL
11 Proxy certificates are defined in RFC 3820. They are used to
12 extend rights to some other entity (a computer process, typically, or
13 sometimes to the user itself). This allows the entity to perform
14 operations on behalf of the owner of the EE (End Entity) certificate.
16 The requirements for a valid proxy certificate are:
22 They are issued by an End Entity, either a normal EE certificate, or
23 another proxy certificate.
27 They must not have the B<subjectAltName> or B<issuerAltName>
32 They must have the B<proxyCertInfo> extension.
36 They must have the subject of their issuer, with one B<commonName>
41 =head2 Enabling proxy certificate verification
43 OpenSSL expects applications that want to use proxy certificates to be
44 specially aware of them, and make that explicit. This is done by
45 setting an X509 verification flag:
47 X509_STORE_CTX_set_flags(ctx, X509_V_FLAG_ALLOW_PROXY_CERTS);
51 X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_ALLOW_PROXY_CERTS);
53 See L</NOTES> for a discussion on this requirement.
55 =head2 Creating proxy certificates
57 Creating proxy certificates can be done using the L<openssl-x509(1)>
58 command, with some extra extensions:
61 # A proxy certificate MUST NEVER be a CA certificate.
62 basicConstraints=CA:FALSE
64 # Usual authority key ID
65 authorityKeyIdentifier=keyid,issuer:always
67 # The extension which marks this certificate as a proxy
68 proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:1,policy:text:AB
70 It's also possible to specify the proxy extension in a separate section:
72 proxyCertInfo=critical,@proxy_ext
75 language=id-ppl-anyLanguage
79 The policy value has a specific syntax, I<syntag>:I<string>, where the
80 I<syntag> determines what will be done with the string. The following
81 I<syntag>s are recognised:
87 indicates that the string is a byte sequence, without any encoding:
89 policy=text:räksmörgås
93 indicates the string is encoded hexadecimal encoded binary data, with
94 colons between each byte (every second hex digit):
96 policy=hex:72:E4:6B:73:6D:F6:72:67:E5:73
100 indicates that the text of the policy should be taken from a file.
101 The string is then a filename. This is useful for policies that are
102 large (more than a few lines, e.g. XML documents).
106 I<NOTE: The proxy policy value is what determines the rights granted
107 to the process during the proxy certificate. It's up to the
108 application to interpret and combine these policies.>
110 With a proxy extension, creating a proxy certificate is a matter of
113 openssl req -new -config proxy.cnf \
114 -out proxy.req -keyout proxy.key \
115 -subj "/DC=org/DC=openssl/DC=users/CN=proxy 1"
117 openssl x509 -req -CAcreateserial -in proxy.req -out proxy.crt \
118 -CA user.crt -CAkey user.key -days 7 \
119 -extfile proxy.cnf -extensions proxy
121 You can also create a proxy certificate using another proxy
122 certificate as issuer (note: using a different configuration
123 section for the proxy extensions):
125 openssl req -new -config proxy.cnf \
126 -out proxy2.req -keyout proxy2.key \
127 -subj "/DC=org/DC=openssl/DC=users/CN=proxy 1/CN=proxy 2"
129 openssl x509 -req -CAcreateserial -in proxy2.req -out proxy2.crt \
130 -CA proxy.crt -CAkey proxy.key -days 7 \
131 -extfile proxy.cnf -extensions proxy_2
133 =head2 Using proxy certs in applications
135 To interpret proxy policies, the application would normally start with
136 some default rights (perhaps none at all), then compute the resulting
137 rights by checking the rights against the chain of proxy certificates,
138 user certificate and CA certificates.
140 The complicated part is figuring out how to pass data between your
141 application and the certificate validation procedure.
143 The following ingredients are needed for such processing:
149 a callback function that will be called for every certificate being
150 validated. The callback is called several times for each certificate,
151 so you must be careful to do the proxy policy interpretation at the
152 right time. You also need to fill in the defaults when the EE
153 certificate is checked.
157 a data structure that is shared between your application code and the
162 a wrapper function that sets it all up.
166 an ex_data index function that creates an index into the generic
167 ex_data store that is attached to an X509 validation context.
171 The following skeleton code can be used as a starting point:
175 #include <openssl/x509.h>
176 #include <openssl/x509v3.h>
178 #define total_rights 25
181 * In this example, I will use a view of granted rights as a bit
182 * array, one bit for each possible right.
184 typedef struct your_rights {
185 unsigned char rights[(total_rights + 7) / 8];
189 * The following procedure will create an index for the ex_data
190 * store in the X509 validation context the first time it's
191 * called. Subsequent calls will return the same index.
193 static int get_proxy_auth_ex_data_idx(X509_STORE_CTX *ctx)
195 static volatile int idx = -1;
198 X509_STORE_lock(X509_STORE_CTX_get0_store(ctx));
200 idx = X509_STORE_CTX_get_ex_new_index(0,
201 "for verify callback",
204 X509_STORE_unlock(X509_STORE_CTX_get0_store(ctx));
209 /* Callback to be given to the X509 validation procedure. */
210 static int verify_callback(int ok, X509_STORE_CTX *ctx)
214 * It's REALLY important you keep the proxy policy check
215 * within this section. It's important to know that when
216 * ok is 1, the certificates are checked from top to
217 * bottom. You get the CA root first, followed by the
218 * possible chain of intermediate CAs, followed by the EE
219 * certificate, followed by the possible proxy
222 X509 *xs = X509_STORE_CTX_get_current_cert(ctx);
224 if (X509_get_extension_flags(xs) & EXFLAG_PROXY) {
225 YOUR_RIGHTS *rights =
226 (YOUR_RIGHTS *)X509_STORE_CTX_get_ex_data(ctx,
227 get_proxy_auth_ex_data_idx(ctx));
228 PROXY_CERT_INFO_EXTENSION *pci =
229 X509_get_ext_d2i(xs, NID_proxyCertInfo, NULL, NULL);
231 switch (OBJ_obj2nid(pci->proxyPolicy->policyLanguage)) {
232 case NID_Independent:
234 * Do whatever you need to grant explicit rights
235 * to this particular proxy certificate, usually
236 * by pulling them from some database. If there
237 * are none to be found, clear all rights (making
238 * this and any subsequent proxy certificate void
241 memset(rights->rights, 0, sizeof(rights->rights));
243 case NID_id_ppl_inheritAll:
245 * This is basically a NOP, we simply let the
246 * current rights stand as they are.
251 * This is usually the most complex section of
252 * code. You really do whatever you want as long
253 * as you follow RFC 3820. In the example we use
254 * here, the simplest thing to do is to build
255 * another, temporary bit array and fill it with
256 * the rights granted by the current proxy
257 * certificate, then use it as a mask on the
258 * accumulated rights bit array, and voilà, you
259 * now have a new accumulated rights bit array.
263 YOUR_RIGHTS tmp_rights;
264 memset(tmp_rights.rights, 0,
265 sizeof(tmp_rights.rights));
268 * process_rights() is supposed to be a
269 * procedure that takes a string and its
270 * length, interprets it and sets the bits
271 * in the YOUR_RIGHTS pointed at by the
274 process_rights((char *) pci->proxyPolicy->policy->data,
275 pci->proxyPolicy->policy->length,
278 for(i = 0; i < total_rights / 8; i++)
279 rights->rights[i] &= tmp_rights.rights[i];
283 PROXY_CERT_INFO_EXTENSION_free(pci);
284 } else if (!(X509_get_extension_flags(xs) & EXFLAG_CA)) {
285 /* We have an EE certificate, let's use it to set default! */
286 YOUR_RIGHTS *rights =
287 (YOUR_RIGHTS *)X509_STORE_CTX_get_ex_data(ctx,
288 get_proxy_auth_ex_data_idx(ctx));
291 * The following procedure finds out what rights the
292 * owner of the current certificate has, and sets them
293 * in the YOUR_RIGHTS structure pointed at by the
296 set_default_rights(xs, rights);
302 static int my_X509_verify_cert(X509_STORE_CTX *ctx,
303 YOUR_RIGHTS *needed_rights)
306 int (*save_verify_cb)(int ok,X509_STORE_CTX *ctx) =
307 X509_STORE_CTX_get_verify_cb(ctx);
310 X509_STORE_CTX_set_verify_cb(ctx, verify_callback);
311 X509_STORE_CTX_set_ex_data(ctx, get_proxy_auth_ex_data_idx(ctx),
313 X509_STORE_CTX_set_flags(ctx, X509_V_FLAG_ALLOW_PROXY_CERTS);
314 ok = X509_verify_cert(ctx);
317 ok = check_needed_rights(rights, needed_rights);
320 X509_STORE_CTX_set_verify_cb(ctx, save_verify_cb);
325 If you use SSL or TLS, you can easily set up a callback to have the
326 certificates checked properly, using the code above:
328 SSL_CTX_set_cert_verify_callback(s_ctx, my_X509_verify_cert,
333 To this date, it seems that proxy certificates have only been used in
334 environments that are aware of them, and no one seems to have
335 investigated how they can be used or misused outside of such an
338 For that reason, OpenSSL requires that applications aware of proxy
339 certificates must also make that explicit.
341 B<subjectAltName> and B<issuerAltName> are forbidden in proxy
342 certificates, and this is enforced in OpenSSL. The subject must be
343 the same as the issuer, with one commonName added on.
347 L<X509_STORE_CTX_set_flags(3)>,
348 L<X509_STORE_CTX_set_verify_cb(3)>,
349 L<X509_VERIFY_PARAM_set_flags(3)>,
350 L<SSL_CTX_set_cert_verify_callback(3)>,
351 L<openssl-req(1)>, L<openssl-x509(1)>,
352 L<RFC 3820|https://tools.ietf.org/html/rfc3820>
356 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
358 Licensed under the Apache License 2.0 (the "License"). You may not use
359 this file except in compliance with the License. You can obtain a copy
360 in the file LICENSE in the source distribution or at
361 L<https://www.openssl.org/source/license.html>.