crmf_local.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. /*-
  2. * Copyright 2007-2025 The OpenSSL Project Authors. All Rights Reserved.
  3. * Copyright Nokia 2007-2019
  4. * Copyright Siemens AG 2015-2019
  5. *
  6. * Licensed under the Apache License 2.0 (the "License"). You may not use
  7. * this file except in compliance with the License. You can obtain a copy
  8. * in the file LICENSE in the source distribution or at
  9. * https://www.openssl.org/source/license.html
  10. *
  11. * CRMF implementation by Martin Peylo, Miikka Viljanen, and David von Oheimb.
  12. */
  13. #ifndef OSSL_CRYPTO_CRMF_LOCAL_H
  14. # define OSSL_CRYPTO_CRMF_LOCAL_H
  15. # include <openssl/crmf.h>
  16. # include <openssl/cms.h> /* for CMS_EnvelopedData and CMS_SignedData */
  17. # include <openssl/err.h>
  18. # include "internal/crmf.h" /* for ossl_crmf_attributetypeandvalue_st */
  19. /* explicit #includes not strictly needed since implied by the above: */
  20. # include <openssl/types.h>
  21. # include <openssl/safestack.h>
  22. # include <openssl/x509.h>
  23. # include <openssl/x509v3.h>
  24. /*-
  25. * EncryptedValue ::= SEQUENCE {
  26. * intendedAlg [0] AlgorithmIdentifier OPTIONAL,
  27. * -- the intended algorithm for which the value will be used
  28. * symmAlg [1] AlgorithmIdentifier OPTIONAL,
  29. * -- the symmetric algorithm used to encrypt the value
  30. * encSymmKey [2] BIT STRING OPTIONAL,
  31. * -- the (encrypted) symmetric key used to encrypt the value
  32. * keyAlg [3] AlgorithmIdentifier OPTIONAL,
  33. * -- algorithm used to encrypt the symmetric key
  34. * valueHint [4] OCTET STRING OPTIONAL,
  35. * -- a brief description or identifier of the encValue content
  36. * -- (may be meaningful only to the sending entity, and
  37. * -- used only if EncryptedValue might be re-examined
  38. * -- by the sending entity in the future)
  39. * encValue BIT STRING
  40. * -- the encrypted value itself
  41. * }
  42. */
  43. struct ossl_crmf_encryptedvalue_st {
  44. X509_ALGOR *intendedAlg; /* 0 */
  45. X509_ALGOR *symmAlg; /* 1 */
  46. ASN1_BIT_STRING *encSymmKey; /* 2 */
  47. X509_ALGOR *keyAlg; /* 3 */
  48. ASN1_OCTET_STRING *valueHint; /* 4 */
  49. ASN1_BIT_STRING *encValue;
  50. } /* OSSL_CRMF_ENCRYPTEDVALUE */;
  51. /*
  52. * EncryptedKey ::= CHOICE {
  53. * encryptedValue EncryptedValue, -- Deprecated
  54. * envelopedData [0] EnvelopedData }
  55. * -- The encrypted private key MUST be placed in the envelopedData
  56. * -- encryptedContentInfo encryptedContent OCTET STRING.
  57. */
  58. # define OSSL_CRMF_ENCRYPTEDKEY_ENVELOPEDDATA 1
  59. struct ossl_crmf_encryptedkey_st {
  60. int type;
  61. union {
  62. OSSL_CRMF_ENCRYPTEDVALUE *encryptedValue; /* 0 */ /* Deprecated */
  63. # ifndef OPENSSL_NO_CMS
  64. CMS_EnvelopedData *envelopedData; /* 1 */
  65. # endif
  66. } value;
  67. } /* OSSL_CRMF_ENCRYPTEDKEY */;
  68. /*-
  69. * Attributes ::= SET OF Attribute
  70. * => X509_ATTRIBUTE
  71. *
  72. * PrivateKeyInfo ::= SEQUENCE {
  73. * version INTEGER,
  74. * privateKeyAlgorithm AlgorithmIdentifier,
  75. * privateKey OCTET STRING,
  76. * attributes [0] IMPLICIT Attributes OPTIONAL
  77. * }
  78. */
  79. typedef struct ossl_crmf_privatekeyinfo_st {
  80. ASN1_INTEGER *version;
  81. X509_ALGOR *privateKeyAlgorithm;
  82. ASN1_OCTET_STRING *privateKey;
  83. STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
  84. } OSSL_CRMF_PRIVATEKEYINFO;
  85. DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_PRIVATEKEYINFO)
  86. /*-
  87. * section 4.2.1 Private Key Info Content Type
  88. * id-ct-encKeyWithID OBJECT IDENTIFIER ::= {id-ct 21}
  89. *
  90. * EncKeyWithID ::= SEQUENCE {
  91. * privateKey PrivateKeyInfo,
  92. * identifier CHOICE {
  93. * string UTF8String,
  94. * generalName GeneralName
  95. * } OPTIONAL
  96. * }
  97. */
  98. typedef struct ossl_crmf_enckeywithid_identifier_st {
  99. int type;
  100. union {
  101. ASN1_UTF8STRING *string;
  102. GENERAL_NAME *generalName;
  103. } value;
  104. } OSSL_CRMF_ENCKEYWITHID_IDENTIFIER;
  105. DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_ENCKEYWITHID_IDENTIFIER)
  106. typedef struct ossl_crmf_enckeywithid_st {
  107. OSSL_CRMF_PRIVATEKEYINFO *privateKey;
  108. /* [0] */
  109. OSSL_CRMF_ENCKEYWITHID_IDENTIFIER *identifier;
  110. } OSSL_CRMF_ENCKEYWITHID;
  111. DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_ENCKEYWITHID)
  112. /*-
  113. * CertId ::= SEQUENCE {
  114. * issuer GeneralName,
  115. * serialNumber INTEGER
  116. * }
  117. */
  118. struct ossl_crmf_certid_st {
  119. GENERAL_NAME *issuer;
  120. ASN1_INTEGER *serialNumber;
  121. } /* OSSL_CRMF_CERTID */;
  122. /*-
  123. * SinglePubInfo ::= SEQUENCE {
  124. * pubMethod INTEGER {
  125. * dontCare (0),
  126. * x500 (1),
  127. * web (2),
  128. * ldap (3) },
  129. * pubLocation GeneralName OPTIONAL
  130. * }
  131. */
  132. struct ossl_crmf_singlepubinfo_st {
  133. ASN1_INTEGER *pubMethod;
  134. GENERAL_NAME *pubLocation;
  135. } /* OSSL_CRMF_SINGLEPUBINFO */;
  136. DEFINE_STACK_OF(OSSL_CRMF_SINGLEPUBINFO)
  137. typedef STACK_OF(OSSL_CRMF_SINGLEPUBINFO) OSSL_CRMF_PUBINFOS;
  138. /*-
  139. * PKIPublicationInfo ::= SEQUENCE {
  140. * action INTEGER {
  141. * dontPublish (0),
  142. * pleasePublish (1) },
  143. * pubInfos SEQUENCE SIZE (1..MAX) OF SinglePubInfo OPTIONAL
  144. * -- pubInfos MUST NOT be present if action is "dontPublish"
  145. * -- (if action is "pleasePublish" and pubInfos is omitted,
  146. * -- "dontCare" is assumed)
  147. * }
  148. */
  149. struct ossl_crmf_pkipublicationinfo_st {
  150. ASN1_INTEGER *action;
  151. OSSL_CRMF_PUBINFOS *pubInfos;
  152. } /* OSSL_CRMF_PKIPUBLICATIONINFO */;
  153. DECLARE_ASN1_DUP_FUNCTION(OSSL_CRMF_PKIPUBLICATIONINFO)
  154. /*-
  155. * PKMACValue ::= SEQUENCE {
  156. * algId AlgorithmIdentifier,
  157. * -- algorithm value shall be PasswordBasedMac {1 2 840 113533 7 66 13}
  158. * -- parameter value is PBMParameter
  159. * value BIT STRING
  160. * }
  161. */
  162. typedef struct ossl_crmf_pkmacvalue_st {
  163. X509_ALGOR *algId;
  164. ASN1_BIT_STRING *value;
  165. } OSSL_CRMF_PKMACVALUE;
  166. DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_PKMACVALUE)
  167. /*-
  168. * SubsequentMessage ::= INTEGER {
  169. * encrCert (0),
  170. * -- requests that resulting certificate be encrypted for the
  171. * -- end entity (following which, POP will be proven in a
  172. * -- confirmation message)
  173. * challengeResp (1)
  174. * -- requests that CA engage in challenge-response exchange with
  175. * -- end entity in order to prove private key possession
  176. * }
  177. *
  178. * POPOPrivKey ::= CHOICE {
  179. * thisMessage [0] BIT STRING, -- Deprecated
  180. * -- possession is proven in this message (which contains the private
  181. * -- key itself (encrypted for the CA))
  182. * subsequentMessage [1] SubsequentMessage,
  183. * -- possession will be proven in a subsequent message
  184. * dhMAC [2] BIT STRING, -- Deprecated
  185. * agreeMAC [3] PKMACValue,
  186. * encryptedKey [4] EnvelopedData
  187. * }
  188. */
  189. typedef struct ossl_crmf_popoprivkey_st {
  190. int type;
  191. union {
  192. ASN1_BIT_STRING *thisMessage; /* 0 */ /* Deprecated */
  193. ASN1_INTEGER *subsequentMessage; /* 1 */
  194. ASN1_BIT_STRING *dhMAC; /* 2 */ /* Deprecated */
  195. OSSL_CRMF_PKMACVALUE *agreeMAC; /* 3 */
  196. ASN1_NULL *encryptedKey; /* 4 */
  197. /* When supported, ASN1_NULL needs to be replaced by CMS_ENVELOPEDDATA */
  198. } value;
  199. } OSSL_CRMF_POPOPRIVKEY;
  200. DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_POPOPRIVKEY)
  201. /*-
  202. * PBMParameter ::= SEQUENCE {
  203. * salt OCTET STRING,
  204. * owf AlgorithmIdentifier,
  205. * -- AlgId for a One-Way Function (SHA-1 recommended)
  206. * iterationCount INTEGER,
  207. * -- number of times the OWF is applied
  208. * mac AlgorithmIdentifier
  209. * -- the MAC AlgId (e.g., DES-MAC, Triple-DES-MAC [PKCS11],
  210. * -- or HMAC [HMAC, RFC2202])
  211. * }
  212. */
  213. struct ossl_crmf_pbmparameter_st {
  214. ASN1_OCTET_STRING *salt;
  215. X509_ALGOR *owf;
  216. ASN1_INTEGER *iterationCount;
  217. X509_ALGOR *mac;
  218. } /* OSSL_CRMF_PBMPARAMETER */;
  219. # define OSSL_CRMF_PBM_MAX_ITERATION_COUNT 100000 /* if too large allows DoS */
  220. /*-
  221. * POPOSigningKeyInput ::= SEQUENCE {
  222. * authInfo CHOICE {
  223. * sender [0] GeneralName,
  224. * -- used only if an authenticated identity has been
  225. * -- established for the sender (e.g., a DN from a
  226. * -- previously-issued and currently-valid certificate)
  227. * publicKeyMAC PKMACValue },
  228. * -- used if no authenticated GeneralName currently exists for
  229. * -- the sender; publicKeyMAC contains a password-based MAC
  230. * -- on the DER-encoded value of publicKey
  231. * publicKey SubjectPublicKeyInfo -- from CertTemplate
  232. * }
  233. */
  234. typedef struct ossl_crmf_poposigningkeyinput_authinfo_st {
  235. int type;
  236. union {
  237. /* 0 */ GENERAL_NAME *sender;
  238. /* 1 */ OSSL_CRMF_PKMACVALUE *publicKeyMAC;
  239. } value;
  240. } OSSL_CRMF_POPOSIGNINGKEYINPUT_AUTHINFO;
  241. DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_POPOSIGNINGKEYINPUT_AUTHINFO)
  242. typedef struct ossl_crmf_poposigningkeyinput_st {
  243. OSSL_CRMF_POPOSIGNINGKEYINPUT_AUTHINFO *authInfo;
  244. X509_PUBKEY *publicKey;
  245. } OSSL_CRMF_POPOSIGNINGKEYINPUT;
  246. DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_POPOSIGNINGKEYINPUT)
  247. /*-
  248. * POPOSigningKey ::= SEQUENCE {
  249. * poposkInput [0] POPOSigningKeyInput OPTIONAL,
  250. * algorithmIdentifier AlgorithmIdentifier,
  251. * signature BIT STRING
  252. * }
  253. */
  254. struct ossl_crmf_poposigningkey_st {
  255. OSSL_CRMF_POPOSIGNINGKEYINPUT *poposkInput;
  256. X509_ALGOR *algorithmIdentifier;
  257. ASN1_BIT_STRING *signature;
  258. } /* OSSL_CRMF_POPOSIGNINGKEY */;
  259. DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_POPOSIGNINGKEY)
  260. /*-
  261. * ProofOfPossession ::= CHOICE {
  262. * raVerified [0] NULL,
  263. * -- used if the RA has already verified that the requester is in
  264. * -- possession of the private key
  265. * signature [1] POPOSigningKey,
  266. * keyEncipherment [2] POPOPrivKey,
  267. * keyAgreement [3] POPOPrivKey
  268. * }
  269. */
  270. typedef struct ossl_crmf_popo_st {
  271. int type;
  272. union {
  273. ASN1_NULL *raVerified; /* 0 */
  274. OSSL_CRMF_POPOSIGNINGKEY *signature; /* 1 */
  275. OSSL_CRMF_POPOPRIVKEY *keyEncipherment; /* 2 */
  276. OSSL_CRMF_POPOPRIVKEY *keyAgreement; /* 3 */
  277. } value;
  278. } OSSL_CRMF_POPO;
  279. DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_POPO)
  280. /*-
  281. * OptionalValidity ::= SEQUENCE {
  282. * notBefore [0] Time OPTIONAL,
  283. * notAfter [1] Time OPTIONAL -- at least one MUST be present
  284. * }
  285. */
  286. struct ossl_crmf_optionalvalidity_st {
  287. /* 0 */ ASN1_TIME *notBefore;
  288. /* 1 */ ASN1_TIME *notAfter;
  289. } /* OSSL_CRMF_OPTIONALVALIDITY */;
  290. DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_OPTIONALVALIDITY)
  291. /*-
  292. * CertTemplate ::= SEQUENCE {
  293. * version [0] Version OPTIONAL,
  294. * serialNumber [1] INTEGER OPTIONAL,
  295. * signingAlg [2] AlgorithmIdentifier OPTIONAL,
  296. * issuer [3] Name OPTIONAL,
  297. * validity [4] OptionalValidity OPTIONAL,
  298. * subject [5] Name OPTIONAL,
  299. * publicKey [6] SubjectPublicKeyInfo OPTIONAL,
  300. * issuerUID [7] UniqueIdentifier OPTIONAL,
  301. * subjectUID [8] UniqueIdentifier OPTIONAL,
  302. * extensions [9] Extensions OPTIONAL
  303. * }
  304. */
  305. struct ossl_crmf_certtemplate_st {
  306. ASN1_INTEGER *version;
  307. ASN1_INTEGER *serialNumber; /* serialNumber MUST be omitted */
  308. /* This field is assigned by the CA during certificate creation */
  309. X509_ALGOR *signingAlg; /* signingAlg MUST be omitted */
  310. /* This field is assigned by the CA during certificate creation */
  311. const X509_NAME *issuer;
  312. OSSL_CRMF_OPTIONALVALIDITY *validity;
  313. const X509_NAME *subject;
  314. X509_PUBKEY *publicKey;
  315. ASN1_BIT_STRING *issuerUID; /* deprecated in version 2 */
  316. /* According to rfc 3280: UniqueIdentifier ::= BIT STRING */
  317. ASN1_BIT_STRING *subjectUID; /* deprecated in version 2 */
  318. /* Could be X509_EXTENSION*S*, but that's only cosmetic */
  319. STACK_OF(X509_EXTENSION) *extensions;
  320. } /* OSSL_CRMF_CERTTEMPLATE */;
  321. /*-
  322. * CertRequest ::= SEQUENCE {
  323. * certReqId INTEGER, -- ID for matching request and reply
  324. * certTemplate CertTemplate, -- Selected fields of cert to be issued
  325. * controls Controls OPTIONAL -- Attributes affecting issuance
  326. * }
  327. */
  328. struct ossl_crmf_certrequest_st {
  329. ASN1_INTEGER *certReqId;
  330. OSSL_CRMF_CERTTEMPLATE *certTemplate;
  331. STACK_OF(OSSL_CRMF_ATTRIBUTETYPEANDVALUE /* Controls expanded */) *controls;
  332. } /* OSSL_CRMF_CERTREQUEST */;
  333. DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_CERTREQUEST)
  334. DECLARE_ASN1_DUP_FUNCTION(OSSL_CRMF_CERTREQUEST)
  335. /*-
  336. * CertReqMessages ::= SEQUENCE SIZE (1..MAX) OF CertReqMsg
  337. * CertReqMsg ::= SEQUENCE {
  338. * certReq CertRequest,
  339. * popo ProofOfPossession OPTIONAL,
  340. * -- content depends upon key type
  341. * regInfo SEQUENCE SIZE(1..MAX) OF AttributeTypeAndValue OPTIONAL
  342. * }
  343. */
  344. struct ossl_crmf_msg_st {
  345. OSSL_CRMF_CERTREQUEST *certReq;
  346. /* 0 */
  347. OSSL_CRMF_POPO *popo;
  348. /* 1 */
  349. STACK_OF(OSSL_CRMF_ATTRIBUTETYPEANDVALUE) *regInfo;
  350. } /* OSSL_CRMF_MSG */;
  351. #endif