proxy-certificates.7ossl 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
  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 7ossl"
  136. .TH PROXY-CERTIFICATES 7ossl "2024-09-03" "3.3.2" "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 7
  185. \& [ proxy ]
  186. \& # A proxy certificate MUST NEVER be a CA certificate.
  187. \& basicConstraints = CA:FALSE
  188. \& # Usual authority key ID
  189. \& authorityKeyIdentifier = keyid,issuer:always
  190. \& # The extension which marks this certificate as a proxy
  191. \& proxyCertInfo = critical,language:id\-ppl\-anyLanguage,pathlen:1,policy:text:AB
  192. .Ve
  193. .PP
  194. It's also possible to specify the proxy extension in a separate section:
  195. .PP
  196. .Vb 1
  197. \& proxyCertInfo = critical,@proxy_ext
  198. \&
  199. \& [ proxy_ext ]
  200. \& language = id\-ppl\-anyLanguage
  201. \& pathlen = 0
  202. \& policy = text:BC
  203. .Ve
  204. .PP
  205. The policy value has a specific syntax, \fIsyntag\fR:\fIstring\fR, where the
  206. \&\fIsyntag\fR determines what will be done with the string. The following
  207. \&\fIsyntag\fRs are recognised:
  208. .IP "\fBtext\fR" 4
  209. .IX Item "text"
  210. indicates that the string is a byte sequence, without any encoding:
  211. .Sp
  212. .Vb 1
  213. \& policy=text:ra\*:ksmo\*:rga\*os
  214. .Ve
  215. .IP "\fBhex\fR" 4
  216. .IX Item "hex"
  217. indicates the string is encoded hexadecimal encoded binary data, with
  218. colons between each byte (every second hex digit):
  219. .Sp
  220. .Vb 1
  221. \& policy=hex:72:E4:6B:73:6D:F6:72:67:E5:73
  222. .Ve
  223. .IP "\fBfile\fR" 4
  224. .IX Item "file"
  225. indicates that the text of the policy should be taken from a file.
  226. The string is then a filename. This is useful for policies that are
  227. more than a few lines, such as \s-1XML\s0 or other markup.
  228. .PP
  229. Note that the proxy policy value is what determines the rights granted
  230. to the process during the proxy certificate, and it is up to the
  231. application to interpret and combine these policies.>
  232. .PP
  233. With a proxy extension, creating a proxy certificate is a matter of
  234. two commands:
  235. .PP
  236. .Vb 3
  237. \& openssl req \-new \-config proxy.cnf \e
  238. \& \-out proxy.req \-keyout proxy.key \e
  239. \& \-subj "/DC=org/DC=openssl/DC=users/CN=proxy"
  240. \&
  241. \& openssl x509 \-req \-CAcreateserial \-in proxy.req \-out proxy.crt \e
  242. \& \-CA user.crt \-CAkey user.key \-days 7 \e
  243. \& \-extfile proxy.cnf \-extensions proxy
  244. .Ve
  245. .PP
  246. You can also create a proxy certificate using another proxy
  247. certificate as issuer. Note that this example uses a different
  248. configuration section for the proxy extensions:
  249. .PP
  250. .Vb 3
  251. \& openssl req \-new \-config proxy.cnf \e
  252. \& \-out proxy2.req \-keyout proxy2.key \e
  253. \& \-subj "/DC=org/DC=openssl/DC=users/CN=proxy/CN=proxy 2"
  254. \&
  255. \& openssl x509 \-req \-CAcreateserial \-in proxy2.req \-out proxy2.crt \e
  256. \& \-CA proxy.crt \-CAkey proxy.key \-days 7 \e
  257. \& \-extfile proxy.cnf \-extensions proxy_2
  258. .Ve
  259. .SS "Using proxy certs in applications"
  260. .IX Subsection "Using proxy certs in applications"
  261. To interpret proxy policies, the application would normally start with
  262. some default rights (perhaps none at all), then compute the resulting
  263. rights by checking the rights against the chain of proxy certificates,
  264. user certificate and \s-1CA\s0 certificates.
  265. .PP
  266. The complicated part is figuring out how to pass data between your
  267. application and the certificate validation procedure.
  268. .PP
  269. The following ingredients are needed for such processing:
  270. .IP "\(bu" 4
  271. a callback function that will be called for every certificate being
  272. validated. The callback is called several times for each certificate,
  273. so you must be careful to do the proxy policy interpretation at the
  274. right time. You also need to fill in the defaults when the \s-1EE\s0
  275. certificate is checked.
  276. .IP "\(bu" 4
  277. a data structure that is shared between your application code and the
  278. callback.
  279. .IP "\(bu" 4
  280. a wrapper function that sets it all up.
  281. .IP "\(bu" 4
  282. an ex_data index function that creates an index into the generic
  283. ex_data store that is attached to an X509 validation context.
  284. .PP
  285. The following skeleton code can be used as a starting point:
  286. .PP
  287. .Vb 4
  288. \& #include <string.h>
  289. \& #include <netdb.h>
  290. \& #include <openssl/x509.h>
  291. \& #include <openssl/x509v3.h>
  292. \&
  293. \& #define total_rights 25
  294. \&
  295. \& /*
  296. \& * In this example, I will use a view of granted rights as a bit
  297. \& * array, one bit for each possible right.
  298. \& */
  299. \& typedef struct your_rights {
  300. \& unsigned char rights[(total_rights + 7) / 8];
  301. \& } YOUR_RIGHTS;
  302. \&
  303. \& /*
  304. \& * The following procedure will create an index for the ex_data
  305. \& * store in the X509 validation context the first time it\*(Aqs
  306. \& * called. Subsequent calls will return the same index.
  307. \& */
  308. \& static int get_proxy_auth_ex_data_idx(X509_STORE_CTX *ctx)
  309. \& {
  310. \& static volatile int idx = \-1;
  311. \&
  312. \& if (idx < 0) {
  313. \& X509_STORE_lock(X509_STORE_CTX_get0_store(ctx));
  314. \& if (idx < 0) {
  315. \& idx = X509_STORE_CTX_get_ex_new_index(0,
  316. \& "for verify callback",
  317. \& NULL,NULL,NULL);
  318. \& }
  319. \& X509_STORE_unlock(X509_STORE_CTX_get0_store(ctx));
  320. \& }
  321. \& return idx;
  322. \& }
  323. \&
  324. \& /* Callback to be given to the X509 validation procedure. */
  325. \& static int verify_callback(int ok, X509_STORE_CTX *ctx)
  326. \& {
  327. \& if (ok == 1) {
  328. \& /*
  329. \& * It\*(Aqs REALLY important you keep the proxy policy check
  330. \& * within this section. It\*(Aqs important to know that when
  331. \& * ok is 1, the certificates are checked from top to
  332. \& * bottom. You get the CA root first, followed by the
  333. \& * possible chain of intermediate CAs, followed by the EE
  334. \& * certificate, followed by the possible proxy
  335. \& * certificates.
  336. \& */
  337. \& X509 *xs = X509_STORE_CTX_get_current_cert(ctx);
  338. \&
  339. \& if (X509_get_extension_flags(xs) & EXFLAG_PROXY) {
  340. \& YOUR_RIGHTS *rights =
  341. \& (YOUR_RIGHTS *)X509_STORE_CTX_get_ex_data(ctx,
  342. \& get_proxy_auth_ex_data_idx(ctx));
  343. \& PROXY_CERT_INFO_EXTENSION *pci =
  344. \& X509_get_ext_d2i(xs, NID_proxyCertInfo, NULL, NULL);
  345. \&
  346. \& switch (OBJ_obj2nid(pci\->proxyPolicy\->policyLanguage)) {
  347. \& case NID_Independent:
  348. \& /*
  349. \& * Do whatever you need to grant explicit rights
  350. \& * to this particular proxy certificate, usually
  351. \& * by pulling them from some database. If there
  352. \& * are none to be found, clear all rights (making
  353. \& * this and any subsequent proxy certificate void
  354. \& * of any rights).
  355. \& */
  356. \& memset(rights\->rights, 0, sizeof(rights\->rights));
  357. \& break;
  358. \& case NID_id_ppl_inheritAll:
  359. \& /*
  360. \& * This is basically a NOP, we simply let the
  361. \& * current rights stand as they are.
  362. \& */
  363. \& break;
  364. \& default:
  365. \& /*
  366. \& * This is usually the most complex section of
  367. \& * code. You really do whatever you want as long
  368. \& * as you follow RFC 3820. In the example we use
  369. \& * here, the simplest thing to do is to build
  370. \& * another, temporary bit array and fill it with
  371. \& * the rights granted by the current proxy
  372. \& * certificate, then use it as a mask on the
  373. \& * accumulated rights bit array, and voila\*`, you
  374. \& * now have a new accumulated rights bit array.
  375. \& */
  376. \& {
  377. \& int i;
  378. \& YOUR_RIGHTS tmp_rights;
  379. \& memset(tmp_rights.rights, 0,
  380. \& sizeof(tmp_rights.rights));
  381. \&
  382. \& /*
  383. \& * process_rights() is supposed to be a
  384. \& * procedure that takes a string and its
  385. \& * length, interprets it and sets the bits
  386. \& * in the YOUR_RIGHTS pointed at by the
  387. \& * third argument.
  388. \& */
  389. \& process_rights((char *) pci\->proxyPolicy\->policy\->data,
  390. \& pci\->proxyPolicy\->policy\->length,
  391. \& &tmp_rights);
  392. \&
  393. \& for(i = 0; i < total_rights / 8; i++)
  394. \& rights\->rights[i] &= tmp_rights.rights[i];
  395. \& }
  396. \& break;
  397. \& }
  398. \& PROXY_CERT_INFO_EXTENSION_free(pci);
  399. \& } else if (!(X509_get_extension_flags(xs) & EXFLAG_CA)) {
  400. \& /* We have an EE certificate, let\*(Aqs use it to set default! */
  401. \& YOUR_RIGHTS *rights =
  402. \& (YOUR_RIGHTS *)X509_STORE_CTX_get_ex_data(ctx,
  403. \& get_proxy_auth_ex_data_idx(ctx));
  404. \&
  405. \& /*
  406. \& * The following procedure finds out what rights the
  407. \& * owner of the current certificate has, and sets them
  408. \& * in the YOUR_RIGHTS structure pointed at by the
  409. \& * second argument.
  410. \& */
  411. \& set_default_rights(xs, rights);
  412. \& }
  413. \& }
  414. \& return ok;
  415. \& }
  416. \&
  417. \& static int my_X509_verify_cert(X509_STORE_CTX *ctx,
  418. \& YOUR_RIGHTS *needed_rights)
  419. \& {
  420. \& int ok;
  421. \& int (*save_verify_cb)(int ok,X509_STORE_CTX *ctx) =
  422. \& X509_STORE_CTX_get_verify_cb(ctx);
  423. \& YOUR_RIGHTS rights;
  424. \&
  425. \& X509_STORE_CTX_set_verify_cb(ctx, verify_callback);
  426. \& X509_STORE_CTX_set_ex_data(ctx, get_proxy_auth_ex_data_idx(ctx),
  427. \& &rights);
  428. \& X509_STORE_CTX_set_flags(ctx, X509_V_FLAG_ALLOW_PROXY_CERTS);
  429. \& ok = X509_verify_cert(ctx);
  430. \&
  431. \& if (ok == 1) {
  432. \& ok = check_needed_rights(rights, needed_rights);
  433. \& }
  434. \&
  435. \& X509_STORE_CTX_set_verify_cb(ctx, save_verify_cb);
  436. \&
  437. \& return ok;
  438. \& }
  439. .Ve
  440. .PP
  441. If you use \s-1SSL\s0 or \s-1TLS,\s0 you can easily set up a callback to have the
  442. certificates checked properly, using the code above:
  443. .PP
  444. .Vb 2
  445. \& SSL_CTX_set_cert_verify_callback(s_ctx, my_X509_verify_cert,
  446. \& &needed_rights);
  447. .Ve
  448. .SH "NOTES"
  449. .IX Header "NOTES"
  450. To this date, it seems that proxy certificates have only been used in
  451. environments that are aware of them, and no one seems to have
  452. investigated how they can be used or misused outside of such an
  453. environment.
  454. .PP
  455. For that reason, OpenSSL requires that applications aware of proxy
  456. certificates must also make that explicit.
  457. .PP
  458. \&\fBsubjectAltName\fR and \fBissuerAltName\fR are forbidden in proxy
  459. certificates, and this is enforced in OpenSSL. The subject must be
  460. the same as the issuer, with one commonName added on.
  461. .SH "SEE ALSO"
  462. .IX Header "SEE ALSO"
  463. \&\fBX509_STORE_CTX_set_flags\fR\|(3),
  464. \&\fBX509_STORE_CTX_set_verify_cb\fR\|(3),
  465. \&\fBX509_VERIFY_PARAM_set_flags\fR\|(3),
  466. \&\fBSSL_CTX_set_cert_verify_callback\fR\|(3),
  467. \&\fBopenssl\-req\fR\|(1), \fBopenssl\-x509\fR\|(1),
  468. \&\s-1RFC 3820\s0 <https://tools.ietf.org/html/rfc3820>
  469. .SH "COPYRIGHT"
  470. .IX Header "COPYRIGHT"
  471. Copyright 2019\-2020 The OpenSSL Project Authors. All Rights Reserved.
  472. .PP
  473. Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use
  474. this file except in compliance with the License. You can obtain a copy
  475. in the file \s-1LICENSE\s0 in the source distribution or at
  476. <https://www.openssl.org/source/license.html>.