summaryrefslogtreecommitdiff
path: root/lib/includes/gnutls/xssl.h
blob: 578eca6e08a494486e4c32daeadf43455f4e1f57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* -*- c -*-
 * Copyright (C) 2013 Nikos Mavrogiannopoulos
 *
 * This file is part of GnuTLS.
 *
 * The GnuTLS library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

#ifndef GNUTLS_SBUF_H
#define GNUTLS_SBUF_H

#include <gnutls/gnutls.h>

/* Buffered session I/O */
typedef struct xssl_st *xssl_t;
typedef struct xssl_cred_st *xssl_cred_t;

ssize_t xssl_printf(xssl_t sb, const char *fmt, ...)
#ifdef __GNUC__
    __attribute__ ((format(printf, 2, 3)))
#endif
    ;

ssize_t xssl_write(xssl_t sb, const void *data, size_t data_size);

ssize_t xssl_flush(xssl_t sb);

ssize_t xssl_read(xssl_t sb, void *data, size_t data_size);

ssize_t
xssl_getdelim(xssl_t sbuf, char **lineptr, size_t * n, int delimiter);

#define xssl_getline(sbuf, ptr, n) xssl_getdelim(sbuf, ptr, n, '\n')

void xssl_deinit(xssl_t sb);

#define GNUTLS_SBUF_WRITE_FLUSHES (1<<0)
int xssl_sinit(xssl_t * isb, gnutls_session_t session, unsigned int flags);

gnutls_session_t xssl_get_session(xssl_t sb);

int xssl_client_init(xssl_t * isb, const char *hostname,
		     const char *service,
		     gnutls_transport_ptr fd,
		     const char *priority, xssl_cred_t cred,
		     unsigned int *status, unsigned int flags);

int xssl_server_init(xssl_t * isb,
		     gnutls_transport_ptr fd,
		     const char *priority, xssl_cred_t cred,
		     unsigned int *status, unsigned int flags);

/* High level credential structures */
typedef enum {
	GNUTLS_VMETHOD_NO_AUTH = 0,
	GNUTLS_VMETHOD_TOFU = 1 << 0,
	GNUTLS_VMETHOD_GIVEN_CAS = 1 << 1,
	GNUTLS_VMETHOD_SYSTEM_CAS = 1 << 2
} gnutls_vmethod_t;

typedef enum {
	GNUTLS_CINPUT_TYPE_FILE = 0,
	GNUTLS_CINPUT_TYPE_MEM = 1,
	GNUTLS_CINPUT_TYPE_PIN_FUNC = 2,
} gnutls_cinput_type_t;

typedef enum {
	GNUTLS_CINPUT_CAS = 1,	/* i1 contains the CAs */
	GNUTLS_CINPUT_CRLS = 2,	/* i1 contains the CRLs */
	GNUTLS_CINPUT_TOFU_DB = 3,	/* i1 contains the DB filename */
	GNUTLS_CINPUT_KEYPAIR = 4,	/* i1 contains the certificate, i2 the key 
					 * or i1.pin_fn contains the pin function, 
					 * and i2.udata the user pointer */
} gnutls_cinput_contents_t;

typedef struct gnutls_cinput_st {
	gnutls_cinput_type_t type;
	gnutls_cinput_contents_t contents;
	gnutls_x509_crt_fmt_t fmt;	/* if applicable */

	union {
		gnutls_pin_callback_t pin_fn;
		const char *file;
		gnutls_datum_t mem;
	} i1;

	union {
		void *udata;
		const char *file;
		gnutls_datum_t mem;
	} i2;

	unsigned long future_pad[8];
} gnutls_cinput_st;

int xssl_cred_init(xssl_cred_t * c, unsigned vflags,
		   gnutls_cinput_st * aux, unsigned aux_size);
void xssl_cred_deinit(xssl_cred_t cred);


#endif				/* GNUTLS_SBUF_H */