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