diff options
Diffstat (limited to 'src/daemon/https/x509/common.c')
-rw-r--r-- | src/daemon/https/x509/common.c | 108 |
1 files changed, 63 insertions, 45 deletions
diff --git a/src/daemon/https/x509/common.c b/src/daemon/https/x509/common.c index 6e7e0853..ca2e355f 100644 --- a/src/daemon/https/x509/common.c +++ b/src/daemon/https/x509/common.c | |||
@@ -258,8 +258,9 @@ MHD__gnutls_x509_oid2ldap_string (const char *oid) | |||
258 | */ | 258 | */ |
259 | int | 259 | int |
260 | MHD__gnutls_x509_oid_data2string (const char *oid, | 260 | MHD__gnutls_x509_oid_data2string (const char *oid, |
261 | void *value, | 261 | void *value, |
262 | int value_size, char *res, size_t * res_size) | 262 | int value_size, char *res, |
263 | size_t * res_size) | ||
263 | { | 264 | { |
264 | char str[MAX_STRING_LEN], tmpname[128]; | 265 | char str[MAX_STRING_LEN], tmpname[128]; |
265 | const char *ANAME = NULL; | 266 | const char *ANAME = NULL; |
@@ -292,17 +293,19 @@ MHD__gnutls_x509_oid_data2string (const char *oid, | |||
292 | MHD_gtls_str_cat (str, sizeof (str), ANAME); | 293 | MHD_gtls_str_cat (str, sizeof (str), ANAME); |
293 | 294 | ||
294 | if ((result = MHD__asn1_create_element (MHD__gnutls_get_pkix (), str, | 295 | if ((result = MHD__asn1_create_element (MHD__gnutls_get_pkix (), str, |
295 | &tmpasn)) != ASN1_SUCCESS) | 296 | &tmpasn)) != ASN1_SUCCESS) |
296 | { | 297 | { |
297 | MHD_gnutls_assert (); | 298 | MHD_gnutls_assert (); |
298 | return MHD_gtls_asn2err (result); | 299 | return MHD_gtls_asn2err (result); |
299 | } | 300 | } |
300 | 301 | ||
301 | if ((result = MHD__asn1_der_decoding (&tmpasn, value, value_size, MHD__asn1_err)) | 302 | if ((result = |
302 | != ASN1_SUCCESS) | 303 | MHD__asn1_der_decoding (&tmpasn, value, value_size, |
304 | MHD__asn1_err)) != ASN1_SUCCESS) | ||
303 | { | 305 | { |
304 | MHD_gnutls_assert (); | 306 | MHD_gnutls_assert (); |
305 | MHD__gnutls_x509_log ("MHD__asn1_der_decoding: %s:%s\n", str, MHD__asn1_err); | 307 | MHD__gnutls_x509_log ("MHD__asn1_der_decoding: %s:%s\n", str, |
308 | MHD__asn1_err); | ||
306 | MHD__asn1_delete_structure (&tmpasn); | 309 | MHD__asn1_delete_structure (&tmpasn); |
307 | return MHD_gtls_asn2err (result); | 310 | return MHD_gtls_asn2err (result); |
308 | } | 311 | } |
@@ -381,7 +384,9 @@ MHD__gnutls_x509_oid_data2string (const char *oid, | |||
381 | } | 384 | } |
382 | else | 385 | else |
383 | { | 386 | { |
384 | result = MHD__gnutls_x509_data2hex ((const unsigned char*) str, len, (unsigned char*) res, res_size); | 387 | result = |
388 | MHD__gnutls_x509_data2hex ((const unsigned char *) str, len, | ||
389 | (unsigned char *) res, res_size); | ||
385 | if (result < 0) | 390 | if (result < 0) |
386 | { | 391 | { |
387 | MHD_gnutls_assert (); | 392 | MHD_gnutls_assert (); |
@@ -400,7 +405,8 @@ MHD__gnutls_x509_oid_data2string (const char *oid, | |||
400 | */ | 405 | */ |
401 | int | 406 | int |
402 | MHD__gnutls_x509_data2hex (const opaque * data, | 407 | MHD__gnutls_x509_data2hex (const opaque * data, |
403 | size_t data_size, opaque * out, size_t * sizeof_out) | 408 | size_t data_size, opaque * out, |
409 | size_t * sizeof_out) | ||
404 | { | 410 | { |
405 | char *res; | 411 | char *res; |
406 | char escaped[MAX_STRING_LEN]; | 412 | char escaped[MAX_STRING_LEN]; |
@@ -425,8 +431,8 @@ MHD__gnutls_x509_data2hex (const opaque * data, | |||
425 | 431 | ||
426 | if (out) | 432 | if (out) |
427 | { | 433 | { |
428 | strcpy ((char*) out, "#"); | 434 | strcpy ((char *) out, "#"); |
429 | strcat ((char*) out, res); | 435 | strcat ((char *) out, res); |
430 | } | 436 | } |
431 | 437 | ||
432 | return 0; | 438 | return 0; |
@@ -726,10 +732,10 @@ MHD__gnutls_x509_san_find_type (char *str_type) | |||
726 | */ | 732 | */ |
727 | int | 733 | int |
728 | MHD__gnutls_x509_export_int (ASN1_TYPE MHD__asn1_data, | 734 | MHD__gnutls_x509_export_int (ASN1_TYPE MHD__asn1_data, |
729 | MHD_gnutls_x509_crt_fmt_t format, | 735 | MHD_gnutls_x509_crt_fmt_t format, |
730 | char *pem_header, | 736 | char *pem_header, |
731 | unsigned char *output_data, | 737 | unsigned char *output_data, |
732 | size_t * output_data_size) | 738 | size_t * output_data_size) |
733 | { | 739 | { |
734 | int result, len; | 740 | int result, len; |
735 | 741 | ||
@@ -741,8 +747,9 @@ MHD__gnutls_x509_export_int (ASN1_TYPE MHD__asn1_data, | |||
741 | 747 | ||
742 | len = *output_data_size; | 748 | len = *output_data_size; |
743 | 749 | ||
744 | if ((result = MHD__asn1_der_coding (MHD__asn1_data, "", output_data, &len, | 750 | if ((result = |
745 | NULL)) != ASN1_SUCCESS) | 751 | MHD__asn1_der_coding (MHD__asn1_data, "", output_data, &len, |
752 | NULL)) != ASN1_SUCCESS) | ||
746 | { | 753 | { |
747 | *output_data_size = len; | 754 | *output_data_size = len; |
748 | if (result == ASN1_MEM_ERROR) | 755 | if (result == ASN1_MEM_ERROR) |
@@ -768,7 +775,8 @@ MHD__gnutls_x509_export_int (ASN1_TYPE MHD__asn1_data, | |||
768 | return result; | 775 | return result; |
769 | } | 776 | } |
770 | 777 | ||
771 | result = MHD__gnutls_fbase64_encode (pem_header, tmp.data, tmp.size, &out); | 778 | result = |
779 | MHD__gnutls_fbase64_encode (pem_header, tmp.data, tmp.size, &out); | ||
772 | 780 | ||
773 | MHD__gnutls_free_datum (&tmp); | 781 | MHD__gnutls_free_datum (&tmp); |
774 | 782 | ||
@@ -815,9 +823,9 @@ MHD__gnutls_x509_export_int (ASN1_TYPE MHD__asn1_data, | |||
815 | */ | 823 | */ |
816 | int | 824 | int |
817 | MHD__gnutls_x509_decode_octet_string (const char *string_type, | 825 | MHD__gnutls_x509_decode_octet_string (const char *string_type, |
818 | const opaque * der, | 826 | const opaque * der, |
819 | size_t der_size, | 827 | size_t der_size, |
820 | opaque * output, size_t * output_size) | 828 | opaque * output, size_t * output_size) |
821 | { | 829 | { |
822 | ASN1_TYPE c2 = ASN1_TYPE_EMPTY; | 830 | ASN1_TYPE c2 = ASN1_TYPE_EMPTY; |
823 | int result, tmp_output_size; | 831 | int result, tmp_output_size; |
@@ -833,7 +841,7 @@ MHD__gnutls_x509_decode_octet_string (const char *string_type, | |||
833 | 841 | ||
834 | if ((result = | 842 | if ((result = |
835 | MHD__asn1_create_element (MHD__gnutls_get_pkix (), strname, | 843 | MHD__asn1_create_element (MHD__gnutls_get_pkix (), strname, |
836 | &c2)) != ASN1_SUCCESS) | 844 | &c2)) != ASN1_SUCCESS) |
837 | { | 845 | { |
838 | MHD_gnutls_assert (); | 846 | MHD_gnutls_assert (); |
839 | result = MHD_gtls_asn2err (result); | 847 | result = MHD_gtls_asn2err (result); |
@@ -875,7 +883,8 @@ cleanup:if (c2) | |||
875 | */ | 883 | */ |
876 | int | 884 | int |
877 | MHD__gnutls_x509_read_value (ASN1_TYPE c, | 885 | MHD__gnutls_x509_read_value (ASN1_TYPE c, |
878 | const char *root, MHD_gnutls_datum_t * ret, int flags) | 886 | const char *root, MHD_gnutls_datum_t * ret, |
887 | int flags) | ||
879 | { | 888 | { |
880 | int len = 0, result; | 889 | int len = 0, result; |
881 | size_t slen; | 890 | size_t slen; |
@@ -917,7 +926,8 @@ MHD__gnutls_x509_read_value (ASN1_TYPE c, | |||
917 | if (flags == 1) | 926 | if (flags == 1) |
918 | { | 927 | { |
919 | slen = len; | 928 | slen = len; |
920 | result = MHD__gnutls_x509_decode_octet_string (NULL, tmp, slen, tmp, &slen); | 929 | result = |
930 | MHD__gnutls_x509_decode_octet_string (NULL, tmp, slen, tmp, &slen); | ||
921 | if (result < 0) | 931 | if (result < 0) |
922 | { | 932 | { |
923 | MHD_gnutls_assert (); | 933 | MHD_gnutls_assert (); |
@@ -942,7 +952,8 @@ cleanup:MHD_gnutls_free (tmp); | |||
942 | */ | 952 | */ |
943 | int | 953 | int |
944 | MHD__gnutls_x509_der_encode (ASN1_TYPE src, | 954 | MHD__gnutls_x509_der_encode (ASN1_TYPE src, |
945 | const char *src_name, MHD_gnutls_datum_t * res, int str) | 955 | const char *src_name, MHD_gnutls_datum_t * res, |
956 | int str) | ||
946 | { | 957 | { |
947 | int size, result; | 958 | int size, result; |
948 | int asize; | 959 | int asize; |
@@ -984,8 +995,9 @@ MHD__gnutls_x509_der_encode (ASN1_TYPE src, | |||
984 | if (str) | 995 | if (str) |
985 | { | 996 | { |
986 | if ((result = | 997 | if ((result = |
987 | MHD__asn1_create_element (MHD__gnutls_get_pkix (), "PKIX1.pkcs-7-Data", | 998 | MHD__asn1_create_element (MHD__gnutls_get_pkix (), |
988 | &c2)) != ASN1_SUCCESS) | 999 | "PKIX1.pkcs-7-Data", |
1000 | &c2)) != ASN1_SUCCESS) | ||
989 | { | 1001 | { |
990 | MHD_gnutls_assert (); | 1002 | MHD_gnutls_assert (); |
991 | result = MHD_gtls_asn2err (result); | 1003 | result = MHD_gtls_asn2err (result); |
@@ -1030,9 +1042,9 @@ cleanup:MHD_gnutls_free (data); | |||
1030 | */ | 1042 | */ |
1031 | int | 1043 | int |
1032 | MHD__gnutls_x509_der_encode_and_copy (ASN1_TYPE src, | 1044 | MHD__gnutls_x509_der_encode_and_copy (ASN1_TYPE src, |
1033 | const char *src_name, | 1045 | const char *src_name, |
1034 | ASN1_TYPE dest, | 1046 | ASN1_TYPE dest, |
1035 | const char *dest_name, int str) | 1047 | const char *dest_name, int str) |
1036 | { | 1048 | { |
1037 | int result; | 1049 | int result; |
1038 | MHD_gnutls_datum_t encoded; | 1050 | MHD_gnutls_datum_t encoded; |
@@ -1047,7 +1059,8 @@ MHD__gnutls_x509_der_encode_and_copy (ASN1_TYPE src, | |||
1047 | 1059 | ||
1048 | /* Write the data. | 1060 | /* Write the data. |
1049 | */ | 1061 | */ |
1050 | result = MHD__asn1_write_value (dest, dest_name, encoded.data, encoded.size); | 1062 | result = |
1063 | MHD__asn1_write_value (dest, dest_name, encoded.data, encoded.size); | ||
1051 | 1064 | ||
1052 | MHD__gnutls_free_datum (&encoded); | 1065 | MHD__gnutls_free_datum (&encoded); |
1053 | 1066 | ||
@@ -1065,8 +1078,8 @@ MHD__gnutls_x509_der_encode_and_copy (ASN1_TYPE src, | |||
1065 | */ | 1078 | */ |
1066 | int | 1079 | int |
1067 | MHD__gnutls_x509_write_value (ASN1_TYPE c, | 1080 | MHD__gnutls_x509_write_value (ASN1_TYPE c, |
1068 | const char *root, | 1081 | const char *root, |
1069 | const MHD_gnutls_datum_t * data, int str) | 1082 | const MHD_gnutls_datum_t * data, int str) |
1070 | { | 1083 | { |
1071 | int result; | 1084 | int result; |
1072 | int asize; | 1085 | int asize; |
@@ -1088,8 +1101,9 @@ MHD__gnutls_x509_write_value (ASN1_TYPE c, | |||
1088 | /* Convert it to OCTET STRING | 1101 | /* Convert it to OCTET STRING |
1089 | */ | 1102 | */ |
1090 | if ((result = | 1103 | if ((result = |
1091 | MHD__asn1_create_element (MHD__gnutls_get_pkix (), "PKIX1.pkcs-7-Data", | 1104 | MHD__asn1_create_element (MHD__gnutls_get_pkix (), |
1092 | &c2)) != ASN1_SUCCESS) | 1105 | "PKIX1.pkcs-7-Data", |
1106 | &c2)) != ASN1_SUCCESS) | ||
1093 | { | 1107 | { |
1094 | MHD_gnutls_assert (); | 1108 | MHD_gnutls_assert (); |
1095 | result = MHD_gtls_asn2err (result); | 1109 | result = MHD_gtls_asn2err (result); |
@@ -1144,10 +1158,11 @@ cleanup:if (val.data != data->data) | |||
1144 | */ | 1158 | */ |
1145 | int | 1159 | int |
1146 | MHD__gnutls_x509_encode_and_copy_PKI_params (ASN1_TYPE dst, | 1160 | MHD__gnutls_x509_encode_and_copy_PKI_params (ASN1_TYPE dst, |
1147 | const char *dst_name, | 1161 | const char *dst_name, |
1148 | enum MHD_GNUTLS_PublicKeyAlgorithm | 1162 | enum |
1149 | pk_algorithm, | 1163 | MHD_GNUTLS_PublicKeyAlgorithm |
1150 | mpi_t * params, int params_size) | 1164 | pk_algorithm, mpi_t * params, |
1165 | int params_size) | ||
1151 | { | 1166 | { |
1152 | const char *pk; | 1167 | const char *pk; |
1153 | MHD_gnutls_datum_t der = { NULL, | 1168 | MHD_gnutls_datum_t der = { NULL, |
@@ -1219,7 +1234,7 @@ MHD__gnutls_x509_encode_and_copy_PKI_params (ASN1_TYPE dst, | |||
1219 | */ | 1234 | */ |
1220 | int | 1235 | int |
1221 | MHD__gnutls_x509_get_pk_algorithm (ASN1_TYPE src, | 1236 | MHD__gnutls_x509_get_pk_algorithm (ASN1_TYPE src, |
1222 | const char *src_name, unsigned int *bits) | 1237 | const char *src_name, unsigned int *bits) |
1223 | { | 1238 | { |
1224 | int result; | 1239 | int result; |
1225 | opaque *str = NULL; | 1240 | opaque *str = NULL; |
@@ -1295,7 +1310,8 @@ MHD__gnutls_x509_get_pk_algorithm (ASN1_TYPE src, | |||
1295 | { | 1310 | { |
1296 | case MHD_GNUTLS_PK_RSA: | 1311 | case MHD_GNUTLS_PK_RSA: |
1297 | { | 1312 | { |
1298 | if ((result = MHD__gnutls_x509_read_rsa_params (str, len, params)) < 0) | 1313 | if ((result = |
1314 | MHD__gnutls_x509_read_rsa_params (str, len, params)) < 0) | ||
1299 | { | 1315 | { |
1300 | MHD_gnutls_assert (); | 1316 | MHD_gnutls_assert (); |
1301 | return result; | 1317 | return result; |
@@ -1321,8 +1337,8 @@ MHD__gnutls_x509_get_pk_algorithm (ASN1_TYPE src, | |||
1321 | */ | 1337 | */ |
1322 | int | 1338 | int |
1323 | MHD__gnutls_x509_get_signed_data (ASN1_TYPE src, | 1339 | MHD__gnutls_x509_get_signed_data (ASN1_TYPE src, |
1324 | const char *src_name, | 1340 | const char *src_name, |
1325 | MHD_gnutls_datum_t * signed_data) | 1341 | MHD_gnutls_datum_t * signed_data) |
1326 | { | 1342 | { |
1327 | MHD_gnutls_datum_t der; | 1343 | MHD_gnutls_datum_t der; |
1328 | int start, end, result; | 1344 | int start, end, result; |
@@ -1337,7 +1353,7 @@ MHD__gnutls_x509_get_signed_data (ASN1_TYPE src, | |||
1337 | /* Get the signed data | 1353 | /* Get the signed data |
1338 | */ | 1354 | */ |
1339 | result = MHD__asn1_der_decoding_startEnd (src, der.data, der.size, src_name, | 1355 | result = MHD__asn1_der_decoding_startEnd (src, der.data, der.size, src_name, |
1340 | &start, &end); | 1356 | &start, &end); |
1341 | if (result != ASN1_SUCCESS) | 1357 | if (result != ASN1_SUCCESS) |
1342 | { | 1358 | { |
1343 | result = MHD_gtls_asn2err (result); | 1359 | result = MHD_gtls_asn2err (result); |
@@ -1345,7 +1361,8 @@ MHD__gnutls_x509_get_signed_data (ASN1_TYPE src, | |||
1345 | goto cleanup; | 1361 | goto cleanup; |
1346 | } | 1362 | } |
1347 | 1363 | ||
1348 | result = MHD__gnutls_set_datum (signed_data, &der.data[start], end - start + 1); | 1364 | result = |
1365 | MHD__gnutls_set_datum (signed_data, &der.data[start], end - start + 1); | ||
1349 | 1366 | ||
1350 | if (result < 0) | 1367 | if (result < 0) |
1351 | { | 1368 | { |
@@ -1365,7 +1382,8 @@ cleanup:MHD__gnutls_free_datum (&der); | |||
1365 | */ | 1382 | */ |
1366 | int | 1383 | int |
1367 | MHD__gnutls_x509_get_signature (ASN1_TYPE src, | 1384 | MHD__gnutls_x509_get_signature (ASN1_TYPE src, |
1368 | const char *src_name, MHD_gnutls_datum_t * signature) | 1385 | const char *src_name, |
1386 | MHD_gnutls_datum_t * signature) | ||
1369 | { | 1387 | { |
1370 | int bits, result, len; | 1388 | int bits, result, len; |
1371 | 1389 | ||