Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rfc6402.py 15KB

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