From 85e649cd4dafd0ec8954e02fc544b801e7409b9d Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Thu, 2 May 2013 18:29:41 -0300 Subject: [PATCH] Inclui pequeno cliente de teste. Este cliente realiza o handshake inicial e o handshake TLS, e envia uma mensagem minima para teste. --- rnetclient.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 rnetclient.c diff --git a/rnetclient.c b/rnetclient.c new file mode 100644 index 0000000..f01e248 --- /dev/null +++ b/rnetclient.c @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2011 Thadeu Lima de Souza Cascardo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static void session_new(gnutls_session_t *session) +{ + static void *cred; + gnutls_init(session, GNUTLS_CLIENT); + gnutls_set_default_priority(*session); +} + +int main(int argc, char **argv) +{ + struct sockaddr_in saddr; + int c; + int r; + char buffer[256]; + gnutls_session_t session; + gnutls_global_init(); + session_new(&session); + c = socket(PF_INET, SOCK_STREAM, 0); + saddr.sin_family = AF_INET; + saddr.sin_port = htons(3456); + saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + connect(c, (struct sockaddr *) &saddr, sizeof(saddr)); + gnutls_transport_set_ptr(session, (gnutls_transport_ptr_t) c); + buffer[0] = 1; + write(c, buffer, 1); + r = read(c, buffer, 1); + if (r != 1 && buffer[0] != 'E') + exit(1); + write(c, "00000000000000", 14); + r = read(c, buffer, 14); + if (r != 14) + exit(1); + if ((r = gnutls_handshake(session)) < 0) + fprintf(stderr, "error in handshake: %s\n", + gnutls_strerror(r)); + else + fprintf(stderr, "handshake ok\n"); + buffer[0] = 0x40; + gnutls_record_send(session, buffer, 1); + while ((r = gnutls_record_recv(session, buffer, sizeof(buffer))) > 0) + write(1, buffer, r); + close(c); + gnutls_global_deinit(); + return 0; +} -- 2.20.1