rfc4210.py 26 KB

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