|
Packit |
549fdc |
/*
|
|
Packit |
549fdc |
* Copyright (C) 2000-2012 Free Software Foundation, Inc.
|
|
Packit |
549fdc |
* Author: Nikos Mavrogiannopoulos
|
|
Packit |
549fdc |
*
|
|
Packit |
549fdc |
* This file is part of GnuTLS.
|
|
Packit |
549fdc |
*
|
|
Packit |
549fdc |
* GnuTLS is free software: you can redistribute it and/or modify
|
|
Packit |
549fdc |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
549fdc |
* the Free Software Foundation, either version 3 of the License, or
|
|
Packit |
549fdc |
* (at your option) any later version.
|
|
Packit |
549fdc |
*
|
|
Packit |
549fdc |
* GnuTLS is distributed in the hope that it will be useful,
|
|
Packit |
549fdc |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
549fdc |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
549fdc |
* GNU General Public License for more details.
|
|
Packit |
549fdc |
*
|
|
Packit |
549fdc |
* You should have received a copy of the GNU General Public License
|
|
Packit |
549fdc |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
549fdc |
*/
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
#ifndef INCLUDE_COMMON_H
|
|
Packit |
549fdc |
# define INCLUDE_COMMON_H
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
#define SERVER "127.0.0.1"
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
#include <config.h>
|
|
Packit |
549fdc |
#include <gnutls/gnutls.h>
|
|
Packit |
549fdc |
#include <certtool-common.h>
|
|
Packit |
549fdc |
#include <c-ctype.h>
|
|
Packit |
549fdc |
#include <string.h>
|
|
Packit |
549fdc |
#include <sys/socket.h>
|
|
Packit |
549fdc |
#include <netdb.h>
|
|
Packit |
549fdc |
#include <unistd.h>
|
|
Packit |
549fdc |
#ifndef _WIN32
|
|
Packit |
549fdc |
#include <netinet/in.h>
|
|
Packit |
549fdc |
#endif
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
#include <signal.h>
|
|
Packit |
549fdc |
#ifdef _WIN32
|
|
Packit |
549fdc |
#include <io.h>
|
|
Packit |
549fdc |
#include <winbase.h>
|
|
Packit |
549fdc |
#include <sys/select.h>
|
|
Packit |
549fdc |
#undef OCSP_RESPONSE
|
|
Packit |
549fdc |
#endif
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
#ifndef __attribute__
|
|
Packit |
549fdc |
#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
|
|
Packit |
549fdc |
#define __attribute__(Spec) /* empty */
|
|
Packit |
549fdc |
#endif
|
|
Packit |
549fdc |
#endif
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
/* the number of elements in the priority structures.
|
|
Packit |
549fdc |
*/
|
|
Packit |
549fdc |
#define PRI_MAX 16
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
extern const char str_unknown[];
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
#define P_PRINT_CERT 1
|
|
Packit |
549fdc |
#define P_WAIT_FOR_CERT (1<<1)
|
|
Packit |
549fdc |
int print_info(gnutls_session_t state, int verbose, int flags);
|
|
Packit |
549fdc |
void print_cert_info(gnutls_session_t, int flag, int print_cert);
|
|
Packit |
549fdc |
void print_cert_info_compact(gnutls_session_t session);
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
void print_cert_info2(gnutls_session_t, int flag, FILE *fp, int print_cert);
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
void print_list(const char *priorities, int verbose);
|
|
Packit |
549fdc |
int cert_verify(gnutls_session_t session, const char *hostname, const char *purpose);
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
const char *raw_to_string(const unsigned char *raw, size_t raw_size);
|
|
Packit |
549fdc |
const char *raw_to_hex(const unsigned char *raw, size_t raw_size);
|
|
Packit |
549fdc |
const char *raw_to_base64(const unsigned char *raw, size_t raw_size);
|
|
Packit |
549fdc |
int check_command(gnutls_session_t session, const char *str);
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
int
|
|
Packit |
549fdc |
pin_callback(void *user, int attempt, const char *token_url,
|
|
Packit |
549fdc |
const char *token_label, unsigned int flags, char *pin,
|
|
Packit |
549fdc |
size_t pin_max);
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
void pkcs11_common(common_info_st *c);
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
inline static int is_ip(const char *hostname)
|
|
Packit |
549fdc |
{
|
|
Packit |
549fdc |
int len = strlen(hostname);
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
if (strchr(hostname, ':') != 0)
|
|
Packit |
549fdc |
return 1;
|
|
Packit |
549fdc |
else if (len > 2 && c_isdigit(hostname[0]) && c_isdigit(hostname[len-1]))
|
|
Packit |
549fdc |
return 1;
|
|
Packit |
549fdc |
return 0;
|
|
Packit |
549fdc |
}
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
void sockets_init(void);
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
#ifdef _WIN32
|
|
Packit |
549fdc |
static int system_recv_timeout(gnutls_transport_ptr_t ptr, unsigned int ms)
|
|
Packit |
549fdc |
{
|
|
Packit |
549fdc |
fd_set rfds;
|
|
Packit |
549fdc |
struct timeval tv;
|
|
Packit |
549fdc |
int ret, fd = (long)ptr;
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
FD_ZERO(&rfds);
|
|
Packit |
549fdc |
FD_SET(fd, &rfds);
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
tv.tv_sec = 0;
|
|
Packit |
549fdc |
tv.tv_usec = ms * 1000;
|
|
Packit |
549fdc |
while (tv.tv_usec >= 1000000) {
|
|
Packit |
549fdc |
tv.tv_usec -= 1000000;
|
|
Packit |
549fdc |
tv.tv_sec++;
|
|
Packit |
549fdc |
}
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
return select(fd + 1, &rfds, NULL, NULL, &tv;;
|
|
Packit |
549fdc |
}
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
static ssize_t
|
|
Packit |
549fdc |
system_write(gnutls_transport_ptr ptr, const void *data, size_t data_size)
|
|
Packit |
549fdc |
{
|
|
Packit |
549fdc |
return send((long)ptr, data, data_size, 0);
|
|
Packit |
549fdc |
}
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
static ssize_t
|
|
Packit |
549fdc |
system_read(gnutls_transport_ptr_t ptr, void *data, size_t data_size)
|
|
Packit |
549fdc |
{
|
|
Packit |
549fdc |
return recv((long)ptr, data, data_size, 0);
|
|
Packit |
549fdc |
}
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
static
|
|
Packit |
549fdc |
void set_read_funcs(gnutls_session_t session)
|
|
Packit |
549fdc |
{
|
|
Packit |
549fdc |
gnutls_transport_set_push_function(session, system_write);
|
|
Packit |
549fdc |
gnutls_transport_set_pull_function(session, system_read);
|
|
Packit |
549fdc |
gnutls_transport_set_pull_timeout_function(session, system_recv_timeout);
|
|
Packit |
549fdc |
}
|
|
Packit |
549fdc |
#else
|
|
Packit |
549fdc |
# define set_read_funcs(x)
|
|
Packit |
549fdc |
#endif
|
|
Packit |
549fdc |
|
|
Packit |
549fdc |
#endif
|