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.

rfc4210.py 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. #
  2. # This file is part of pyasn1-modules software.
  3. #
  4. # Copyright (c) 2005-2018, Ilya Etingof <etingof@gmail.com>
  5. # License: http://snmplabs.com/pyasn1/license.html
  6. #
  7. # Certificate Management Protocol structures as per RFC4210
  8. #
  9. # Based on Alex Railean's work
  10. #
  11. from pyasn1.type import char
  12. from pyasn1.type import constraint
  13. from pyasn1.type import namedtype
  14. from pyasn1.type import namedval
  15. from pyasn1.type import tag
  16. from pyasn1.type import univ
  17. from pyasn1.type import useful
  18. from pyasn1_modules import rfc2314
  19. from pyasn1_modules import rfc2459
  20. from pyasn1_modules import rfc2511
  21. MAX = float('inf')
  22. class KeyIdentifier(univ.OctetString):
  23. pass
  24. class CMPCertificate(rfc2459.Certificate):
  25. pass
  26. class OOBCert(CMPCertificate):
  27. pass
  28. class CertAnnContent(CMPCertificate):
  29. pass
  30. class PKIFreeText(univ.SequenceOf):
  31. """
  32. PKIFreeText ::= SEQUENCE SIZE (1..MAX) OF UTF8String
  33. """
  34. componentType = char.UTF8String()
  35. subtypeSpec = univ.SequenceOf.subtypeSpec + constraint.ValueSizeConstraint(1, MAX)
  36. class PollRepContent(univ.SequenceOf):
  37. """
  38. PollRepContent ::= SEQUENCE OF SEQUENCE {
  39. certReqId INTEGER,
  40. checkAfter INTEGER, -- time in seconds
  41. reason PKIFreeText OPTIONAL
  42. }
  43. """
  44. class CertReq(univ.Sequence):
  45. componentType = namedtype.NamedTypes(
  46. namedtype.NamedType('certReqId', univ.Integer()),
  47. namedtype.NamedType('checkAfter', univ.Integer()),
  48. namedtype.OptionalNamedType('reason', PKIFreeText())
  49. )
  50. componentType = CertReq()
  51. class PollReqContent(univ.SequenceOf):
  52. """
  53. PollReqContent ::= SEQUENCE OF SEQUENCE {
  54. certReqId INTEGER
  55. }
  56. """
  57. class CertReq(univ.Sequence):
  58. componentType = namedtype.NamedTypes(
  59. namedtype.NamedType('certReqId', univ.Integer())
  60. )
  61. componentType = CertReq()
  62. class InfoTypeAndValue(univ.Sequence):
  63. """
  64. InfoTypeAndValue ::= SEQUENCE {
  65. infoType OBJECT IDENTIFIER,
  66. infoValue ANY DEFINED BY infoType OPTIONAL
  67. }"""
  68. componentType = namedtype.NamedTypes(
  69. namedtype.NamedType('infoType', univ.ObjectIdentifier()),
  70. namedtype.OptionalNamedType('infoValue', univ.Any())
  71. )
  72. class GenRepContent(univ.SequenceOf):
  73. componentType = InfoTypeAndValue()
  74. class GenMsgContent(univ.SequenceOf):
  75. componentType = InfoTypeAndValue()
  76. class PKIConfirmContent(univ.Null):
  77. pass
  78. class CRLAnnContent(univ.SequenceOf):
  79. componentType = rfc2459.CertificateList()
  80. class CAKeyUpdAnnContent(univ.Sequence):
  81. """
  82. CAKeyUpdAnnContent ::= SEQUENCE {
  83. oldWithNew CMPCertificate,
  84. newWithOld CMPCertificate,
  85. newWithNew CMPCertificate
  86. }
  87. """
  88. componentType = namedtype.NamedTypes(
  89. namedtype.NamedType('oldWithNew', CMPCertificate()),
  90. namedtype.NamedType('newWithOld', CMPCertificate()),
  91. namedtype.NamedType('newWithNew', CMPCertificate())
  92. )
  93. class RevDetails(univ.Sequence):
  94. """
  95. RevDetails ::= SEQUENCE {
  96. certDetails CertTemplate,
  97. crlEntryDetails Extensions OPTIONAL
  98. }
  99. """
  100. componentType = namedtype.NamedTypes(
  101. namedtype.NamedType('certDetails', rfc2511.CertTemplate()),
  102. namedtype.OptionalNamedType('crlEntryDetails', rfc2459.Extensions())
  103. )
  104. class RevReqContent(univ.SequenceOf):
  105. componentType = RevDetails()
  106. class CertOrEncCert(univ.Choice):
  107. """
  108. CertOrEncCert ::= CHOICE {
  109. certificate [0] CMPCertificate,
  110. encryptedCert [1] EncryptedValue
  111. }
  112. """
  113. componentType = namedtype.NamedTypes(
  114. namedtype.NamedType('certificate', CMPCertificate().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
  115. namedtype.NamedType('encryptedCert', rfc2511.EncryptedValue().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1)))
  116. )
  117. class CertifiedKeyPair(univ.Sequence):
  118. """
  119. CertifiedKeyPair ::= SEQUENCE {
  120. certOrEncCert CertOrEncCert,
  121. privateKey [0] EncryptedValue OPTIONAL,
  122. publicationInfo [1] PKIPublicationInfo OPTIONAL
  123. }
  124. """
  125. componentType = namedtype.NamedTypes(
  126. namedtype.NamedType('certOrEncCert', CertOrEncCert()),
  127. namedtype.OptionalNamedType('privateKey', rfc2511.EncryptedValue().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
  128. namedtype.OptionalNamedType('publicationInfo', rfc2511.PKIPublicationInfo().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1)))
  129. )
  130. class POPODecKeyRespContent(univ.SequenceOf):
  131. componentType = univ.Integer()
  132. class Challenge(univ.Sequence):
  133. """
  134. Challenge ::= SEQUENCE {
  135. owf AlgorithmIdentifier OPTIONAL,
  136. witness OCTET STRING,
  137. challenge OCTET STRING
  138. }
  139. """
  140. componentType = namedtype.NamedTypes(
  141. namedtype.OptionalNamedType('owf', rfc2459.AlgorithmIdentifier()),
  142. namedtype.NamedType('witness', univ.OctetString()),
  143. namedtype.NamedType('challenge', univ.OctetString())
  144. )
  145. class PKIStatus(univ.Integer):
  146. """
  147. PKIStatus ::= INTEGER {
  148. accepted (0),
  149. grantedWithMods (1),
  150. rejection (2),
  151. waiting (3),
  152. revocationWarning (4),
  153. revocationNotification (5),
  154. keyUpdateWarning (6)
  155. }
  156. """
  157. namedValues = namedval.NamedValues(
  158. ('accepted', 0),
  159. ('grantedWithMods', 1),
  160. ('rejection', 2),
  161. ('waiting', 3),
  162. ('revocationWarning', 4),
  163. ('revocationNotification', 5),
  164. ('keyUpdateWarning', 6)
  165. )
  166. class PKIFailureInfo(univ.BitString):
  167. """
  168. PKIFailureInfo ::= BIT STRING {
  169. badAlg (0),
  170. badMessageCheck (1),
  171. badRequest (2),
  172. badTime (3),
  173. badCertId (4),
  174. badDataFormat (5),
  175. wrongAuthority (6),
  176. incorrectData (7),
  177. missingTimeStamp (8),
  178. badPOP (9),
  179. certRevoked (10),
  180. certConfirmed (11),
  181. wrongIntegrity (12),
  182. badRecipientNonce (13),
  183. timeNotAvailable (14),
  184. unacceptedPolicy (15),
  185. unacceptedExtension (16),
  186. addInfoNotAvailable (17),
  187. badSenderNonce (18),
  188. badCertTemplate (19),
  189. signerNotTrusted (20),
  190. transactionIdInUse (21),
  191. unsupportedVersion (22),
  192. notAuthorized (23),
  193. systemUnavail (24),
  194. systemFailure (25),
  195. duplicateCertReq (26)
  196. """
  197. namedValues = namedval.NamedValues(
  198. ('badAlg', 0),
  199. ('badMessageCheck', 1),
  200. ('badRequest', 2),
  201. ('badTime', 3),
  202. ('badCertId', 4),
  203. ('badDataFormat', 5),
  204. ('wrongAuthority', 6),
  205. ('incorrectData', 7),
  206. ('missingTimeStamp', 8),
  207. ('badPOP', 9),
  208. ('certRevoked', 10),
  209. ('certConfirmed', 11),
  210. ('wrongIntegrity', 12),
  211. ('badRecipientNonce', 13),
  212. ('timeNotAvailable', 14),
  213. ('unacceptedPolicy', 15),
  214. ('unacceptedExtension', 16),
  215. ('addInfoNotAvailable', 17),
  216. ('badSenderNonce', 18),
  217. ('badCertTemplate', 19),
  218. ('signerNotTrusted', 20),
  219. ('transactionIdInUse', 21),
  220. ('unsupportedVersion', 22),
  221. ('notAuthorized', 23),
  222. ('systemUnavail', 24),
  223. ('systemFailure', 25),
  224. ('duplicateCertReq', 26)
  225. )
  226. class PKIStatusInfo(univ.Sequence):
  227. """
  228. PKIStatusInfo ::= SEQUENCE {
  229. status PKIStatus,
  230. statusString PKIFreeText OPTIONAL,
  231. failInfo PKIFailureInfo OPTIONAL
  232. }
  233. """
  234. componentType = namedtype.NamedTypes(
  235. namedtype.NamedType('status', PKIStatus()),
  236. namedtype.OptionalNamedType('statusString', PKIFreeText()),
  237. namedtype.OptionalNamedType('failInfo', PKIFailureInfo())
  238. )
  239. class ErrorMsgContent(univ.Sequence):
  240. """
  241. ErrorMsgContent ::= SEQUENCE {
  242. pKIStatusInfo PKIStatusInfo,
  243. errorCode INTEGER OPTIONAL,
  244. -- implementation-specific error codes
  245. errorDetails PKIFreeText OPTIONAL
  246. -- implementation-specific error details
  247. }
  248. """
  249. componentType = namedtype.NamedTypes(
  250. namedtype.NamedType('pKIStatusInfo', PKIStatusInfo()),
  251. namedtype.OptionalNamedType('errorCode', univ.Integer()),
  252. namedtype.OptionalNamedType('errorDetails', PKIFreeText())
  253. )
  254. class CertStatus(univ.Sequence):
  255. """
  256. CertStatus ::= SEQUENCE {
  257. certHash OCTET STRING,
  258. certReqId INTEGER,
  259. statusInfo PKIStatusInfo OPTIONAL
  260. }
  261. """
  262. componentType = namedtype.NamedTypes(
  263. namedtype.NamedType('certHash', univ.OctetString()),
  264. namedtype.NamedType('certReqId', univ.Integer()),
  265. namedtype.OptionalNamedType('statusInfo', PKIStatusInfo())
  266. )
  267. class CertConfirmContent(univ.SequenceOf):
  268. componentType = CertStatus()
  269. class RevAnnContent(univ.Sequence):
  270. """
  271. RevAnnContent ::= SEQUENCE {
  272. status PKIStatus,
  273. certId CertId,
  274. willBeRevokedAt GeneralizedTime,
  275. badSinceDate GeneralizedTime,
  276. crlDetails Extensions OPTIONAL
  277. }
  278. """
  279. componentType = namedtype.NamedTypes(
  280. namedtype.NamedType('status', PKIStatus()),
  281. namedtype.NamedType('certId', rfc2511.CertId()),
  282. namedtype.NamedType('willBeRevokedAt', useful.GeneralizedTime()),
  283. namedtype.NamedType('badSinceDate', useful.GeneralizedTime()),
  284. namedtype.OptionalNamedType('crlDetails', rfc2459.Extensions())
  285. )
  286. class RevRepContent(univ.Sequence):
  287. """
  288. RevRepContent ::= SEQUENCE {
  289. status SEQUENCE SIZE (1..MAX) OF PKIStatusInfo,
  290. revCerts [0] SEQUENCE SIZE (1..MAX) OF CertId
  291. OPTIONAL,
  292. crls [1] SEQUENCE SIZE (1..MAX) OF CertificateList
  293. OPTIONAL
  294. """
  295. componentType = namedtype.NamedTypes(
  296. namedtype.NamedType('status', PKIStatusInfo()),
  297. namedtype.OptionalNamedType(
  298. 'revCerts', univ.SequenceOf(componentType=rfc2511.CertId()).subtype(
  299. subtypeSpec=constraint.ValueSizeConstraint(1, MAX),
  300. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0)
  301. )
  302. ),
  303. namedtype.OptionalNamedType(
  304. 'crls', univ.SequenceOf(componentType=rfc2459.CertificateList()).subtype(
  305. subtypeSpec=constraint.ValueSizeConstraint(1, MAX),
  306. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1)
  307. )
  308. )
  309. )
  310. class KeyRecRepContent(univ.Sequence):
  311. """
  312. KeyRecRepContent ::= SEQUENCE {
  313. status PKIStatusInfo,
  314. newSigCert [0] CMPCertificate OPTIONAL,
  315. caCerts [1] SEQUENCE SIZE (1..MAX) OF
  316. CMPCertificate OPTIONAL,
  317. keyPairHist [2] SEQUENCE SIZE (1..MAX) OF
  318. CertifiedKeyPair OPTIONAL
  319. }
  320. """
  321. componentType = namedtype.NamedTypes(
  322. namedtype.NamedType('status', PKIStatusInfo()),
  323. namedtype.OptionalNamedType(
  324. 'newSigCert', CMPCertificate().subtype(
  325. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0)
  326. )
  327. ),
  328. namedtype.OptionalNamedType(
  329. 'caCerts', univ.SequenceOf(componentType=CMPCertificate()).subtype(
  330. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1),
  331. subtypeSpec=constraint.ValueSizeConstraint(1, MAX)
  332. )
  333. ),
  334. namedtype.OptionalNamedType('keyPairHist', univ.SequenceOf(componentType=CertifiedKeyPair()).subtype(
  335. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2),
  336. subtypeSpec=constraint.ValueSizeConstraint(1, MAX))
  337. )
  338. )
  339. class CertResponse(univ.Sequence):
  340. """
  341. CertResponse ::= SEQUENCE {
  342. certReqId INTEGER,
  343. status PKIStatusInfo,
  344. certifiedKeyPair CertifiedKeyPair OPTIONAL,
  345. rspInfo OCTET STRING OPTIONAL
  346. }
  347. """
  348. componentType = namedtype.NamedTypes(
  349. namedtype.NamedType('certReqId', univ.Integer()),
  350. namedtype.NamedType('status', PKIStatusInfo()),
  351. namedtype.OptionalNamedType('certifiedKeyPair', CertifiedKeyPair()),
  352. namedtype.OptionalNamedType('rspInfo', univ.OctetString())
  353. )
  354. class CertRepMessage(univ.Sequence):
  355. """
  356. CertRepMessage ::= SEQUENCE {
  357. caPubs [1] SEQUENCE SIZE (1..MAX) OF CMPCertificate
  358. OPTIONAL,
  359. response SEQUENCE OF CertResponse
  360. }
  361. """
  362. componentType = namedtype.NamedTypes(
  363. namedtype.OptionalNamedType(
  364. 'caPubs', univ.SequenceOf(
  365. componentType=CMPCertificate()
  366. ).subtype(subtypeSpec=constraint.ValueSizeConstraint(1, MAX), explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))
  367. ),
  368. namedtype.NamedType('response', univ.SequenceOf(componentType=CertResponse()))
  369. )
  370. class POPODecKeyChallContent(univ.SequenceOf):
  371. componentType = Challenge()
  372. class OOBCertHash(univ.Sequence):
  373. """
  374. OOBCertHash ::= SEQUENCE {
  375. hashAlg [0] AlgorithmIdentifier OPTIONAL,
  376. certId [1] CertId OPTIONAL,
  377. hashVal BIT STRING
  378. }
  379. """
  380. componentType = namedtype.NamedTypes(
  381. namedtype.OptionalNamedType(
  382. 'hashAlg', rfc2459.AlgorithmIdentifier().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))
  383. ),
  384. namedtype.OptionalNamedType(
  385. 'certId', rfc2511.CertId().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))
  386. ),
  387. namedtype.NamedType('hashVal', univ.BitString())
  388. )
  389. # pyasn1 does not naturally handle recursive definitions, thus this hack:
  390. # NestedMessageContent ::= PKIMessages
  391. class NestedMessageContent(univ.SequenceOf):
  392. """
  393. NestedMessageContent ::= PKIMessages
  394. """
  395. componentType = univ.Any()
  396. class DHBMParameter(univ.Sequence):
  397. """
  398. DHBMParameter ::= SEQUENCE {
  399. owf AlgorithmIdentifier,
  400. -- AlgId for a One-Way Function (SHA-1 recommended)
  401. mac AlgorithmIdentifier
  402. -- the MAC AlgId (e.g., DES-MAC, Triple-DES-MAC [PKCS11],
  403. } -- or HMAC [RFC2104, RFC2202])
  404. """
  405. componentType = namedtype.NamedTypes(
  406. namedtype.NamedType('owf', rfc2459.AlgorithmIdentifier()),
  407. namedtype.NamedType('mac', rfc2459.AlgorithmIdentifier())
  408. )
  409. id_DHBasedMac = univ.ObjectIdentifier('1.2.840.113533.7.66.30')
  410. class PBMParameter(univ.Sequence):
  411. """
  412. PBMParameter ::= SEQUENCE {
  413. salt OCTET STRING,
  414. owf AlgorithmIdentifier,
  415. iterationCount INTEGER,
  416. mac AlgorithmIdentifier
  417. }
  418. """
  419. componentType = namedtype.NamedTypes(
  420. namedtype.NamedType(
  421. 'salt', univ.OctetString().subtype(subtypeSpec=constraint.ValueSizeConstraint(0, 128))
  422. ),
  423. namedtype.NamedType('owf', rfc2459.AlgorithmIdentifier()),
  424. namedtype.NamedType('iterationCount', univ.Integer()),
  425. namedtype.NamedType('mac', rfc2459.AlgorithmIdentifier())
  426. )
  427. id_PasswordBasedMac = univ.ObjectIdentifier('1.2.840.113533.7.66.13')
  428. class PKIProtection(univ.BitString):
  429. pass
  430. # pyasn1 does not naturally handle recursive definitions, thus this hack:
  431. # NestedMessageContent ::= PKIMessages
  432. nestedMessageContent = NestedMessageContent().subtype(
  433. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 20))
  434. class PKIBody(univ.Choice):
  435. """
  436. PKIBody ::= CHOICE { -- message-specific body elements
  437. ir [0] CertReqMessages, --Initialization Request
  438. ip [1] CertRepMessage, --Initialization Response
  439. cr [2] CertReqMessages, --Certification Request
  440. cp [3] CertRepMessage, --Certification Response
  441. p10cr [4] CertificationRequest, --imported from [PKCS10]
  442. popdecc [5] POPODecKeyChallContent, --pop Challenge
  443. popdecr [6] POPODecKeyRespContent, --pop Response
  444. kur [7] CertReqMessages, --Key Update Request
  445. kup [8] CertRepMessage, --Key Update Response
  446. krr [9] CertReqMessages, --Key Recovery Request
  447. krp [10] KeyRecRepContent, --Key Recovery Response
  448. rr [11] RevReqContent, --Revocation Request
  449. rp [12] RevRepContent, --Revocation Response
  450. ccr [13] CertReqMessages, --Cross-Cert. Request
  451. ccp [14] CertRepMessage, --Cross-Cert. Response
  452. ckuann [15] CAKeyUpdAnnContent, --CA Key Update Ann.
  453. cann [16] CertAnnContent, --Certificate Ann.
  454. rann [17] RevAnnContent, --Revocation Ann.
  455. crlann [18] CRLAnnContent, --CRL Announcement
  456. pkiconf [19] PKIConfirmContent, --Confirmation
  457. nested [20] NestedMessageContent, --Nested Message
  458. genm [21] GenMsgContent, --General Message
  459. genp [22] GenRepContent, --General Response
  460. error [23] ErrorMsgContent, --Error Message
  461. certConf [24] CertConfirmContent, --Certificate confirm
  462. pollReq [25] PollReqContent, --Polling request
  463. pollRep [26] PollRepContent --Polling response
  464. """
  465. componentType = namedtype.NamedTypes(
  466. namedtype.NamedType(
  467. 'ir', rfc2511.CertReqMessages().subtype(
  468. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0)
  469. )
  470. ),
  471. namedtype.NamedType(
  472. 'ip', CertRepMessage().subtype(
  473. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1)
  474. )
  475. ),
  476. namedtype.NamedType(
  477. 'cr', rfc2511.CertReqMessages().subtype(
  478. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2)
  479. )
  480. ),
  481. namedtype.NamedType(
  482. 'cp', CertRepMessage().subtype(
  483. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3)
  484. )
  485. ),
  486. namedtype.NamedType(
  487. 'p10cr', rfc2314.CertificationRequest().subtype(
  488. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 4)
  489. )
  490. ),
  491. namedtype.NamedType(
  492. 'popdecc', POPODecKeyChallContent().subtype(
  493. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 5)
  494. )
  495. ),
  496. namedtype.NamedType(
  497. 'popdecr', POPODecKeyRespContent().subtype(
  498. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 6)
  499. )
  500. ),
  501. namedtype.NamedType(
  502. 'kur', rfc2511.CertReqMessages().subtype(
  503. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 7)
  504. )
  505. ),
  506. namedtype.NamedType(
  507. 'kup', CertRepMessage().subtype(
  508. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 8)
  509. )
  510. ),
  511. namedtype.NamedType(
  512. 'krr', rfc2511.CertReqMessages().subtype(
  513. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 9)
  514. )
  515. ),
  516. namedtype.NamedType(
  517. 'krp', KeyRecRepContent().subtype(
  518. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 10)
  519. )
  520. ),
  521. namedtype.NamedType(
  522. 'rr', RevReqContent().subtype(
  523. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 11)
  524. )
  525. ),
  526. namedtype.NamedType(
  527. 'rp', RevRepContent().subtype(
  528. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 12)
  529. )
  530. ),
  531. namedtype.NamedType(
  532. 'ccr', rfc2511.CertReqMessages().subtype(
  533. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 13)
  534. )
  535. ),
  536. namedtype.NamedType(
  537. 'ccp', CertRepMessage().subtype(
  538. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 14)
  539. )
  540. ),
  541. namedtype.NamedType(
  542. 'ckuann', CAKeyUpdAnnContent().subtype(
  543. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 15)
  544. )
  545. ),
  546. namedtype.NamedType(
  547. 'cann', CertAnnContent().subtype(
  548. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 16)
  549. )
  550. ),
  551. namedtype.NamedType(
  552. 'rann', RevAnnContent().subtype(
  553. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 17)
  554. )
  555. ),
  556. namedtype.NamedType(
  557. 'crlann', CRLAnnContent().subtype(
  558. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 18)
  559. )
  560. ),
  561. namedtype.NamedType(
  562. 'pkiconf', PKIConfirmContent().subtype(
  563. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 19)
  564. )
  565. ),
  566. namedtype.NamedType(
  567. 'nested', nestedMessageContent
  568. ),
  569. # namedtype.NamedType('nested', NestedMessageContent().subtype(
  570. # explicitTag=tag.Tag(tag.tagClassContext,tag.tagFormatConstructed,20)
  571. # )
  572. # ),
  573. namedtype.NamedType(
  574. 'genm', GenMsgContent().subtype(
  575. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 21)
  576. )
  577. ),
  578. namedtype.NamedType(
  579. 'gen', GenRepContent().subtype(
  580. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 22)
  581. )
  582. ),
  583. namedtype.NamedType(
  584. 'error', ErrorMsgContent().subtype(
  585. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 23)
  586. )
  587. ),
  588. namedtype.NamedType(
  589. 'certConf', CertConfirmContent().subtype(
  590. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 24)
  591. )
  592. ),
  593. namedtype.NamedType(
  594. 'pollReq', PollReqContent().subtype(
  595. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 25)
  596. )
  597. ),
  598. namedtype.NamedType(
  599. 'pollRep', PollRepContent().subtype(
  600. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 26)
  601. )
  602. )
  603. )
  604. class PKIHeader(univ.Sequence):
  605. """
  606. PKIHeader ::= SEQUENCE {
  607. pvno INTEGER { cmp1999(1), cmp2000(2) },
  608. sender GeneralName,
  609. recipient GeneralName,
  610. messageTime [0] GeneralizedTime OPTIONAL,
  611. protectionAlg [1] AlgorithmIdentifier OPTIONAL,
  612. senderKID [2] KeyIdentifier OPTIONAL,
  613. recipKID [3] KeyIdentifier OPTIONAL,
  614. transactionID [4] OCTET STRING OPTIONAL,
  615. senderNonce [5] OCTET STRING OPTIONAL,
  616. recipNonce [6] OCTET STRING OPTIONAL,
  617. freeText [7] PKIFreeText OPTIONAL,
  618. generalInfo [8] SEQUENCE SIZE (1..MAX) OF
  619. InfoTypeAndValue OPTIONAL
  620. }
  621. """
  622. componentType = namedtype.NamedTypes(
  623. namedtype.NamedType(
  624. 'pvno', univ.Integer(
  625. namedValues=namedval.NamedValues(('cmp1999', 1), ('cmp2000', 2))
  626. )
  627. ),
  628. namedtype.NamedType('sender', rfc2459.GeneralName()),
  629. namedtype.NamedType('recipient', rfc2459.GeneralName()),
  630. namedtype.OptionalNamedType('messageTime', useful.GeneralizedTime().subtype(
  631. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  632. namedtype.OptionalNamedType('protectionAlg', rfc2459.AlgorithmIdentifier().subtype(
  633. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))),
  634. namedtype.OptionalNamedType('senderKID', rfc2459.KeyIdentifier().subtype(
  635. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))),
  636. namedtype.OptionalNamedType('recipKID', rfc2459.KeyIdentifier().subtype(
  637. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3))),
  638. namedtype.OptionalNamedType('transactionID', univ.OctetString().subtype(
  639. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4))),
  640. namedtype.OptionalNamedType('senderNonce', univ.OctetString().subtype(
  641. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 5))),
  642. namedtype.OptionalNamedType('recipNonce', univ.OctetString().subtype(
  643. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 6))),
  644. namedtype.OptionalNamedType('freeText', PKIFreeText().subtype(
  645. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 7))),
  646. namedtype.OptionalNamedType('generalInfo',
  647. univ.SequenceOf(
  648. componentType=InfoTypeAndValue().subtype(
  649. subtypeSpec=constraint.ValueSizeConstraint(1, MAX),
  650. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 8)
  651. )
  652. )
  653. )
  654. )
  655. class ProtectedPart(univ.Sequence):
  656. """
  657. ProtectedPart ::= SEQUENCE {
  658. header PKIHeader,
  659. body PKIBody
  660. }
  661. """
  662. componentType = namedtype.NamedTypes(
  663. namedtype.NamedType('header', PKIHeader()),
  664. namedtype.NamedType('infoValue', PKIBody())
  665. )
  666. class PKIMessage(univ.Sequence):
  667. """
  668. PKIMessage ::= SEQUENCE {
  669. header PKIHeader,
  670. body PKIBody,
  671. protection [0] PKIProtection OPTIONAL,
  672. extraCerts [1] SEQUENCE SIZE (1..MAX) OF CMPCertificate
  673. OPTIONAL
  674. }"""
  675. componentType = namedtype.NamedTypes(
  676. namedtype.NamedType('header', PKIHeader()),
  677. namedtype.NamedType('body', PKIBody()),
  678. namedtype.OptionalNamedType('protection', PKIProtection().subtype(
  679. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  680. namedtype.OptionalNamedType('extraCerts',
  681. univ.SequenceOf(
  682. componentType=CMPCertificate()
  683. ).subtype(
  684. subtypeSpec=constraint.ValueSizeConstraint(1, MAX),
  685. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1)
  686. )
  687. )
  688. )
  689. class PKIMessages(univ.SequenceOf):
  690. """
  691. PKIMessages ::= SEQUENCE SIZE (1..MAX) OF PKIMessage
  692. """
  693. componentType = PKIMessage()
  694. subtypeSpec = univ.SequenceOf.subtypeSpec + constraint.ValueSizeConstraint(1, MAX)
  695. # pyasn1 does not naturally handle recursive definitions, thus this hack:
  696. # NestedMessageContent ::= PKIMessages
  697. NestedMessageContent._componentType = PKIMessages()
  698. nestedMessageContent._componentType = PKIMessages()