CMS_verify.3ossl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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 "CMS_VERIFY 3ossl"
  136. .TH CMS_VERIFY 3ossl "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. CMS_verify, CMS_SignedData_verify,
  143. CMS_get0_signers \- verify a CMS SignedData structure
  144. .SH "SYNOPSIS"
  145. .IX Header "SYNOPSIS"
  146. .Vb 1
  147. \& #include <openssl/cms.h>
  148. \&
  149. \& int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, X509_STORE *store,
  150. \& BIO *detached_data, BIO *out, unsigned int flags);
  151. \& BIO *CMS_SignedData_verify(CMS_SignedData *sd, BIO *detached_data,
  152. \& STACK_OF(X509) *scerts, X509_STORE *store,
  153. \& STACK_OF(X509) *extra, STACK_OF(X509_CRL) *crls,
  154. \& unsigned int flags,
  155. \& OSSL_LIB_CTX *libctx, const char *propq);
  156. \&
  157. \& STACK_OF(X509) *CMS_get0_signers(CMS_ContentInfo *cms);
  158. .Ve
  159. .SH "DESCRIPTION"
  160. .IX Header "DESCRIPTION"
  161. \&\fBCMS_verify()\fR is very similar to \fBPKCS7_verify\fR\|(3). It verifies a
  162. \&\fB\s-1CMS\s0 SignedData\fR structure contained in a structure of type \fBCMS_ContentInfo\fR.
  163. \&\fIcms\fR points to the \fBCMS_ContentInfo\fR structure to verify.
  164. The optional \fIcerts\fR parameter refers to a set of certificates
  165. in which to search for signing certificates.
  166. \&\fIcms\fR may contain extra untrusted \s-1CA\s0 certificates that may be used for
  167. chain building as well as CRLs that may be used for certificate validation.
  168. \&\fIstore\fR may be \s-1NULL\s0 or point to
  169. the trusted certificate store to use for chain verification.
  170. \&\fIdetached_data\fR refers to the signed data if the content is detached from \fIcms\fR.
  171. Otherwise \fIdetached_data\fR should be \s-1NULL\s0 and the signed data must be in \fIcms\fR.
  172. The content is written to the \s-1BIO\s0 \fIout\fR unless it is \s-1NULL.\s0
  173. \&\fIflags\fR is an optional set of flags, which can be used to modify the operation.
  174. .PP
  175. \&\fBCMS_SignedData_verify()\fR is like \fBCMS_verify()\fR except that
  176. it operates on \fB\s-1CMS\s0 SignedData\fR input in the \fIsd\fR argument,
  177. it has some additional parameters described next,
  178. and on success it returns the verified content as a memory \s-1BIO.\s0
  179. The optional \fIextra\fR parameter may be used to provide untrusted \s-1CA\s0
  180. certificates that may be helpful for chain building in certificate validation.
  181. This list of certificates must not contain duplicates.
  182. The optional \fIcrls\fR parameter may be used to provide extra CRLs.
  183. Also the list of CRLs must not contain duplicates.
  184. The optional parameters library context \fIlibctx\fR and property query \fIpropq\fR
  185. are used when retrieving algorithms from providers.
  186. .PP
  187. \&\fBCMS_get0_signers()\fR retrieves the signing certificate(s) from \fIcms\fR; it may only
  188. be called after a successful \fBCMS_verify()\fR or \fBCMS_SignedData_verify()\fR operation.
  189. .SH "VERIFY PROCESS"
  190. .IX Header "VERIFY PROCESS"
  191. Normally the verify process proceeds as follows.
  192. .PP
  193. Initially some sanity checks are performed on \fIcms\fR. The type of \fIcms\fR must
  194. be SignedData. There must be at least one signature on the data and if
  195. the content is detached \fIdetached_data\fR cannot be \s-1NULL.\s0
  196. .PP
  197. An attempt is made to locate all the signing certificate(s), first looking in
  198. the \fIcerts\fR parameter (if it is not \s-1NULL\s0) and then looking in any
  199. certificates contained in the \fIcms\fR structure unless \fB\s-1CMS_NOINTERN\s0\fR is set.
  200. If any signing certificate cannot be located the operation fails.
  201. .PP
  202. Each signing certificate is chain verified using the \fIsmimesign\fR purpose and
  203. using the trusted certificate store \fIstore\fR if supplied.
  204. Any internal certificates in the message, which may have been added using
  205. \&\fBCMS_add1_cert\fR\|(3), are used as untrusted CAs.
  206. If \s-1CRL\s0 checking is enabled in \fIstore\fR and \fB\s-1CMS_NOCRL\s0\fR is not set,
  207. any internal CRLs, which may have been added using \fBCMS_add1_crl\fR\|(3),
  208. are used in addition to attempting to look them up in \fIstore\fR.
  209. If \fIstore\fR is not \s-1NULL\s0 and any chain verify fails an error code is returned.
  210. .PP
  211. Finally the signed content is read (and written to \fIout\fR unless it is \s-1NULL\s0)
  212. and the signature is checked.
  213. .PP
  214. If all signatures verify correctly then the function is successful.
  215. .PP
  216. Any of the following flags (ored together) can be passed in the \fIflags\fR
  217. parameter to change the default verify behaviour.
  218. .PP
  219. If \fB\s-1CMS_NOINTERN\s0\fR is set the certificates in the message itself are not
  220. searched when locating the signing certificate(s).
  221. This means that all the signing certificates must be in the \fIcerts\fR parameter.
  222. .PP
  223. If \fB\s-1CMS_NOCRL\s0\fR is set and \s-1CRL\s0 checking is enabled in \fIstore\fR then any
  224. CRLs in the message itself and provided via the \fIcrls\fR parameter are ignored.
  225. .PP
  226. If the \fB\s-1CMS_TEXT\s0\fR flag is set \s-1MIME\s0 headers for type \f(CW\*(C`text/plain\*(C'\fR are deleted
  227. from the content. If the content is not of type \f(CW\*(C`text/plain\*(C'\fR then an error is
  228. returned.
  229. .PP
  230. If \fB\s-1CMS_NO_SIGNER_CERT_VERIFY\s0\fR is set the signing certificates are not
  231. chain verified, unless \fB\s-1CMS_CADES\s0\fR flag is also set.
  232. .PP
  233. If \fB\s-1CMS_NO_ATTR_VERIFY\s0\fR is set the signed attributes signature is not
  234. verified, unless \s-1CMS_CADES\s0 flag is also set.
  235. .PP
  236. If \fB\s-1CMS_CADES\s0\fR is set, each signer certificate is checked against the
  237. \&\s-1ESS\s0 signingCertificate or \s-1ESS\s0 signingCertificateV2 extension
  238. that is required in the signed attributes of the signature.
  239. .PP
  240. If \fB\s-1CMS_NO_CONTENT_VERIFY\s0\fR is set then the content digest is not checked.
  241. .SH "NOTES"
  242. .IX Header "NOTES"
  243. One application of \fB\s-1CMS_NOINTERN\s0\fR is to only accept messages signed by
  244. a small number of certificates. The acceptable certificates would be passed
  245. in the \fIcerts\fR parameter. In this case if the signer certificate is not one
  246. of the certificates supplied in \fIcerts\fR then the verify will fail because the
  247. signer cannot be found.
  248. .PP
  249. In some cases the standard techniques for looking up and validating
  250. certificates are not appropriate: for example an application may wish to
  251. lookup certificates in a database or perform customised verification. This
  252. can be achieved by setting and verifying the signer certificates manually
  253. using the signed data utility functions.
  254. .PP
  255. Care should be taken when modifying the default verify behaviour, for example
  256. setting \fB\s-1CMS_NO_CONTENT_VERIFY\s0\fR will totally disable all content verification
  257. and any modified content will be considered valid. This combination is however
  258. useful if one merely wishes to write the content to \fIout\fR and its validity
  259. is not considered important.
  260. .PP
  261. Chain verification should arguably be performed using the signing time rather
  262. than the current time. However, since the signing time is supplied by the
  263. signer it cannot be trusted without additional evidence (such as a trusted
  264. timestamp).
  265. .SH "RETURN VALUES"
  266. .IX Header "RETURN VALUES"
  267. \&\fBCMS_verify()\fR returns 1 for a successful verification and 0 if an error occurred.
  268. .PP
  269. \&\fBCMS_SignedData_verify()\fR returns a memory \s-1BIO\s0 containing the verified content,
  270. or \s-1NULL\s0 on error.
  271. .PP
  272. \&\fBCMS_get0_signers()\fR returns all signers or \s-1NULL\s0 if an error occurred.
  273. .PP
  274. The error can be obtained from \fBERR_get_error\fR\|(3).
  275. .SH "BUGS"
  276. .IX Header "BUGS"
  277. The trusted certificate store is not searched for the signing certificate.
  278. This is primarily due to the inadequacies of the current \fBX509_STORE\fR
  279. functionality.
  280. .PP
  281. The lack of single pass processing means that the signed content must all
  282. be held in memory if it is not detached.
  283. .SH "SEE ALSO"
  284. .IX Header "SEE ALSO"
  285. \&\fBPKCS7_verify\fR\|(3), \fBCMS_add1_cert\fR\|(3), \fBCMS_add1_crl\fR\|(3),
  286. \&\fBOSSL_ESS_check_signing_certs\fR\|(3),
  287. \&\fBERR_get_error\fR\|(3), \fBCMS_sign\fR\|(3)
  288. .SH "HISTORY"
  289. .IX Header "HISTORY"
  290. \&\fBCMS_SignedData_verify()\fR was added in OpenSSL 3.2.
  291. .SH "COPYRIGHT"
  292. .IX Header "COPYRIGHT"
  293. Copyright 2008\-2023 The OpenSSL Project Authors. All Rights Reserved.
  294. .PP
  295. Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use
  296. this file except in compliance with the License. You can obtain a copy
  297. in the file \s-1LICENSE\s0 in the source distribution or at
  298. <https://www.openssl.org/source/license.html>.