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.

476 lines
14 KiB

  1. #include <windows.h>
  2. #include "snego.h"
  3. ASN1module_t SNEGO_Module = NULL;
  4. static int ASN1CALL ASN1Enc_MechTypeList2(ASN1encoding_t enc, ASN1uint32_t tag, PMechTypeList2 *val);
  5. static int ASN1CALL ASN1Enc_NegHints2(ASN1encoding_t enc, ASN1uint32_t tag, NegHints2 *val);
  6. static int ASN1CALL ASN1Enc_NegTokenReq2(ASN1encoding_t enc, ASN1uint32_t tag, NegTokenReq2 *val);
  7. static int ASN1CALL ASN1Enc_NegResultList2(ASN1encoding_t enc, ASN1uint32_t tag, PNegResultList2 *val);
  8. static int ASN1CALL ASN1Enc_NegTokenRep2(ASN1encoding_t enc, ASN1uint32_t tag, NegTokenRep2 *val);
  9. static int ASN1CALL ASN1Enc_NegotiationToken2(ASN1encoding_t enc, ASN1uint32_t tag, NegotiationToken2 *val);
  10. static int ASN1CALL ASN1Dec_MechTypeList2(ASN1decoding_t dec, ASN1uint32_t tag, PMechTypeList2 *val);
  11. static int ASN1CALL ASN1Dec_NegHints2(ASN1decoding_t dec, ASN1uint32_t tag, NegHints2 *val);
  12. static int ASN1CALL ASN1Dec_NegTokenReq2(ASN1decoding_t dec, ASN1uint32_t tag, NegTokenReq2 *val);
  13. static int ASN1CALL ASN1Dec_NegResultList2(ASN1decoding_t dec, ASN1uint32_t tag, PNegResultList2 *val);
  14. static int ASN1CALL ASN1Dec_NegTokenRep2(ASN1decoding_t dec, ASN1uint32_t tag, NegTokenRep2 *val);
  15. static int ASN1CALL ASN1Dec_NegotiationToken2(ASN1decoding_t dec, ASN1uint32_t tag, NegotiationToken2 *val);
  16. static void ASN1CALL ASN1Free_MechTypeList2(PMechTypeList2 *val);
  17. static void ASN1CALL ASN1Free_NegHints2(NegHints2 *val);
  18. static void ASN1CALL ASN1Free_NegTokenReq2(NegTokenReq2 *val);
  19. static void ASN1CALL ASN1Free_NegResultList2(PNegResultList2 *val);
  20. static void ASN1CALL ASN1Free_NegTokenRep2(NegTokenRep2 *val);
  21. static void ASN1CALL ASN1Free_NegotiationToken2(NegotiationToken2 *val);
  22. typedef ASN1BerEncFun_t ASN1EncFun_t;
  23. static const ASN1EncFun_t encfntab[1] = {
  24. (ASN1EncFun_t) ASN1Enc_NegotiationToken2,
  25. };
  26. typedef ASN1BerDecFun_t ASN1DecFun_t;
  27. static const ASN1DecFun_t decfntab[1] = {
  28. (ASN1DecFun_t) ASN1Dec_NegotiationToken2,
  29. };
  30. static const ASN1FreeFun_t freefntab[1] = {
  31. (ASN1FreeFun_t) ASN1Free_NegotiationToken2,
  32. };
  33. static const ULONG sizetab[1] = {
  34. SIZE_SNEGO_Module_PDU_0,
  35. };
  36. /* forward declarations of values: */
  37. /* definitions of value components: */
  38. /* definitions of values: */
  39. void ASN1CALL SNEGO_Module_Startup(void)
  40. {
  41. SNEGO_Module = ASN1_CreateModule(0x10000, ASN1_BER_RULE_DER, ASN1FLAGS_NONE, 1, (const ASN1GenericFun_t *) encfntab, (const ASN1GenericFun_t *) decfntab, freefntab, sizetab, 0x67656e73);
  42. }
  43. void ASN1CALL SNEGO_Module_Cleanup(void)
  44. {
  45. ASN1_CloseModule(SNEGO_Module);
  46. SNEGO_Module = NULL;
  47. }
  48. static int ASN1CALL ASN1Enc_MechTypeList2(ASN1encoding_t enc, ASN1uint32_t tag, PMechTypeList2 *val)
  49. {
  50. PMechTypeList2 f;
  51. ASN1uint32_t nLenOff;
  52. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  53. return 0;
  54. for (f = *val; f; f = f->next) {
  55. if (!ASN1BEREncObjectIdentifier(enc, 0x6, &f->value))
  56. return 0;
  57. }
  58. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  59. return 0;
  60. return 1;
  61. }
  62. static int ASN1CALL ASN1Dec_MechTypeList2(ASN1decoding_t dec, ASN1uint32_t tag, PMechTypeList2 *val)
  63. {
  64. PMechTypeList2 *f;
  65. ASN1decoding_t dd;
  66. ASN1octet_t *di;
  67. ASN1uint32_t t;
  68. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  69. return 0;
  70. f = val;
  71. while (ASN1BERDecNotEndOfContents(dd, di)) {
  72. if (!ASN1BERDecPeekTag(dd, &t))
  73. return 0;
  74. if (!(*f = (PMechTypeList2)ASN1DecAlloc(dd, sizeof(**f))))
  75. return 0;
  76. if (!ASN1BERDecObjectIdentifier(dd, 0x6, &(*f)->value))
  77. return 0;
  78. f = &(*f)->next;
  79. }
  80. *f = NULL;
  81. if (!ASN1BERDecEndOfContents(dec, dd, di))
  82. return 0;
  83. return 1;
  84. }
  85. static void ASN1CALL ASN1Free_MechTypeList2(PMechTypeList2 *val)
  86. {
  87. PMechTypeList2 f, ff;
  88. if (val) {
  89. for (f = *val; f; f = ff) {
  90. ASN1objectidentifier_free(&f->value);
  91. ff = f->next;
  92. ASN1Free(f);
  93. }
  94. }
  95. }
  96. static int ASN1CALL ASN1Enc_NegHints2(ASN1encoding_t enc, ASN1uint32_t tag, NegHints2 *val)
  97. {
  98. ASN1uint32_t nLenOff;
  99. ASN1uint32_t t;
  100. ASN1uint32_t nLenOff0;
  101. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  102. return 0;
  103. if ((val)->o[0] & 0x80) {
  104. t = lstrlenA((val)->hintName);
  105. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  106. return 0;
  107. if (!ASN1DEREncCharString(enc, 0x1b, t, (val)->hintName))
  108. return 0;
  109. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  110. return 0;
  111. }
  112. if ((val)->o[0] & 0x40) {
  113. if (!ASN1BEREncExplicitTag(enc, 0x80000001, &nLenOff0))
  114. return 0;
  115. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->hintAddress).length, ((val)->hintAddress).value))
  116. return 0;
  117. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  118. return 0;
  119. }
  120. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  121. return 0;
  122. return 1;
  123. }
  124. static int ASN1CALL ASN1Dec_NegHints2(ASN1decoding_t dec, ASN1uint32_t tag, NegHints2 *val)
  125. {
  126. ASN1decoding_t dd;
  127. ASN1octet_t *di;
  128. ASN1uint32_t t;
  129. ASN1decoding_t dd0;
  130. ASN1octet_t *di0;
  131. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  132. return 0;
  133. ZeroMemory((val)->o, 1);
  134. ASN1BERDecPeekTag(dd, &t);
  135. if (t == 0x80000000) {
  136. (val)->o[0] |= 0x80;
  137. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  138. return 0;
  139. if (!ASN1BERDecZeroCharString(dd0, 0x1b, &(val)->hintName))
  140. return 0;
  141. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  142. return 0;
  143. }
  144. ASN1BERDecPeekTag(dd, &t);
  145. if (t == 0x80000001) {
  146. (val)->o[0] |= 0x40;
  147. if (!ASN1BERDecExplicitTag(dd, 0x80000001, &dd0, &di0))
  148. return 0;
  149. if (!ASN1BERDecOctetString(dd0, 0x4, &(val)->hintAddress))
  150. return 0;
  151. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  152. return 0;
  153. }
  154. if (!ASN1BERDecEndOfContents(dec, dd, di))
  155. return 0;
  156. return 1;
  157. }
  158. static void ASN1CALL ASN1Free_NegHints2(NegHints2 *val)
  159. {
  160. if (val) {
  161. if ((val)->o[0] & 0x80) {
  162. ASN1ztcharstring_free((val)->hintName);
  163. }
  164. if ((val)->o[0] & 0x40) {
  165. ASN1octetstring_free(&(val)->hintAddress);
  166. }
  167. }
  168. }
  169. static int ASN1CALL ASN1Enc_NegTokenReq2(ASN1encoding_t enc, ASN1uint32_t tag, NegTokenReq2 *val)
  170. {
  171. ASN1uint32_t nLenOff;
  172. ASN1uint32_t nLenOff0;
  173. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  174. return 0;
  175. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  176. return 0;
  177. if (!ASN1Enc_MechTypeList2(enc, 0, &(val)->mechTypes))
  178. return 0;
  179. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  180. return 0;
  181. if ((val)->o[0] & 0x80) {
  182. if (!ASN1BEREncExplicitTag(enc, 0x80000001, &nLenOff0))
  183. return 0;
  184. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->desiredToken).length, ((val)->desiredToken).value))
  185. return 0;
  186. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  187. return 0;
  188. }
  189. if ((val)->o[0] & 0x40) {
  190. if (!ASN1BEREncExplicitTag(enc, 0x80000002, &nLenOff0))
  191. return 0;
  192. if (!ASN1Enc_NegHints2(enc, 0, &(val)->negHints2))
  193. return 0;
  194. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  195. return 0;
  196. }
  197. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  198. return 0;
  199. return 1;
  200. }
  201. static int ASN1CALL ASN1Dec_NegTokenReq2(ASN1decoding_t dec, ASN1uint32_t tag, NegTokenReq2 *val)
  202. {
  203. ASN1decoding_t dd;
  204. ASN1octet_t *di;
  205. ASN1decoding_t dd0;
  206. ASN1octet_t *di0;
  207. ASN1uint32_t t;
  208. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  209. return 0;
  210. ZeroMemory((val)->o, 1);
  211. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  212. return 0;
  213. if (!ASN1Dec_MechTypeList2(dd0, 0, &(val)->mechTypes))
  214. return 0;
  215. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  216. return 0;
  217. ASN1BERDecPeekTag(dd, &t);
  218. if (t == 0x80000001) {
  219. (val)->o[0] |= 0x80;
  220. if (!ASN1BERDecExplicitTag(dd, 0x80000001, &dd0, &di0))
  221. return 0;
  222. if (!ASN1BERDecOctetString(dd0, 0x4, &(val)->desiredToken))
  223. return 0;
  224. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  225. return 0;
  226. }
  227. ASN1BERDecPeekTag(dd, &t);
  228. if (t == 0x80000002) {
  229. (val)->o[0] |= 0x40;
  230. if (!ASN1BERDecExplicitTag(dd, 0x80000002, &dd0, &di0))
  231. return 0;
  232. if (!ASN1Dec_NegHints2(dd0, 0, &(val)->negHints2))
  233. return 0;
  234. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  235. return 0;
  236. }
  237. if (!ASN1BERDecEndOfContents(dec, dd, di))
  238. return 0;
  239. return 1;
  240. }
  241. static void ASN1CALL ASN1Free_NegTokenReq2(NegTokenReq2 *val)
  242. {
  243. if (val) {
  244. ASN1Free_MechTypeList2(&(val)->mechTypes);
  245. if ((val)->o[0] & 0x80) {
  246. ASN1octetstring_free(&(val)->desiredToken);
  247. }
  248. if ((val)->o[0] & 0x40) {
  249. ASN1Free_NegHints2(&(val)->negHints2);
  250. }
  251. }
  252. }
  253. static int ASN1CALL ASN1Enc_NegResultList2(ASN1encoding_t enc, ASN1uint32_t tag, PNegResultList2 *val)
  254. {
  255. PNegResultList2 f;
  256. ASN1uint32_t nLenOff;
  257. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  258. return 0;
  259. for (f = *val; f; f = f->next) {
  260. if (!ASN1BEREncU32(enc, 0xa, f->value))
  261. return 0;
  262. }
  263. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  264. return 0;
  265. return 1;
  266. }
  267. static int ASN1CALL ASN1Dec_NegResultList2(ASN1decoding_t dec, ASN1uint32_t tag, PNegResultList2 *val)
  268. {
  269. PNegResultList2 *f;
  270. ASN1decoding_t dd;
  271. ASN1octet_t *di;
  272. ASN1uint32_t t;
  273. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  274. return 0;
  275. f = val;
  276. while (ASN1BERDecNotEndOfContents(dd, di)) {
  277. if (!ASN1BERDecPeekTag(dd, &t))
  278. return 0;
  279. if (!(*f = (PNegResultList2)ASN1DecAlloc(dd, sizeof(**f))))
  280. return 0;
  281. if (!ASN1BERDecU32Val(dd, 0xa, (ASN1uint32_t *)&(*f)->value))
  282. return 0;
  283. f = &(*f)->next;
  284. }
  285. *f = NULL;
  286. if (!ASN1BERDecEndOfContents(dec, dd, di))
  287. return 0;
  288. return 1;
  289. }
  290. static void ASN1CALL ASN1Free_NegResultList2(PNegResultList2 *val)
  291. {
  292. PNegResultList2 f, ff;
  293. if (val) {
  294. for (f = *val; f; f = ff) {
  295. ff = f->next;
  296. ASN1Free(f);
  297. }
  298. }
  299. }
  300. static int ASN1CALL ASN1Enc_NegTokenRep2(ASN1encoding_t enc, ASN1uint32_t tag, NegTokenRep2 *val)
  301. {
  302. ASN1uint32_t nLenOff;
  303. ASN1uint32_t nLenOff0;
  304. if (!ASN1BEREncExplicitTag(enc, tag ? tag : 0x10, &nLenOff))
  305. return 0;
  306. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  307. return 0;
  308. if (!ASN1Enc_NegResultList2(enc, 0, &(val)->negResultList))
  309. return 0;
  310. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  311. return 0;
  312. if ((val)->o[0] & 0x80) {
  313. if (!ASN1BEREncExplicitTag(enc, 0x80000001, &nLenOff0))
  314. return 0;
  315. if (!ASN1BEREncObjectIdentifier(enc, 0x6, &(val)->supportedMech2))
  316. return 0;
  317. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  318. return 0;
  319. }
  320. if ((val)->o[0] & 0x40) {
  321. if (!ASN1BEREncExplicitTag(enc, 0x80000002, &nLenOff0))
  322. return 0;
  323. if (!ASN1DEREncOctetString(enc, 0x4, ((val)->mechSpecInfo2).length, ((val)->mechSpecInfo2).value))
  324. return 0;
  325. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  326. return 0;
  327. }
  328. if (!ASN1BEREncEndOfContents(enc, nLenOff))
  329. return 0;
  330. return 1;
  331. }
  332. static int ASN1CALL ASN1Dec_NegTokenRep2(ASN1decoding_t dec, ASN1uint32_t tag, NegTokenRep2 *val)
  333. {
  334. ASN1decoding_t dd;
  335. ASN1octet_t *di;
  336. ASN1decoding_t dd0;
  337. ASN1octet_t *di0;
  338. ASN1uint32_t t;
  339. if (!ASN1BERDecExplicitTag(dec, tag ? tag : 0x10, &dd, &di))
  340. return 0;
  341. ZeroMemory((val)->o, 1);
  342. if (!ASN1BERDecExplicitTag(dd, 0x80000000, &dd0, &di0))
  343. return 0;
  344. if (!ASN1Dec_NegResultList2(dd0, 0, &(val)->negResultList))
  345. return 0;
  346. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  347. return 0;
  348. ASN1BERDecPeekTag(dd, &t);
  349. if (t == 0x80000001) {
  350. (val)->o[0] |= 0x80;
  351. if (!ASN1BERDecExplicitTag(dd, 0x80000001, &dd0, &di0))
  352. return 0;
  353. if (!ASN1BERDecObjectIdentifier(dd0, 0x6, &(val)->supportedMech2))
  354. return 0;
  355. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  356. return 0;
  357. }
  358. ASN1BERDecPeekTag(dd, &t);
  359. if (t == 0x80000002) {
  360. (val)->o[0] |= 0x40;
  361. if (!ASN1BERDecExplicitTag(dd, 0x80000002, &dd0, &di0))
  362. return 0;
  363. if (!ASN1BERDecOctetString(dd0, 0x4, &(val)->mechSpecInfo2))
  364. return 0;
  365. if (!ASN1BERDecEndOfContents(dd, dd0, di0))
  366. return 0;
  367. }
  368. if (!ASN1BERDecEndOfContents(dec, dd, di))
  369. return 0;
  370. return 1;
  371. }
  372. static void ASN1CALL ASN1Free_NegTokenRep2(NegTokenRep2 *val)
  373. {
  374. if (val) {
  375. ASN1Free_NegResultList2(&(val)->negResultList);
  376. if ((val)->o[0] & 0x80) {
  377. ASN1objectidentifier_free(&(val)->supportedMech2);
  378. }
  379. if ((val)->o[0] & 0x40) {
  380. ASN1octetstring_free(&(val)->mechSpecInfo2);
  381. }
  382. }
  383. }
  384. static int ASN1CALL ASN1Enc_NegotiationToken2(ASN1encoding_t enc, ASN1uint32_t tag, NegotiationToken2 *val)
  385. {
  386. ASN1uint32_t nLenOff0;
  387. switch ((val)->choice) {
  388. case 1:
  389. if (!ASN1BEREncExplicitTag(enc, 0x80000000, &nLenOff0))
  390. return 0;
  391. if (!ASN1Enc_NegTokenReq2(enc, 0, &(val)->u.negTokenReq))
  392. return 0;
  393. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  394. return 0;
  395. break;
  396. case 2:
  397. if (!ASN1BEREncExplicitTag(enc, 0x80000001, &nLenOff0))
  398. return 0;
  399. if (!ASN1Enc_NegTokenRep2(enc, 0, &(val)->u.negTokenRep))
  400. return 0;
  401. if (!ASN1BEREncEndOfContents(enc, nLenOff0))
  402. return 0;
  403. break;
  404. }
  405. return 1;
  406. }
  407. static int ASN1CALL ASN1Dec_NegotiationToken2(ASN1decoding_t dec, ASN1uint32_t tag, NegotiationToken2 *val)
  408. {
  409. ASN1uint32_t t;
  410. ASN1decoding_t dd0;
  411. ASN1octet_t *di0;
  412. if (!ASN1BERDecPeekTag(dec, &t))
  413. return 0;
  414. switch (t) {
  415. case 0x80000000:
  416. (val)->choice = 1;
  417. if (!ASN1BERDecExplicitTag(dec, 0x80000000, &dd0, &di0))
  418. return 0;
  419. if (!ASN1Dec_NegTokenReq2(dd0, 0, &(val)->u.negTokenReq))
  420. return 0;
  421. if (!ASN1BERDecEndOfContents(dec, dd0, di0))
  422. return 0;
  423. break;
  424. case 0x80000001:
  425. (val)->choice = 2;
  426. if (!ASN1BERDecExplicitTag(dec, 0x80000001, &dd0, &di0))
  427. return 0;
  428. if (!ASN1Dec_NegTokenRep2(dd0, 0, &(val)->u.negTokenRep))
  429. return 0;
  430. if (!ASN1BERDecEndOfContents(dec, dd0, di0))
  431. return 0;
  432. break;
  433. default:
  434. ASN1DecSetError(dec, ASN1_ERR_CORRUPT);
  435. return 0;
  436. }
  437. return 1;
  438. }
  439. static void ASN1CALL ASN1Free_NegotiationToken2(NegotiationToken2 *val)
  440. {
  441. if (val) {
  442. switch ((val)->choice) {
  443. case 1:
  444. ASN1Free_NegTokenReq2(&(val)->u.negTokenReq);
  445. break;
  446. case 2:
  447. ASN1Free_NegTokenRep2(&(val)->u.negTokenRep);
  448. break;
  449. }
  450. }
  451. }