aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/https/tls/ext_oprfi.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/https/tls/ext_oprfi.c')
-rw-r--r--src/daemon/https/tls/ext_oprfi.c217
1 files changed, 0 insertions, 217 deletions
diff --git a/src/daemon/https/tls/ext_oprfi.c b/src/daemon/https/tls/ext_oprfi.c
deleted file mode 100644
index 060155e4..00000000
--- a/src/daemon/https/tls/ext_oprfi.c
+++ /dev/null
@@ -1,217 +0,0 @@
1/*
2 * Copyright (C) 2007 Free Software Foundation
3 *
4 * Author: Simon Josefsson
5 *
6 * This file is part of GNUTLS.
7 *
8 * The GNUTLS library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 * USA
22 *
23 */
24
25/* Implementation of Opaque PRF Input:
26 * http://tools.ietf.org/id/draft-rescorla-tls-opaque-prf-input-00.txt
27 *
28 */
29
30#include "MHD_config.h"
31#include <ext_oprfi.h>
32
33#include <gnutls_errors.h>
34#include <gnutls_num.h>
35
36static int
37oprfi_recv_server (MHD_gtls_session_t session,
38 const opaque * data, size_t _data_size)
39{
40 ssize_t data_size = _data_size;
41 uint16_t len;
42
43 if (!session->security_parameters.extensions.oprfi_cb)
44 {
45 MHD_gnutls_assert ();
46 return 0;
47 }
48
49 DECR_LEN (data_size, 2);
50 len = MHD_gtls_read_uint16 (data);
51 data += 2;
52
53 if (len != data_size)
54 {
55 MHD_gnutls_assert ();
56 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
57 }
58
59 /* Store incoming data. */
60 session->security_parameters.extensions.oprfi_client_len = len;
61 session->security_parameters.extensions.oprfi_client =
62 MHD_gnutls_malloc (len);
63 if (!session->security_parameters.extensions.oprfi_client)
64 {
65 MHD_gnutls_assert ();
66 return GNUTLS_E_MEMORY_ERROR;
67 }
68 memcpy (session->security_parameters.extensions.oprfi_client, data, len);
69
70 return 0;
71}
72
73#if MHD_DEBUG_TLS
74static int
75oprfi_recv_client (MHD_gtls_session_t session,
76 const opaque * data, size_t _data_size)
77{
78 ssize_t data_size = _data_size;
79 uint16_t len;
80
81 if (session->security_parameters.extensions.oprfi_client == NULL)
82 {
83 MHD_gnutls_assert ();
84 return 0;
85 }
86
87 DECR_LEN (data_size, 2);
88 len = MHD_gtls_read_uint16 (data);
89 data += 2;
90
91 if (len != data_size)
92 {
93 MHD_gnutls_assert ();
94 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
95 }
96
97 if (len != session->security_parameters.extensions.oprfi_client_len)
98 {
99 MHD_gnutls_assert ();
100 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER;
101 }
102
103 /* Store incoming data. */
104 session->security_parameters.extensions.oprfi_server_len = len;
105 session->security_parameters.extensions.oprfi_server =
106 MHD_gnutls_malloc (len);
107 if (!session->security_parameters.extensions.oprfi_server)
108 {
109 MHD_gnutls_assert ();
110 return GNUTLS_E_MEMORY_ERROR;
111 }
112 memcpy (session->security_parameters.extensions.oprfi_server, data, len);
113
114 return 0;
115}
116#endif
117
118int
119MHD_gtls_oprfi_recv_params (MHD_gtls_session_t session,
120 const opaque * data, size_t data_size)
121{
122#if MHD_DEBUG_TLS
123 if (session->security_parameters.entity == GNUTLS_CLIENT)
124 return oprfi_recv_client (session, data, data_size);
125 else
126#endif
127 return oprfi_recv_server (session, data, data_size);
128}
129
130#if MHD_DEBUG_TLS
131static int
132oprfi_send_client (MHD_gtls_session_t session, opaque * data,
133 size_t _data_size)
134{
135 opaque *p = data;
136 ssize_t data_size = _data_size;
137 int oprf_size = session->security_parameters.extensions.oprfi_client_len;
138
139 if (oprf_size == 0)
140 return 0;
141
142 DECR_LENGTH_RET (data_size, 2, GNUTLS_E_SHORT_MEMORY_BUFFER);
143 MHD_gtls_write_uint16 (oprf_size, p);
144 p += 2;
145
146 DECR_LENGTH_RET (data_size, oprf_size, GNUTLS_E_SHORT_MEMORY_BUFFER);
147
148 memcpy (p, session->security_parameters.extensions.oprfi_client, oprf_size);
149
150 return 2 + oprf_size;
151}
152#endif
153
154static int
155oprfi_send_server (MHD_gtls_session_t session, opaque * data,
156 size_t _data_size)
157{
158 opaque *p = data;
159 int ret;
160 ssize_t data_size = _data_size;
161
162 if (!session->security_parameters.extensions.oprfi_client ||
163 !session->security_parameters.extensions.oprfi_cb)
164 return 0;
165
166 /* Allocate buffer for outgoing data. */
167 session->security_parameters.extensions.oprfi_server_len =
168 session->security_parameters.extensions.oprfi_client_len;
169 session->security_parameters.extensions.oprfi_server =
170 MHD_gnutls_malloc (session->security_parameters.extensions.
171 oprfi_server_len);
172 if (!session->security_parameters.extensions.oprfi_server)
173 {
174 MHD_gnutls_assert ();
175 return GNUTLS_E_MEMORY_ERROR;
176 }
177
178 /* Get outgoing data. */
179 ret = session->security_parameters.extensions.oprfi_cb
180 (session, session->security_parameters.extensions.oprfi_userdata,
181 session->security_parameters.extensions.oprfi_client_len,
182 session->security_parameters.extensions.oprfi_client,
183 session->security_parameters.extensions.oprfi_server);
184 if (ret < 0)
185 {
186 MHD_gnutls_assert ();
187 MHD_gnutls_free (session->security_parameters.extensions.oprfi_server);
188 return ret;
189 }
190
191 DECR_LENGTH_RET (data_size, 2, GNUTLS_E_SHORT_MEMORY_BUFFER);
192 MHD_gtls_write_uint16 (session->security_parameters.extensions.
193 oprfi_server_len, p);
194 p += 2;
195
196 DECR_LENGTH_RET (data_size,
197 session->security_parameters.extensions.oprfi_server_len,
198 GNUTLS_E_SHORT_MEMORY_BUFFER);
199
200 memcpy (p, session->security_parameters.extensions.oprfi_server,
201 session->security_parameters.extensions.oprfi_server_len);
202
203 return 2 + session->security_parameters.extensions.oprfi_server_len;
204}
205
206int
207MHD_gtls_oprfi_send_params (MHD_gtls_session_t session,
208 opaque * data, size_t data_size)
209{
210#if MHD_DEBUG_TLS
211 if (session->security_parameters.entity == GNUTLS_CLIENT)
212 return oprfi_send_client (session, data, data_size);
213 else
214#endif
215 return oprfi_send_server (session, data, data_size);
216}
217