f7ea75b27012e8f723208b470865c5744dacc396
[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 libpttls
18 *
19 * @addtogroup pt_tls
20 * @{
21 */
22
23 #ifndef PT_TLS_H_
24 #define PT_TLS_H_
25
26 #include <bio/bio_reader.h>
27 #include <bio/bio_writer.h>
28 #include <tls_socket.h>
29
30 /**
31 * PT-TLS version we support
32 */
33 #define PT_TLS_VERSION 1
34
35 /**
36 * Length of a PT-TLS header
37 */
38 #define PT_TLS_HEADER_LEN 16
39
40 /**
41 * Default PT-TLS port
42 */
43 #define PT_TLS_PORT 271
44
45 typedef enum pt_tls_message_type_t pt_tls_message_type_t;
46 typedef enum pt_tls_sasl_result_t pt_tls_sasl_result_t;
47 typedef enum pt_tls_auth_t pt_tls_auth_t;
48
49 /**
50 * Message types, as defined by NEA PT-TLS
51 */
52 enum pt_tls_message_type_t {
53 PT_TLS_EXPERIMENTAL = 0,
54 PT_TLS_VERSION_REQUEST = 1,
55 PT_TLS_VERSION_RESPONSE = 2,
56 PT_TLS_SASL_MECHS = 3,
57 PT_TLS_SASL_MECH_SELECTION = 4,
58 PT_TLS_SASL_AUTH_DATA = 5,
59 PT_TLS_SASL_RESULT = 6,
60 PT_TLS_PB_TNC_BATCH = 7,
61 PT_TLS_ERROR = 8,
62 };
63
64 extern enum_name_t *pt_tls_message_type_names;
65
66 /**
67 * Result code for a single SASL mechansim, as sent in PT_TLS_SASL_RESULT
68 */
69 enum pt_tls_sasl_result_t {
70 PT_TLS_SASL_RESULT_SUCCESS = 0,
71 PT_TLS_SASL_RESULT_FAILURE = 1,
72 PT_TLS_SASL_RESULT_ABORT = 2,
73 PT_TLS_SASL_RESULT_MECH_FAILURE = 3,
74 };
75
76 extern enum_name_t *pt_tls_sasl_result_names;
77
78 /**
79 * Client authentication to require as PT-TLS server.
80 */
81 enum pt_tls_auth_t {
82 /** don't require TLS client certificate or request SASL authentication */
83 PT_TLS_AUTH_NONE,
84 /** require TLS certificate authentication, no SASL */
85 PT_TLS_AUTH_TLS,
86 /** do SASL regardless of TLS certificate authentication */
87 PT_TLS_AUTH_SASL,
88 /* if client does not authenticate with a TLS certificate, request SASL */
89 PT_TLS_AUTH_TLS_OR_SASL,
90 /* require both, TLS certificate authentication and SASL */
91 PT_TLS_AUTH_TLS_AND_SASL,
92 };
93
94 /**
95 * Read a PT-TLS message, create reader over Message Value.
96 *
97 * @param tls TLS socket to read from
98 * @param vendor receives Message Type Vendor ID from header
99 * @param type receives Message Type from header
100 * @param identifier receives Message Identifer
101 * @return reader over message value, NULL on error
102 */
103 bio_reader_t* pt_tls_read(tls_socket_t *tls, u_int32_t *vendor,
104 u_int32_t *type, u_int32_t *identifier);
105
106 /**
107 * Prepend a PT-TLS header to a writer, send data, destroy writer.
108 *
109 * @param tls TLS socket to write to
110 * @param writer prepared Message value to write
111 * @param type Message Type to write
112 * @param identifier Message Identifier to write
113 * @return TRUE if data written successfully
114 */
115 bool pt_tls_write(tls_socket_t *tls, bio_writer_t *writer,
116 pt_tls_message_type_t type, u_int32_t identifier);
117
118 /**
119 * @}
120 * @addtogroup libpttls
121 * @{
122 *
123 * Dummy libpttls initialization function needed for integrity test
124 */
125 void libpttls_init(void);
126
127 #endif /** PT_TLS_H_ @}*/