rfc6402.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. # coding: utf-8
  2. #
  3. # This file is part of pyasn1-modules software.
  4. #
  5. # Created by Stanisław Pitucha with asn1ate tool.
  6. # Copyright (c) 2005-2017, Ilya Etingof <etingof@gmail.com>
  7. # License: http://pyasn1.sf.net/license.html
  8. #
  9. # Certificate Management over CMS (CMC) Updates
  10. #
  11. # ASN.1 source from:
  12. # http://www.ietf.org/rfc/rfc6402.txt
  13. #
  14. from pyasn1.type import univ, char, namedtype, namedval, tag, constraint, useful
  15. from pyasn1_modules import rfc4211
  16. from pyasn1_modules import rfc5280
  17. from pyasn1_modules import rfc5652
  18. MAX = 64
  19. def _buildOid(*components):
  20. output = []
  21. for x in tuple(components):
  22. if isinstance(x, univ.ObjectIdentifier):
  23. output.extend(list(x))
  24. else:
  25. output.append(int(x))
  26. return univ.ObjectIdentifier(output)
  27. class ChangeSubjectName(univ.Sequence):
  28. pass
  29. ChangeSubjectName.componentType = namedtype.NamedTypes(
  30. namedtype.OptionalNamedType('subject', rfc5280.Name()),
  31. namedtype.OptionalNamedType('subjectAlt', rfc5280.GeneralNames())
  32. )
  33. class AttributeValue(univ.Any):
  34. pass
  35. class CMCStatus(univ.Integer):
  36. pass
  37. CMCStatus.namedValues = namedval.NamedValues(
  38. ('success', 0),
  39. ('failed', 2),
  40. ('pending', 3),
  41. ('noSupport', 4),
  42. ('confirmRequired', 5),
  43. ('popRequired', 6),
  44. ('partial', 7)
  45. )
  46. class PendInfo(univ.Sequence):
  47. pass
  48. PendInfo.componentType = namedtype.NamedTypes(
  49. namedtype.NamedType('pendToken', univ.OctetString()),
  50. namedtype.NamedType('pendTime', useful.GeneralizedTime())
  51. )
  52. bodyIdMax = univ.Integer(4294967295)
  53. class BodyPartID(univ.Integer):
  54. pass
  55. BodyPartID.subtypeSpec = constraint.ValueRangeConstraint(0, bodyIdMax)
  56. class BodyPartPath(univ.SequenceOf):
  57. pass
  58. BodyPartPath.componentType = BodyPartID()
  59. BodyPartPath.subtypeSpec = constraint.ValueSizeConstraint(1, MAX)
  60. class BodyPartReference(univ.Choice):
  61. pass
  62. BodyPartReference.componentType = namedtype.NamedTypes(
  63. namedtype.NamedType('bodyPartID', BodyPartID()),
  64. namedtype.NamedType('bodyPartPath', BodyPartPath())
  65. )
  66. class CMCFailInfo(univ.Integer):
  67. pass
  68. CMCFailInfo.namedValues = namedval.NamedValues(
  69. ('badAlg', 0),
  70. ('badMessageCheck', 1),
  71. ('badRequest', 2),
  72. ('badTime', 3),
  73. ('badCertId', 4),
  74. ('unsupportedExt', 5),
  75. ('mustArchiveKeys', 6),
  76. ('badIdentity', 7),
  77. ('popRequired', 8),
  78. ('popFailed', 9),
  79. ('noKeyReuse', 10),
  80. ('internalCAError', 11),
  81. ('tryLater', 12),
  82. ('authDataFail', 13)
  83. )
  84. class CMCStatusInfoV2(univ.Sequence):
  85. pass
  86. CMCStatusInfoV2.componentType = namedtype.NamedTypes(
  87. namedtype.NamedType('cMCStatus', CMCStatus()),
  88. namedtype.NamedType('bodyList', univ.SequenceOf(componentType=BodyPartReference())),
  89. namedtype.OptionalNamedType('statusString', char.UTF8String()),
  90. namedtype.OptionalNamedType(
  91. 'otherInfo', univ.Choice(
  92. componentType=namedtype.NamedTypes(
  93. namedtype.NamedType('failInfo', CMCFailInfo()),
  94. namedtype.NamedType('pendInfo', PendInfo()),
  95. namedtype.NamedType(
  96. 'extendedFailInfo', univ.Sequence(
  97. componentType=namedtype.NamedTypes(
  98. namedtype.NamedType('failInfoOID', univ.ObjectIdentifier()),
  99. namedtype.NamedType('failInfoValue', AttributeValue()))
  100. )
  101. )
  102. )
  103. )
  104. )
  105. )
  106. class GetCRL(univ.Sequence):
  107. pass
  108. GetCRL.componentType = namedtype.NamedTypes(
  109. namedtype.NamedType('issuerName', rfc5280.Name()),
  110. namedtype.OptionalNamedType('cRLName', rfc5280.GeneralName()),
  111. namedtype.OptionalNamedType('time', useful.GeneralizedTime()),
  112. namedtype.OptionalNamedType('reasons', rfc5280.ReasonFlags())
  113. )
  114. id_pkix = _buildOid(1, 3, 6, 1, 5, 5, 7)
  115. id_cmc = _buildOid(id_pkix, 7)
  116. id_cmc_batchResponses = _buildOid(id_cmc, 29)
  117. id_cmc_popLinkWitness = _buildOid(id_cmc, 23)
  118. class PopLinkWitnessV2(univ.Sequence):
  119. pass
  120. PopLinkWitnessV2.componentType = namedtype.NamedTypes(
  121. namedtype.NamedType('keyGenAlgorithm', rfc5280.AlgorithmIdentifier()),
  122. namedtype.NamedType('macAlgorithm', rfc5280.AlgorithmIdentifier()),
  123. namedtype.NamedType('witness', univ.OctetString())
  124. )
  125. id_cmc_popLinkWitnessV2 = _buildOid(id_cmc, 33)
  126. id_cmc_identityProofV2 = _buildOid(id_cmc, 34)
  127. id_cmc_revokeRequest = _buildOid(id_cmc, 17)
  128. id_cmc_recipientNonce = _buildOid(id_cmc, 7)
  129. class ControlsProcessed(univ.Sequence):
  130. pass
  131. ControlsProcessed.componentType = namedtype.NamedTypes(
  132. namedtype.NamedType('bodyList', univ.SequenceOf(componentType=BodyPartReference()))
  133. )
  134. class CertificationRequest(univ.Sequence):
  135. pass
  136. CertificationRequest.componentType = namedtype.NamedTypes(
  137. namedtype.NamedType(
  138. 'certificationRequestInfo', univ.Sequence(
  139. componentType=namedtype.NamedTypes(
  140. namedtype.NamedType('version', univ.Integer()),
  141. namedtype.NamedType('subject', rfc5280.Name()),
  142. namedtype.NamedType(
  143. 'subjectPublicKeyInfo', univ.Sequence(
  144. componentType=namedtype.NamedTypes(
  145. namedtype.NamedType('algorithm', rfc5280.AlgorithmIdentifier()),
  146. namedtype.NamedType('subjectPublicKey', univ.BitString())
  147. )
  148. )
  149. ),
  150. namedtype.NamedType(
  151. 'attributes', univ.SetOf(
  152. componentType=rfc5652.Attribute()).subtype(
  153. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))
  154. )
  155. )
  156. )
  157. ),
  158. namedtype.NamedType('signatureAlgorithm', rfc5280.AlgorithmIdentifier()),
  159. namedtype.NamedType('signature', univ.BitString())
  160. )
  161. class TaggedCertificationRequest(univ.Sequence):
  162. pass
  163. TaggedCertificationRequest.componentType = namedtype.NamedTypes(
  164. namedtype.NamedType('bodyPartID', BodyPartID()),
  165. namedtype.NamedType('certificationRequest', CertificationRequest())
  166. )
  167. class TaggedRequest(univ.Choice):
  168. pass
  169. TaggedRequest.componentType = namedtype.NamedTypes(
  170. namedtype.NamedType('tcr', TaggedCertificationRequest().subtype(
  171. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
  172. namedtype.NamedType('crm',
  173. rfc4211.CertReqMsg().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
  174. namedtype.NamedType('orm', univ.Sequence(componentType=namedtype.NamedTypes(
  175. namedtype.NamedType('bodyPartID', BodyPartID()),
  176. namedtype.NamedType('requestMessageType', univ.ObjectIdentifier()),
  177. namedtype.NamedType('requestMessageValue', univ.Any())
  178. ))
  179. .subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2)))
  180. )
  181. id_cmc_popLinkRandom = _buildOid(id_cmc, 22)
  182. id_cmc_statusInfo = _buildOid(id_cmc, 1)
  183. id_cmc_trustedAnchors = _buildOid(id_cmc, 26)
  184. id_cmc_transactionId = _buildOid(id_cmc, 5)
  185. id_cmc_encryptedPOP = _buildOid(id_cmc, 9)
  186. class PublishTrustAnchors(univ.Sequence):
  187. pass
  188. PublishTrustAnchors.componentType = namedtype.NamedTypes(
  189. namedtype.NamedType('seqNumber', univ.Integer()),
  190. namedtype.NamedType('hashAlgorithm', rfc5280.AlgorithmIdentifier()),
  191. namedtype.NamedType('anchorHashes', univ.SequenceOf(componentType=univ.OctetString()))
  192. )
  193. class RevokeRequest(univ.Sequence):
  194. pass
  195. RevokeRequest.componentType = namedtype.NamedTypes(
  196. namedtype.NamedType('issuerName', rfc5280.Name()),
  197. namedtype.NamedType('serialNumber', univ.Integer()),
  198. namedtype.NamedType('reason', rfc5280.CRLReason()),
  199. namedtype.OptionalNamedType('invalidityDate', useful.GeneralizedTime()),
  200. namedtype.OptionalNamedType('passphrase', univ.OctetString()),
  201. namedtype.OptionalNamedType('comment', char.UTF8String())
  202. )
  203. id_cmc_senderNonce = _buildOid(id_cmc, 6)
  204. id_cmc_authData = _buildOid(id_cmc, 27)
  205. class TaggedContentInfo(univ.Sequence):
  206. pass
  207. TaggedContentInfo.componentType = namedtype.NamedTypes(
  208. namedtype.NamedType('bodyPartID', BodyPartID()),
  209. namedtype.NamedType('contentInfo', rfc5652.ContentInfo())
  210. )
  211. class IdentifyProofV2(univ.Sequence):
  212. pass
  213. IdentifyProofV2.componentType = namedtype.NamedTypes(
  214. namedtype.NamedType('proofAlgID', rfc5280.AlgorithmIdentifier()),
  215. namedtype.NamedType('macAlgId', rfc5280.AlgorithmIdentifier()),
  216. namedtype.NamedType('witness', univ.OctetString())
  217. )
  218. class CMCPublicationInfo(univ.Sequence):
  219. pass
  220. CMCPublicationInfo.componentType = namedtype.NamedTypes(
  221. namedtype.NamedType('hashAlg', rfc5280.AlgorithmIdentifier()),
  222. namedtype.NamedType('certHashes', univ.SequenceOf(componentType=univ.OctetString())),
  223. namedtype.NamedType('pubInfo', rfc4211.PKIPublicationInfo())
  224. )
  225. id_kp_cmcCA = _buildOid(rfc5280.id_kp, 27)
  226. id_cmc_confirmCertAcceptance = _buildOid(id_cmc, 24)
  227. id_cmc_raIdentityWitness = _buildOid(id_cmc, 35)
  228. id_ExtensionReq = _buildOid(1, 2, 840, 113549, 1, 9, 14)
  229. id_cct = _buildOid(id_pkix, 12)
  230. id_cct_PKIData = _buildOid(id_cct, 2)
  231. id_kp_cmcRA = _buildOid(rfc5280.id_kp, 28)
  232. class CMCStatusInfo(univ.Sequence):
  233. pass
  234. CMCStatusInfo.componentType = namedtype.NamedTypes(
  235. namedtype.NamedType('cMCStatus', CMCStatus()),
  236. namedtype.NamedType('bodyList', univ.SequenceOf(componentType=BodyPartID())),
  237. namedtype.OptionalNamedType('statusString', char.UTF8String()),
  238. namedtype.OptionalNamedType(
  239. 'otherInfo', univ.Choice(
  240. componentType=namedtype.NamedTypes(
  241. namedtype.NamedType('failInfo', CMCFailInfo()),
  242. namedtype.NamedType('pendInfo', PendInfo())
  243. )
  244. )
  245. )
  246. )
  247. class DecryptedPOP(univ.Sequence):
  248. pass
  249. DecryptedPOP.componentType = namedtype.NamedTypes(
  250. namedtype.NamedType('bodyPartID', BodyPartID()),
  251. namedtype.NamedType('thePOPAlgID', rfc5280.AlgorithmIdentifier()),
  252. namedtype.NamedType('thePOP', univ.OctetString())
  253. )
  254. id_cmc_addExtensions = _buildOid(id_cmc, 8)
  255. id_cmc_modCertTemplate = _buildOid(id_cmc, 31)
  256. class TaggedAttribute(univ.Sequence):
  257. pass
  258. TaggedAttribute.componentType = namedtype.NamedTypes(
  259. namedtype.NamedType('bodyPartID', BodyPartID()),
  260. namedtype.NamedType('attrType', univ.ObjectIdentifier()),
  261. namedtype.NamedType('attrValues', univ.SetOf(componentType=AttributeValue()))
  262. )
  263. class OtherMsg(univ.Sequence):
  264. pass
  265. OtherMsg.componentType = namedtype.NamedTypes(
  266. namedtype.NamedType('bodyPartID', BodyPartID()),
  267. namedtype.NamedType('otherMsgType', univ.ObjectIdentifier()),
  268. namedtype.NamedType('otherMsgValue', univ.Any())
  269. )
  270. class PKIData(univ.Sequence):
  271. pass
  272. PKIData.componentType = namedtype.NamedTypes(
  273. namedtype.NamedType('controlSequence', univ.SequenceOf(componentType=TaggedAttribute())),
  274. namedtype.NamedType('reqSequence', univ.SequenceOf(componentType=TaggedRequest())),
  275. namedtype.NamedType('cmsSequence', univ.SequenceOf(componentType=TaggedContentInfo())),
  276. namedtype.NamedType('otherMsgSequence', univ.SequenceOf(componentType=OtherMsg()))
  277. )
  278. class BodyPartList(univ.SequenceOf):
  279. pass
  280. BodyPartList.componentType = BodyPartID()
  281. BodyPartList.subtypeSpec = constraint.ValueSizeConstraint(1, MAX)
  282. id_cmc_responseBody = _buildOid(id_cmc, 37)
  283. class AuthPublish(BodyPartID):
  284. pass
  285. class CMCUnsignedData(univ.Sequence):
  286. pass
  287. CMCUnsignedData.componentType = namedtype.NamedTypes(
  288. namedtype.NamedType('bodyPartPath', BodyPartPath()),
  289. namedtype.NamedType('identifier', univ.ObjectIdentifier()),
  290. namedtype.NamedType('content', univ.Any())
  291. )
  292. class CMCCertId(rfc5652.IssuerAndSerialNumber):
  293. pass
  294. class PKIResponse(univ.Sequence):
  295. pass
  296. PKIResponse.componentType = namedtype.NamedTypes(
  297. namedtype.NamedType('controlSequence', univ.SequenceOf(componentType=TaggedAttribute())),
  298. namedtype.NamedType('cmsSequence', univ.SequenceOf(componentType=TaggedContentInfo())),
  299. namedtype.NamedType('otherMsgSequence', univ.SequenceOf(componentType=OtherMsg()))
  300. )
  301. class ResponseBody(PKIResponse):
  302. pass
  303. id_cmc_statusInfoV2 = _buildOid(id_cmc, 25)
  304. id_cmc_lraPOPWitness = _buildOid(id_cmc, 11)
  305. class ModCertTemplate(univ.Sequence):
  306. pass
  307. ModCertTemplate.componentType = namedtype.NamedTypes(
  308. namedtype.NamedType('pkiDataReference', BodyPartPath()),
  309. namedtype.NamedType('certReferences', BodyPartList()),
  310. namedtype.DefaultedNamedType('replace', univ.Boolean().subtype(value=1)),
  311. namedtype.NamedType('certTemplate', rfc4211.CertTemplate())
  312. )
  313. id_cmc_regInfo = _buildOid(id_cmc, 18)
  314. id_cmc_identityProof = _buildOid(id_cmc, 3)
  315. class ExtensionReq(univ.SequenceOf):
  316. pass
  317. ExtensionReq.componentType = rfc5280.Extension()
  318. ExtensionReq.subtypeSpec = constraint.ValueSizeConstraint(1, MAX)
  319. id_kp_cmcArchive = _buildOid(rfc5280.id_kp, 28)
  320. id_cmc_publishCert = _buildOid(id_cmc, 30)
  321. id_cmc_dataReturn = _buildOid(id_cmc, 4)
  322. class LraPopWitness(univ.Sequence):
  323. pass
  324. LraPopWitness.componentType = namedtype.NamedTypes(
  325. namedtype.NamedType('pkiDataBodyid', BodyPartID()),
  326. namedtype.NamedType('bodyIds', univ.SequenceOf(componentType=BodyPartID()))
  327. )
  328. id_aa = _buildOid(1, 2, 840, 113549, 1, 9, 16, 2)
  329. id_aa_cmc_unsignedData = _buildOid(id_aa, 34)
  330. id_cmc_getCert = _buildOid(id_cmc, 15)
  331. id_cmc_batchRequests = _buildOid(id_cmc, 28)
  332. id_cmc_decryptedPOP = _buildOid(id_cmc, 10)
  333. id_cmc_responseInfo = _buildOid(id_cmc, 19)
  334. id_cmc_changeSubjectName = _buildOid(id_cmc, 36)
  335. class GetCert(univ.Sequence):
  336. pass
  337. GetCert.componentType = namedtype.NamedTypes(
  338. namedtype.NamedType('issuerName', rfc5280.GeneralName()),
  339. namedtype.NamedType('serialNumber', univ.Integer())
  340. )
  341. id_cmc_identification = _buildOid(id_cmc, 2)
  342. id_cmc_queryPending = _buildOid(id_cmc, 21)
  343. class AddExtensions(univ.Sequence):
  344. pass
  345. AddExtensions.componentType = namedtype.NamedTypes(
  346. namedtype.NamedType('pkiDataReference', BodyPartID()),
  347. namedtype.NamedType('certReferences', univ.SequenceOf(componentType=BodyPartID())),
  348. namedtype.NamedType('extensions', univ.SequenceOf(componentType=rfc5280.Extension()))
  349. )
  350. class EncryptedPOP(univ.Sequence):
  351. pass
  352. EncryptedPOP.componentType = namedtype.NamedTypes(
  353. namedtype.NamedType('request', TaggedRequest()),
  354. namedtype.NamedType('cms', rfc5652.ContentInfo()),
  355. namedtype.NamedType('thePOPAlgID', rfc5280.AlgorithmIdentifier()),
  356. namedtype.NamedType('witnessAlgID', rfc5280.AlgorithmIdentifier()),
  357. namedtype.NamedType('witness', univ.OctetString())
  358. )
  359. id_cmc_getCRL = _buildOid(id_cmc, 16)
  360. id_cct_PKIResponse = _buildOid(id_cct, 3)
  361. id_cmc_controlProcessed = _buildOid(id_cmc, 32)
  362. class NoSignatureValue(univ.OctetString):
  363. pass
  364. id_ad_cmc = _buildOid(rfc5280.id_ad, 12)
  365. id_alg_noSignature = _buildOid(id_pkix, 6, 2)