Leaked source code of windows server 2003
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.

2719 lines
71 KiB

  1. //==============================================================================
  2. //
  3. // MODULE: ASN1Parser.hxx
  4. //
  5. // Description:
  6. //
  7. // Basic building blocks for ASN.1 parsing
  8. //
  9. // Modification History
  10. //
  11. // Mark Pustilnik Date: 06/08/02 - created
  12. //
  13. //==============================================================================
  14. #ifndef __ASN1PARSER_HXX
  15. #define __ASN1PARSER_HXX
  16. #include <windows.h>
  17. #include <netmon.h>
  18. #include <kerbcon.h>
  19. #include <ntsecapi.h>
  20. #include "..\inc\kerberr.h"
  21. //
  22. // Utility macros
  23. //
  24. #define ARRAY_COUNT( a ) ( sizeof( a ) / sizeof ( a[ 0 ] ) )
  25. #define SET_OF( s ) { ARRAY_COUNT( s ), s }
  26. //
  27. // Shortcut for property access
  28. //
  29. #define PROP( a ) g_KerberosDatabase[a].hProperty
  30. //
  31. // Kerberos packet types
  32. //
  33. enum
  34. {
  35. ASN1_KRB_AS_REQ = 0x0A,
  36. ASN1_KRB_AS_REP = 0x0B,
  37. ASN1_KRB_TGS_REQ = 0x0C,
  38. ASN1_KRB_TGS_REP = 0x0D,
  39. ASN1_KRB_AP_REQ = 0x0E,
  40. ASN1_KRB_AP_REP = 0x0F,
  41. ASN1_KRB_SAFE = 0x14,
  42. ASN1_KRB_PRIV = 0x15,
  43. ASN1_KRB_CRED = 0x16,
  44. ASN1_KRB_ERROR = 0x1E,
  45. };
  46. //
  47. // Kerberos address types
  48. //
  49. enum
  50. {
  51. KERB_ADDRTYPE_UNSPEC = 0x0,
  52. KERB_ADDRTYPE_LOCAL = 0x1,
  53. KERB_ADDRTYPE_INET = 0x2,
  54. KERB_ADDRTYPE_IMPLINK = 0x3,
  55. KERB_ADDRTYPE_PUP = 0x4,
  56. KERB_ADDRTYPE_CHAOS = 0x5,
  57. KERB_ADDRTYPE_NS = 0x6,
  58. KERB_ADDRTYPE_NBS = 0x7,
  59. KERB_ADDRTYPE_ECMA = 0x8,
  60. KERB_ADDRTYPE_DATAKIT = 0x9,
  61. KERB_ADDRTYPE_CCITT = 0xA,
  62. KERB_ADDRTYPE_SNA = 0xB,
  63. KERB_ADDRTYPE_DECnet = 0xC,
  64. KERB_ADDRTYPE_DLI = 0xD,
  65. KERB_ADDRTYPE_LAT = 0xE,
  66. KERB_ADDRTYPE_HYLINK = 0xF,
  67. KERB_ADDRTYPE_APPLETALK = 0x10,
  68. KERB_ADDRTYPE_BSC = 0x11,
  69. KERB_ADDRTYPE_DSS = 0x12,
  70. KERB_ADDRTYPE_OSI = 0x13,
  71. KERB_ADDRTYPE_NETBIOS = 0x14,
  72. KERB_ADDRTYPE_X25 = 0x15,
  73. KERB_ADDRTYPE_IPv6 = 0x18,
  74. };
  75. //
  76. // PAC Sections
  77. //
  78. enum
  79. {
  80. PAC_LOGON_INFO = 1,
  81. PAC_CREDENTIAL_TYPE = 2,
  82. PAC_SERVER_CHECKSUM = 6,
  83. PAC_PRIVSVR_CHECKSUM = 7,
  84. PAC_CLIENT_INFO_TYPE = 10,
  85. PAC_DELEGATION_INFO = 11,
  86. PAC_CLIENT_IDENTITY = 13,
  87. PAC_COMPOUND_IDENTITY = 14,
  88. };
  89. //
  90. // Netmon property IDs
  91. //
  92. enum
  93. {
  94. KRB_AS_REQ,
  95. KRB_AS_REP,
  96. KRB_TGS_REQ,
  97. KRB_TGS_REP,
  98. KRB_AP_REQ,
  99. KRB_AP_REP,
  100. KRB_SAFE,
  101. KRB_PRIV,
  102. KRB_CRED,
  103. KRB_ERROR,
  104. HostAddresses_HostAddress,
  105. EncryptedData_etype,
  106. EncryptedData_kvno,
  107. EncryptedData_cipher,
  108. PA_DATA_type,
  109. PA_DATA_value,
  110. PrincipalName_type,
  111. PrincipalName_string,
  112. Ticket_tkt_vno,
  113. Ticket_realm,
  114. Ticket_sname,
  115. Ticket_enc_part,
  116. AP_REQ_pvno,
  117. AP_REQ_msg_type,
  118. AP_REQ_ap_options_summary,
  119. AP_REQ_ap_options_value,
  120. AP_REQ_ticket,
  121. AP_REQ_authenticator,
  122. KDC_REQ_BODY_kdc_options_summary,
  123. KDC_REQ_BODY_kdc_options_value,
  124. KDC_REQ_BODY_cname,
  125. KDC_REQ_BODY_realm,
  126. KDC_REQ_BODY_sname,
  127. KDC_REQ_BODY_from,
  128. KDC_REQ_BODY_till,
  129. KDC_REQ_BODY_rtime,
  130. KDC_REQ_BODY_nonce,
  131. KDC_REQ_BODY_etype,
  132. KDC_REQ_BODY_addresses,
  133. KDC_REQ_BODY_enc_authorization_data,
  134. KDC_REQ_BODY_additional_tickets,
  135. KDC_REQ,
  136. KDC_REQ_pvno,
  137. KDC_REQ_msg_type,
  138. KDC_REQ_padata,
  139. KDC_REQ_req_body,
  140. KDC_REP_pvno,
  141. KDC_REP_msg_type,
  142. KDC_REP_padata,
  143. KDC_REP_crealm,
  144. KDC_REP_cname,
  145. KDC_REP_ticket,
  146. KDC_REP_enc_part,
  147. KRB_ERR_pvno,
  148. KRB_ERR_msg_type,
  149. KRB_ERR_ctime,
  150. KRB_ERR_cusec,
  151. KRB_ERR_stime,
  152. KRB_ERR_susec,
  153. KRB_ERR_error_code,
  154. KRB_ERR_crealm,
  155. KRB_ERR_cname,
  156. KRB_ERR_realm,
  157. KRB_ERR_sname,
  158. KRB_ERR_e_text,
  159. KRB_ERR_e_data,
  160. KERB_PA_PAC_REQUEST_include_pac,
  161. KERB_PA_PAC_REQUEST_EX_include_pac,
  162. KERB_PA_PAC_REQUEST_EX_pac_sections,
  163. KERB_PA_PAC_REQUEST_EX_pac_sections_desc,
  164. KERB_ETYPE_INFO_ENTRY_encryption_type,
  165. KERB_ETYPE_INFO_ENTRY_salt,
  166. KERB_PREAUTH_DATA_LIST,
  167. TYPED_DATA_type,
  168. TYPED_DATA_value,
  169. PA_PW_SALT_salt,
  170. PA_FOR_USER_userName,
  171. PA_FOR_USER_userRealm,
  172. PA_FOR_USER_cksum,
  173. PA_FOR_USER_authentication_package,
  174. PA_FOR_USER_authorization_data,
  175. KERB_CHECKSUM_type,
  176. KERB_CHECKSUM_checksum,
  177. AdditionalTicket,
  178. EncryptionType,
  179. ContinuationPacket,
  180. INTEGER_NOT_IN_ASN,
  181. CompoundIdentity,
  182. CompoundIdentityTicket,
  183. MAX_PROP_VALUE, // dummy value to ensure consistency
  184. };
  185. //
  186. // externs
  187. //
  188. extern PROPERTYINFO g_KerberosDatabase[MAX_PROP_VALUE];
  189. //==============================================================================
  190. //
  191. // ASN.1 constructs
  192. //
  193. //==============================================================================
  194. //
  195. // Class tags
  196. //
  197. typedef enum ClassTag
  198. {
  199. ctUniversal = 0x00, // 00000000
  200. ctApplication = 0x40, // 01000000
  201. ctContextSpecific = 0x80, // 10000000
  202. ctPrivate = 0xC0, // 11000000
  203. };
  204. inline
  205. ClassTag
  206. ClassTagFromByte(
  207. IN BYTE b
  208. )
  209. {
  210. return (ClassTag)( b & 0xC0 );
  211. }
  212. //
  213. // Primitive-Constructed
  214. //
  215. typedef enum PC
  216. {
  217. pcPrimitive = 0x00, // 00000000
  218. pcConstructed = 0x20, // 00100000
  219. };
  220. inline
  221. PC
  222. PCFromByte(
  223. IN BYTE b
  224. )
  225. {
  226. return (PC)( b & 0x20 );
  227. }
  228. //
  229. // Tags
  230. //
  231. const BYTE MaxTag = 0x1F; // Max value of a tag
  232. inline
  233. BYTE
  234. TagFromByte(
  235. IN BYTE b
  236. )
  237. {
  238. return ( b & 0x1F ); // Tags are 5 bits long
  239. }
  240. //
  241. // Universal tags
  242. //
  243. typedef enum UniversalTag
  244. {
  245. utBoolean = 0x01, // 00001
  246. utInteger = 0x02, // 00010
  247. utBitString = 0x03, // 00011
  248. utOctetString = 0x04, // 00100
  249. utNULL = 0x05, // 00101
  250. utObjectIdentifer = 0x06, // 00110
  251. utObjectDescriptor = 0x07, // 00111
  252. utExternal = 0x08, // 01000
  253. utReal = 0x09, // 01001
  254. utEnumerated = 0x0A, // 01010
  255. utSequence = 0x10, // 10000
  256. utSet = 0x11, // 10001
  257. utNumericString = 0x12, // 10010
  258. utPrintableString = 0x13, // 10011
  259. utT61String = 0x14, // 10100
  260. utVideotexString = 0x15, // 10101
  261. utIA5String = 0x16, // 10110
  262. utUTCTime = 0x17, // 10111
  263. utGeneralizedTime = 0x18, // 11000
  264. utGraphicString = 0x19, // 11001
  265. utVisibleString = 0x1A, // 11010
  266. utGeneralString = 0x1B, // 11011
  267. };
  268. inline
  269. BYTE
  270. BuildDescriptor(
  271. IN ClassTag ct,
  272. IN PC pc,
  273. IN ULONG tag
  274. )
  275. {
  276. //
  277. // TODO: add an assert that tag fits in one byte (or rather 0x1F bits)
  278. //
  279. return (BYTE)ct | (BYTE)pc | ((BYTE)tag & 0x1F );
  280. }
  281. //==============================================================================
  282. //
  283. // Class declarations
  284. //
  285. //==============================================================================
  286. struct ASN1FRAME
  287. {
  288. //
  289. // Starting address of the frame
  290. //
  291. ULPBYTE Address;
  292. //
  293. // Netmon frame handle
  294. //
  295. HFRAME hFrame;
  296. //
  297. // Netmon indentation offset
  298. //
  299. DWORD Level;
  300. };
  301. // Necessary forward declaration for the subparser member
  302. class ASN1ParserBase;
  303. struct ASN1VALUE
  304. {
  305. //
  306. // Constructor and destructor
  307. //
  308. ASN1VALUE(
  309. ) : Address( NULL ),
  310. Length( 0 ),
  311. ut( utNULL ),
  312. Allocated( FALSE ),
  313. SubParser( NULL ) {}
  314. ~ASN1VALUE();
  315. void
  316. Purge()
  317. {
  318. if ( Allocated &&
  319. ( ut == utOctetString ||
  320. ut == utGeneralString ))
  321. {
  322. delete [] string.s;
  323. string.s = NULL;
  324. string.l = 0;
  325. }
  326. }
  327. //
  328. // Creates dynamically allocated copy of ASN1VALUE passed in
  329. //
  330. ASN1VALUE *
  331. Clone();
  332. //
  333. // Address of the actual unadulterated value
  334. //
  335. ULPBYTE Address;
  336. //
  337. // Length of the actual unadulterated value
  338. //
  339. DWORD Length;
  340. //
  341. // Type of value that follows
  342. //
  343. UniversalTag ut;
  344. //
  345. // Dynamically allocated? ('s' only)
  346. //
  347. BOOL Allocated;
  348. union
  349. {
  350. BOOL b; // utBoolean
  351. DWORD dw; // utInteger, utBitString
  352. struct {
  353. ULONG l;
  354. ULPBYTE s;
  355. } string; // utOctetString, utGeneralString
  356. SYSTEMTIME st; // utGeneralizedTime
  357. };
  358. //
  359. // Subparser (for binary blob types only)
  360. //
  361. ASN1ParserBase * SubParser; // TODO: refcount this type if deep copy becomes necessary
  362. };
  363. typedef ASN1VALUE * PASN1VALUE;
  364. // -----------------------------------------------------------------------------
  365. //
  366. // +----------------+
  367. // | ASN1ParserBase |<------------------------+
  368. // +----------------+ |
  369. // ^ |
  370. // | |
  371. // +----------------+------------------+ |
  372. // | | |
  373. // +----------------+ +--------------------+ |
  374. // | ASN1ParserUnit | | ASN1ParserSequence |<>--+
  375. // +----------------+ +--------------------+
  376. //
  377. // -----------------------------------------------------------------------------
  378. class ASN1ParserSequence; // necessary forward declaration for value collectors
  379. class ASN1ParserBase
  380. {
  381. public:
  382. //
  383. // Constructor and destructor
  384. //
  385. ASN1ParserBase(
  386. IN BOOL IsOptional,
  387. IN BYTE Descriptor,
  388. IN HPROPERTY hPropertySummary,
  389. IN HPROPERTY hPropertyValue
  390. ) : m_IsOptional( IsOptional ),
  391. m_Descriptor( Descriptor ),
  392. m_AppDescriptor( 0 ),
  393. m_hPropertySummary( hPropertySummary ),
  394. m_hPropertyValue( hPropertyValue ),
  395. m_Modifier( NULL ),
  396. m_Modifyee( NULL ),
  397. m_ValueCollector( NULL ) {}
  398. virtual
  399. ~ASN1ParserBase() { delete m_Modifier; }
  400. //
  401. // Parses the data in the block pointed to by the Frame,
  402. // and displays the resulting data in the appropriate format
  403. // Upon exit, Frame points to the next block to be parsed
  404. //
  405. virtual
  406. DWORD
  407. Parse(
  408. IN OUT ASN1FRAME * Frame ) = 0;
  409. DWORD
  410. Display(
  411. IN ASN1FRAME * Frame,
  412. IN ASN1VALUE * Value,
  413. IN HPROPERTY hProperty,
  414. IN DWORD IFlags );
  415. //
  416. // Computes length of the block pointed to by Frame
  417. //
  418. DWORD
  419. DataLength(
  420. IN ASN1FRAME * Frame );
  421. //
  422. // Queries "optionality" of this parser block
  423. //
  424. BOOL
  425. IsOptional() { return m_IsOptional; }
  426. //
  427. // "Modifiers" are values which affect subsequent parsing
  428. // in a context-specific fashion
  429. //
  430. DWORD
  431. SetModifier(
  432. IN ASN1VALUE * NewModifier )
  433. {
  434. ASN1VALUE * Modifier = NewModifier->Clone();
  435. if ( Modifier == NULL )
  436. {
  437. return ERROR_NOT_ENOUGH_MEMORY;
  438. }
  439. delete m_Modifier;
  440. m_Modifier = Modifier;
  441. return ERROR_SUCCESS;
  442. }
  443. ASN1VALUE *
  444. QueryModifier() { return m_Modifier; }
  445. //
  446. // "Modifyees" are objects being modified during parsing
  447. //
  448. void
  449. SetModifyee(
  450. IN ASN1ParserBase * Modifyee ) { m_Modifyee = Modifyee; }
  451. ASN1ParserBase *
  452. QueryModifyee() { return m_Modifyee; }
  453. //
  454. // A parser can have a 'value collector' - a sequence object
  455. // which collects the values parsed out by this parser for subsequent
  456. // processing and display
  457. //
  458. void
  459. SetValueCollector(
  460. IN ASN1ParserSequence * ValueCollector ) { m_ValueCollector = ValueCollector; }
  461. ASN1ParserSequence *
  462. QueryValueCollector() { return m_ValueCollector; }
  463. protected:
  464. //
  465. // Verifies the item header and skips past the item length block
  466. // that follows it
  467. //
  468. DWORD
  469. VerifyAndSkipHeader(
  470. IN OUT ASN1FRAME * Frame );
  471. //
  472. // Computes the length of the length header
  473. //
  474. ULONG
  475. HeaderLength(
  476. IN ULPBYTE Address );
  477. //
  478. // Netmon property handles
  479. // Either is optional, if both are present, they are displayed
  480. // in a hierarchical fashion
  481. //
  482. HPROPERTY m_hPropertySummary;
  483. HPROPERTY m_hPropertyValue;
  484. //
  485. // Set the application descriptor (rare so better not done during construction time)
  486. //
  487. void
  488. SetAppDescriptor(
  489. IN BYTE AppDescriptor ) { m_AppDescriptor = AppDescriptor; }
  490. private:
  491. //
  492. // If TRUE, the item is optional and may not be present
  493. //
  494. BOOL m_IsOptional;
  495. //
  496. // One-BYTE Descriptor of the expected data that follows,
  497. // for example 10 1 00001 (Context-Specific[10] Constructed[1] pvno[1])
  498. // m_AppDescriptor exists for [APPLICATION 1] types of situations
  499. //
  500. BYTE m_Descriptor;
  501. BYTE m_AppDescriptor;
  502. //
  503. // Modifier value
  504. //
  505. ASN1VALUE * m_Modifier;
  506. //
  507. // Modifyee value
  508. //
  509. ASN1ParserBase * m_Modifyee;
  510. //
  511. // Value collector
  512. //
  513. ASN1ParserSequence * m_ValueCollector;
  514. };
  515. // -----------------------------------------------------------------------------
  516. //
  517. // Derived classes of ASN1ParserBase follow
  518. //
  519. // -----------------------------------------------------------------------------
  520. // -----------------------------------------------------------------------------
  521. //
  522. // +----------------+
  523. // | ASN1ParserUnit |
  524. // +----------------+
  525. // ^
  526. // |
  527. // +--------------+--------+--------- ... ... ...
  528. // ^ ^
  529. // +-------------------+ +-------------------+
  530. // | ASN1ParserInteger | | ASN1ParserBoolean |
  531. // +-------------------+ +-------------------+
  532. //
  533. // -----------------------------------------------------------------------------
  534. //
  535. // A 'unit' is essentially anything that is a leaf in the parse tree
  536. // Most units have values, some don't
  537. //
  538. class ASN1ParserUnit : public ASN1ParserBase
  539. {
  540. public:
  541. //
  542. // Constructor
  543. //
  544. ASN1ParserUnit(
  545. IN BOOL IsOptional,
  546. IN BYTE Descriptor,
  547. IN HPROPERTY hPropertySummary,
  548. IN HPROPERTY hPropertyValue,
  549. IN DWORD IFlags
  550. ) : ASN1ParserBase(
  551. IsOptional,
  552. Descriptor,
  553. hPropertySummary,
  554. hPropertyValue ),
  555. m_IFlags( IFlags ) {}
  556. //
  557. // Parses the unit and calls into the derived class (through Display)
  558. // to display it in Netmon
  559. //
  560. DWORD
  561. Parse(
  562. IN OUT ASN1FRAME * Frame );
  563. //
  564. // A Unit-descendant that does not have a value should set the value type
  565. // to 'void' and still delineate the value and length of the octet string
  566. // properly so that it can be displayed correctly
  567. //
  568. virtual
  569. DWORD
  570. GetValue(
  571. IN OUT ASN1FRAME * Frame,
  572. OUT ASN1VALUE * Value ) = 0;
  573. protected:
  574. //
  575. // Netmon display flags
  576. //
  577. DWORD m_IFlags;
  578. };
  579. // -----------------------------------------------------------------------------
  580. //
  581. // Derived classes of ASN1ParserUnit follow
  582. //
  583. // -----------------------------------------------------------------------------
  584. class ASN1ParserBitString : public ASN1ParserUnit
  585. {
  586. public:
  587. //
  588. // Constructor
  589. //
  590. ASN1ParserBitString(
  591. IN BOOL IsOptional,
  592. IN BYTE Descriptor,
  593. IN HPROPERTY hPropertySummary,
  594. IN HPROPERTY hPropertyValue,
  595. IN DWORD IFlags,
  596. IN DWORD BitMask = 0xFFFFFFFF
  597. ) : ASN1ParserUnit(
  598. IsOptional,
  599. Descriptor,
  600. hPropertySummary,
  601. hPropertyValue,
  602. IFlags ),
  603. m_BitMask( BitMask ) {}
  604. //
  605. // Parses the bit string
  606. //
  607. DWORD
  608. GetValue(
  609. IN OUT ASN1FRAME * Frame,
  610. OUT ASN1VALUE * Value
  611. );
  612. protected:
  613. DWORD m_BitMask;
  614. };
  615. class ASN1ParserBoolean : public ASN1ParserUnit
  616. {
  617. public:
  618. //
  619. // Constructor
  620. //
  621. ASN1ParserBoolean(
  622. IN BOOL IsOptional,
  623. IN BYTE Descriptor,
  624. IN HPROPERTY hPropertyValue,
  625. IN DWORD IFlags
  626. ) : ASN1ParserUnit(
  627. IsOptional,
  628. Descriptor,
  629. NULL, // Boolean is directly displayable, no need for summary
  630. hPropertyValue,
  631. IFlags ) {}
  632. //
  633. // Parses the boolean
  634. //
  635. DWORD
  636. GetValue(
  637. IN OUT ASN1FRAME * Frame,
  638. OUT ASN1VALUE * Value
  639. );
  640. };
  641. class ASN1ParserInteger : public ASN1ParserUnit
  642. {
  643. public:
  644. //
  645. // Constructor
  646. //
  647. ASN1ParserInteger(
  648. IN BOOL IsOptional,
  649. IN BYTE Descriptor,
  650. IN HPROPERTY hPropertyValue,
  651. IN DWORD IFlags,
  652. IN DWORD BitMask = 0xFFFFFFFF
  653. ) : ASN1ParserUnit(
  654. IsOptional,
  655. Descriptor,
  656. NULL, // Integer is directly displayable, no need for summary
  657. hPropertyValue,
  658. IFlags ),
  659. m_BitMask( BitMask ) {}
  660. //
  661. // Parses the integer
  662. //
  663. DWORD
  664. GetValue(
  665. IN OUT ASN1FRAME * Frame,
  666. OUT ASN1VALUE * Value
  667. );
  668. protected:
  669. DWORD m_BitMask;
  670. };
  671. class ASN1ParserGeneralizedTime : public ASN1ParserUnit
  672. {
  673. public:
  674. //
  675. // Constructor
  676. //
  677. ASN1ParserGeneralizedTime(
  678. IN BOOL IsOptional,
  679. IN BYTE Descriptor,
  680. IN HPROPERTY hPropertyValue
  681. ) : ASN1ParserUnit(
  682. IsOptional,
  683. Descriptor,
  684. NULL, // Time is directly displayable, no need for summary
  685. hPropertyValue,
  686. 0 ) {}
  687. //
  688. // Parses the octet string
  689. //
  690. DWORD
  691. GetValue(
  692. IN OUT ASN1FRAME * Frame,
  693. OUT ASN1VALUE * Value );
  694. };
  695. class ASN1ParserGeneralString : public ASN1ParserUnit
  696. {
  697. public:
  698. //
  699. // Constructor
  700. //
  701. ASN1ParserGeneralString(
  702. IN BOOL IsOptional,
  703. IN BYTE Descriptor,
  704. IN HPROPERTY hPropertyValue,
  705. IN DWORD IFlags
  706. ) : ASN1ParserUnit(
  707. IsOptional,
  708. Descriptor,
  709. NULL, // String is directly displayable, no need for summary
  710. hPropertyValue,
  711. IFlags ) {}
  712. //
  713. // Parses the octet string
  714. //
  715. DWORD
  716. GetValue(
  717. IN OUT ASN1FRAME * Frame,
  718. OUT ASN1VALUE * Value );
  719. };
  720. //
  721. // An octet string is just a binary blob that needs special decoding
  722. // in most cases. In those cases, the class needs to be subclassed to parse
  723. // out the actual value
  724. //
  725. class ASN1ParserOctetString : public ASN1ParserUnit
  726. {
  727. public:
  728. //
  729. // Constructor
  730. //
  731. ASN1ParserOctetString(
  732. IN BOOL IsOptional,
  733. IN BYTE Descriptor,
  734. IN HPROPERTY hPropertyValue,
  735. IN DWORD IFlags
  736. ) : ASN1ParserUnit(
  737. IsOptional,
  738. Descriptor,
  739. NULL, // String is directly displayable, no need for summary
  740. hPropertyValue,
  741. IFlags ) {}
  742. //
  743. // Parses the octet string
  744. //
  745. DWORD
  746. GetValue(
  747. IN OUT ASN1FRAME * Frame,
  748. OUT ASN1VALUE * Value );
  749. protected:
  750. virtual
  751. DWORD
  752. ParseBlob(
  753. IN OUT ASN1VALUE * Value ) { return ERROR_SUCCESS; }
  754. };
  755. class ASN1ParserAddressBuffer : public ASN1ParserOctetString
  756. {
  757. public:
  758. //
  759. // Constructor
  760. //
  761. ASN1ParserAddressBuffer(
  762. IN BOOL IsOptional,
  763. IN BYTE Descriptor,
  764. IN HPROPERTY hProperty
  765. ) : ASN1ParserOctetString(
  766. IsOptional,
  767. Descriptor,
  768. hProperty,
  769. 0 ) {}
  770. protected:
  771. DWORD
  772. ParseBlob(
  773. IN OUT ASN1VALUE * Value );
  774. };
  775. class ASN1ParserErrorData : public ASN1ParserOctetString
  776. {
  777. public:
  778. //
  779. // Constructor
  780. //
  781. ASN1ParserErrorData(
  782. IN BOOL IsOptional,
  783. IN BYTE Descriptor,
  784. IN HPROPERTY hProperty
  785. ) : ASN1ParserOctetString(
  786. IsOptional,
  787. Descriptor,
  788. hProperty,
  789. 0 ) {}
  790. protected:
  791. DWORD
  792. ParseBlob(
  793. IN OUT ASN1VALUE * Value );
  794. };
  795. // -----------------------------------------------------------------------------
  796. //
  797. // +--------------------+
  798. // | ASN1ParserSequence |
  799. // +--------------------+
  800. // ^
  801. // |
  802. // +---------------+---------+--------- ... ... ...
  803. // ^ ^
  804. // +------------------+ +-------------------------+
  805. // | ASN1ParserPaData | | ASN1ParserPrincipalName |
  806. // +------------------+ +-------------------------+
  807. //
  808. // -----------------------------------------------------------------------------
  809. //
  810. // A sequence is a collection of units or sequences, much like a directory
  811. // contains files or other directories
  812. //
  813. class ASN1ParserSequence : public ASN1ParserBase
  814. {
  815. public:
  816. //
  817. // Constructor
  818. //
  819. ASN1ParserSequence(
  820. IN BOOL IsOptional,
  821. IN BYTE Descriptor,
  822. IN HPROPERTY hPropertySummary,
  823. IN ULONG Count,
  824. IN ASN1ParserBase * * Parsers,
  825. IN OPTIONAL BOOL Extensible = FALSE
  826. ) : ASN1ParserBase(
  827. IsOptional,
  828. Descriptor,
  829. hPropertySummary,
  830. NULL ), // no value property on sequences (yet?)
  831. m_Count( Count ),
  832. m_Parsers( Parsers ),
  833. m_ValueCount( 0 ),
  834. m_ValuesCollected( NULL ),
  835. m_Extensible( Extensible ) {}
  836. ~ASN1ParserSequence() { PurgeCollectedValues(); }
  837. //
  838. // Parses the sequence by invoking successive sub-parsers as necessary
  839. //
  840. DWORD
  841. Parse(
  842. IN OUT ASN1FRAME * Frame );
  843. //
  844. // This method is called if this object is acting as a value collector for
  845. // another object. A value collected is appended to the end of the array
  846. // of like values
  847. //
  848. DWORD
  849. CollectValue(
  850. IN ASN1VALUE * Value );
  851. ULONG
  852. QueryCollectedCount() { return m_ValueCount; }
  853. ASN1VALUE *
  854. QueryCollectedValue(
  855. IN ULONG Index ) { return m_ValuesCollected[Index]; } // TODO: add range-check assert
  856. void
  857. PurgeCollectedValues()
  858. {
  859. for ( ULONG i = 0; i < m_ValueCount; i++)
  860. {
  861. delete m_ValuesCollected[i];
  862. }
  863. delete [] m_ValuesCollected;
  864. m_ValuesCollected = NULL;
  865. m_ValueCount = 0;
  866. }
  867. protected:
  868. virtual
  869. DWORD
  870. DisplayCollectedValues(
  871. IN ASN1FRAME * Frame,
  872. IN ULONG Length,
  873. IN ULPBYTE Address )
  874. {
  875. //
  876. // TODO: add an assert in addition to this error check
  877. //
  878. return QueryCollectedCount() > 0 ?
  879. ERROR_NOT_SUPPORTED :
  880. ERROR_SUCCESS;
  881. }
  882. private:
  883. //
  884. // Number of items in the sequence
  885. //
  886. ULONG m_Count;
  887. //
  888. // Array of parser objects - one for every sequence item
  889. //
  890. ASN1ParserBase * * m_Parsers;
  891. //
  892. // Values collected
  893. //
  894. ULONG m_ValueCount;
  895. PASN1VALUE * m_ValuesCollected;
  896. //
  897. // Are extensibility markers employed in the ASN.1 syntax?
  898. //
  899. BOOL m_Extensible;
  900. };
  901. // -----------------------------------------------------------------------------
  902. //
  903. // Derived classes of ASN1ParserSequence follow
  904. //
  905. // -----------------------------------------------------------------------------
  906. // -----------------------------------------------------------------------------
  907. // HostAddress ::= SEQUENCE {
  908. // addr-type[0] INTEGER,
  909. // address[1] OCTET STRING
  910. // }
  911. // -----------------------------------------------------------------------------
  912. class ASN1ParserHostAddress : public ASN1ParserSequence
  913. {
  914. public:
  915. //
  916. // Constructor
  917. //
  918. ASN1ParserHostAddress(
  919. IN BOOL IsOptional,
  920. IN BYTE Descriptor
  921. ) : ASN1ParserSequence(
  922. IsOptional,
  923. Descriptor,
  924. NULL,
  925. ARRAY_COUNT( m_p ),
  926. m_p ),
  927. m_addr_type(
  928. FALSE,
  929. BuildDescriptor( ctContextSpecific, pcConstructed, e_addr_type ),
  930. NULL,
  931. 0 ),
  932. m_address(
  933. FALSE,
  934. BuildDescriptor( ctContextSpecific, pcConstructed, e_address ),
  935. NULL )
  936. {
  937. m_p[0] = &m_addr_type;
  938. m_p[1] = &m_address;
  939. //
  940. // Address type affects the parsing of the address portion
  941. //
  942. m_addr_type.SetModifyee( &m_address );
  943. //
  944. // We would like to handle the display of address type and address
  945. // value ourselves (allows for user-friendly display on the same line)
  946. //
  947. m_addr_type.SetValueCollector( this );
  948. m_address.SetValueCollector( this );
  949. }
  950. protected:
  951. DWORD
  952. DisplayCollectedValues(
  953. IN ASN1FRAME * Frame,
  954. IN ULONG Length,
  955. IN ULPBYTE Address );
  956. private:
  957. enum
  958. {
  959. e_addr_type = 0,
  960. e_address = 1,
  961. };
  962. ASN1ParserBase * m_p[2];
  963. ASN1ParserInteger m_addr_type;
  964. ASN1ParserAddressBuffer m_address;
  965. };
  966. // -----------------------------------------------------------------------------
  967. // HostAddresses ::= SEQUENCE OF HostAddress
  968. // -----------------------------------------------------------------------------
  969. class ASN1ParserHostAddresses : public ASN1ParserSequence
  970. {
  971. public:
  972. //
  973. // Constructor
  974. //
  975. ASN1ParserHostAddresses(
  976. IN BOOL IsOptional,
  977. IN BYTE Descriptor,
  978. IN HPROPERTY hProperty
  979. ) : ASN1ParserSequence(
  980. IsOptional,
  981. Descriptor,
  982. hProperty,
  983. ARRAY_COUNT( m_p ),
  984. m_p ),
  985. m_HostAddress(
  986. FALSE,
  987. 0 ) // no descriptor on individual addresses sequences
  988. {
  989. m_p[0] = &m_HostAddress;
  990. }
  991. private:
  992. ASN1ParserBase * m_p[1];
  993. ASN1ParserHostAddress m_HostAddress;
  994. };
  995. // -----------------------------------------------------------------------------
  996. // EncryptedData ::= SEQUENCE {
  997. // etype[0] INTEGER, -- EncryptionType
  998. // kvno[1] INTEGER OPTIONAL,
  999. // cipher[2] OCTET STRING -- ciphertext
  1000. // }
  1001. // -----------------------------------------------------------------------------
  1002. class ASN1ParserEncryptedData : public ASN1ParserSequence
  1003. {
  1004. public:
  1005. //
  1006. // Constructor
  1007. //
  1008. ASN1ParserEncryptedData(
  1009. IN BOOL IsOptional,
  1010. IN BYTE Descriptor,
  1011. IN HPROPERTY hProperty
  1012. ) : ASN1ParserSequence(
  1013. IsOptional,
  1014. Descriptor,
  1015. hProperty,
  1016. ARRAY_COUNT( m_p ),
  1017. m_p
  1018. ),
  1019. m_etype(
  1020. FALSE,
  1021. BuildDescriptor( ctContextSpecific, pcConstructed, e_etype ),
  1022. PROP( EncryptedData_etype ),
  1023. 0 ),
  1024. m_kvno(
  1025. TRUE,
  1026. BuildDescriptor( ctContextSpecific, pcConstructed, e_kvno ),
  1027. PROP( EncryptedData_kvno ),
  1028. 0 ),
  1029. m_cipher(
  1030. FALSE,
  1031. BuildDescriptor( ctContextSpecific, pcConstructed, e_cipher ),
  1032. PROP( EncryptedData_cipher ),
  1033. 0 )
  1034. {
  1035. m_p[0] = &m_etype;
  1036. m_p[1] = &m_kvno;
  1037. m_p[2] = &m_cipher;
  1038. //
  1039. // m_etype type is not modifying either m_kvno or m_cipher,
  1040. // but it conceivably could
  1041. //
  1042. }
  1043. private:
  1044. enum
  1045. {
  1046. e_etype = 0,
  1047. e_kvno = 1,
  1048. e_cipher = 2,
  1049. };
  1050. ASN1ParserBase * m_p[3];
  1051. ASN1ParserInteger m_etype;
  1052. ASN1ParserInteger m_kvno;
  1053. ASN1ParserOctetString m_cipher;
  1054. };
  1055. class ASN1ParserGStringSequence : public ASN1ParserSequence
  1056. {
  1057. public:
  1058. //
  1059. // Constructor
  1060. //
  1061. ASN1ParserGStringSequence(
  1062. IN BOOL IsOptional,
  1063. IN BYTE Descriptor,
  1064. IN HPROPERTY hProperty
  1065. ) : ASN1ParserSequence(
  1066. IsOptional,
  1067. Descriptor,
  1068. hProperty,
  1069. ARRAY_COUNT( m_p ),
  1070. m_p ),
  1071. m_string(
  1072. FALSE,
  1073. 0, // No descriptor on individual general string entries
  1074. NULL, // No property since we're acting as the value collector
  1075. 0 )
  1076. {
  1077. m_p[0] = &m_string;
  1078. //
  1079. // Act as the value collector for the string sequence
  1080. //
  1081. m_string.SetValueCollector( this );
  1082. }
  1083. private:
  1084. ASN1ParserBase * m_p[1];
  1085. ASN1ParserGeneralString m_string;
  1086. };
  1087. class ASN1ParserPrincipalNameSequence : public ASN1ParserGStringSequence
  1088. {
  1089. public:
  1090. //
  1091. // Constructor
  1092. //
  1093. ASN1ParserPrincipalNameSequence(
  1094. IN BOOL IsOptional,
  1095. IN BYTE Descriptor
  1096. ) : ASN1ParserGStringSequence(
  1097. IsOptional,
  1098. Descriptor,
  1099. NULL ) {} // let the value collector display the value
  1100. protected:
  1101. DWORD
  1102. DisplayCollectedValues(
  1103. IN ASN1FRAME * Frame,
  1104. IN ULONG Length,
  1105. IN ULPBYTE Address );
  1106. };
  1107. class ASN1ParserIntegerSequence : public ASN1ParserSequence
  1108. {
  1109. public:
  1110. //
  1111. // Constructor
  1112. //
  1113. ASN1ParserIntegerSequence(
  1114. IN BOOL IsOptional,
  1115. IN BYTE Descriptor,
  1116. IN HPROPERTY hPropertySeq,
  1117. IN HPROPERTY hPropertyInteger
  1118. ) : ASN1ParserSequence(
  1119. IsOptional,
  1120. Descriptor,
  1121. hPropertySeq,
  1122. ARRAY_COUNT( m_p ),
  1123. m_p ),
  1124. m_integer(
  1125. FALSE,
  1126. 0, // No descriptor on individual integer entries
  1127. NULL, // No property since we're acting as the value collector
  1128. 0 ),
  1129. m_hPropertyInteger( hPropertyInteger )
  1130. {
  1131. m_p[0] = &m_integer;
  1132. //
  1133. // Act as the value collector for the integer sequence
  1134. //
  1135. m_integer.SetValueCollector( this );
  1136. }
  1137. protected:
  1138. DWORD
  1139. DisplayCollectedValues(
  1140. IN ASN1FRAME * Frame,
  1141. IN ULONG Length,
  1142. IN ULPBYTE Address );
  1143. private:
  1144. ASN1ParserBase * m_p[1];
  1145. ASN1ParserInteger m_integer;
  1146. HPROPERTY m_hPropertyInteger;
  1147. };
  1148. // -----------------------------------------------------------------------------
  1149. // KERB-PA-PAC-REQUEST ::= SEQUENCE {
  1150. // include-pac[0] BOOLEAN
  1151. // -- if TRUE, and no pac present,
  1152. // -- include PAC. If FALSE, and pac
  1153. // -- PAC present, remove PAC
  1154. // } --#public--
  1155. // -----------------------------------------------------------------------------
  1156. class ASN1ParserKerbPaPacRequest : public ASN1ParserSequence
  1157. {
  1158. public:
  1159. ASN1ParserKerbPaPacRequest(
  1160. IN BOOL IsOptional,
  1161. IN BYTE Descriptor,
  1162. IN HPROPERTY hProperty
  1163. ) : ASN1ParserSequence(
  1164. IsOptional,
  1165. Descriptor,
  1166. hProperty,
  1167. ARRAY_COUNT( m_p ),
  1168. m_p
  1169. ),
  1170. m_include_pac(
  1171. FALSE,
  1172. BuildDescriptor( ctContextSpecific, pcConstructed, e_include_pac ),
  1173. PROP( KERB_PA_PAC_REQUEST_include_pac ),
  1174. 0 )
  1175. {
  1176. m_p[0] = &m_include_pac;
  1177. }
  1178. private:
  1179. enum
  1180. {
  1181. e_include_pac = 0,
  1182. };
  1183. ASN1ParserBase * m_p[1];
  1184. ASN1ParserBoolean m_include_pac;
  1185. };
  1186. // -----------------------------------------------------------------------------
  1187. // KERB-PA-PAC-REQUEST-EX ::= SEQUENCE {
  1188. // include-pac[0] BOOLEAN,
  1189. // -- if TRUE, and no pac present,
  1190. // -- include PAC. If FALSE, and pac
  1191. // -- PAC present, remove PAC
  1192. // pac-sections[1] SEQUENCE OF INTEGER OPTIONAL
  1193. // } --#public--
  1194. // -----------------------------------------------------------------------------
  1195. class ASN1ParserPaPacRequestEx : public ASN1ParserSequence
  1196. {
  1197. public:
  1198. //
  1199. // Constructor
  1200. //
  1201. ASN1ParserPaPacRequestEx(
  1202. IN BOOL IsOptional,
  1203. IN BYTE Descriptor,
  1204. IN HPROPERTY hProperty
  1205. ) : ASN1ParserSequence(
  1206. IsOptional,
  1207. Descriptor,
  1208. hProperty,
  1209. ARRAY_COUNT( m_p ),
  1210. m_p
  1211. ),
  1212. m_include_pac(
  1213. FALSE,
  1214. BuildDescriptor( ctContextSpecific, pcConstructed, e_include_pac ),
  1215. PROP( KERB_PA_PAC_REQUEST_EX_include_pac ),
  1216. 0 ),
  1217. m_pac_sections(
  1218. TRUE,
  1219. BuildDescriptor( ctContextSpecific, pcConstructed, e_pac_sections ),
  1220. PROP( KERB_PA_PAC_REQUEST_EX_pac_sections ),
  1221. PROP( KERB_PA_PAC_REQUEST_EX_pac_sections_desc ))
  1222. {
  1223. m_p[0] = &m_include_pac;
  1224. m_p[1] = &m_pac_sections;
  1225. }
  1226. private:
  1227. enum
  1228. {
  1229. e_include_pac = 0,
  1230. e_pac_sections = 1,
  1231. };
  1232. ASN1ParserBase * m_p[2];
  1233. ASN1ParserBoolean m_include_pac;
  1234. ASN1ParserIntegerSequence m_pac_sections;
  1235. };
  1236. // -----------------------------------------------------------------------------
  1237. // PA-DATA ::= SEQUENCE {
  1238. // padata-type[1] INTEGER,
  1239. // padata-value[2] OCTET STRING, -- might be encoded AP-REQ
  1240. // }
  1241. // -----------------------------------------------------------------------------
  1242. //
  1243. // PA-DATA types
  1244. //
  1245. enum
  1246. {
  1247. PA_NONE = 0x00,
  1248. PA_APTGS_REQ = 0x01,
  1249. PA_ENC_TIMESTAMP = 0x02,
  1250. PA_PW_SALT = 0x03,
  1251. PA_RESERVED = 0x04,
  1252. PA_ENC_UNIX_TIME = 0x05,
  1253. PA_SANDIA_SECUREID = 0x06,
  1254. PA_SESAME = 0x07,
  1255. PA_OSF_DCE = 0x08,
  1256. PA_CYBERSAFE_SECUREID = 0x09,
  1257. PA_AFS3_SALT = 0x0A,
  1258. PA_ETYPE_INFO = 0x0B,
  1259. SAM_CHALLENGE = 0x0C,
  1260. SAM_RESPONSE = 0x0D,
  1261. PA_PK_AS_REQ = 0x0E,
  1262. PA_PK_AS_REP = 0x0F,
  1263. PA_PK_AS_SIGN = 0x10,
  1264. PA_PK_KEY_REQ = 0x11,
  1265. PA_PK_KEY_REP = 0x12,
  1266. PA_USE_SPECIFIED_KVNO = 0x14,
  1267. SAM_REDIRECT = 0x15,
  1268. PA_GET_FROM_TYPED_DATA = 0x16,
  1269. PA_SAM_ETYPE_INFO = 0x17,
  1270. PA_ALT_PRINC = 0x18,
  1271. PA_REFERRAL_INFO = 0x20,
  1272. TD_PKINIT_CMS_CERTIFICATES = 0x65,
  1273. TD_KRB_PRINCIPAL = 0x66,
  1274. TD_KRB_REALM = 0x67,
  1275. TD_TRUSTED_CERTIFIERS = 0x68,
  1276. TD_CERTIFICATE_INDEX = 0x69,
  1277. TD_APP_DEFINED_ERROR = 0x6A,
  1278. TD_REQ_NONCE = 0x6B,
  1279. TD_REQ_SEQ = 0x6C,
  1280. PA_PAC_REQUEST = 0x80,
  1281. PA_FOR_USER = 0x81,
  1282. PA_COMPOUND_IDENTITY = 0x82,
  1283. PA_PAC_REQUEST_EX = 0x83,
  1284. PA_CLIENT_VERSION = 0x84,
  1285. PA_XBOX_SERVICE_REQUEST = 0xC9,
  1286. PA_XBOX_SERVICE_ADDRESS = 0xCA,
  1287. PA_XBOX_ACCOUNT_CREATION = 0xCB,
  1288. PA_XBOX_PPA = 0xCC,
  1289. PA_XBOX_ECHO = 0xCD,
  1290. };
  1291. class ASN1ParserPaData : public ASN1ParserSequence
  1292. {
  1293. public:
  1294. //
  1295. // Constructor
  1296. //
  1297. ASN1ParserPaData(
  1298. IN BOOL IsOptional,
  1299. IN BYTE Descriptor
  1300. ) : ASN1ParserSequence(
  1301. IsOptional,
  1302. Descriptor,
  1303. NULL,
  1304. ARRAY_COUNT( m_p ),
  1305. m_p ),
  1306. m_type(
  1307. FALSE,
  1308. BuildDescriptor( ctContextSpecific, pcConstructed, e_type ),
  1309. NULL,
  1310. 0 ),
  1311. m_value(
  1312. FALSE,
  1313. BuildDescriptor( ctContextSpecific, pcConstructed, e_value ),
  1314. NULL,
  1315. 0 )
  1316. {
  1317. m_p[0] = &m_type;
  1318. m_p[1] = &m_value;
  1319. //
  1320. // Name type affects the parsing of the value portion
  1321. //
  1322. m_type.SetModifyee( &m_value );
  1323. //
  1324. // Collect the values for both type and value for later processing
  1325. //
  1326. m_type.SetValueCollector( this );
  1327. m_value.SetValueCollector( this );
  1328. }
  1329. protected:
  1330. DWORD
  1331. DisplayCollectedValues(
  1332. IN ASN1FRAME * Frame,
  1333. IN ULONG Length,
  1334. IN ULPBYTE Address );
  1335. private:
  1336. enum
  1337. {
  1338. e_type = 1,
  1339. e_value = 2,
  1340. };
  1341. ASN1ParserBase * m_p[2];
  1342. ASN1ParserInteger m_type;
  1343. ASN1ParserOctetString m_value; // TODO: subclass for pa-data-type modifications
  1344. };
  1345. class ASN1ParserPaDataSequence : public ASN1ParserSequence
  1346. {
  1347. public:
  1348. //
  1349. // Constructor
  1350. //
  1351. ASN1ParserPaDataSequence(
  1352. IN BOOL IsOptional,
  1353. IN BYTE Descriptor,
  1354. IN HPROPERTY hProperty
  1355. ) : ASN1ParserSequence(
  1356. IsOptional,
  1357. Descriptor,
  1358. hProperty,
  1359. ARRAY_COUNT( m_p ),
  1360. m_p ),
  1361. m_padata(
  1362. FALSE,
  1363. 0 ) // No descriptor on individual pa-data entries
  1364. {
  1365. m_p[0] = &m_padata;
  1366. }
  1367. private:
  1368. ASN1ParserBase * m_p[1];
  1369. ASN1ParserPaData m_padata;
  1370. };
  1371. // -----------------------------------------------------------------------------
  1372. // KERB-TYPED-DATA ::= SEQUENCE {
  1373. // data-type [0] INTEGER,
  1374. // data-value [1] OCTET STRING
  1375. // }
  1376. // -----------------------------------------------------------------------------
  1377. class ASN1ParserTypedData : public ASN1ParserSequence
  1378. {
  1379. public:
  1380. //
  1381. // Constructor
  1382. //
  1383. ASN1ParserTypedData(
  1384. IN BOOL IsOptional,
  1385. IN BYTE Descriptor,
  1386. IN HPROPERTY hProperty
  1387. ) : ASN1ParserSequence(
  1388. IsOptional,
  1389. Descriptor,
  1390. hProperty,
  1391. ARRAY_COUNT( m_p ),
  1392. m_p ),
  1393. m_data_type(
  1394. FALSE,
  1395. BuildDescriptor( ctContextSpecific, pcConstructed, e_data_type ),
  1396. PROP( TYPED_DATA_type ),
  1397. 0 ),
  1398. m_data_value(
  1399. FALSE,
  1400. BuildDescriptor( ctContextSpecific, pcConstructed, e_data_value ),
  1401. PROP( TYPED_DATA_value ),
  1402. 0 )
  1403. {
  1404. m_p[0] = &m_data_type;
  1405. m_p[1] = &m_data_value;
  1406. //
  1407. // Data type affects how data value is parsed
  1408. //
  1409. m_data_type.SetModifyee( &m_data_value );
  1410. }
  1411. private:
  1412. enum
  1413. {
  1414. e_data_type = 0,
  1415. e_data_value = 1,
  1416. };
  1417. ASN1ParserBase * m_p[2];
  1418. ASN1ParserInteger m_data_type;
  1419. ASN1ParserOctetString m_data_value; // TODO: change type to allow subparsers
  1420. };
  1421. // -----------------------------------------------------------------------------
  1422. //
  1423. // PrincipalName ::= SEQUENCE {
  1424. // name-type[0] INTEGER,
  1425. // name-string[1] SEQUENCE OF GeneralString
  1426. // }
  1427. // -----------------------------------------------------------------------------
  1428. class ASN1ParserPrincipalName : public ASN1ParserSequence
  1429. {
  1430. public:
  1431. //
  1432. // Constructor
  1433. //
  1434. ASN1ParserPrincipalName(
  1435. IN BOOL IsOptional,
  1436. IN BYTE Descriptor,
  1437. IN HPROPERTY hProperty
  1438. ) : ASN1ParserSequence(
  1439. IsOptional,
  1440. Descriptor,
  1441. NULL,
  1442. ARRAY_COUNT( m_p ),
  1443. m_p ),
  1444. m_hPropertyTopLevel( hProperty ),
  1445. m_type(
  1446. FALSE,
  1447. BuildDescriptor( ctContextSpecific, pcConstructed, e_type ),
  1448. NULL,
  1449. 0 ),
  1450. m_string_seq(
  1451. FALSE,
  1452. BuildDescriptor( ctContextSpecific, pcConstructed, e_string ))
  1453. {
  1454. m_p[0] = &m_type;
  1455. m_p[1] = &m_string_seq;
  1456. //
  1457. // Act as the value collector for the data inside the sequence
  1458. //
  1459. m_type.SetValueCollector( this );
  1460. m_string_seq.SetValueCollector( this );
  1461. }
  1462. protected:
  1463. DWORD
  1464. DisplayCollectedValues(
  1465. IN ASN1FRAME * Frame,
  1466. IN ULONG Length,
  1467. IN ULPBYTE Address );
  1468. HPROPERTY m_hPropertyTopLevel;
  1469. private:
  1470. enum
  1471. {
  1472. e_type = 0,
  1473. e_string = 1,
  1474. };
  1475. ASN1ParserBase * m_p[2];
  1476. ASN1ParserInteger m_type;
  1477. ASN1ParserPrincipalNameSequence m_string_seq;
  1478. };
  1479. // -----------------------------------------------------------------------------
  1480. // KERB-CHECKSUM ::= SEQUENCE {
  1481. // checksum-type[0] INTEGER,
  1482. // checksum[1] OCTET STRING
  1483. // } --#public--
  1484. // -----------------------------------------------------------------------------
  1485. class ASN1ParserKerbChecksum : public ASN1ParserSequence
  1486. {
  1487. public:
  1488. //
  1489. // Constructor
  1490. //
  1491. ASN1ParserKerbChecksum(
  1492. IN BOOL IsOptional,
  1493. IN BYTE Descriptor,
  1494. IN HPROPERTY hProperty
  1495. ) : ASN1ParserSequence(
  1496. IsOptional,
  1497. Descriptor,
  1498. hProperty,
  1499. ARRAY_COUNT( m_p ),
  1500. m_p ),
  1501. m_checksum_type(
  1502. FALSE,
  1503. BuildDescriptor( ctContextSpecific, pcConstructed, e_checksum_type ),
  1504. PROP( KERB_CHECKSUM_type ),
  1505. 0 ),
  1506. m_checksum(
  1507. FALSE,
  1508. BuildDescriptor( ctContextSpecific, pcConstructed, e_checksum ),
  1509. PROP( KERB_CHECKSUM_checksum ),
  1510. 0 )
  1511. {
  1512. m_p[0] = &m_checksum_type;
  1513. m_p[1] = &m_checksum;
  1514. }
  1515. private:
  1516. enum
  1517. {
  1518. e_checksum_type = 0,
  1519. e_checksum = 1,
  1520. };
  1521. ASN1ParserBase * m_p[2];
  1522. ASN1ParserInteger m_checksum_type;
  1523. ASN1ParserOctetString m_checksum;
  1524. };
  1525. // -----------------------------------------------------------------------------
  1526. // Ticket ::= [APPLICATION 1] SEQUENCE {
  1527. // tkt-vno[0] INTEGER,
  1528. // realm[1] Realm,
  1529. // sname[2] PrincipalName,
  1530. // enc-part[3] EncryptedData
  1531. // }
  1532. // -----------------------------------------------------------------------------
  1533. class ASN1ParserTicket : public ASN1ParserSequence
  1534. {
  1535. public:
  1536. //
  1537. // Constructor
  1538. //
  1539. ASN1ParserTicket(
  1540. IN BOOL IsOptional,
  1541. IN BYTE Descriptor,
  1542. IN HPROPERTY hProperty
  1543. ) : ASN1ParserSequence(
  1544. IsOptional,
  1545. Descriptor,
  1546. hProperty,
  1547. ARRAY_COUNT( m_p ),
  1548. m_p ),
  1549. m_tkt_vno(
  1550. FALSE,
  1551. BuildDescriptor( ctContextSpecific, pcConstructed, e_tkt_vno ),
  1552. PROP( Ticket_tkt_vno ),
  1553. 0 ),
  1554. m_realm(
  1555. FALSE,
  1556. BuildDescriptor( ctContextSpecific, pcConstructed, e_realm ),
  1557. PROP( Ticket_realm ),
  1558. 0 ),
  1559. m_sname(
  1560. FALSE,
  1561. BuildDescriptor( ctContextSpecific, pcConstructed, e_sname ),
  1562. PROP( Ticket_sname )),
  1563. m_enc_part(
  1564. FALSE,
  1565. BuildDescriptor( ctContextSpecific, pcConstructed, e_enc_part ),
  1566. PROP( Ticket_enc_part ))
  1567. {
  1568. SetAppDescriptor(
  1569. BuildDescriptor( ctApplication, pcConstructed, 1 )
  1570. );
  1571. m_p[0] = &m_tkt_vno;
  1572. m_p[1] = &m_realm;
  1573. m_p[2] = &m_sname;
  1574. m_p[3] = &m_enc_part;
  1575. }
  1576. private:
  1577. enum
  1578. {
  1579. e_tkt_vno = 0,
  1580. e_realm = 1,
  1581. e_sname = 2,
  1582. e_enc_part = 3
  1583. };
  1584. ASN1ParserBase * m_p[4];
  1585. ASN1ParserInteger m_tkt_vno;
  1586. ASN1ParserGeneralString m_realm;
  1587. ASN1ParserPrincipalName m_sname;
  1588. ASN1ParserEncryptedData m_enc_part;
  1589. };
  1590. class ASN1ParserTicketSequence : public ASN1ParserSequence
  1591. {
  1592. public:
  1593. //
  1594. // Constructor
  1595. //
  1596. ASN1ParserTicketSequence(
  1597. IN BOOL IsOptional,
  1598. IN BYTE Descriptor,
  1599. IN HPROPERTY hPropertySeq,
  1600. IN HPROPERTY hPropertyTicket
  1601. ) : ASN1ParserSequence(
  1602. IsOptional,
  1603. Descriptor,
  1604. hPropertySeq,
  1605. ARRAY_COUNT( m_p ),
  1606. m_p ),
  1607. m_ticket(
  1608. FALSE,
  1609. 0, // No descriptor on sequences of tickets
  1610. hPropertyTicket )
  1611. {
  1612. m_p[0] = &m_ticket;
  1613. }
  1614. private:
  1615. ASN1ParserBase * m_p[1];
  1616. ASN1ParserTicket m_ticket;
  1617. };
  1618. // -----------------------------------------------------------------------------
  1619. // KDC-REQ-BODY ::= SEQUENCE {
  1620. // kdc-options[0] KDCOptions,
  1621. // cname[1] PrincipalName OPTIONAL,
  1622. // -- Used only in AS-REQ
  1623. // realm[2] Realm, -- Server's realm
  1624. // -- Also client's in AS-REQ
  1625. // sname[3] PrincipalName OPTIONAL,
  1626. // from[4] KerberosTime OPTIONAL,
  1627. // till[5] KerberosTime,
  1628. // rtime[6] KerberosTime OPTIONAL,
  1629. // nonce[7] INTEGER,
  1630. // etype[8] SEQUENCE OF INTEGER,
  1631. // -- EncryptionType,
  1632. // -- in preference order
  1633. // addresses[9] HostAddresses OPTIONAL,
  1634. // enc-authorization-data[10] EncryptedData OPTIONAL,
  1635. // -- Encrypted AuthorizationData encoding
  1636. // additional-tickets[11] SEQUENCE OF Ticket OPTIONAL
  1637. // }
  1638. // -----------------------------------------------------------------------------
  1639. class ASN1ParserKdcReqBody : public ASN1ParserSequence
  1640. {
  1641. public:
  1642. ASN1ParserKdcReqBody(
  1643. IN BOOL IsOptional,
  1644. IN BYTE Descriptor,
  1645. IN HPROPERTY hProperty
  1646. ) : ASN1ParserSequence(
  1647. IsOptional,
  1648. Descriptor,
  1649. hProperty,
  1650. ARRAY_COUNT( m_p ),
  1651. m_p ),
  1652. m_kdc_options(
  1653. FALSE,
  1654. BuildDescriptor( ctContextSpecific, pcConstructed, e_kdc_options ),
  1655. PROP( KDC_REQ_BODY_kdc_options_summary ),
  1656. PROP( KDC_REQ_BODY_kdc_options_value ),
  1657. 0 ),
  1658. m_cname( // TODO: enforce the fact that TGS KDC-REQ-BODY does not have this
  1659. TRUE,
  1660. BuildDescriptor( ctContextSpecific, pcConstructed, e_cname ),
  1661. PROP( KDC_REQ_BODY_cname )),
  1662. m_realm(
  1663. FALSE,
  1664. BuildDescriptor( ctContextSpecific, pcConstructed, e_realm ),
  1665. PROP( KDC_REQ_BODY_realm ),
  1666. 0 ),
  1667. m_sname(
  1668. TRUE,
  1669. BuildDescriptor( ctContextSpecific, pcConstructed, e_sname ),
  1670. PROP( KDC_REQ_BODY_sname )),
  1671. m_from(
  1672. TRUE,
  1673. BuildDescriptor( ctContextSpecific, pcConstructed, e_from ),
  1674. PROP( KDC_REQ_BODY_from)),
  1675. m_till(
  1676. FALSE,
  1677. BuildDescriptor( ctContextSpecific, pcConstructed, e_till ),
  1678. PROP( KDC_REQ_BODY_till )),
  1679. m_rtime(
  1680. TRUE,
  1681. BuildDescriptor( ctContextSpecific, pcConstructed, e_rtime ),
  1682. PROP( KDC_REQ_BODY_rtime )),
  1683. m_nonce(
  1684. FALSE,
  1685. BuildDescriptor( ctContextSpecific, pcConstructed, e_nonce ),
  1686. PROP( KDC_REQ_BODY_nonce ),
  1687. 0 ),
  1688. m_etype(
  1689. FALSE,
  1690. BuildDescriptor( ctContextSpecific, pcConstructed, e_etype ),
  1691. PROP( KDC_REQ_BODY_etype ),
  1692. PROP( EncryptionType )),
  1693. m_addresses(
  1694. TRUE,
  1695. BuildDescriptor( ctContextSpecific, pcConstructed, e_addresses ),
  1696. PROP( KDC_REQ_BODY_addresses )),
  1697. m_enc_authorization_data(
  1698. TRUE,
  1699. BuildDescriptor( ctContextSpecific, pcConstructed, e_enc_authorization_data ),
  1700. PROP( KDC_REQ_BODY_enc_authorization_data)),
  1701. m_additional_tickets(
  1702. TRUE,
  1703. BuildDescriptor( ctContextSpecific, pcConstructed, e_additional_tickets ),
  1704. PROP( KDC_REQ_BODY_additional_tickets ),
  1705. PROP( AdditionalTicket ))
  1706. {
  1707. m_p[0] = &m_kdc_options;
  1708. m_p[1] = &m_cname;
  1709. m_p[2] = &m_realm;
  1710. m_p[3] = &m_sname;
  1711. m_p[4] = &m_from;
  1712. m_p[5] = &m_till;
  1713. m_p[6] = &m_rtime;
  1714. m_p[7] = &m_nonce;
  1715. m_p[8] = &m_etype;
  1716. m_p[9] = &m_addresses;
  1717. m_p[10] = &m_enc_authorization_data;
  1718. m_p[11] = &m_additional_tickets;
  1719. }
  1720. private:
  1721. enum
  1722. {
  1723. e_kdc_options = 0,
  1724. e_cname = 1,
  1725. e_realm = 2,
  1726. e_sname = 3,
  1727. e_from = 4,
  1728. e_till = 5,
  1729. e_rtime = 6,
  1730. e_nonce = 7,
  1731. e_etype = 8,
  1732. e_addresses = 9,
  1733. e_enc_authorization_data = 10,
  1734. e_additional_tickets = 11,
  1735. };
  1736. ASN1ParserBase * m_p[12];
  1737. ASN1ParserBitString m_kdc_options;
  1738. ASN1ParserPrincipalName m_cname;
  1739. ASN1ParserGeneralString m_realm;
  1740. ASN1ParserPrincipalName m_sname;
  1741. ASN1ParserGeneralizedTime m_from;
  1742. ASN1ParserGeneralizedTime m_till;
  1743. ASN1ParserGeneralizedTime m_rtime;
  1744. ASN1ParserInteger m_nonce;
  1745. ASN1ParserIntegerSequence m_etype;
  1746. ASN1ParserHostAddresses m_addresses;
  1747. ASN1ParserEncryptedData m_enc_authorization_data;
  1748. ASN1ParserTicketSequence m_additional_tickets;
  1749. };
  1750. // -----------------------------------------------------------------------------
  1751. // KDC-REQ ::= SEQUENCE {
  1752. // pvno[1] INTEGER,
  1753. // msg-type[2] INTEGER,
  1754. // padata[3] SEQUENCE OF PA-DATA OPTIONAL,
  1755. // req-body[4] KDC-REQ-BODY
  1756. // }
  1757. // -----------------------------------------------------------------------------
  1758. class ASN1ParserKdcReq : public ASN1ParserSequence
  1759. {
  1760. public:
  1761. //
  1762. // Constructor
  1763. //
  1764. ASN1ParserKdcReq(
  1765. IN BOOL IsOptional,
  1766. IN BYTE Descriptor,
  1767. IN HPROPERTY hProperty
  1768. ) : ASN1ParserSequence(
  1769. IsOptional,
  1770. Descriptor,
  1771. hProperty,
  1772. ARRAY_COUNT( m_p ),
  1773. m_p ),
  1774. m_pvno(
  1775. FALSE,
  1776. BuildDescriptor( ctContextSpecific, pcConstructed, e_pvno ),
  1777. PROP( KDC_REQ_pvno ),
  1778. 0 ),
  1779. m_msg_type(
  1780. FALSE,
  1781. BuildDescriptor( ctContextSpecific, pcConstructed, e_msg_type ),
  1782. PROP( KDC_REQ_msg_type ),
  1783. 0,
  1784. 0x1F ), // only care about the bottom five bits of the value
  1785. m_padata(
  1786. TRUE,
  1787. BuildDescriptor( ctContextSpecific, pcConstructed, e_padata ),
  1788. PROP( KDC_REQ_padata )),
  1789. m_kdc_req_body(
  1790. FALSE,
  1791. BuildDescriptor( ctContextSpecific, pcConstructed, e_req_body ),
  1792. PROP( KDC_REQ_req_body ))
  1793. {
  1794. m_p[0] = &m_pvno;
  1795. m_p[1] = &m_msg_type;
  1796. m_p[2] = &m_padata;
  1797. m_p[3] = &m_kdc_req_body;
  1798. }
  1799. private:
  1800. enum
  1801. {
  1802. e_pvno = 1,
  1803. e_msg_type = 2,
  1804. e_padata = 3,
  1805. e_req_body = 4,
  1806. };
  1807. ASN1ParserBase * m_p[4];
  1808. ASN1ParserInteger m_pvno;
  1809. ASN1ParserInteger m_msg_type;
  1810. ASN1ParserPaDataSequence m_padata;
  1811. ASN1ParserKdcReqBody m_kdc_req_body;
  1812. };
  1813. // -----------------------------------------------------------------------------
  1814. // KDC-REP ::= SEQUENCE {
  1815. // pvno[0] INTEGER,
  1816. // msg-type[1] INTEGER,
  1817. // padata[2] SEQUENCE OF PA-DATA OPTIONAL,
  1818. // crealm[3] Realm,
  1819. // cname[4] PrincipalName,
  1820. // ticket[5] Ticket,
  1821. // enc-part[6] EncryptedData
  1822. // }
  1823. // -----------------------------------------------------------------------------
  1824. class ASN1ParserKdcRep : public ASN1ParserSequence
  1825. {
  1826. public:
  1827. //
  1828. // Constructor
  1829. //
  1830. ASN1ParserKdcRep(
  1831. IN BOOL IsOptional,
  1832. IN BYTE Descriptor,
  1833. IN HPROPERTY hProperty
  1834. ) : ASN1ParserSequence(
  1835. IsOptional,
  1836. Descriptor,
  1837. hProperty,
  1838. ARRAY_COUNT( m_p ),
  1839. m_p ),
  1840. m_pvno(
  1841. FALSE,
  1842. BuildDescriptor( ctContextSpecific, pcConstructed, e_pvno ),
  1843. PROP( KDC_REP_pvno ),
  1844. 0 ),
  1845. m_msg_type(
  1846. FALSE,
  1847. BuildDescriptor( ctContextSpecific, pcConstructed, e_msg_type ),
  1848. PROP( KDC_REP_msg_type ),
  1849. 0 ),
  1850. m_padata(
  1851. TRUE,
  1852. BuildDescriptor( ctContextSpecific, pcConstructed, e_padata ),
  1853. PROP( KDC_REP_padata )),
  1854. m_crealm(
  1855. FALSE,
  1856. BuildDescriptor( ctContextSpecific, pcConstructed, e_crealm ),
  1857. PROP( KDC_REP_crealm ),
  1858. 0 ),
  1859. m_cname(
  1860. FALSE,
  1861. BuildDescriptor( ctContextSpecific, pcConstructed, e_cname ),
  1862. PROP( KDC_REP_cname )),
  1863. m_ticket(
  1864. FALSE,
  1865. BuildDescriptor( ctContextSpecific, pcConstructed, e_ticket ),
  1866. PROP( KDC_REP_ticket )),
  1867. m_enc_part(
  1868. FALSE,
  1869. BuildDescriptor( ctContextSpecific, pcConstructed, e_enc_part ),
  1870. PROP( KDC_REP_enc_part ))
  1871. {
  1872. m_p[0] = &m_pvno;
  1873. m_p[1] = &m_msg_type;
  1874. m_p[2] = &m_padata;
  1875. m_p[3] = &m_crealm;
  1876. m_p[4] = &m_cname;
  1877. m_p[5] = &m_ticket;
  1878. m_p[6] = &m_enc_part;
  1879. }
  1880. private:
  1881. enum
  1882. {
  1883. e_pvno = 0,
  1884. e_msg_type = 1,
  1885. e_padata = 2,
  1886. e_crealm = 3,
  1887. e_cname = 4,
  1888. e_ticket = 5,
  1889. e_enc_part = 6,
  1890. };
  1891. ASN1ParserBase * m_p[7];
  1892. ASN1ParserInteger m_pvno;
  1893. ASN1ParserInteger m_msg_type;
  1894. ASN1ParserPaDataSequence m_padata;
  1895. ASN1ParserGeneralString m_crealm;
  1896. ASN1ParserPrincipalName m_cname;
  1897. ASN1ParserTicket m_ticket;
  1898. ASN1ParserEncryptedData m_enc_part;
  1899. };
  1900. // -----------------------------------------------------------------------------
  1901. // KRB-ERROR ::= [APPLICATION 30] SEQUENCE {
  1902. // pvno[0] INTEGER,
  1903. // msg-type[1] INTEGER,
  1904. // ctime[2] KerberosTime OPTIONAL,
  1905. // cusec[3] INTEGER OPTIONAL,
  1906. // stime[4] KerberosTime,
  1907. // susec[5] INTEGER,
  1908. // error-code[6] INTEGER,
  1909. // crealm[7] Realm OPTIONAL,
  1910. // cname[8] PrincipalName OPTIONAL,
  1911. // realm[9] Realm, -- Correct realm
  1912. // sname[10] PrincipalName, -- Correct name
  1913. // e-text[11] GeneralString OPTIONAL,
  1914. // e-data[12] OCTET STRING OPTIONAL
  1915. // }
  1916. // -----------------------------------------------------------------------------
  1917. class ASN1ParserKrbError : public ASN1ParserSequence
  1918. {
  1919. public:
  1920. //
  1921. // Constructor
  1922. //
  1923. ASN1ParserKrbError(
  1924. IN BOOL IsOptional,
  1925. IN BYTE Descriptor,
  1926. IN HPROPERTY hProperty
  1927. ) : ASN1ParserSequence(
  1928. IsOptional,
  1929. Descriptor,
  1930. hProperty,
  1931. ARRAY_COUNT( m_p ),
  1932. m_p ),
  1933. m_pvno(
  1934. FALSE,
  1935. BuildDescriptor( ctContextSpecific, pcConstructed, e_pvno ),
  1936. PROP( KRB_ERR_pvno ),
  1937. 0 ),
  1938. m_msg_type(
  1939. FALSE,
  1940. BuildDescriptor( ctContextSpecific, pcConstructed, e_msg_type ),
  1941. PROP( KRB_ERR_msg_type ),
  1942. 0 ),
  1943. m_ctime(
  1944. TRUE,
  1945. BuildDescriptor( ctContextSpecific, pcConstructed, e_ctime ),
  1946. PROP( KRB_ERR_ctime )),
  1947. m_cusec(
  1948. TRUE,
  1949. BuildDescriptor( ctContextSpecific, pcConstructed, e_cusec ),
  1950. PROP( KRB_ERR_cusec ),
  1951. 0 ),
  1952. m_stime(
  1953. FALSE,
  1954. BuildDescriptor( ctContextSpecific, pcConstructed, e_stime ),
  1955. PROP( KRB_ERR_stime )),
  1956. m_susec(
  1957. FALSE,
  1958. BuildDescriptor( ctContextSpecific, pcConstructed, e_susec ),
  1959. PROP( KRB_ERR_susec ),
  1960. 0 ),
  1961. m_error_code(
  1962. FALSE,
  1963. BuildDescriptor( ctContextSpecific, pcConstructed, e_error_code ),
  1964. PROP( KRB_ERR_error_code ),
  1965. 0 ),
  1966. m_crealm(
  1967. TRUE,
  1968. BuildDescriptor( ctContextSpecific, pcConstructed, e_crealm ),
  1969. PROP( KRB_ERR_crealm ),
  1970. 0 ),
  1971. m_cname(
  1972. TRUE,
  1973. BuildDescriptor( ctContextSpecific, pcConstructed, e_cname ),
  1974. PROP( KRB_ERR_cname )),
  1975. m_realm(
  1976. FALSE,
  1977. BuildDescriptor( ctContextSpecific, pcConstructed, e_realm ),
  1978. PROP( KRB_ERR_realm ),
  1979. 0 ),
  1980. m_sname(
  1981. FALSE,
  1982. BuildDescriptor( ctContextSpecific, pcConstructed, e_sname ),
  1983. PROP( KRB_ERR_sname )),
  1984. m_e_text(
  1985. TRUE,
  1986. BuildDescriptor( ctContextSpecific, pcConstructed, e_e_text ),
  1987. PROP( KRB_ERR_e_text ),
  1988. 0 ),
  1989. m_e_data(
  1990. TRUE,
  1991. BuildDescriptor( ctContextSpecific, pcConstructed, e_e_data ),
  1992. PROP( KRB_ERR_e_data ))
  1993. {
  1994. m_p[0] = &m_pvno;
  1995. m_p[1] = &m_msg_type;
  1996. m_p[2] = &m_ctime;
  1997. m_p[3] = &m_cusec;
  1998. m_p[4] = &m_stime;
  1999. m_p[5] = &m_susec;
  2000. m_p[6] = &m_error_code;
  2001. m_p[7] = &m_crealm;
  2002. m_p[8] = &m_cname;
  2003. m_p[9] = &m_realm;
  2004. m_p[10] = &m_sname;
  2005. m_p[11] = &m_e_text;
  2006. m_p[12] = &m_e_data;
  2007. //
  2008. // Address type affects the parsing of the error data portion
  2009. //
  2010. m_error_code.SetModifyee( &m_e_data );
  2011. }
  2012. private:
  2013. enum
  2014. {
  2015. e_pvno = 0,
  2016. e_msg_type = 1,
  2017. e_ctime = 2,
  2018. e_cusec = 3,
  2019. e_stime = 4,
  2020. e_susec = 5,
  2021. e_error_code = 6,
  2022. e_crealm = 7,
  2023. e_cname = 8,
  2024. e_realm = 9,
  2025. e_sname = 10,
  2026. e_e_text = 11,
  2027. e_e_data = 12,
  2028. };
  2029. ASN1ParserBase * m_p[13];
  2030. ASN1ParserInteger m_pvno;
  2031. ASN1ParserInteger m_msg_type;
  2032. ASN1ParserGeneralizedTime m_ctime;
  2033. ASN1ParserInteger m_cusec;
  2034. ASN1ParserGeneralizedTime m_stime;
  2035. ASN1ParserInteger m_susec;
  2036. ASN1ParserInteger m_error_code;
  2037. ASN1ParserGeneralString m_crealm;
  2038. ASN1ParserPrincipalName m_cname;
  2039. ASN1ParserGeneralString m_realm;
  2040. ASN1ParserPrincipalName m_sname;
  2041. ASN1ParserGeneralString m_e_text;
  2042. ASN1ParserErrorData m_e_data;
  2043. };
  2044. // -----------------------------------------------------------------------------
  2045. // KERB-ETYPE-INFO-ENTRY ::= SEQUENCE {
  2046. // encryption-type[0] INTEGER,
  2047. // salt[1] OCTET STRING OPTIONAL
  2048. // }
  2049. // -----------------------------------------------------------------------------
  2050. class ASN1ParserKerbEtypeInfoEntry : public ASN1ParserSequence
  2051. {
  2052. public:
  2053. //
  2054. // Constructor
  2055. //
  2056. ASN1ParserKerbEtypeInfoEntry(
  2057. IN BOOL IsOptional,
  2058. IN BYTE Descriptor
  2059. ) : ASN1ParserSequence(
  2060. IsOptional,
  2061. Descriptor,
  2062. NULL,
  2063. ARRAY_COUNT( m_p ),
  2064. m_p ),
  2065. m_encryption_type(
  2066. FALSE,
  2067. BuildDescriptor( ctContextSpecific, pcConstructed, e_encryption_type ),
  2068. NULL,
  2069. 0 ),
  2070. m_salt(
  2071. TRUE,
  2072. BuildDescriptor( ctContextSpecific, pcConstructed, e_salt ),
  2073. NULL,
  2074. 0 ),
  2075. m_what_is_this_integer(
  2076. TRUE,
  2077. BuildDescriptor( ctContextSpecific, pcConstructed, e_what_is_this_integer ),
  2078. NULL,
  2079. 0 )
  2080. {
  2081. m_p[0] = &m_encryption_type;
  2082. m_p[1] = &m_salt;
  2083. m_p[2] = &m_what_is_this_integer;
  2084. //
  2085. // Handle the display of this one for ease of readability
  2086. //
  2087. m_encryption_type.SetValueCollector( this );
  2088. m_salt.SetValueCollector( this );
  2089. m_what_is_this_integer.SetValueCollector( this );
  2090. }
  2091. protected:
  2092. DWORD
  2093. DisplayCollectedValues(
  2094. IN ASN1FRAME * Frame,
  2095. IN ULONG Length,
  2096. IN ULPBYTE Address );
  2097. private:
  2098. enum
  2099. {
  2100. e_encryption_type = 0,
  2101. e_salt = 1,
  2102. e_what_is_this_integer = 2,
  2103. };
  2104. ASN1ParserBase * m_p[3];
  2105. ASN1ParserInteger m_encryption_type;
  2106. ASN1ParserOctetString m_salt;
  2107. ASN1ParserInteger m_what_is_this_integer;
  2108. };
  2109. // -----------------------------------------------------------------------------
  2110. // PKERB-ETYPE-INFO ::= SEQUENCE OF KERB-ETYPE-INFO-ENTRY
  2111. // -----------------------------------------------------------------------------
  2112. class ASN1ParserKerbEtypeInfo : public ASN1ParserSequence
  2113. {
  2114. public:
  2115. //
  2116. // Constructor
  2117. //
  2118. ASN1ParserKerbEtypeInfo(
  2119. IN BOOL IsOptional,
  2120. IN BYTE Descriptor,
  2121. IN HPROPERTY hProperty
  2122. ) : ASN1ParserSequence(
  2123. IsOptional,
  2124. Descriptor,
  2125. hProperty,
  2126. ARRAY_COUNT( m_p ),
  2127. m_p ),
  2128. m_kerb_etype_info_entry(
  2129. FALSE,
  2130. 0 ) // no descriptor on individual addresses sequences
  2131. {
  2132. m_p[0] = &m_kerb_etype_info_entry;
  2133. }
  2134. private:
  2135. ASN1ParserBase * m_p[1];
  2136. ASN1ParserKerbEtypeInfoEntry m_kerb_etype_info_entry;
  2137. };
  2138. // -----------------------------------------------------------------------------
  2139. // KERB-PA-FOR-USER ::= SEQUENCE {
  2140. // -- PA TYPE 129
  2141. // userName [0] KERB-PRINCIPAL-NAME,
  2142. // userRealm [1] KERB-REALM,
  2143. // cksum [2] KERB-CHECKSUM,
  2144. // authentication-package [3] GeneralString,
  2145. // authorization-data [4] OCTET STRING OPTIONAL,
  2146. // ...
  2147. // }--#public--
  2148. // -----------------------------------------------------------------------------
  2149. class ASN1ParserKerbPaForUser : public ASN1ParserSequence
  2150. {
  2151. public:
  2152. //
  2153. // Constructor
  2154. //
  2155. ASN1ParserKerbPaForUser(
  2156. IN BOOL IsOptional,
  2157. IN BYTE Descriptor,
  2158. IN HPROPERTY hProperty
  2159. ) : ASN1ParserSequence(
  2160. IsOptional,
  2161. Descriptor,
  2162. hProperty,
  2163. ARRAY_COUNT( m_p ),
  2164. m_p,
  2165. TRUE ),
  2166. m_userName(
  2167. FALSE,
  2168. BuildDescriptor( ctContextSpecific, pcConstructed, e_userName ),
  2169. PROP( PA_FOR_USER_userName )),
  2170. m_userRealm(
  2171. FALSE,
  2172. BuildDescriptor( ctContextSpecific, pcConstructed, e_userRealm ),
  2173. PROP( PA_FOR_USER_userRealm ),
  2174. 0 ),
  2175. m_cksum(
  2176. FALSE,
  2177. BuildDescriptor( ctContextSpecific, pcConstructed, e_cksum ),
  2178. PROP( PA_FOR_USER_cksum )),
  2179. m_authentication_package(
  2180. FALSE,
  2181. BuildDescriptor( ctContextSpecific, pcConstructed, e_authentication_package ),
  2182. PROP( PA_FOR_USER_authentication_package ),
  2183. 0 ),
  2184. m_authorization_data(
  2185. TRUE,
  2186. BuildDescriptor( ctContextSpecific, pcConstructed, e_authorization_data ),
  2187. PROP( PA_FOR_USER_authorization_data ),
  2188. 0 )
  2189. {
  2190. m_p[0] = &m_userName;
  2191. m_p[1] = &m_userRealm;
  2192. m_p[2] = &m_cksum;
  2193. m_p[3] = &m_authentication_package;
  2194. m_p[4] = &m_authorization_data;
  2195. }
  2196. private:
  2197. enum
  2198. {
  2199. e_userName = 0,
  2200. e_userRealm = 1,
  2201. e_cksum = 2,
  2202. e_authentication_package = 3,
  2203. e_authorization_data = 4,
  2204. };
  2205. ASN1ParserBase * m_p[5];
  2206. ASN1ParserPrincipalName m_userName;
  2207. ASN1ParserGeneralString m_userRealm;
  2208. ASN1ParserKerbChecksum m_cksum;
  2209. ASN1ParserGeneralString m_authentication_package;
  2210. ASN1ParserOctetString m_authorization_data;
  2211. };
  2212. // -----------------------------------------------------------------------------
  2213. // AP-REQ ::= [APPLICATION 14] SEQUENCE {
  2214. // pvno[0] INTEGER,
  2215. // msg-type[1] INTEGER,
  2216. // ap-options[2] APOptions,
  2217. // ticket[3] Ticket,
  2218. // authenticator[4] EncryptedData
  2219. // }
  2220. // -----------------------------------------------------------------------------
  2221. class ASN1ParserApReq : public ASN1ParserSequence
  2222. {
  2223. public:
  2224. //
  2225. // Constructor
  2226. //
  2227. ASN1ParserApReq(
  2228. IN BOOL IsOptional,
  2229. IN BYTE Descriptor,
  2230. IN HPROPERTY hProperty
  2231. ) : ASN1ParserSequence(
  2232. IsOptional,
  2233. Descriptor,
  2234. hProperty,
  2235. ARRAY_COUNT( m_p ),
  2236. m_p ),
  2237. m_pvno(
  2238. FALSE,
  2239. BuildDescriptor( ctContextSpecific, pcConstructed, e_pvno ),
  2240. PROP( AP_REQ_pvno ),
  2241. 0 ),
  2242. m_msg_type(
  2243. FALSE,
  2244. BuildDescriptor( ctContextSpecific, pcConstructed, e_msg_type ),
  2245. PROP( AP_REQ_msg_type ),
  2246. 0 ),
  2247. m_ap_options(
  2248. FALSE,
  2249. BuildDescriptor( ctContextSpecific, pcConstructed, e_ap_options ),
  2250. PROP( AP_REQ_ap_options_summary ),
  2251. PROP( AP_REQ_ap_options_value ),
  2252. 0 ),
  2253. m_ticket(
  2254. FALSE,
  2255. BuildDescriptor( ctContextSpecific, pcConstructed, e_ticket ),
  2256. PROP( AP_REQ_ticket )),
  2257. m_authenticator(
  2258. FALSE,
  2259. BuildDescriptor( ctContextSpecific, pcConstructed, e_authenticator ),
  2260. PROP( AP_REQ_authenticator ))
  2261. {
  2262. SetAppDescriptor(
  2263. BuildDescriptor( ctApplication, pcConstructed, ASN1_KRB_AP_REQ )
  2264. );
  2265. m_p[0] = &m_pvno;
  2266. m_p[1] = &m_msg_type;
  2267. m_p[2] = &m_ap_options;
  2268. m_p[3] = &m_ticket;
  2269. m_p[4] = &m_authenticator;
  2270. }
  2271. private:
  2272. enum
  2273. {
  2274. e_pvno = 0,
  2275. e_msg_type = 1,
  2276. e_ap_options = 2,
  2277. e_ticket = 3,
  2278. e_authenticator = 4,
  2279. };
  2280. ASN1ParserBase * m_p[5];
  2281. ASN1ParserInteger m_pvno;
  2282. ASN1ParserInteger m_msg_type;
  2283. ASN1ParserBitString m_ap_options;
  2284. ASN1ParserTicket m_ticket;
  2285. ASN1ParserEncryptedData m_authenticator;
  2286. };
  2287. #endif // __ASN1PARSER_HXX