Source code of Windows XP (NT5)
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.

737 lines
21 KiB

  1. #include <windows.h>
  2. #include "spnego.h"
  3. ASN1module_t SPNEGO_Module = NULL;
  4. static int ASN1CALL ASN1Enc_SavedMechTypeList(ASN1encoding_t enc, ASN1uint32_t tag, SavedMechTypeList *val);
  5. static int ASN1CALL ASN1Enc_MechTypeList(ASN1encoding_t enc, ASN1uint32_t tag, PMechTypeList *val);
  6. static int ASN1CALL ASN1Enc_NegHints(ASN1encoding_t enc, ASN1uint32_t tag, NegHints *val);
  7. static int ASN1CALL ASN1Enc_NegTokenInit(ASN1encoding_t enc, ASN1uint32_t tag, NegTokenInit *val);
  8. static int ASN1CALL ASN1Enc_NegTokenInit2(ASN1encoding_t enc, ASN1uint32_t tag, NegTokenInit2 *val);
  9. static int ASN1CALL ASN1Enc_NegTokenTarg(ASN1encoding_t enc, ASN1uint32_t tag, NegTokenTarg *val);
  10. static int ASN1CALL ASN1Enc_NegotiationToken(ASN1encoding_t enc, ASN1uint32_t tag, NegotiationToken *val);
  11. static int ASN1CALL ASN1Enc_InitialNegToken(ASN1encoding_t enc, ASN1uint32_t tag, InitialNegToken *val);
  12. static int ASN1CALL ASN1Dec_SavedMechTypeList(ASN1decoding_t dec, ASN1uint32_t tag, SavedMechTypeList *val);
  13. static int ASN1CALL ASN1Dec_MechTypeList(ASN1decoding_t dec, ASN1uint32_t tag, PMechTypeList *val);
  14. static int ASN1CALL ASN1Dec_NegHints(ASN1decoding_t dec, ASN1uint32_t tag, NegHints *val);
  15. static int ASN1CALL ASN1Dec_NegTokenInit(ASN1decoding_t dec, ASN1uint32_t tag, NegTokenInit *val);
  16. static int ASN1CALL ASN1Dec_NegTokenInit2(ASN1decoding_t dec, ASN1uint32_t tag, NegTokenInit2 *val);
  17. static int ASN1CALL ASN1Dec_NegTokenTarg(ASN1decoding_t dec, ASN1uint32_t tag, NegTokenTarg *val);
  18. static int ASN1CALL ASN1Dec_NegotiationToken(ASN1decoding_t dec, ASN1uint32_t tag, NegotiationToken *val);
  19. static int ASN1CALL ASN1Dec_InitialNegToken(ASN1decoding_t dec, ASN1uint32_t tag, InitialNegToken *val);
  20. static void ASN1CALL ASN1Free_SavedMechTypeList(SavedMechTypeList *val);
  21. static void ASN1CALL ASN1Free_MechTypeList(PMechTypeList *val);
  22. static void ASN1CALL ASN1Free_NegHints(NegHints *val);
  23. static void ASN1CALL ASN1Free_NegTokenInit(NegTokenInit *val);
  24. static void ASN1CALL ASN1Free_NegTokenInit2(NegTokenInit2 *val);
  25. static void ASN1CALL ASN1Free_NegTokenTarg(NegTokenTarg *val);
  26. static void ASN1CALL ASN1Free_NegotiationToken(NegotiationToken *val);
  27. static void ASN1CALL ASN1Free_InitialNegToken(InitialNegToken *val);
  28. typedef ASN1BerEncFun_t ASN1EncFun_t;
  29. static const ASN1EncFun_t encfntab[3] = {
  30. (ASN1EncFun_t) ASN1Enc_SavedMechTypeList,
  31. (ASN1EncFun_t) ASN1Enc_NegotiationToken,
  32. (ASN1EncFun_t) ASN1Enc_InitialNegToken,
  33. };
  34. typedef ASN1BerDecFun_t ASN1DecFun_t;
  35. static const ASN1DecFun_t decfntab[3] = {
  36. (ASN1DecFun_t) ASN1Dec_SavedMechTypeList,
  37. (ASN1DecFun_t) ASN1Dec_NegotiationToken,
  38. (ASN1DecFun_t) ASN1Dec_InitialNegToken,
  39. };
  40. static const ASN1FreeFun_t freefntab[3] = {
  41. (ASN1FreeFun_t) ASN1Free_SavedMechTypeList,
  42. (ASN1FreeFun_t) ASN1Free_NegotiationToken,
  43. (ASN1FreeFun_t) ASN1Free_InitialNegToken,
  44. };
  45. static const ULONG sizetab[3] = {
  46. SIZE_SPNEGO_Module_PDU_0,
  47. SIZE_SPNEGO_Module_PDU_1,
  48. SIZE_SPNEGO_Module_PDU_2,
  49. };
  50. /* forward declarations of values: */
  51. /* definitions of value components: */
  52. /* definitions of values: */
  53. void ASN1CALL SPNEGO_Module_Startup(void)
  54. {
  55. SPNEGO_Module = ASN1_CreateModule(0x10000, ASN1_BER_RULE_DER, ASN1FLAGS_NONE, 3, (const ASN1GenericFun_t *) encfntab, (const ASN1GenericFun_t *) decfntab, freefntab, sizetab, 0x656e7073);
  56. }
  57. void ASN1CALL SPNEGO_Module_Cleanup(void)
  58. {
  59. ASN1_CloseModule(SPNEGO_Module);
  60. SPNEGO_Module = NULL;
  61. }
  62. static int ASN1CALL ASN1Enc_SavedMechTypeList(ASN1encoding_t enc, ASN1uint32_t tag, SavedMechTypeList *val)
  63. {
  64. if (!ASN1Enc_MechTypeList(enc, tag, val))
  65. return 0;
  66. return 1;
  67. }
  68. static int ASN1CALL ASN1Dec_SavedMechTypeList(ASN1decoding_t dec, ASN1uint32_t tag, SavedMechTypeList *val)
  69. {
  70. if (!ASN1Dec_MechTypeList(dec, tag, val))
  71. return 0;
  72. return 1;
  73. }
  74. static void ASN1CALL ASN1Free_SavedMechTypeList(SavedMechTypeList *val)
  75. {
  76. if (val) {
  77. ASN1Free_MechTypeList(val);
  78. }
  79. }
  80. static int ASN1CALL ASN1Enc_MechTypeList(ASN1encoding_t enc, ASN1uint32_t tag, PMechTypeList *val)
  81. {
  82. PMechTypeList f;
  83. ASN1uint32_t nLenOff;
  84. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  85. return 0;
  86. for (f = *val; f; f = f->next) {
  87. if (!ASN1BEREncObjectIdentifier(enc, 0x6, &f->value))
  88. return 0;
  89. }
  90. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  91. return 0;
  92. return 1;
  93. }
  94. static int ASN1CALL ASN1Dec_MechTypeList(ASN1decoding_t dec, ASN1uint32_t tag, PMechTypeList *val)
  95. {
  96. PMechTypeList *f;
  97. ASN1decoding_t dd;
  98. ASN1octet_t *di;
  99. ASN1uint32_t t;
  100. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  101. return 0;
  102. f = val;
  103. while (ASN1BERDecNotEndOfContents(dd, di)) {
  104. if (!ASN1BERDecPeekTag(dd, &t))
  105. return 0;
  106. if (!(*f = (PMechTypeList)ASN1DecAlloc(dd, sizeof(**f))))
  107. return 0;
  108. if (!ASN1BERDecObjectIdentifier(dd, 0x6, &(*f)->value))
  109. return 0;
  110. f = &(*f)->next;
  111. }
  112. *f = NULL;
  113. if (!ASN1BERDecEndOfContents(dec, dd, di))
  114. return 0;
  115. return 1;
  116. }
  117. static void ASN1CALL ASN1Free_MechTypeList(PMechTypeList *val)
  118. {
  119. PMechTypeList f, ff;
  120. if (val) {
  121. for (f = *val; f; f = ff) {
  122. ASN1objectidentifier_free(&f->value);
  123. ff = f->next;
  124. ASN1Free(f);
  125. }
  126. }
  127. }
  128. static int ASN1CALL ASN1Enc_NegHints(ASN1encoding_t enc, ASN1uint32_t tag, NegHints *val)
  129. {
  130. ASN1uint32_t nLenOff;
  131. ASN1uint32_t t;
  132. ASN1uint32_t nLenOff0;
  133. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  134. return 0;
  135. if ((val)->o[0] & 0x80) {
  136. t = lstrlenA((val)->hintName);
  137. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  138. return 0;
  139. if (!ASN1DEREncCharString(enc, 0x1b, t, (val)->hintName))
  140. return 0;
  141. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  142. return 0;
  143. }
  144. if ((val)->o[0] & 0x40) {
  145. if (!ASN1BEREncExplicitTag(enc, 0x80000001, &nLenOff0))
  146. return 0;
  147. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->hintAddress).length, ((val)->hintAddress).value))
  148. return 0;
  149. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  150. return 0;
  151. }
  152. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  153. return 0;
  154. return 1;
  155. }
  156. static int ASN1CALL ASN1Dec_NegHints(ASN1decoding_t dec, ASN1uint32_t tag, NegHints *val)
  157. {
  158. ASN1decoding_t dd;
  159. ASN1octet_t *di;
  160. ASN1uint32_t t;
  161. ASN1decoding_t dd0;
  162. ASN1octet_t *di0;
  163. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  164. return 0;
  165. ZeroMemory((val)->o, 1);
  166. ASN1BERDecPeekTag(dd, &t);
  167. if (t == 0x80000000) {
  168. (val)->o[0] |= 0x80;
  169. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  170. return 0;
  171. if (!ASN1BERDecZeroCharString(dd0, 0x1b, &(val)->hintName))
  172. return 0;
  173. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  174. return 0;
  175. }
  176. ASN1BERDecPeekTag(dd, &t);
  177. if (t == 0x80000001) {
  178. (val)->o[0] |= 0x40;
  179. if (!ASN1BERDecExplicitTag(dd, 0x80000001, &dd0, &di0))
  180. return 0;
  181. if (!ASN1BERDecOctetString(dd0, 0x4, &(val)->hintAddress))
  182. return 0;
  183. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  184. return 0;
  185. }
  186. if (!ASN1BERDecEndOfContents(dec, dd, di))
  187. return 0;
  188. return 1;
  189. }
  190. static void ASN1CALL ASN1Free_NegHints(NegHints *val)
  191. {
  192. if (val) {
  193. if ((val)->o[0] & 0x80) {
  194. ASN1ztcharstring_free((val)->hintName);
  195. }
  196. if ((val)->o[0] & 0x40) {
  197. ASN1octetstring_free(&(val)->hintAddress);
  198. }
  199. }
  200. }
  201. static int ASN1CALL ASN1Enc_NegTokenInit(ASN1encoding_t enc, ASN1uint32_t tag, NegTokenInit *val)
  202. {
  203. ASN1uint32_t nLenOff;
  204. ASN1uint32_t nLenOff0;
  205. ASN1uint32_t r;
  206. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  207. return 0;
  208. if ((val)->o[0] & 0x80) {
  209. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  210. return 0;
  211. if (!ASN1Enc_MechTypeList(enc, 0, &(val)->mechTypes))
  212. return 0;
  213. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  214. return 0;
  215. }
  216. if ((val)->o[0] & 0x40) {
  217. r = ((val)->reqFlags).length;
  218. ASN1BEREncRemoveZeroBits(&r, ((val)->reqFlags).value);
  219. if (!ASN1BEREncExplicitTag(enc, 0x80000001, &nLenOff0))
  220. return 0;
  221. if (!ASN1DEREncBitString(enc, 0x3, r, ((val)->reqFlags).value))
  222. return 0;
  223. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  224. return 0;
  225. }
  226. if ((val)->o[0] & 0x20) {
  227. if (!ASN1BEREncExplicitTag(enc, 0x80000002, &nLenOff0))
  228. return 0;
  229. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->mechToken).length, ((val)->mechToken).value))
  230. return 0;
  231. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  232. return 0;
  233. }
  234. if ((val)->o[0] & 0x10) {
  235. if (!ASN1BEREncExplicitTag(enc, 0x80000003, &nLenOff0))
  236. return 0;
  237. if (!ASN1Enc_NegHints(enc, 0, &(val)->negHints))
  238. return 0;
  239. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  240. return 0;
  241. }
  242. if ((val)->o[0] & 0x8) {
  243. if (!ASN1BEREncExplicitTag(enc, 0x80000004, &nLenOff0))
  244. return 0;
  245. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->mechListMIC).length, ((val)->mechListMIC).value))
  246. return 0;
  247. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  248. return 0;
  249. }
  250. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  251. return 0;
  252. return 1;
  253. }
  254. static int ASN1CALL ASN1Dec_NegTokenInit(ASN1decoding_t dec, ASN1uint32_t tag, NegTokenInit *val)
  255. {
  256. ASN1decoding_t dd;
  257. ASN1octet_t *di;
  258. ASN1uint32_t t;
  259. ASN1decoding_t dd0;
  260. ASN1octet_t *di0;
  261. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  262. return 0;
  263. ZeroMemory((val)->o, 1);
  264. ASN1BERDecPeekTag(dd, &t);
  265. if (t == 0x80000000) {
  266. (val)->o[0] |= 0x80;
  267. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  268. return 0;
  269. if (!ASN1Dec_MechTypeList(dd0, 0, &(val)->mechTypes))
  270. return 0;
  271. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  272. return 0;
  273. }
  274. ASN1BERDecPeekTag(dd, &t);
  275. if (t == 0x80000001) {
  276. (val)->o[0] |= 0x40;
  277. if (!ASN1BERDecExplicitTag(dd, 0x80000001, &dd0, &di0))
  278. return 0;
  279. if (!ASN1BERDecBitString(dd0, 0x3, &(val)->reqFlags))
  280. return 0;
  281. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  282. return 0;
  283. }
  284. ASN1BERDecPeekTag(dd, &t);
  285. if (t == 0x80000002) {
  286. (val)->o[0] |= 0x20;
  287. if (!ASN1BERDecExplicitTag(dd, 0x80000002, &dd0, &di0))
  288. return 0;
  289. if (!ASN1BERDecOctetString(dd0, 0x4, &(val)->mechToken))
  290. return 0;
  291. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  292. return 0;
  293. }
  294. ASN1BERDecPeekTag(dd, &t);
  295. if (t == 0x80000003) {
  296. (val)->o[0] |= 0x10;
  297. if (!ASN1BERDecExplicitTag(dd, 0x80000003, &dd0, &di0))
  298. return 0;
  299. if (!ASN1Dec_NegHints(dd0, 0, &(val)->negHints))
  300. return 0;
  301. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  302. return 0;
  303. }
  304. ASN1BERDecPeekTag(dd, &t);
  305. if (t == 0x80000004) {
  306. (val)->o[0] |= 0x8;
  307. if (!ASN1BERDecExplicitTag(dd, 0x80000004, &dd0, &di0))
  308. return 0;
  309. if (!ASN1BERDecOctetString(dd0, 0x4, &(val)->mechListMIC))
  310. return 0;
  311. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  312. return 0;
  313. }
  314. if (!ASN1BERDecEndOfContents(dec, dd, di))
  315. return 0;
  316. return 1;
  317. }
  318. static void ASN1CALL ASN1Free_NegTokenInit(NegTokenInit *val)
  319. {
  320. if (val) {
  321. if ((val)->o[0] & 0x80) {
  322. ASN1Free_MechTypeList(&(val)->mechTypes);
  323. }
  324. if ((val)->o[0] & 0x40) {
  325. ASN1bitstring_free(&(val)->reqFlags);
  326. }
  327. if ((val)->o[0] & 0x20) {
  328. ASN1octetstring_free(&(val)->mechToken);
  329. }
  330. if ((val)->o[0] & 0x10) {
  331. ASN1Free_NegHints(&(val)->negHints);
  332. }
  333. if ((val)->o[0] & 0x8) {
  334. ASN1octetstring_free(&(val)->mechListMIC);
  335. }
  336. }
  337. }
  338. static int ASN1CALL ASN1Enc_NegTokenInit2(ASN1encoding_t enc, ASN1uint32_t tag, NegTokenInit2 *val)
  339. {
  340. ASN1uint32_t nLenOff;
  341. ASN1uint32_t nLenOff0;
  342. ASN1uint32_t r;
  343. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  344. return 0;
  345. if ((val)->o[0] & 0x80) {
  346. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  347. return 0;
  348. if (!ASN1Enc_MechTypeList(enc, 0, &(val)->mechTypes))
  349. return 0;
  350. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  351. return 0;
  352. }
  353. if ((val)->o[0] & 0x40) {
  354. r = ((val)->reqFlags).length;
  355. ASN1BEREncRemoveZeroBits(&r, ((val)->reqFlags).value);
  356. if (!ASN1BEREncExplicitTag(enc, 0x80000001, &nLenOff0))
  357. return 0;
  358. if (!ASN1DEREncBitString(enc, 0x3, r, ((val)->reqFlags).value))
  359. return 0;
  360. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  361. return 0;
  362. }
  363. if ((val)->o[0] & 0x20) {
  364. if (!ASN1BEREncExplicitTag(enc, 0x80000002, &nLenOff0))
  365. return 0;
  366. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->mechToken).length, ((val)->mechToken).value))
  367. return 0;
  368. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  369. return 0;
  370. }
  371. if ((val)->o[0] & 0x10) {
  372. if (!ASN1BEREncExplicitTag(enc, 0x80000003, &nLenOff0))
  373. return 0;
  374. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->mechListMIC).length, ((val)->mechListMIC).value))
  375. return 0;
  376. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  377. return 0;
  378. }
  379. if ((val)->o[0] & 0x8) {
  380. if (!ASN1BEREncExplicitTag(enc, 0x80000004, &nLenOff0))
  381. return 0;
  382. if (!ASN1Enc_NegHints(enc, 0, &(val)->negHints))
  383. return 0;
  384. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  385. return 0;
  386. }
  387. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  388. return 0;
  389. return 1;
  390. }
  391. static int ASN1CALL ASN1Dec_NegTokenInit2(ASN1decoding_t dec, ASN1uint32_t tag, NegTokenInit2 *val)
  392. {
  393. ASN1decoding_t dd;
  394. ASN1octet_t *di;
  395. ASN1uint32_t t;
  396. ASN1decoding_t dd0;
  397. ASN1octet_t *di0;
  398. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  399. return 0;
  400. ZeroMemory((val)->o, 1);
  401. ASN1BERDecPeekTag(dd, &t);
  402. if (t == 0x80000000) {
  403. (val)->o[0] |= 0x80;
  404. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  405. return 0;
  406. if (!ASN1Dec_MechTypeList(dd0, 0, &(val)->mechTypes))
  407. return 0;
  408. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  409. return 0;
  410. }
  411. ASN1BERDecPeekTag(dd, &t);
  412. if (t == 0x80000001) {
  413. (val)->o[0] |= 0x40;
  414. if (!ASN1BERDecExplicitTag(dd, 0x80000001, &dd0, &di0))
  415. return 0;
  416. if (!ASN1BERDecBitString(dd0, 0x3, &(val)->reqFlags))
  417. return 0;
  418. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  419. return 0;
  420. }
  421. ASN1BERDecPeekTag(dd, &t);
  422. if (t == 0x80000002) {
  423. (val)->o[0] |= 0x20;
  424. if (!ASN1BERDecExplicitTag(dd, 0x80000002, &dd0, &di0))
  425. return 0;
  426. if (!ASN1BERDecOctetString(dd0, 0x4, &(val)->mechToken))
  427. return 0;
  428. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  429. return 0;
  430. }
  431. ASN1BERDecPeekTag(dd, &t);
  432. if (t == 0x80000003) {
  433. (val)->o[0] |= 0x10;
  434. if (!ASN1BERDecExplicitTag(dd, 0x80000003, &dd0, &di0))
  435. return 0;
  436. if (!ASN1BERDecOctetString(dd0, 0x4, &(val)->mechListMIC))
  437. return 0;
  438. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  439. return 0;
  440. }
  441. ASN1BERDecPeekTag(dd, &t);
  442. if (t == 0x80000004) {
  443. (val)->o[0] |= 0x8;
  444. if (!ASN1BERDecExplicitTag(dd, 0x80000004, &dd0, &di0))
  445. return 0;
  446. if (!ASN1Dec_NegHints(dd0, 0, &(val)->negHints))
  447. return 0;
  448. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  449. return 0;
  450. }
  451. if (!ASN1BERDecEndOfContents(dec, dd, di))
  452. return 0;
  453. return 1;
  454. }
  455. static void ASN1CALL ASN1Free_NegTokenInit2(NegTokenInit2 *val)
  456. {
  457. if (val) {
  458. if ((val)->o[0] & 0x80) {
  459. ASN1Free_MechTypeList(&(val)->mechTypes);
  460. }
  461. if ((val)->o[0] & 0x40) {
  462. ASN1bitstring_free(&(val)->reqFlags);
  463. }
  464. if ((val)->o[0] & 0x20) {
  465. ASN1octetstring_free(&(val)->mechToken);
  466. }
  467. if ((val)->o[0] & 0x10) {
  468. ASN1octetstring_free(&(val)->mechListMIC);
  469. }
  470. if ((val)->o[0] & 0x8) {
  471. ASN1Free_NegHints(&(val)->negHints);
  472. }
  473. }
  474. }
  475. static int ASN1CALL ASN1Enc_NegTokenTarg(ASN1encoding_t enc, ASN1uint32_t tag, NegTokenTarg *val)
  476. {
  477. ASN1uint32_t nLenOff;
  478. ASN1uint32_t nLenOff0;
  479. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  480. return 0;
  481. if ((val)->o[0] & 0x80) {
  482. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  483. return 0;
  484. if (!ASN1BEREncU32(enc, 0xa, (val)->negResult))
  485. return 0;
  486. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  487. return 0;
  488. }
  489. if ((val)->o[0] & 0x40) {
  490. if (!ASN1BEREncExplicitTag(enc, 0x80000001, &nLenOff0))
  491. return 0;
  492. if (!ASN1BEREncObjectIdentifier(enc, 0x6, &(val)->supportedMech))
  493. return 0;
  494. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  495. return 0;
  496. }
  497. if ((val)->o[0] & 0x20) {
  498. if (!ASN1BEREncExplicitTag(enc, 0x80000002, &nLenOff0))
  499. return 0;
  500. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->responseToken).length, ((val)->responseToken).value))
  501. return 0;
  502. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  503. return 0;
  504. }
  505. if ((val)->o[0] & 0x10) {
  506. if (!ASN1BEREncExplicitTag(enc, 0x80000003, &nLenOff0))
  507. return 0;
  508. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->mechListMIC).length, ((val)->mechListMIC).value))
  509. return 0;
  510. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  511. return 0;
  512. }
  513. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  514. return 0;
  515. return 1;
  516. }
  517. static int ASN1CALL ASN1Dec_NegTokenTarg(ASN1decoding_t dec, ASN1uint32_t tag, NegTokenTarg *val)
  518. {
  519. ASN1decoding_t dd;
  520. ASN1octet_t *di;
  521. ASN1uint32_t t;
  522. ASN1decoding_t dd0;
  523. ASN1octet_t *di0;
  524. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  525. return 0;
  526. ZeroMemory((val)->o, 1);
  527. ASN1BERDecPeekTag(dd, &t);
  528. if (t == 0x80000000) {
  529. (val)->o[0] |= 0x80;
  530. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  531. return 0;
  532. if (!ASN1BERDecU32Val(dd0, 0xa, (ASN1uint32_t *) &(val)->negResult))
  533. return 0;
  534. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  535. return 0;
  536. }
  537. ASN1BERDecPeekTag(dd, &t);
  538. if (t == 0x80000001) {
  539. (val)->o[0] |= 0x40;
  540. if (!ASN1BERDecExplicitTag(dd, 0x80000001, &dd0, &di0))
  541. return 0;
  542. if (!ASN1BERDecObjectIdentifier(dd0, 0x6, &(val)->supportedMech))
  543. return 0;
  544. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  545. return 0;
  546. }
  547. ASN1BERDecPeekTag(dd, &t);
  548. if (t == 0x80000002) {
  549. (val)->o[0] |= 0x20;
  550. if (!ASN1BERDecExplicitTag(dd, 0x80000002, &dd0, &di0))
  551. return 0;
  552. if (!ASN1BERDecOctetString(dd0, 0x4, &(val)->responseToken))
  553. return 0;
  554. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  555. return 0;
  556. }
  557. ASN1BERDecPeekTag(dd, &t);
  558. if (t == 0x80000003) {
  559. (val)->o[0] |= 0x10;
  560. if (!ASN1BERDecExplicitTag(dd, 0x80000003, &dd0, &di0))
  561. return 0;
  562. if (!ASN1BERDecOctetString(dd0, 0x4, &(val)->mechListMIC))
  563. return 0;
  564. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  565. return 0;
  566. }
  567. if (!ASN1BERDecEndOfContents(dec, dd, di))
  568. return 0;
  569. return 1;
  570. }
  571. static void ASN1CALL ASN1Free_NegTokenTarg(NegTokenTarg *val)
  572. {
  573. if (val) {
  574. if ((val)->o[0] & 0x40) {
  575. ASN1objectidentifier_free(&(val)->supportedMech);
  576. }
  577. if ((val)->o[0] & 0x20) {
  578. ASN1octetstring_free(&(val)->responseToken);
  579. }
  580. if ((val)->o[0] & 0x10) {
  581. ASN1octetstring_free(&(val)->mechListMIC);
  582. }
  583. }
  584. }
  585. static int ASN1CALL ASN1Enc_NegotiationToken(ASN1encoding_t enc, ASN1uint32_t tag, NegotiationToken *val)
  586. {
  587. ASN1uint32_t nLenOff0;
  588. switch ((val)->choice) {
  589. case 1:
  590. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  591. return 0;
  592. if (!ASN1Enc_NegTokenInit(enc, 0, &(val)->u.negTokenInit))
  593. return 0;
  594. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  595. return 0;
  596. break;
  597. case 2:
  598. if (!ASN1BEREncExplicitTag(enc, 0x80000001, &nLenOff0))
  599. return 0;
  600. if (!ASN1Enc_NegTokenTarg(enc, 0, &(val)->u.negTokenTarg))
  601. return 0;
  602. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  603. return 0;
  604. break;
  605. case 3:
  606. if (!ASN1BEREncExplicitTag(enc, 0x80000002, &nLenOff0))
  607. return 0;
  608. if (!ASN1Enc_NegTokenInit2(enc, 0, &(val)->u.negTokenInit2))
  609. return 0;
  610. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  611. return 0;
  612. break;
  613. }
  614. return 1;
  615. }
  616. static int ASN1CALL ASN1Dec_NegotiationToken(ASN1decoding_t dec, ASN1uint32_t tag, NegotiationToken *val)
  617. {
  618. ASN1uint32_t t;
  619. ASN1decoding_t dd0;
  620. ASN1octet_t *di0;
  621. if (!ASN1BERDecPeekTag(dec, &t))
  622. return 0;
  623. switch (t) {
  624. case 0x80000000:
  625. (val)->choice = 1;
  626. if (!ASN1BERDecExplicitTag(dec, 0x80000000, &dd0, &di0))
  627. return 0;
  628. if (!ASN1Dec_NegTokenInit(dd0, 0, &(val)->u.negTokenInit))
  629. return 0;
  630. if (!ASN1BERDecEndOfContents(dec, dd0, di0))
  631. return 0;
  632. break;
  633. case 0x80000001:
  634. (val)->choice = 2;
  635. if (!ASN1BERDecExplicitTag(dec, 0x80000001, &dd0, &di0))
  636. return 0;
  637. if (!ASN1Dec_NegTokenTarg(dd0, 0, &(val)->u.negTokenTarg))
  638. return 0;
  639. if (!ASN1BERDecEndOfContents(dec, dd0, di0))
  640. return 0;
  641. break;
  642. case 0x80000002:
  643. (val)->choice = 3;
  644. if (!ASN1BERDecExplicitTag(dec, 0x80000002, &dd0, &di0))
  645. return 0;
  646. if (!ASN1Dec_NegTokenInit2(dd0, 0, &(val)->u.negTokenInit2))
  647. return 0;
  648. if (!ASN1BERDecEndOfContents(dec, dd0, di0))
  649. return 0;
  650. break;
  651. default:
  652. ASN1DecSetError(dec, ASN1_ERR_CORRUPT);
  653. return 0;
  654. }
  655. return 1;
  656. }
  657. static void ASN1CALL ASN1Free_NegotiationToken(NegotiationToken *val)
  658. {
  659. if (val) {
  660. switch ((val)->choice) {
  661. case 1:
  662. ASN1Free_NegTokenInit(&(val)->u.negTokenInit);
  663. break;
  664. case 2:
  665. ASN1Free_NegTokenTarg(&(val)->u.negTokenTarg);
  666. break;
  667. case 3:
  668. ASN1Free_NegTokenInit2(&(val)->u.negTokenInit2);
  669. break;
  670. }
  671. }
  672. }
  673. static int ASN1CALL ASN1Enc_InitialNegToken(ASN1encoding_t enc, ASN1uint32_t tag, InitialNegToken *val)
  674. {
  675. ASN1uint32_t nLenOff;
  676. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x40000000, &nLenOff))
  677. return 0;
  678. if (!ASN1BEREncObjectIdentifier(enc, 0x6, &(val)->spnegoMech))
  679. return 0;
  680. if (!ASN1Enc_NegotiationToken(enc, 0, &(val)->negToken))
  681. return 0;
  682. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  683. return 0;
  684. return 1;
  685. }
  686. static int ASN1CALL ASN1Dec_InitialNegToken(ASN1decoding_t dec, ASN1uint32_t tag, InitialNegToken *val)
  687. {
  688. ASN1decoding_t dd;
  689. ASN1octet_t *di;
  690. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x40000000, &dd, &di))
  691. return 0;
  692. if (!ASN1BERDecObjectIdentifier(dd, 0x6, &(val)->spnegoMech))
  693. return 0;
  694. if (!ASN1Dec_NegotiationToken(dd, 0, &(val)->negToken))
  695. return 0;
  696. if (!ASN1BERDecEndOfContents(dec, dd, di))
  697. return 0;
  698. return 1;
  699. }
  700. static void ASN1CALL ASN1Free_InitialNegToken(InitialNegToken *val)
  701. {
  702. if (val) {
  703. ASN1objectidentifier_free(&(val)->spnegoMech);
  704. ASN1Free_NegotiationToken(&(val)->negToken);
  705. }
  706. }