diff options
Diffstat (limited to 'src/daemon/https/minitasn1/parser_aux.c')
-rw-r--r-- | src/daemon/https/minitasn1/parser_aux.c | 330 |
1 files changed, 13 insertions, 317 deletions
diff --git a/src/daemon/https/minitasn1/parser_aux.c b/src/daemon/https/minitasn1/parser_aux.c index 6e82dd71..5f36a5ff 100644 --- a/src/daemon/https/minitasn1/parser_aux.c +++ b/src/daemon/https/minitasn1/parser_aux.c | |||
@@ -27,6 +27,8 @@ | |||
27 | #include "structure.h" | 27 | #include "structure.h" |
28 | #include "element.h" | 28 | #include "element.h" |
29 | 29 | ||
30 | |||
31 | |||
30 | char MHD__asn1_identifierMissing[MAX_NAME_SIZE + 1]; /* identifier name not found */ | 32 | char MHD__asn1_identifierMissing[MAX_NAME_SIZE + 1]; /* identifier name not found */ |
31 | 33 | ||
32 | /***********************************************/ | 34 | /***********************************************/ |
@@ -279,42 +281,6 @@ MHD__asn1_set_right (node_asn * node, node_asn * right) | |||
279 | } | 281 | } |
280 | 282 | ||
281 | /******************************************************************/ | 283 | /******************************************************************/ |
282 | /* Function : MHD__asn1_get_right */ | ||
283 | /* Description: returns the element pointed by the RIGHT field of */ | ||
284 | /* a NODE_ASN element. */ | ||
285 | /* Parameters: */ | ||
286 | /* node: NODE_ASN element pointer. */ | ||
287 | /* Return: field RIGHT of NODE. */ | ||
288 | /******************************************************************/ | ||
289 | node_asn * | ||
290 | MHD__asn1_get_right (node_asn * node) | ||
291 | { | ||
292 | if (node == NULL) | ||
293 | return NULL; | ||
294 | return node->right; | ||
295 | } | ||
296 | |||
297 | /******************************************************************/ | ||
298 | /* Function : MHD__asn1_get_last_right */ | ||
299 | /* Description: return the last element along the right chain. */ | ||
300 | /* Parameters: */ | ||
301 | /* node: starting element pointer. */ | ||
302 | /* Return: pointer to the last element along the right chain. */ | ||
303 | /******************************************************************/ | ||
304 | node_asn * | ||
305 | MHD__asn1_get_last_right (node_asn * node) | ||
306 | { | ||
307 | node_asn *p; | ||
308 | |||
309 | if (node == NULL) | ||
310 | return NULL; | ||
311 | p = node; | ||
312 | while (p->right) | ||
313 | p = p->right; | ||
314 | return p; | ||
315 | } | ||
316 | |||
317 | /******************************************************************/ | ||
318 | /* Function : MHD__asn1_set_down */ | 284 | /* Function : MHD__asn1_set_down */ |
319 | /* Description: sets the field DOWN in a NODE_ASN element. */ | 285 | /* Description: sets the field DOWN in a NODE_ASN element. */ |
320 | /* Parameters: */ | 286 | /* Parameters: */ |
@@ -335,58 +301,6 @@ MHD__asn1_set_down (node_asn * node, node_asn * down) | |||
335 | } | 301 | } |
336 | 302 | ||
337 | /******************************************************************/ | 303 | /******************************************************************/ |
338 | /* Function : MHD__asn1_get_down */ | ||
339 | /* Description: returns the element pointed by the DOWN field of */ | ||
340 | /* a NODE_ASN element. */ | ||
341 | /* Parameters: */ | ||
342 | /* node: NODE_ASN element pointer. */ | ||
343 | /* Return: field DOWN of NODE. */ | ||
344 | /******************************************************************/ | ||
345 | node_asn * | ||
346 | MHD__asn1_get_down (node_asn * node) | ||
347 | { | ||
348 | if (node == NULL) | ||
349 | return NULL; | ||
350 | return node->down; | ||
351 | } | ||
352 | |||
353 | /******************************************************************/ | ||
354 | /* Function : MHD__asn1_get_name */ | ||
355 | /* Description: returns the name of a NODE_ASN element. */ | ||
356 | /* Parameters: */ | ||
357 | /* node: NODE_ASN element pointer. */ | ||
358 | /* Return: a null terminated string. */ | ||
359 | /******************************************************************/ | ||
360 | char * | ||
361 | MHD__asn1_get_name (node_asn * node) | ||
362 | { | ||
363 | if (node == NULL) | ||
364 | return NULL; | ||
365 | return node->name; | ||
366 | } | ||
367 | |||
368 | /******************************************************************/ | ||
369 | /* Function : MHD__asn1_mod_type */ | ||
370 | /* Description: change the field TYPE of an NODE_ASN element. */ | ||
371 | /* The new value is the old one | (bitwise or) the */ | ||
372 | /* paramener VALUE. */ | ||
373 | /* Parameters: */ | ||
374 | /* node: NODE_ASN element pointer. */ | ||
375 | /* value: the integer value that must be or-ed with the current */ | ||
376 | /* value of field TYPE. */ | ||
377 | /* Return: NODE pointer. */ | ||
378 | /******************************************************************/ | ||
379 | node_asn * | ||
380 | MHD__asn1_mod_type (node_asn * node, unsigned int value) | ||
381 | { | ||
382 | if (node == NULL) | ||
383 | return node; | ||
384 | node->type |= value; | ||
385 | return node; | ||
386 | } | ||
387 | |||
388 | |||
389 | /******************************************************************/ | ||
390 | /* Function : MHD__asn1_remove_node */ | 304 | /* Function : MHD__asn1_remove_node */ |
391 | /* Description: gets free the memory allocated for an NODE_ASN */ | 305 | /* Description: gets free the memory allocated for an NODE_ASN */ |
392 | /* element (not the elements pointed by it). */ | 306 | /* element (not the elements pointed by it). */ |
@@ -529,7 +443,7 @@ MHD__asn1_change_integer_value (ASN1_TYPE node) | |||
529 | { | 443 | { |
530 | if (p->value) | 444 | if (p->value) |
531 | { | 445 | { |
532 | MHD__asn1_convert_integer (p->value, val, sizeof (val), &len); | 446 | MHD__asn1_convert_integer ((const char*) p->value, val, sizeof (val), &len); |
533 | MHD__asn1_octet_der (val, len, val2, &len); | 447 | MHD__asn1_octet_der (val, len, val2, &len); |
534 | MHD__asn1_set_value (p, val2, len); | 448 | MHD__asn1_set_value (p, val2, len); |
535 | } | 449 | } |
@@ -607,7 +521,7 @@ MHD__asn1_expand_object_id (ASN1_TYPE node) | |||
607 | { | 521 | { |
608 | MHD__asn1_str_cpy (name2, sizeof (name2), name_root); | 522 | MHD__asn1_str_cpy (name2, sizeof (name2), name_root); |
609 | MHD__asn1_str_cat (name2, sizeof (name2), "."); | 523 | MHD__asn1_str_cat (name2, sizeof (name2), "."); |
610 | MHD__asn1_str_cat (name2, sizeof (name2), p2->value); | 524 | MHD__asn1_str_cat (name2, sizeof (name2), (const char*) p2->value); |
611 | p3 = MHD__asn1_find_node (node, name2); | 525 | p3 = MHD__asn1_find_node (node, name2); |
612 | if (!p3 || (type_field (p3->type) != TYPE_OBJECT_ID) || | 526 | if (!p3 || (type_field (p3->type) != TYPE_OBJECT_ID) || |
613 | !(p3->type & CONST_ASSIGN)) | 527 | !(p3->type & CONST_ASSIGN)) |
@@ -622,7 +536,7 @@ MHD__asn1_expand_object_id (ASN1_TYPE node) | |||
622 | { | 536 | { |
623 | p5 = MHD__asn1_add_node_only (TYPE_CONSTANT); | 537 | p5 = MHD__asn1_add_node_only (TYPE_CONSTANT); |
624 | MHD__asn1_set_name (p5, p4->name); | 538 | MHD__asn1_set_name (p5, p4->name); |
625 | tlen = strlen (p4->value); | 539 | tlen = strlen ( (const char*) p4->value); |
626 | if (tlen > 0) | 540 | if (tlen > 0) |
627 | MHD__asn1_set_value (p5, p4->value, tlen + 1); | 541 | MHD__asn1_set_value (p5, p4->value, tlen + 1); |
628 | if (p2 == p) | 542 | if (p2 == p) |
@@ -693,7 +607,7 @@ MHD__asn1_expand_object_id (ASN1_TYPE node) | |||
693 | { | 607 | { |
694 | MHD__asn1_str_cpy (name2, sizeof (name2), name_root); | 608 | MHD__asn1_str_cpy (name2, sizeof (name2), name_root); |
695 | MHD__asn1_str_cat (name2, sizeof (name2), "."); | 609 | MHD__asn1_str_cat (name2, sizeof (name2), "."); |
696 | MHD__asn1_str_cat (name2, sizeof (name2), p2->value); | 610 | MHD__asn1_str_cat (name2, sizeof (name2), (const char*) p2->value); |
697 | p3 = MHD__asn1_find_node (node, name2); | 611 | p3 = MHD__asn1_find_node (node, name2); |
698 | if (!p3 || (type_field (p3->type) != TYPE_OBJECT_ID) || | 612 | if (!p3 || (type_field (p3->type) != TYPE_OBJECT_ID) || |
699 | !(p3->type & CONST_ASSIGN)) | 613 | !(p3->type & CONST_ASSIGN)) |
@@ -706,7 +620,7 @@ MHD__asn1_expand_object_id (ASN1_TYPE node) | |||
706 | { | 620 | { |
707 | if (name2[0]) | 621 | if (name2[0]) |
708 | MHD__asn1_str_cat (name2, sizeof (name2), "."); | 622 | MHD__asn1_str_cat (name2, sizeof (name2), "."); |
709 | MHD__asn1_str_cat (name2, sizeof (name2), p4->value); | 623 | MHD__asn1_str_cat (name2, sizeof (name2), (const char*) p4->value); |
710 | } | 624 | } |
711 | p4 = p4->right; | 625 | p4 = p4->right; |
712 | } | 626 | } |
@@ -748,77 +662,6 @@ MHD__asn1_expand_object_id (ASN1_TYPE node) | |||
748 | return ASN1_SUCCESS; | 662 | return ASN1_SUCCESS; |
749 | } | 663 | } |
750 | 664 | ||
751 | |||
752 | /******************************************************************/ | ||
753 | /* Function : MHD__asn1_type_set_config */ | ||
754 | /* Description: sets the CONST_SET and CONST_NOT_USED properties */ | ||
755 | /* in the fields of the SET elements. */ | ||
756 | /* Parameters: */ | ||
757 | /* node: root of an ASN1 element. */ | ||
758 | /* Return: */ | ||
759 | /* ASN1_ELEMENT_NOT_FOUND if NODE is NULL, */ | ||
760 | /* otherwise ASN1_SUCCESS */ | ||
761 | /******************************************************************/ | ||
762 | MHD__asn1_retCode | ||
763 | MHD__asn1_type_set_config (ASN1_TYPE node) | ||
764 | { | ||
765 | node_asn *p, *p2; | ||
766 | int move; | ||
767 | |||
768 | if (node == NULL) | ||
769 | return ASN1_ELEMENT_NOT_FOUND; | ||
770 | |||
771 | p = node; | ||
772 | move = DOWN; | ||
773 | |||
774 | while (!((p == node) && (move == UP))) | ||
775 | { | ||
776 | if (move != UP) | ||
777 | { | ||
778 | if (type_field (p->type) == TYPE_SET) | ||
779 | { | ||
780 | p2 = p->down; | ||
781 | while (p2) | ||
782 | { | ||
783 | if (type_field (p2->type) != TYPE_TAG) | ||
784 | p2->type |= CONST_SET | CONST_NOT_USED; | ||
785 | p2 = p2->right; | ||
786 | } | ||
787 | } | ||
788 | move = DOWN; | ||
789 | } | ||
790 | else | ||
791 | move = RIGHT; | ||
792 | |||
793 | if (move == DOWN) | ||
794 | { | ||
795 | if (p->down) | ||
796 | p = p->down; | ||
797 | else | ||
798 | move = RIGHT; | ||
799 | } | ||
800 | |||
801 | if (p == node) | ||
802 | { | ||
803 | move = UP; | ||
804 | continue; | ||
805 | } | ||
806 | |||
807 | if (move == RIGHT) | ||
808 | { | ||
809 | if (p->right) | ||
810 | p = p->right; | ||
811 | else | ||
812 | move = UP; | ||
813 | } | ||
814 | if (move == UP) | ||
815 | p = MHD__asn1_find_up (p); | ||
816 | } | ||
817 | |||
818 | return ASN1_SUCCESS; | ||
819 | } | ||
820 | |||
821 | |||
822 | /******************************************************************/ | 665 | /******************************************************************/ |
823 | /* Function : MHD__asn1_check_identifier */ | 666 | /* Function : MHD__asn1_check_identifier */ |
824 | /* Description: checks the definitions of all the identifiers */ | 667 | /* Description: checks the definitions of all the identifiers */ |
@@ -848,11 +691,11 @@ MHD__asn1_check_identifier (ASN1_TYPE node) | |||
848 | { | 691 | { |
849 | MHD__asn1_str_cpy (name2, sizeof (name2), node->name); | 692 | MHD__asn1_str_cpy (name2, sizeof (name2), node->name); |
850 | MHD__asn1_str_cat (name2, sizeof (name2), "."); | 693 | MHD__asn1_str_cat (name2, sizeof (name2), "."); |
851 | MHD__asn1_str_cat (name2, sizeof (name2), p->value); | 694 | MHD__asn1_str_cat (name2, sizeof (name2), (const char*) p->value); |
852 | p2 = MHD__asn1_find_node (node, name2); | 695 | p2 = MHD__asn1_find_node (node, name2); |
853 | if (p2 == NULL) | 696 | if (p2 == NULL) |
854 | { | 697 | { |
855 | strcpy (MHD__asn1_identifierMissing, p->value); | 698 | strcpy (MHD__asn1_identifierMissing, (const char*) p->value); |
856 | return ASN1_IDENTIFIER_NOT_FOUND; | 699 | return ASN1_IDENTIFIER_NOT_FOUND; |
857 | } | 700 | } |
858 | } | 701 | } |
@@ -864,8 +707,8 @@ MHD__asn1_check_identifier (ASN1_TYPE node) | |||
864 | { | 707 | { |
865 | MHD__asn1_str_cpy (name2, sizeof (name2), node->name); | 708 | MHD__asn1_str_cpy (name2, sizeof (name2), node->name); |
866 | MHD__asn1_str_cat (name2, sizeof (name2), "."); | 709 | MHD__asn1_str_cat (name2, sizeof (name2), "."); |
867 | MHD__asn1_str_cat (name2, sizeof (name2), p2->value); | 710 | MHD__asn1_str_cat (name2, sizeof (name2), (const char*) p2->value); |
868 | strcpy (MHD__asn1_identifierMissing, p2->value); | 711 | strcpy (MHD__asn1_identifierMissing, (const char*) p2->value); |
869 | p2 = MHD__asn1_find_node (node, name2); | 712 | p2 = MHD__asn1_find_node (node, name2); |
870 | if (!p2 || (type_field (p2->type) != TYPE_OBJECT_ID) || | 713 | if (!p2 || (type_field (p2->type) != TYPE_OBJECT_ID) || |
871 | !(p2->type & CONST_ASSIGN)) | 714 | !(p2->type & CONST_ASSIGN)) |
@@ -884,8 +727,8 @@ MHD__asn1_check_identifier (ASN1_TYPE node) | |||
884 | { | 727 | { |
885 | MHD__asn1_str_cpy (name2, sizeof (name2), node->name); | 728 | MHD__asn1_str_cpy (name2, sizeof (name2), node->name); |
886 | MHD__asn1_str_cat (name2, sizeof (name2), "."); | 729 | MHD__asn1_str_cat (name2, sizeof (name2), "."); |
887 | MHD__asn1_str_cat (name2, sizeof (name2), p2->value); | 730 | MHD__asn1_str_cat (name2, sizeof (name2), (const char*) p2->value); |
888 | strcpy (MHD__asn1_identifierMissing, p2->value); | 731 | strcpy (MHD__asn1_identifierMissing, (const char*) p2->value); |
889 | p2 = MHD__asn1_find_node (node, name2); | 732 | p2 = MHD__asn1_find_node (node, name2); |
890 | if (!p2 || (type_field (p2->type) != TYPE_OBJECT_ID) || | 733 | if (!p2 || (type_field (p2->type) != TYPE_OBJECT_ID) || |
891 | !(p2->type & CONST_ASSIGN)) | 734 | !(p2->type & CONST_ASSIGN)) |
@@ -923,150 +766,3 @@ MHD__asn1_check_identifier (ASN1_TYPE node) | |||
923 | 766 | ||
924 | return ASN1_SUCCESS; | 767 | return ASN1_SUCCESS; |
925 | } | 768 | } |
926 | |||
927 | |||
928 | /******************************************************************/ | ||
929 | /* Function : MHD__asn1_set_default_tag */ | ||
930 | /* Description: sets the default IMPLICIT or EXPLICIT property in */ | ||
931 | /* the tagged elements that don't have this declaration. */ | ||
932 | /* Parameters: */ | ||
933 | /* node: pointer to a DEFINITIONS element. */ | ||
934 | /* Return: */ | ||
935 | /* ASN1_ELEMENT_NOT_FOUND if NODE is NULL or not a pointer to */ | ||
936 | /* a DEFINITIONS element, */ | ||
937 | /* otherwise ASN1_SUCCESS */ | ||
938 | /******************************************************************/ | ||
939 | MHD__asn1_retCode | ||
940 | MHD__asn1_set_default_tag (ASN1_TYPE node) | ||
941 | { | ||
942 | node_asn *p; | ||
943 | |||
944 | if ((node == NULL) || (type_field (node->type) != TYPE_DEFINITIONS)) | ||
945 | return ASN1_ELEMENT_NOT_FOUND; | ||
946 | |||
947 | p = node; | ||
948 | while (p) | ||
949 | { | ||
950 | if ((type_field (p->type) == TYPE_TAG) && | ||
951 | !(p->type & CONST_EXPLICIT) && !(p->type & CONST_IMPLICIT)) | ||
952 | { | ||
953 | if (node->type & CONST_EXPLICIT) | ||
954 | p->type |= CONST_EXPLICIT; | ||
955 | else | ||
956 | p->type |= CONST_IMPLICIT; | ||
957 | } | ||
958 | |||
959 | if (p->down) | ||
960 | { | ||
961 | p = p->down; | ||
962 | } | ||
963 | else if (p->right) | ||
964 | p = p->right; | ||
965 | else | ||
966 | { | ||
967 | while (1) | ||
968 | { | ||
969 | p = MHD__asn1_find_up (p); | ||
970 | if (p == node) | ||
971 | { | ||
972 | p = NULL; | ||
973 | break; | ||
974 | } | ||
975 | if (p->right) | ||
976 | { | ||
977 | p = p->right; | ||
978 | break; | ||
979 | } | ||
980 | } | ||
981 | } | ||
982 | } | ||
983 | |||
984 | return ASN1_SUCCESS; | ||
985 | } | ||
986 | |||
987 | |||
988 | |||
989 | static const char * | ||
990 | parse_version_number (const char *s, int *number) | ||
991 | { | ||
992 | int val = 0; | ||
993 | |||
994 | if (*s == '0' && isdigit (s[1])) | ||
995 | return NULL; /* leading zeros are not allowed */ | ||
996 | for (; isdigit (*s); s++) | ||
997 | { | ||
998 | val *= 10; | ||
999 | val += *s - '0'; | ||
1000 | } | ||
1001 | *number = val; | ||
1002 | return val < 0 ? NULL : s; | ||
1003 | } | ||
1004 | |||
1005 | /* The parse version functions were copied from libgcrypt. | ||
1006 | */ | ||
1007 | static const char * | ||
1008 | parse_version_string (const char *s, int *major, int *minor, int *micro) | ||
1009 | { | ||
1010 | s = parse_version_number (s, major); | ||
1011 | if (!s || *s != '.') | ||
1012 | return NULL; | ||
1013 | s++; | ||
1014 | s = parse_version_number (s, minor); | ||
1015 | if (!s) | ||
1016 | return NULL; | ||
1017 | if (*s != '.') | ||
1018 | { | ||
1019 | *micro = 0; | ||
1020 | return s; | ||
1021 | } | ||
1022 | s++; | ||
1023 | s = parse_version_number (s, micro); | ||
1024 | if (!s) | ||
1025 | return NULL; | ||
1026 | return s; /* patchlevel */ | ||
1027 | } | ||
1028 | |||
1029 | /** | ||
1030 | * MHD__asn1_check_version - check for library version | ||
1031 | * @req_version: Required version number, or NULL. | ||
1032 | * | ||
1033 | * Check that the the version of the library is at minimum the | ||
1034 | * requested one and return the version string; return %NULL if the | ||
1035 | * condition is not satisfied. If a %NULL is passed to this function, | ||
1036 | * no check is done, but the version string is simply returned. | ||
1037 | * | ||
1038 | * See %LIBTASN1_VERSION for a suitable @req_version string. | ||
1039 | * | ||
1040 | * Return value: Version string of run-time library, or %NULL if the | ||
1041 | * run-time library does not meet the required version number. | ||
1042 | */ | ||
1043 | const char * | ||
1044 | MHD__asn1_check_version (const char *req_version) | ||
1045 | { | ||
1046 | const char *ver = LIBTASN1_VERSION; | ||
1047 | int my_major, my_minor, my_micro; | ||
1048 | int rq_major, rq_minor, rq_micro; | ||
1049 | const char *my_plvl, *rq_plvl; | ||
1050 | |||
1051 | if (!req_version) | ||
1052 | return ver; | ||
1053 | |||
1054 | my_plvl = parse_version_string (ver, &my_major, &my_minor, &my_micro); | ||
1055 | if (!my_plvl) | ||
1056 | return NULL; /* very strange our own version is bogus */ | ||
1057 | rq_plvl = parse_version_string (req_version, &rq_major, &rq_minor, | ||
1058 | &rq_micro); | ||
1059 | if (!rq_plvl) | ||
1060 | return NULL; /* req version string is invalid */ | ||
1061 | |||
1062 | if (my_major > rq_major | ||
1063 | || (my_major == rq_major && my_minor > rq_minor) | ||
1064 | || (my_major == rq_major && my_minor == rq_minor | ||
1065 | && my_micro > rq_micro) | ||
1066 | || (my_major == rq_major && my_minor == rq_minor | ||
1067 | && my_micro == rq_micro && strcmp (my_plvl, rq_plvl) >= 0)) | ||
1068 | { | ||
1069 | return ver; | ||
1070 | } | ||
1071 | return NULL; | ||
1072 | } | ||