2 * Copyright (C) 2000,2001,2002,2003,2006 Nikos Mavroyanopoulos
3 * Copyright (C) 2004,2005 Free Software Foundation
5 * This file is part of GNUTLS.
7 * GNUTLS is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * GNUTLS is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 #include <sys/types.h>
28 #include <gnutls/gnutls.h>
29 #include <gnutls/extra.h>
33 #include <tls_test-gaa.h>
43 #define SA struct sockaddr
44 #define ERR(err,s) if (err==-1) {perror(s);return(1);}
47 /* global stuff here */
49 char *hostname
= NULL
;
55 gnutls_srp_client_credentials srp_cred
;
56 gnutls_anon_client_credentials anon_cred
;
57 gnutls_certificate_credentials xcred
;
59 /* end of global stuff */
69 tls_log_func (int level
, const char *str
)
71 fprintf (stderr
, "|<%d>| %s", level
, str
);
74 typedef test_code_t (*TEST_FUNC
) (gnutls_session
);
85 static const TLS_TEST tls_tests
[] = {
86 {"for TLS 1.1 support", test_tls1_1
, "yes", "no", "dunno"},
87 {"fallback from TLS 1.1 to", test_tls1_1_fallback
, "TLS 1.0", "failed",
89 {"for TLS 1.0 support", test_tls1
, "yes", "no", "dunno"},
90 {"for SSL 3.0 support", test_ssl3
, "yes", "no", "dunno"},
91 {"for HTTPS server name", test_server
, "", "failed", "not checked"},
92 {"for version rollback bug in RSA PMS", test_rsa_pms
, "no", "yes",
94 {"for version rollback bug in Client Hello", test_version_rollback
,
95 "no", "yes", "dunno"},
97 /* this test will disable TLS 1.0 if the server is
99 {"whether we need to disable TLS 1.0", test_tls_disable
, "no", "yes",
102 {"whether the server ignores the RSA PMS version",
103 test_rsa_pms_version_check
, "yes", "no", "dunno"},
104 {"whether the server can accept Hello Extensions",
105 test_hello_extension
, "yes", "no", "dunno"},
106 {"whether the server can accept cipher suites not in SSL 3.0 spec",
107 test_unknown_ciphersuites
, "yes", "no", "dunno"},
108 {"whether the server can accept a bogus TLS record version in the client hello", test_version_oob
, "yes", "no", "dunno"},
109 {"for certificate information", test_certificate
, "", "", ""},
110 {"for trusted CAs", test_server_cas
, "", "", ""},
111 {"whether the server understands TLS closure alerts", test_bye
, "yes",
113 /* the fact that is after the closure alert test does matter.
115 {"whether the server supports session resumption",
116 test_session_resume2
, "yes", "no", "dunno"},
117 {"for export-grade ciphersuite support", test_export
, "yes", "no",
119 {"RSA-export ciphersuite info", test_export_info
, "", "N/A", "N/A"},
121 {"for anonymous authentication support", test_anonymous
, "yes", "no",
123 {"anonymous Diffie Hellman group info", test_dhe_group
, "", "N/A",
126 {"for ephemeral Diffie Hellman support", test_dhe
, "yes", "no",
128 {"ephemeral Diffie Hellman group info", test_dhe_group
, "", "N/A",
130 {"for AES cipher support (TLS extension)", test_aes
, "yes", "no",
132 {"for 3DES cipher support", test_3des
, "yes", "no", "dunno"},
133 {"for ARCFOUR 128 cipher support", test_arcfour
, "yes", "no", "dunno"},
134 {"for ARCFOUR 40 cipher support", test_arcfour_40
, "yes", "no",
136 {"for MD5 MAC support", test_md5
, "yes", "no", "dunno"},
137 {"for SHA1 MAC support", test_sha
, "yes", "no", "dunno"},
139 {"for ZLIB compression support (TLS extension)", test_zlib
, "yes",
142 {"for LZO compression support (GnuTLS extension)", test_lzo
, "yes",
144 {"for max record size (TLS extension)", test_max_record_size
, "yes",
147 {"for SRP authentication support (TLS extension)", test_srp
, "yes",
150 {"for OpenPGP authentication support (TLS extension)", test_openpgp1
,
151 "yes", "no", "dunno"},
152 {NULL
, NULL
, NULL
, NULL
, NULL
}
158 static void gaa_parser (int argc
, char **argv
);
161 main (int argc
, char **argv
)
165 gnutls_session state
;
166 char buffer
[MAX_BUF
+ 1];
168 struct addrinfo hints
, *res
, *ptr
;
170 gaa_parser (argc
, argv
);
173 signal (SIGPIPE
, SIG_IGN
);
178 if (gnutls_global_init () < 0)
180 fprintf (stderr
, "global state initialization error\n");
184 gnutls_global_set_log_function (tls_log_func
);
185 gnutls_global_set_log_level (debug
);
187 if (gnutls_global_init_extra () < 0)
189 fprintf (stderr
, "global state initialization error\n");
193 printf ("Resolving '%s'...\n", hostname
);
194 /* get server name */
195 memset (&hints
, 0, sizeof (hints
));
196 hints
.ai_socktype
= SOCK_STREAM
;
198 snprintf (portname
, sizeof (portname
), "%d", port
);
199 if ((err
= getaddrinfo (hostname
, portname
, &hints
, &res
)) != 0)
201 fprintf (stderr
, "Cannot resolve %s: %s\n", hostname
,
207 if (gnutls_certificate_allocate_credentials (&xcred
) < 0)
208 { /* space for 2 certificates */
209 fprintf (stderr
, "memory error\n");
215 if (gnutls_srp_allocate_client_credentials (&srp_cred
) < 0)
217 fprintf (stderr
, "memory error\n");
224 if (gnutls_anon_allocate_client_credentials (&anon_cred
) < 0)
226 fprintf (stderr
, "memory error\n");
236 if (tls_tests
[i
].test_name
== NULL
)
237 break; /* finished */
239 /* if neither of SSL3 and TLSv1 are supported, exit
241 if (i
> 3 && tls1_1_ok
== 0 && tls1_ok
== 0 && ssl3_ok
== 0)
244 "\nServer does not support none of SSL 3.0, TLS 1.0 and TLS 1.1\n");
249 for (ptr
= res
; ptr
!= NULL
; ptr
= ptr
->ai_next
)
251 sd
= socket(ptr
->ai_family
, ptr
->ai_socktype
, ptr
->ai_protocol
);
257 getnameinfo (ptr
->ai_addr
, ptr
->ai_addrlen
, buffer
, MAX_BUF
,
258 NULL
, 0, NI_NUMERICHOST
);
259 if (tt
++ == 0) printf("Connecting to '%s:%d'...\n", buffer
, port
);
260 if ((err
= connect(sd
, ptr
->ai_addr
, ptr
->ai_addrlen
)) != 0)
269 gnutls_init (&state
, GNUTLS_CLIENT
);
270 gnutls_transport_set_ptr (state
, (gnutls_transport_ptr
) sd
);
274 printf ("Checking %s...", tls_tests
[i
].test_name
);
276 ret
= tls_tests
[i
].func (state
);
278 if (ret
== TEST_SUCCEED
)
279 printf (" %s\n", tls_tests
[i
].suc_str
);
280 else if (ret
== TEST_FAILED
)
281 printf (" %s\n", tls_tests
[i
].fail_str
);
282 else if (ret
== TEST_UNSURE
)
283 printf (" %s\n", tls_tests
[i
].unsure_str
);
284 else if (ret
== TEST_IGNORE
)
290 while (ret
== TEST_IGNORE
&& tls_tests
[i
].test_name
!= NULL
);
292 gnutls_deinit (state
);
294 shutdown (sd
, SHUT_RDWR
); /* no more receptions */
304 gnutls_srp_free_client_credentials (srp_cred
);
306 gnutls_certificate_free_credentials (xcred
);
308 gnutls_anon_free_client_credentials (anon_cred
);
310 gnutls_global_deinit ();
317 gaa_parser (int argc
, char **argv
)
319 if (gaa (argc
, argv
, &info
) != -1)
322 "Error in the arguments. Use the -h or --help parameters to get more info.\n");
327 if (info
.rest_args
== NULL
)
328 hostname
= "localhost";
330 hostname
= info
.rest_args
;
334 verbose
= info
.more_info
;
339 tls_test_version (void)
341 const char *v
= gnutls_check_version (NULL
);
343 printf ("gnutls-cli-debug (GnuTLS) %s\n", LIBGNUTLS_VERSION
);
344 if (strcmp (v
, LIBGNUTLS_VERSION
) != 0)
345 printf ("libgnutls %s\n", v
);