Add a libpttls providing NEA PT-TLS / TNC IF-T for TLS transport layer
[strongswan.git] / src / libpttls / pt_tls.h
1 /*
2 * Copyright (C) 2012 Martin Willi
3 * Copyright (C) 2012 revosec AG
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup pt_tls pt_tls
18 * @{ @ingroup pt_tls
19 */
20
21 #ifndef PT_TLS_H_
22 #define PT_TLS_H_
23
24 #include <bio/bio_reader.h>
25 #include <bio/bio_writer.h>
26 #include <tls_socket.h>
27
28 /**
29 * PT-TLS version we support
30 */
31 #define PT_TLS_VERSION 1
32
33 /**
34 * Length of a PT-TLS header
35 */
36 #define PT_TLS_HEADER_LEN 16
37
38 typedef enum pt_tls_message_type_t pt_tls_message_type_t;
39
40 /**
41 * Message types, as defined by NEA PT-TLS
42 */
43 enum pt_tls_message_type_t {
44 PT_TLS_EXPERIMENTAL = 0,
45 PT_TLS_VERSION_REQUEST = 1,
46 PT_TLS_VERSION_RESPONSE = 2,
47 PT_TLS_SASL_MECHS = 3,
48 PT_TLS_SASL_MECH_SELECTION = 4,
49 PT_TLS_SASL_AUTH_DATA = 5,
50 PT_TLS_SASL_RESULT = 6,
51 PT_TLS_PB_TNC_BATCH = 7,
52 PT_TLS_ERROR = 8,
53 };
54
55 /**
56 * Read a PT-TLS message, create reader over Message Value.
57 *
58 * @param tls TLS socket to read from
59 * @param vendor receives Message Type Vendor ID from header
60 * @param type receives Message Type from header
61 * @param identifier receives Message Identifer
62 * @return reader over message value, NULL on error
63 */
64 bio_reader_t* pt_tls_read(tls_socket_t *tls, u_int32_t *vendor,
65 u_int32_t *type, u_int32_t *identifier);
66
67 /**
68 * Prepend a PT-TLS header to a writer, send data, destroy writer.
69 *
70 * @param tls TLS socket to write to
71 * @param writer prepared Message value to write
72 * @param type Message Type to write
73 * @param identifier Message Identifier to write
74 * @return TRUE if data written successfully
75 */
76 bool pt_tls_write(tls_socket_t *tls, bio_writer_t *writer,
77 pt_tls_message_type_t type, u_int32_t identifier);
78
79 #endif /** PT_TLS_H_ @}*/