rfc4210.py 28 KB

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