crmf_local.h 13 KB

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