aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2014-11-25 09:20:19 -0800
committerPaul Eggert2014-11-25 09:23:33 -0800
commit50cc8073770db118b51ae16a00112fb3e0607486 (patch)
tree043e37d1a25d55189b78f28655d8c93bbe17d8f1 /src
parentc8a2d631966f6a9569d68a3ac08c186d044e3a88 (diff)
downloademacs-50cc8073770db118b51ae16a00112fb3e0607486.tar.gz
emacs-50cc8073770db118b51ae16a00112fb3e0607486.zip
Use usual GNU style for white space.
Diffstat (limited to 'src')
-rw-r--r--src/gnutls.c205
1 files changed, 108 insertions, 97 deletions
diff --git a/src/gnutls.c b/src/gnutls.c
index 3b345a8c49b..3c067418952 100644
--- a/src/gnutls.c
+++ b/src/gnutls.c
@@ -318,7 +318,7 @@ init_gnutls_functions (void)
318#define fn_gnutls_x509_crt_deinit gnutls_x509_crt_deinit 318#define fn_gnutls_x509_crt_deinit gnutls_x509_crt_deinit
319#define fn_gnutls_x509_crt_import gnutls_x509_crt_import 319#define fn_gnutls_x509_crt_import gnutls_x509_crt_import
320#define fn_gnutls_x509_crt_init gnutls_x509_crt_init 320#define fn_gnutls_x509_crt_init gnutls_x509_crt_init
321#define fn_gnutls_x509_crt_get_fingerprint gnutls_x509_crt_get_fingerprint 321#define fn_gnutls_x509_crt_get_fingerprint gnutls_x509_crt_get_fingerprint
322#define fn_gnutls_x509_crt_get_version gnutls_x509_crt_get_version 322#define fn_gnutls_x509_crt_get_version gnutls_x509_crt_get_version
323#define fn_gnutls_x509_crt_get_serial gnutls_x509_crt_get_serial 323#define fn_gnutls_x509_crt_get_serial gnutls_x509_crt_get_serial
324#define fn_gnutls_x509_crt_get_issuer_dn gnutls_x509_crt_get_issuer_dn 324#define fn_gnutls_x509_crt_get_issuer_dn gnutls_x509_crt_get_issuer_dn
@@ -769,7 +769,8 @@ DEFUN ("gnutls-available-p", Fgnutls_available_p, Sgnutls_available_p, 0, 0, 0,
769} 769}
770 770
771static Lisp_Object 771static Lisp_Object
772gnutls_hex_string (char *buf, size_t buf_size, const char *prefix) { 772gnutls_hex_string (char *buf, size_t buf_size, const char *prefix)
773{
773 size_t prefix_length = strlen (prefix); 774 size_t prefix_length = strlen (prefix);
774 char *string = malloc (buf_size * 3 + prefix_length); 775 char *string = malloc (buf_size * 3 + prefix_length);
775 Lisp_Object ret; 776 Lisp_Object ret;
@@ -778,8 +779,8 @@ gnutls_hex_string (char *buf, size_t buf_size, const char *prefix) {
778 779
779 for (int i = 0; i < buf_size; i++) 780 for (int i = 0; i < buf_size; i++)
780 sprintf (string + i * 3 + prefix_length, 781 sprintf (string + i * 3 + prefix_length,
781 i == buf_size - 1? "%02x": "%02x:", 782 i == buf_size - 1 ? "%02x" : "%02x:",
782 ((unsigned char*)buf)[i]); 783 ((unsigned char*) buf)[i]);
783 784
784 ret = build_string (string); 785 ret = build_string (string);
785 free (string); 786 free (string);
@@ -805,15 +806,16 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
805 size_t serial_size = 0; 806 size_t serial_size = 0;
806 807
807 err = fn_gnutls_x509_crt_get_serial (cert, NULL, &serial_size); 808 err = fn_gnutls_x509_crt_get_serial (cert, NULL, &serial_size);
808 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) { 809 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
809 char *serial = malloc (serial_size); 810 {
810 err = fn_gnutls_x509_crt_get_serial (cert, serial, &serial_size); 811 char *serial = malloc (serial_size);
811 if (err >= GNUTLS_E_SUCCESS) { 812 err = fn_gnutls_x509_crt_get_serial (cert, serial, &serial_size);
812 res = nconc2 (res, list2 (intern (":serial-number"), 813 if (err >= GNUTLS_E_SUCCESS)
813 gnutls_hex_string (serial, serial_size, ""))); 814 res = nconc2 (res, list2 (intern (":serial-number"),
815 gnutls_hex_string (serial, serial_size,
816 "")));
817 free (serial);
814 } 818 }
815 free (serial);
816 }
817 } 819 }
818 820
819 /* Issuer. */ 821 /* Issuer. */
@@ -821,14 +823,15 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
821 size_t dn_size = 0; 823 size_t dn_size = 0;
822 824
823 err = fn_gnutls_x509_crt_get_issuer_dn (cert, NULL, &dn_size); 825 err = fn_gnutls_x509_crt_get_issuer_dn (cert, NULL, &dn_size);
824 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) { 826 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
825 char *dn = malloc (dn_size); 827 {
826 err = fn_gnutls_x509_crt_get_issuer_dn (cert, dn, &dn_size); 828 char *dn = malloc (dn_size);
827 if (err >= GNUTLS_E_SUCCESS) 829 err = fn_gnutls_x509_crt_get_issuer_dn (cert, dn, &dn_size);
828 res = nconc2 (res, list2 (intern (":issuer"), 830 if (err >= GNUTLS_E_SUCCESS)
829 make_string (dn, dn_size))); 831 res = nconc2 (res, list2 (intern (":issuer"),
830 free (dn); 832 make_string (dn, dn_size)));
831 } 833 free (dn);
834 }
832 } 835 }
833 836
834 /* Validity. */ 837 /* Validity. */
@@ -853,14 +856,15 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
853 size_t dn_size = 0; 856 size_t dn_size = 0;
854 857
855 err = fn_gnutls_x509_crt_get_dn (cert, NULL, &dn_size); 858 err = fn_gnutls_x509_crt_get_dn (cert, NULL, &dn_size);
856 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) { 859 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
857 char *dn = malloc (dn_size); 860 {
858 err = fn_gnutls_x509_crt_get_dn (cert, dn, &dn_size); 861 char *dn = malloc (dn_size);
859 if (err >= GNUTLS_E_SUCCESS) 862 err = fn_gnutls_x509_crt_get_dn (cert, dn, &dn_size);
860 res = nconc2 (res, list2 (intern (":subject"), 863 if (err >= GNUTLS_E_SUCCESS)
861 make_string (dn, dn_size))); 864 res = nconc2 (res, list2 (intern (":subject"),
862 free (dn); 865 make_string (dn, dn_size)));
863 } 866 free (dn);
867 }
864 } 868 }
865 869
866 /* Versions older than 2.11 doesn't have these four functions. */ 870 /* Versions older than 2.11 doesn't have these four functions. */
@@ -870,17 +874,18 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
870 unsigned int bits; 874 unsigned int bits;
871 875
872 err = fn_gnutls_x509_crt_get_pk_algorithm (cert, &bits); 876 err = fn_gnutls_x509_crt_get_pk_algorithm (cert, &bits);
873 if (err >= GNUTLS_E_SUCCESS) { 877 if (err >= GNUTLS_E_SUCCESS)
874 const char *name = fn_gnutls_pk_algorithm_get_name (err); 878 {
875 if (name) 879 const char *name = fn_gnutls_pk_algorithm_get_name (err);
876 res = nconc2 (res, list2 (intern (":public-key-algorithm"), 880 if (name)
881 res = nconc2 (res, list2 (intern (":public-key-algorithm"),
882 build_string (name)));
883
884 name = fn_gnutls_sec_param_get_name (fn_gnutls_pk_bits_to_sec_param
885 (err, bits));
886 res = nconc2 (res, list2 (intern (":certificate-security-level"),
877 build_string (name))); 887 build_string (name)));
878 888 }
879 name = fn_gnutls_sec_param_get_name (fn_gnutls_pk_bits_to_sec_param
880 (err, bits));
881 res = nconc2 (res, list2 (intern (":certificate-security-level"),
882 build_string (name)));
883 }
884 } 889 }
885 890
886 /* Unique IDs. */ 891 /* Unique IDs. */
@@ -888,25 +893,27 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
888 size_t buf_size = 0; 893 size_t buf_size = 0;
889 894
890 err = fn_gnutls_x509_crt_get_issuer_unique_id (cert, NULL, &buf_size); 895 err = fn_gnutls_x509_crt_get_issuer_unique_id (cert, NULL, &buf_size);
891 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) { 896 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
892 char *buf = malloc (buf_size); 897 {
893 err = fn_gnutls_x509_crt_get_issuer_unique_id (cert, buf, &buf_size); 898 char *buf = malloc (buf_size);
894 if (err >= GNUTLS_E_SUCCESS) 899 err = fn_gnutls_x509_crt_get_issuer_unique_id (cert, buf, &buf_size);
895 res = nconc2 (res, list2 (intern (":issuer-unique-id"), 900 if (err >= GNUTLS_E_SUCCESS)
896 make_string (buf, buf_size))); 901 res = nconc2 (res, list2 (intern (":issuer-unique-id"),
897 free (buf); 902 make_string (buf, buf_size)));
898 } 903 free (buf);
904 }
899 905
900 buf_size = 0; 906 buf_size = 0;
901 err = fn_gnutls_x509_crt_get_subject_unique_id (cert, NULL, &buf_size); 907 err = fn_gnutls_x509_crt_get_subject_unique_id (cert, NULL, &buf_size);
902 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) { 908 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
903 char *buf = malloc (buf_size); 909 {
904 err = fn_gnutls_x509_crt_get_subject_unique_id (cert, buf, &buf_size); 910 char *buf = malloc (buf_size);
905 if (err >= GNUTLS_E_SUCCESS) 911 err = fn_gnutls_x509_crt_get_subject_unique_id (cert, buf, &buf_size);
906 res = nconc2 (res, list2 (intern (":subject-unique-id"), 912 if (err >= GNUTLS_E_SUCCESS)
907 make_string (buf, buf_size))); 913 res = nconc2 (res, list2 (intern (":subject-unique-id"),
908 free (buf); 914 make_string (buf, buf_size)));
909 } 915 free (buf);
916 }
910 } 917 }
911#endif 918#endif
912 919
@@ -915,23 +922,25 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
915 size_t buf_size = 0; 922 size_t buf_size = 0;
916 923
917 err = fn_gnutls_x509_crt_get_signature_algorithm (cert); 924 err = fn_gnutls_x509_crt_get_signature_algorithm (cert);
918 if (err >= GNUTLS_E_SUCCESS) { 925 if (err >= GNUTLS_E_SUCCESS)
919 const char *name = fn_gnutls_sign_algorithm_get_name (err); 926 {
920 if (name) 927 const char *name = fn_gnutls_sign_algorithm_get_name (err);
921 res = nconc2 (res, list2 (intern (":signature-algorithm"), 928 if (name)
922 build_string (name))); 929 res = nconc2 (res, list2 (intern (":signature-algorithm"),
923 930 build_string (name)));
924 err = fn_gnutls_x509_crt_get_signature (cert, NULL, &buf_size); 931
925 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) { 932 err = fn_gnutls_x509_crt_get_signature (cert, NULL, &buf_size);
926 char *buf = malloc (buf_size); 933 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
927 err = fn_gnutls_x509_crt_get_signature (cert, buf, &buf_size); 934 {
928 if (err >= GNUTLS_E_SUCCESS) { 935 char *buf = malloc (buf_size);
929 res = nconc2 (res, list2 (intern (":signature"), 936 err = fn_gnutls_x509_crt_get_signature (cert, buf, &buf_size);
930 gnutls_hex_string (buf, buf_size, ""))); 937 if (err >= GNUTLS_E_SUCCESS) {
931 } 938 res = nconc2 (res, list2 (intern (":signature"),
932 free (buf); 939 gnutls_hex_string (buf, buf_size, "")));
940 }
941 free (buf);
942 }
933 } 943 }
934 }
935 } 944 }
936 945
937 /* Public key ID. */ 946 /* Public key ID. */
@@ -939,15 +948,16 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
939 size_t buf_size = 0; 948 size_t buf_size = 0;
940 949
941 err = fn_gnutls_x509_crt_get_key_id (cert, 0, NULL, &buf_size); 950 err = fn_gnutls_x509_crt_get_key_id (cert, 0, NULL, &buf_size);
942 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) { 951 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
943 unsigned char *buf = malloc (buf_size); 952 {
944 err = fn_gnutls_x509_crt_get_key_id (cert, 0, buf, &buf_size); 953 unsigned char *buf = malloc (buf_size);
945 if (err >= GNUTLS_E_SUCCESS) 954 err = fn_gnutls_x509_crt_get_key_id (cert, 0, buf, &buf_size);
955 if (err >= GNUTLS_E_SUCCESS)
946 res = nconc2 (res, list2 (intern (":public-key-id"), 956 res = nconc2 (res, list2 (intern (":public-key-id"),
947 gnutls_hex_string ((char *)buf, 957 gnutls_hex_string ((char *)buf,
948 buf_size, "sha1:"))); 958 buf_size, "sha1:")));
949 free (buf); 959 free (buf);
950 } 960 }
951 } 961 }
952 962
953 /* Certificate fingerprint. */ 963 /* Certificate fingerprint. */
@@ -956,16 +966,17 @@ gnutls_certificate_details (gnutls_x509_crt_t cert)
956 966
957 err = fn_gnutls_x509_crt_get_fingerprint (cert, GNUTLS_DIG_SHA1, 967 err = fn_gnutls_x509_crt_get_fingerprint (cert, GNUTLS_DIG_SHA1,
958 NULL, &buf_size); 968 NULL, &buf_size);
959 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) { 969 if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
960 unsigned char *buf = malloc (buf_size); 970 {
961 err = fn_gnutls_x509_crt_get_fingerprint (cert, GNUTLS_DIG_SHA1, 971 unsigned char *buf = malloc (buf_size);
962 buf, &buf_size); 972 err = fn_gnutls_x509_crt_get_fingerprint (cert, GNUTLS_DIG_SHA1,
963 if (err >= GNUTLS_E_SUCCESS) 973 buf, &buf_size);
974 if (err >= GNUTLS_E_SUCCESS)
964 res = nconc2 (res, list2 (intern (":certificate-id"), 975 res = nconc2 (res, list2 (intern (":certificate-id"),
965 gnutls_hex_string ((char *)buf, 976 gnutls_hex_string ((char *)buf,
966 buf_size, "sha1:"))); 977 buf_size, "sha1:")));
967 free (buf); 978 free (buf);
968 } 979 }
969 } 980 }
970 981
971 return res; 982 return res;
@@ -977,28 +988,28 @@ DEFUN ("gnutls-peer-status-warning-describe", Fgnutls_peer_status_warning_descri
977{ 988{
978 CHECK_SYMBOL (status_symbol); 989 CHECK_SYMBOL (status_symbol);
979 990
980 if ( EQ (status_symbol, intern (":invalid"))) 991 if (EQ (status_symbol, intern (":invalid")))
981 return build_string ("certificate could not be verified"); 992 return build_string ("certificate could not be verified");
982 993
983 if ( EQ (status_symbol, intern (":revoked")) ) 994 if (EQ (status_symbol, intern (":revoked")))
984 return build_string ("certificate was revoked (CRL)"); 995 return build_string ("certificate was revoked (CRL)");
985 996
986 if ( EQ (status_symbol, intern (":self-signed")) ) 997 if (EQ (status_symbol, intern (":self-signed")))
987 return build_string ("certificate signer was not found (self-signed)"); 998 return build_string ("certificate signer was not found (self-signed)");
988 999
989 if ( EQ (status_symbol, intern (":not-ca")) ) 1000 if (EQ (status_symbol, intern (":not-ca")))
990 return build_string ("certificate signer is not a CA"); 1001 return build_string ("certificate signer is not a CA");
991 1002
992 if ( EQ (status_symbol, intern (":insecure")) ) 1003 if (EQ (status_symbol, intern (":insecure")))
993 return build_string ("certificate was signed with an insecure algorithm"); 1004 return build_string ("certificate was signed with an insecure algorithm");
994 1005
995 if ( EQ (status_symbol, intern (":not-activated")) ) 1006 if (EQ (status_symbol, intern (":not-activated")))
996 return build_string ("certificate is not yet activated"); 1007 return build_string ("certificate is not yet activated");
997 1008
998 if ( EQ (status_symbol, intern (":expired")) ) 1009 if (EQ (status_symbol, intern (":expired")))
999 return build_string ("certificate has expired"); 1010 return build_string ("certificate has expired");
1000 1011
1001 if ( EQ (status_symbol, intern (":no-host-match")) ) 1012 if (EQ (status_symbol, intern (":no-host-match")))
1002 return build_string ("certificate host does not match hostname"); 1013 return build_string ("certificate host does not match hostname");
1003 1014
1004 return Qnil; 1015 return Qnil;
@@ -1016,7 +1027,7 @@ The return value is a property list with top-level keys :warnings and
1016 1027
1017 CHECK_PROCESS (proc); 1028 CHECK_PROCESS (proc);
1018 1029
1019 if ( GNUTLS_INITSTAGE (proc) < GNUTLS_STAGE_INIT ) 1030 if (GNUTLS_INITSTAGE (proc) < GNUTLS_STAGE_INIT)
1020 return Qnil; 1031 return Qnil;
1021 1032
1022 /* Then collect any warnings already computed by the handshake. */ 1033 /* Then collect any warnings already computed by the handshake. */
@@ -1052,7 +1063,7 @@ The return value is a property list with top-level keys :warnings and
1052 1063
1053 /* This could get called in the INIT stage, when the certificate is 1064 /* This could get called in the INIT stage, when the certificate is
1054 not yet set. */ 1065 not yet set. */
1055 if ( XPROCESS (proc)->gnutls_certificate != NULL ) 1066 if (XPROCESS (proc)->gnutls_certificate != NULL)
1056 result = nconc2 (result, list2 1067 result = nconc2 (result, list2
1057 (intern (":certificate"), 1068 (intern (":certificate"),
1058 gnutls_certificate_details (XPROCESS (proc)->gnutls_certificate))); 1069 gnutls_certificate_details (XPROCESS (proc)->gnutls_certificate)));
@@ -1413,7 +1424,7 @@ one trustfile (usually a CA bundle). */)
1413 http://www.gnu.org/software/gnutls/manual/html_node/Verifying-peer_0027s-certificate.html. 1424 http://www.gnu.org/software/gnutls/manual/html_node/Verifying-peer_0027s-certificate.html.
1414 The peer should present at least one certificate in the chain; do a 1425 The peer should present at least one certificate in the chain; do a
1415 check of the certificate's hostname with 1426 check of the certificate's hostname with
1416 gnutls_x509_crt_check_hostname() against :hostname. */ 1427 gnutls_x509_crt_check_hostname against :hostname. */
1417 1428
1418 ret = fn_gnutls_certificate_verify_peers2 (state, &peer_verification); 1429 ret = fn_gnutls_certificate_verify_peers2 (state, &peer_verification);
1419 if (ret < GNUTLS_E_SUCCESS) 1430 if (ret < GNUTLS_E_SUCCESS)
@@ -1422,15 +1433,15 @@ one trustfile (usually a CA bundle). */)
1422 XPROCESS (proc)->gnutls_peer_verification = peer_verification; 1433 XPROCESS (proc)->gnutls_peer_verification = peer_verification;
1423 1434
1424 warnings = Fplist_get (Fgnutls_peer_status (proc), intern (":warnings")); 1435 warnings = Fplist_get (Fgnutls_peer_status (proc), intern (":warnings"));
1425 if ( !NILP (warnings) ) 1436 if (!NILP (warnings))
1426 { 1437 {
1427 Lisp_Object tail; 1438 Lisp_Object tail;
1428 for (tail = warnings; CONSP (tail); tail = XCDR (tail)) 1439 for (tail = warnings; CONSP (tail); tail = XCDR (tail))
1429 { 1440 {
1430 Lisp_Object warning = XCAR (tail); 1441 Lisp_Object warning = XCAR (tail);
1431 Lisp_Object message = Fgnutls_peer_status_warning_describe (warning); 1442 Lisp_Object message = Fgnutls_peer_status_warning_describe (warning);
1432 if ( !NILP (message) ) 1443 if (!NILP (message))
1433 GNUTLS_LOG2 (1, max_log_level, "verification:", SDATA(message)); 1444 GNUTLS_LOG2 (1, max_log_level, "verification:", SDATA (message));
1434 } 1445 }
1435 } 1446 }
1436 1447