diff options
Diffstat (limited to 'src/daemon/https/minitasn1/structure.c')
-rw-r--r-- | src/daemon/https/minitasn1/structure.c | 456 |
1 files changed, 8 insertions, 448 deletions
diff --git a/src/daemon/https/minitasn1/structure.c b/src/daemon/https/minitasn1/structure.c index af5fdf75..6a910af6 100644 --- a/src/daemon/https/minitasn1/structure.c +++ b/src/daemon/https/minitasn1/structure.c | |||
@@ -37,6 +37,9 @@ | |||
37 | 37 | ||
38 | extern char MHD__asn1_identifierMissing[]; | 38 | extern char MHD__asn1_identifierMissing[]; |
39 | 39 | ||
40 | static node_asn *MHD__asn1_copy_structure2 (node_asn * root, const char *source_name); | ||
41 | |||
42 | |||
40 | 43 | ||
41 | /******************************************************/ | 44 | /******************************************************/ |
42 | /* Function : MHD__asn1_add_node_only */ | 45 | /* Function : MHD__asn1_add_node_only */ |
@@ -79,85 +82,6 @@ MHD__asn1_find_left (node_asn * node) | |||
79 | } | 82 | } |
80 | 83 | ||
81 | 84 | ||
82 | MHD__asn1_retCode | ||
83 | MHD__asn1_create_static_structure (ASN1_TYPE pointer, char *output_file_name, | ||
84 | char *vector_name) | ||
85 | { | ||
86 | FILE *file; | ||
87 | node_asn *p; | ||
88 | unsigned long t; | ||
89 | |||
90 | file = fopen (output_file_name, "w"); | ||
91 | |||
92 | if (file == NULL) | ||
93 | return ASN1_FILE_NOT_FOUND; | ||
94 | |||
95 | fprintf (file, "#if HAVE_CONFIG_H\n"); | ||
96 | fprintf (file, "# include \"config.h\"\n"); | ||
97 | fprintf (file, "#endif\n\n"); | ||
98 | |||
99 | fprintf (file, "#include <libtasn1.h>\n\n"); | ||
100 | |||
101 | fprintf (file, "extern const ASN1_ARRAY_TYPE %s[]={\n", vector_name); | ||
102 | |||
103 | p = pointer; | ||
104 | |||
105 | while (p) | ||
106 | { | ||
107 | fprintf (file, " {"); | ||
108 | |||
109 | if (p->name) | ||
110 | fprintf (file, "\"%s\",", p->name); | ||
111 | else | ||
112 | fprintf (file, "0,"); | ||
113 | |||
114 | t = p->type; | ||
115 | if (p->down) | ||
116 | t |= CONST_DOWN; | ||
117 | if (p->right) | ||
118 | t |= CONST_RIGHT; | ||
119 | |||
120 | fprintf (file, "%lu,", t); | ||
121 | |||
122 | if (p->value) | ||
123 | fprintf (file, "\"%s\"},\n", p->value); | ||
124 | else | ||
125 | fprintf (file, "0},\n"); | ||
126 | |||
127 | if (p->down) | ||
128 | { | ||
129 | p = p->down; | ||
130 | } | ||
131 | else if (p->right) | ||
132 | { | ||
133 | p = p->right; | ||
134 | } | ||
135 | else | ||
136 | { | ||
137 | while (1) | ||
138 | { | ||
139 | p = MHD__asn1_find_up (p); | ||
140 | if (p == pointer) | ||
141 | { | ||
142 | p = NULL; | ||
143 | break; | ||
144 | } | ||
145 | if (p->right) | ||
146 | { | ||
147 | p = p->right; | ||
148 | break; | ||
149 | } | ||
150 | } | ||
151 | } | ||
152 | } | ||
153 | |||
154 | fprintf (file, " {0,0,0}\n};\n"); | ||
155 | |||
156 | fclose (file); | ||
157 | |||
158 | return ASN1_SUCCESS; | ||
159 | } | ||
160 | |||
161 | 85 | ||
162 | /** | 86 | /** |
163 | * MHD__asn1_array2tree - Creates the structures needed to manage the ASN1 definitions. | 87 | * MHD__asn1_array2tree - Creates the structures needed to manage the ASN1 definitions. |
@@ -455,7 +379,7 @@ MHD__asn1_copy_structure3 (node_asn * source_node) | |||
455 | } | 379 | } |
456 | 380 | ||
457 | 381 | ||
458 | node_asn * | 382 | static node_asn * |
459 | MHD__asn1_copy_structure2 (node_asn * root, const char *source_name) | 383 | MHD__asn1_copy_structure2 (node_asn * root, const char *source_name) |
460 | { | 384 | { |
461 | node_asn *source_node; | 385 | node_asn *source_node; |
@@ -467,7 +391,7 @@ MHD__asn1_copy_structure2 (node_asn * root, const char *source_name) | |||
467 | } | 391 | } |
468 | 392 | ||
469 | 393 | ||
470 | MHD__asn1_retCode | 394 | static MHD__asn1_retCode |
471 | MHD__asn1_type_choice_config (node_asn * node) | 395 | MHD__asn1_type_choice_config (node_asn * node) |
472 | { | 396 | { |
473 | node_asn *p, *p2, *p3, *p4; | 397 | node_asn *p, *p2, *p3, *p4; |
@@ -497,7 +421,7 @@ MHD__asn1_type_choice_config (node_asn * node) | |||
497 | if (type_field (p3->type) == TYPE_TAG) | 421 | if (type_field (p3->type) == TYPE_TAG) |
498 | { | 422 | { |
499 | p4 = MHD__asn1_add_node_only (p3->type); | 423 | p4 = MHD__asn1_add_node_only (p3->type); |
500 | tlen = strlen (p3->value); | 424 | tlen = strlen ((const char*) p3->value); |
501 | if (tlen > 0) | 425 | if (tlen > 0) |
502 | MHD__asn1_set_value (p4, p3->value, tlen + 1); | 426 | MHD__asn1_set_value (p4, p3->value, tlen + 1); |
503 | MHD__asn1_set_right (p4, p2->down); | 427 | MHD__asn1_set_right (p4, p2->down); |
@@ -552,7 +476,7 @@ MHD__asn1_type_choice_config (node_asn * node) | |||
552 | } | 476 | } |
553 | 477 | ||
554 | 478 | ||
555 | MHD__asn1_retCode | 479 | static MHD__asn1_retCode |
556 | MHD__asn1_expand_identifier (node_asn ** node, node_asn * root) | 480 | MHD__asn1_expand_identifier (node_asn ** node, node_asn * root) |
557 | { | 481 | { |
558 | node_asn *p, *p2, *p3; | 482 | node_asn *p, *p2, *p3; |
@@ -573,7 +497,7 @@ MHD__asn1_expand_identifier (node_asn ** node, node_asn * root) | |||
573 | { | 497 | { |
574 | MHD__asn1_str_cpy (name2, sizeof (name2), root->name); | 498 | MHD__asn1_str_cpy (name2, sizeof (name2), root->name); |
575 | MHD__asn1_str_cat (name2, sizeof (name2), "."); | 499 | MHD__asn1_str_cat (name2, sizeof (name2), "."); |
576 | MHD__asn1_str_cat (name2, sizeof (name2), p->value); | 500 | MHD__asn1_str_cat (name2, sizeof (name2), (const char*) p->value); |
577 | p2 = MHD__asn1_copy_structure2 (root, name2); | 501 | p2 = MHD__asn1_copy_structure2 (root, name2); |
578 | if (p2 == NULL) | 502 | if (p2 == NULL) |
579 | { | 503 | { |
@@ -704,370 +628,6 @@ MHD__asn1_create_element (ASN1_TYPE definitions, const char *source_name, | |||
704 | 628 | ||
705 | 629 | ||
706 | /** | 630 | /** |
707 | * MHD__asn1_print_structure - Prints on the standard output the structure's tree | ||
708 | * @out: pointer to the output file (e.g. stdout). | ||
709 | * @structure: pointer to the structure that you want to visit. | ||
710 | * @name: an element of the structure | ||
711 | * @mode: specify how much of the structure to print, can be | ||
712 | * %ASN1_PRINT_NAME, %ASN1_PRINT_NAME_TYPE, | ||
713 | * %ASN1_PRINT_NAME_TYPE_VALUE, or %ASN1_PRINT_ALL. | ||
714 | * | ||
715 | * Prints on the @out file descriptor the structure's tree starting | ||
716 | * from the @name element inside the structure @structure. | ||
717 | **/ | ||
718 | void | ||
719 | MHD__asn1_print_structure (FILE * out, ASN1_TYPE structure, const char *name, | ||
720 | int mode) | ||
721 | { | ||
722 | node_asn *p, *root; | ||
723 | int k, indent = 0, len, len2, len3; | ||
724 | |||
725 | if (out == NULL) | ||
726 | return; | ||
727 | |||
728 | root = MHD__asn1_find_node (structure, name); | ||
729 | |||
730 | if (root == NULL) | ||
731 | return; | ||
732 | |||
733 | p = root; | ||
734 | while (p) | ||
735 | { | ||
736 | if (mode == ASN1_PRINT_ALL) | ||
737 | { | ||
738 | for (k = 0; k < indent; k++) | ||
739 | fprintf (out, " "); | ||
740 | fprintf (out, "name:"); | ||
741 | if (p->name) | ||
742 | fprintf (out, "%s ", p->name); | ||
743 | else | ||
744 | fprintf (out, "NULL "); | ||
745 | } | ||
746 | else | ||
747 | { | ||
748 | switch (type_field (p->type)) | ||
749 | { | ||
750 | case TYPE_CONSTANT: | ||
751 | case TYPE_TAG: | ||
752 | case TYPE_SIZE: | ||
753 | break; | ||
754 | default: | ||
755 | for (k = 0; k < indent; k++) | ||
756 | fprintf (out, " "); | ||
757 | fprintf (out, "name:"); | ||
758 | if (p->name) | ||
759 | fprintf (out, "%s ", p->name); | ||
760 | else | ||
761 | fprintf (out, "NULL "); | ||
762 | } | ||
763 | } | ||
764 | |||
765 | if (mode != ASN1_PRINT_NAME) | ||
766 | { | ||
767 | switch (type_field (p->type)) | ||
768 | { | ||
769 | case TYPE_CONSTANT: | ||
770 | if (mode == ASN1_PRINT_ALL) | ||
771 | fprintf (out, "type:CONST"); | ||
772 | break; | ||
773 | case TYPE_TAG: | ||
774 | if (mode == ASN1_PRINT_ALL) | ||
775 | fprintf (out, "type:TAG"); | ||
776 | break; | ||
777 | case TYPE_SIZE: | ||
778 | if (mode == ASN1_PRINT_ALL) | ||
779 | fprintf (out, "type:SIZE"); | ||
780 | break; | ||
781 | case TYPE_DEFAULT: | ||
782 | fprintf (out, "type:DEFAULT"); | ||
783 | break; | ||
784 | case TYPE_NULL: | ||
785 | fprintf (out, "type:NULL"); | ||
786 | break; | ||
787 | case TYPE_IDENTIFIER: | ||
788 | fprintf (out, "type:IDENTIFIER"); | ||
789 | break; | ||
790 | case TYPE_INTEGER: | ||
791 | fprintf (out, "type:INTEGER"); | ||
792 | break; | ||
793 | case TYPE_ENUMERATED: | ||
794 | fprintf (out, "type:ENUMERATED"); | ||
795 | break; | ||
796 | case TYPE_TIME: | ||
797 | fprintf (out, "type:TIME"); | ||
798 | break; | ||
799 | case TYPE_BOOLEAN: | ||
800 | fprintf (out, "type:BOOLEAN"); | ||
801 | break; | ||
802 | case TYPE_SEQUENCE: | ||
803 | fprintf (out, "type:SEQUENCE"); | ||
804 | break; | ||
805 | case TYPE_BIT_STRING: | ||
806 | fprintf (out, "type:BIT_STR"); | ||
807 | break; | ||
808 | case TYPE_OCTET_STRING: | ||
809 | fprintf (out, "type:OCT_STR"); | ||
810 | break; | ||
811 | case TYPE_GENERALSTRING: | ||
812 | fprintf (out, "type:GENERALSTRING"); | ||
813 | break; | ||
814 | case TYPE_SEQUENCE_OF: | ||
815 | fprintf (out, "type:SEQ_OF"); | ||
816 | break; | ||
817 | case TYPE_OBJECT_ID: | ||
818 | fprintf (out, "type:OBJ_ID"); | ||
819 | break; | ||
820 | case TYPE_ANY: | ||
821 | fprintf (out, "type:ANY"); | ||
822 | break; | ||
823 | case TYPE_SET: | ||
824 | fprintf (out, "type:SET"); | ||
825 | break; | ||
826 | case TYPE_SET_OF: | ||
827 | fprintf (out, "type:SET_OF"); | ||
828 | break; | ||
829 | case TYPE_CHOICE: | ||
830 | fprintf (out, "type:CHOICE"); | ||
831 | break; | ||
832 | case TYPE_DEFINITIONS: | ||
833 | fprintf (out, "type:DEFINITIONS"); | ||
834 | break; | ||
835 | default: | ||
836 | break; | ||
837 | } | ||
838 | } | ||
839 | |||
840 | if ((mode == ASN1_PRINT_NAME_TYPE_VALUE) || (mode == ASN1_PRINT_ALL)) | ||
841 | { | ||
842 | switch (type_field (p->type)) | ||
843 | { | ||
844 | case TYPE_CONSTANT: | ||
845 | if (mode == ASN1_PRINT_ALL) | ||
846 | if (p->value) | ||
847 | fprintf (out, " value:%s", p->value); | ||
848 | break; | ||
849 | case TYPE_TAG: | ||
850 | if (mode == ASN1_PRINT_ALL) | ||
851 | if (p->value) | ||
852 | fprintf (out, " value:%s", p->value); | ||
853 | break; | ||
854 | case TYPE_SIZE: | ||
855 | if (mode == ASN1_PRINT_ALL) | ||
856 | if (p->value) | ||
857 | fprintf (out, " value:%s", p->value); | ||
858 | break; | ||
859 | case TYPE_DEFAULT: | ||
860 | if (p->value) | ||
861 | fprintf (out, " value:%s", p->value); | ||
862 | else if (p->type & CONST_TRUE) | ||
863 | fprintf (out, " value:TRUE"); | ||
864 | else if (p->type & CONST_FALSE) | ||
865 | fprintf (out, " value:FALSE"); | ||
866 | break; | ||
867 | case TYPE_IDENTIFIER: | ||
868 | if (p->value) | ||
869 | fprintf (out, " value:%s", p->value); | ||
870 | break; | ||
871 | case TYPE_INTEGER: | ||
872 | if (p->value) | ||
873 | { | ||
874 | len2 = -1; | ||
875 | len = MHD__asn1_get_length_der (p->value, p->value_len, &len2); | ||
876 | fprintf (out, " value:0x"); | ||
877 | if (len > 0) | ||
878 | for (k = 0; k < len; k++) | ||
879 | fprintf (out, "%02x", (p->value)[k + len2]); | ||
880 | } | ||
881 | break; | ||
882 | case TYPE_ENUMERATED: | ||
883 | if (p->value) | ||
884 | { | ||
885 | len2 = -1; | ||
886 | len = MHD__asn1_get_length_der (p->value, p->value_len, &len2); | ||
887 | fprintf (out, " value:0x"); | ||
888 | if (len > 0) | ||
889 | for (k = 0; k < len; k++) | ||
890 | fprintf (out, "%02x", (p->value)[k + len2]); | ||
891 | } | ||
892 | break; | ||
893 | case TYPE_TIME: | ||
894 | if (p->value) | ||
895 | fprintf (out, " value:%s", p->value); | ||
896 | break; | ||
897 | case TYPE_BOOLEAN: | ||
898 | if (p->value) | ||
899 | { | ||
900 | if (p->value[0] == 'T') | ||
901 | fprintf (out, " value:TRUE"); | ||
902 | else if (p->value[0] == 'F') | ||
903 | fprintf (out, " value:FALSE"); | ||
904 | } | ||
905 | break; | ||
906 | case TYPE_BIT_STRING: | ||
907 | if (p->value) | ||
908 | { | ||
909 | len2 = -1; | ||
910 | len = MHD__asn1_get_length_der (p->value, p->value_len, &len2); | ||
911 | if (len > 0) | ||
912 | { | ||
913 | fprintf (out, " value(%i):", | ||
914 | (len - 1) * 8 - (p->value[len2])); | ||
915 | for (k = 1; k < len; k++) | ||
916 | fprintf (out, "%02x", (p->value)[k + len2]); | ||
917 | } | ||
918 | } | ||
919 | break; | ||
920 | case TYPE_OCTET_STRING: | ||
921 | if (p->value) | ||
922 | { | ||
923 | len2 = -1; | ||
924 | len = MHD__asn1_get_length_der (p->value, p->value_len, &len2); | ||
925 | fprintf (out, " value:"); | ||
926 | if (len > 0) | ||
927 | for (k = 0; k < len; k++) | ||
928 | fprintf (out, "%02x", (p->value)[k + len2]); | ||
929 | } | ||
930 | break; | ||
931 | case TYPE_GENERALSTRING: | ||
932 | if (p->value) | ||
933 | { | ||
934 | len2 = -1; | ||
935 | len = MHD__asn1_get_length_der (p->value, p->value_len, &len2); | ||
936 | fprintf (out, " value:"); | ||
937 | if (len > 0) | ||
938 | for (k = 0; k < len; k++) | ||
939 | fprintf (out, "%02x", (p->value)[k + len2]); | ||
940 | } | ||
941 | break; | ||
942 | case TYPE_OBJECT_ID: | ||
943 | if (p->value) | ||
944 | fprintf (out, " value:%s", p->value); | ||
945 | break; | ||
946 | case TYPE_ANY: | ||
947 | if (p->value) | ||
948 | { | ||
949 | len3 = -1; | ||
950 | len2 = MHD__asn1_get_length_der (p->value, p->value_len, &len3); | ||
951 | fprintf (out, " value:"); | ||
952 | if (len2 > 0) | ||
953 | for (k = 0; k < len2; k++) | ||
954 | fprintf (out, "%02x", (p->value)[k + len3]); | ||
955 | } | ||
956 | break; | ||
957 | case TYPE_SET: | ||
958 | case TYPE_SET_OF: | ||
959 | case TYPE_CHOICE: | ||
960 | case TYPE_DEFINITIONS: | ||
961 | case TYPE_SEQUENCE_OF: | ||
962 | case TYPE_SEQUENCE: | ||
963 | case TYPE_NULL: | ||
964 | break; | ||
965 | default: | ||
966 | break; | ||
967 | } | ||
968 | } | ||
969 | |||
970 | if (mode == ASN1_PRINT_ALL) | ||
971 | { | ||
972 | if (p->type & 0x1FFFFF00) | ||
973 | { | ||
974 | fprintf (out, " attr:"); | ||
975 | if (p->type & CONST_UNIVERSAL) | ||
976 | fprintf (out, "UNIVERSAL,"); | ||
977 | if (p->type & CONST_PRIVATE) | ||
978 | fprintf (out, "PRIVATE,"); | ||
979 | if (p->type & CONST_APPLICATION) | ||
980 | fprintf (out, "APPLICATION,"); | ||
981 | if (p->type & CONST_EXPLICIT) | ||
982 | fprintf (out, "EXPLICIT,"); | ||
983 | if (p->type & CONST_IMPLICIT) | ||
984 | fprintf (out, "IMPLICIT,"); | ||
985 | if (p->type & CONST_TAG) | ||
986 | fprintf (out, "TAG,"); | ||
987 | if (p->type & CONST_DEFAULT) | ||
988 | fprintf (out, "DEFAULT,"); | ||
989 | if (p->type & CONST_TRUE) | ||
990 | fprintf (out, "TRUE,"); | ||
991 | if (p->type & CONST_FALSE) | ||
992 | fprintf (out, "FALSE,"); | ||
993 | if (p->type & CONST_LIST) | ||
994 | fprintf (out, "LIST,"); | ||
995 | if (p->type & CONST_MIN_MAX) | ||
996 | fprintf (out, "MIN_MAX,"); | ||
997 | if (p->type & CONST_OPTION) | ||
998 | fprintf (out, "OPTION,"); | ||
999 | if (p->type & CONST_1_PARAM) | ||
1000 | fprintf (out, "1_PARAM,"); | ||
1001 | if (p->type & CONST_SIZE) | ||
1002 | fprintf (out, "SIZE,"); | ||
1003 | if (p->type & CONST_DEFINED_BY) | ||
1004 | fprintf (out, "DEF_BY,"); | ||
1005 | if (p->type & CONST_GENERALIZED) | ||
1006 | fprintf (out, "GENERALIZED,"); | ||
1007 | if (p->type & CONST_UTC) | ||
1008 | fprintf (out, "UTC,"); | ||
1009 | if (p->type & CONST_SET) | ||
1010 | fprintf (out, "SET,"); | ||
1011 | if (p->type & CONST_NOT_USED) | ||
1012 | fprintf (out, "NOT_USED,"); | ||
1013 | if (p->type & CONST_ASSIGN) | ||
1014 | fprintf (out, "ASSIGNMENT,"); | ||
1015 | } | ||
1016 | } | ||
1017 | |||
1018 | if (mode == ASN1_PRINT_ALL) | ||
1019 | { | ||
1020 | fprintf (out, "\n"); | ||
1021 | } | ||
1022 | else | ||
1023 | { | ||
1024 | switch (type_field (p->type)) | ||
1025 | { | ||
1026 | case TYPE_CONSTANT: | ||
1027 | case TYPE_TAG: | ||
1028 | case TYPE_SIZE: | ||
1029 | break; | ||
1030 | default: | ||
1031 | fprintf (out, "\n"); | ||
1032 | } | ||
1033 | } | ||
1034 | |||
1035 | if (p->down) | ||
1036 | { | ||
1037 | p = p->down; | ||
1038 | indent += 2; | ||
1039 | } | ||
1040 | else if (p == root) | ||
1041 | { | ||
1042 | p = NULL; | ||
1043 | break; | ||
1044 | } | ||
1045 | else if (p->right) | ||
1046 | p = p->right; | ||
1047 | else | ||
1048 | { | ||
1049 | while (1) | ||
1050 | { | ||
1051 | p = MHD__asn1_find_up (p); | ||
1052 | if (p == root) | ||
1053 | { | ||
1054 | p = NULL; | ||
1055 | break; | ||
1056 | } | ||
1057 | indent -= 2; | ||
1058 | if (p->right) | ||
1059 | { | ||
1060 | p = p->right; | ||
1061 | break; | ||
1062 | } | ||
1063 | } | ||
1064 | } | ||
1065 | } | ||
1066 | } | ||
1067 | |||
1068 | |||
1069 | |||
1070 | /** | ||
1071 | * MHD__asn1_number_of_elements - Counts the number of elements of a structure. | 631 | * MHD__asn1_number_of_elements - Counts the number of elements of a structure. |
1072 | * @element: pointer to the root of an ASN1 structure. | 632 | * @element: pointer to the root of an ASN1 structure. |
1073 | * @name: the name of a sub-structure of ROOT. | 633 | * @name: the name of a sub-structure of ROOT. |