2
0

crmf_local.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /*-
  2. * Copyright 2007-2021 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. ASN1_NULL *encryptedKey; /* 4 */
  178. /* When supported, ASN1_NULL needs to be replaced by CMS_ENVELOPEDDATA */
  179. } value;
  180. } OSSL_CRMF_POPOPRIVKEY;
  181. DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_POPOPRIVKEY)
  182. /*-
  183. * PBMParameter ::= SEQUENCE {
  184. * salt OCTET STRING,
  185. * owf AlgorithmIdentifier,
  186. * -- AlgId for a One-Way Function (SHA-1 recommended)
  187. * iterationCount INTEGER,
  188. * -- number of times the OWF is applied
  189. * mac AlgorithmIdentifier
  190. * -- the MAC AlgId (e.g., DES-MAC, Triple-DES-MAC [PKCS11],
  191. * -- or HMAC [HMAC, RFC2202])
  192. * }
  193. */
  194. struct ossl_crmf_pbmparameter_st {
  195. ASN1_OCTET_STRING *salt;
  196. X509_ALGOR *owf;
  197. ASN1_INTEGER *iterationCount;
  198. X509_ALGOR *mac;
  199. } /* OSSL_CRMF_PBMPARAMETER */;
  200. # define OSSL_CRMF_PBM_MAX_ITERATION_COUNT 100000 /* if too large allows DoS */
  201. /*-
  202. * POPOSigningKeyInput ::= SEQUENCE {
  203. * authInfo CHOICE {
  204. * sender [0] GeneralName,
  205. * -- used only if an authenticated identity has been
  206. * -- established for the sender (e.g., a DN from a
  207. * -- previously-issued and currently-valid certificate)
  208. * publicKeyMAC PKMACValue },
  209. * -- used if no authenticated GeneralName currently exists for
  210. * -- the sender; publicKeyMAC contains a password-based MAC
  211. * -- on the DER-encoded value of publicKey
  212. * publicKey SubjectPublicKeyInfo -- from CertTemplate
  213. * }
  214. */
  215. typedef struct ossl_crmf_poposigningkeyinput_authinfo_st {
  216. int type;
  217. union {
  218. /* 0 */ GENERAL_NAME *sender;
  219. /* 1 */ OSSL_CRMF_PKMACVALUE *publicKeyMAC;
  220. } value;
  221. } OSSL_CRMF_POPOSIGNINGKEYINPUT_AUTHINFO;
  222. DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_POPOSIGNINGKEYINPUT_AUTHINFO)
  223. typedef struct ossl_crmf_poposigningkeyinput_st {
  224. OSSL_CRMF_POPOSIGNINGKEYINPUT_AUTHINFO *authInfo;
  225. X509_PUBKEY *publicKey;
  226. } OSSL_CRMF_POPOSIGNINGKEYINPUT;
  227. DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_POPOSIGNINGKEYINPUT)
  228. /*-
  229. * POPOSigningKey ::= SEQUENCE {
  230. * poposkInput [0] POPOSigningKeyInput OPTIONAL,
  231. * algorithmIdentifier AlgorithmIdentifier,
  232. * signature BIT STRING
  233. * }
  234. */
  235. struct ossl_crmf_poposigningkey_st {
  236. OSSL_CRMF_POPOSIGNINGKEYINPUT *poposkInput;
  237. X509_ALGOR *algorithmIdentifier;
  238. ASN1_BIT_STRING *signature;
  239. } /* OSSL_CRMF_POPOSIGNINGKEY */;
  240. DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_POPOSIGNINGKEY)
  241. /*-
  242. * ProofOfPossession ::= CHOICE {
  243. * raVerified [0] NULL,
  244. * -- used if the RA has already verified that the requester is in
  245. * -- possession of the private key
  246. * signature [1] POPOSigningKey,
  247. * keyEncipherment [2] POPOPrivKey,
  248. * keyAgreement [3] POPOPrivKey
  249. * }
  250. */
  251. typedef struct ossl_crmf_popo_st {
  252. int type;
  253. union {
  254. ASN1_NULL *raVerified; /* 0 */
  255. OSSL_CRMF_POPOSIGNINGKEY *signature; /* 1 */
  256. OSSL_CRMF_POPOPRIVKEY *keyEncipherment; /* 2 */
  257. OSSL_CRMF_POPOPRIVKEY *keyAgreement; /* 3 */
  258. } value;
  259. } OSSL_CRMF_POPO;
  260. DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_POPO)
  261. /*-
  262. * OptionalValidity ::= SEQUENCE {
  263. * notBefore [0] Time OPTIONAL,
  264. * notAfter [1] Time OPTIONAL -- at least one MUST be present
  265. * }
  266. */
  267. struct ossl_crmf_optionalvalidity_st {
  268. /* 0 */ ASN1_TIME *notBefore;
  269. /* 1 */ ASN1_TIME *notAfter;
  270. } /* OSSL_CRMF_OPTIONALVALIDITY */;
  271. DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_OPTIONALVALIDITY)
  272. /*-
  273. * CertTemplate ::= SEQUENCE {
  274. * version [0] Version OPTIONAL,
  275. * serialNumber [1] INTEGER OPTIONAL,
  276. * signingAlg [2] AlgorithmIdentifier OPTIONAL,
  277. * issuer [3] Name OPTIONAL,
  278. * validity [4] OptionalValidity OPTIONAL,
  279. * subject [5] Name OPTIONAL,
  280. * publicKey [6] SubjectPublicKeyInfo OPTIONAL,
  281. * issuerUID [7] UniqueIdentifier OPTIONAL,
  282. * subjectUID [8] UniqueIdentifier OPTIONAL,
  283. * extensions [9] Extensions OPTIONAL
  284. * }
  285. */
  286. struct ossl_crmf_certtemplate_st {
  287. ASN1_INTEGER *version;
  288. ASN1_INTEGER *serialNumber; /* serialNumber MUST be omitted */
  289. /* This field is assigned by the CA during certificate creation */
  290. X509_ALGOR *signingAlg; /* signingAlg MUST be omitted */
  291. /* This field is assigned by the CA during certificate creation */
  292. const X509_NAME *issuer;
  293. OSSL_CRMF_OPTIONALVALIDITY *validity;
  294. const X509_NAME *subject;
  295. X509_PUBKEY *publicKey;
  296. ASN1_BIT_STRING *issuerUID; /* deprecated in version 2 */
  297. /* According to rfc 3280: UniqueIdentifier ::= BIT STRING */
  298. ASN1_BIT_STRING *subjectUID; /* deprecated in version 2 */
  299. /* Could be X509_EXTENSION*S*, but that's only cosmetic */
  300. STACK_OF(X509_EXTENSION) *extensions;
  301. } /* OSSL_CRMF_CERTTEMPLATE */;
  302. /*-
  303. * CertRequest ::= SEQUENCE {
  304. * certReqId INTEGER, -- ID for matching request and reply
  305. * certTemplate CertTemplate, -- Selected fields of cert to be issued
  306. * controls Controls OPTIONAL -- Attributes affecting issuance
  307. * }
  308. */
  309. struct ossl_crmf_certrequest_st {
  310. ASN1_INTEGER *certReqId;
  311. OSSL_CRMF_CERTTEMPLATE *certTemplate;
  312. STACK_OF(OSSL_CRMF_ATTRIBUTETYPEANDVALUE /* Controls expanded */) *controls;
  313. } /* OSSL_CRMF_CERTREQUEST */;
  314. DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_CERTREQUEST)
  315. DECLARE_ASN1_DUP_FUNCTION(OSSL_CRMF_CERTREQUEST)
  316. struct ossl_crmf_attributetypeandvalue_st {
  317. ASN1_OBJECT *type;
  318. union {
  319. /* NID_id_regCtrl_regToken */
  320. ASN1_UTF8STRING *regToken;
  321. /* NID_id_regCtrl_authenticator */
  322. ASN1_UTF8STRING *authenticator;
  323. /* NID_id_regCtrl_pkiPublicationInfo */
  324. OSSL_CRMF_PKIPUBLICATIONINFO *pkiPublicationInfo;
  325. /* NID_id_regCtrl_oldCertID */
  326. OSSL_CRMF_CERTID *oldCertID;
  327. /* NID_id_regCtrl_protocolEncrKey */
  328. X509_PUBKEY *protocolEncrKey;
  329. /* NID_id_regInfo_utf8Pairs */
  330. ASN1_UTF8STRING *utf8Pairs;
  331. /* NID_id_regInfo_certReq */
  332. OSSL_CRMF_CERTREQUEST *certReq;
  333. ASN1_TYPE *other;
  334. } value;
  335. } /* OSSL_CRMF_ATTRIBUTETYPEANDVALUE */;
  336. DECLARE_ASN1_FUNCTIONS(OSSL_CRMF_ATTRIBUTETYPEANDVALUE)
  337. DEFINE_STACK_OF(OSSL_CRMF_ATTRIBUTETYPEANDVALUE)
  338. DECLARE_ASN1_DUP_FUNCTION(OSSL_CRMF_ATTRIBUTETYPEANDVALUE)
  339. /*-
  340. * CertReqMessages ::= SEQUENCE SIZE (1..MAX) OF CertReqMsg
  341. * CertReqMsg ::= SEQUENCE {
  342. * certReq CertRequest,
  343. * popo ProofOfPossession OPTIONAL,
  344. * -- content depends upon key type
  345. * regInfo SEQUENCE SIZE(1..MAX) OF AttributeTypeAndValue OPTIONAL
  346. * }
  347. */
  348. struct ossl_crmf_msg_st {
  349. OSSL_CRMF_CERTREQUEST *certReq;
  350. /* 0 */
  351. OSSL_CRMF_POPO *popo;
  352. /* 1 */
  353. STACK_OF(OSSL_CRMF_ATTRIBUTETYPEANDVALUE) *regInfo;
  354. } /* OSSL_CRMF_MSG */;
  355. #endif