2 * Copyright (C) 2000-2012 Free Software Foundation, Inc.
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of GnuTLS.
8 * The GnuTLS 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 3 of
11 * the License, or (at your option) any later version.
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.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
22 #include "gnutls_int.h"
23 #include "gnutls_errors.h"
25 #include <gnutls_session_pack.h>
26 #include <gnutls_datum.h>
29 * gnutls_session_get_data:
30 * @session: is a #gnutls_session_t structure.
31 * @session_data: is a pointer to space to hold the session.
32 * @session_data_size: is the session_data's size, or it will be set by the function.
34 * Returns all session parameters, in order to support resuming. The
35 * client should call this, and keep the returned session, if he
36 * wants to resume that current version later by calling
37 * gnutls_session_set_data() This function must be called after a
38 * successful handshake.
40 * Resuming sessions is really useful and speedups connections after
43 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise
44 * an error code is returned.
47 gnutls_session_get_data (gnutls_session_t session
,
48 void *session_data
, size_t * session_data_size
)
51 gnutls_datum_t psession
;
54 if (session
->internals
.resumable
== RESUME_FALSE
)
55 return GNUTLS_E_INVALID_SESSION
;
57 psession
.data
= session_data
;
59 ret
= _gnutls_session_pack (session
, &psession
);
66 if (psession
.size
> *session_data_size
)
68 *session_data_size
= psession
.size
;
69 ret
= GNUTLS_E_SHORT_MEMORY_BUFFER
;
72 *session_data_size
= psession
.size
;
74 if (session_data
!= NULL
)
75 memcpy (session_data
, psession
.data
, psession
.size
);
80 _gnutls_free_datum (&psession
);
85 * gnutls_session_get_data2:
86 * @session: is a #gnutls_session_t structure.
87 * @data: is a pointer to a datum that will hold the session.
89 * Returns all session parameters, in order to support resuming. The
90 * client should call this, and keep the returned session, if he wants
91 * to resume that current version later by calling
92 * gnutls_session_set_data(). This function must be called after a
93 * successful handshake. The returned datum must be freed with
96 * Resuming sessions is really useful and speedups connections after
99 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise
100 * an error code is returned.
103 gnutls_session_get_data2 (gnutls_session_t session
, gnutls_datum_t
* data
)
110 return GNUTLS_E_INVALID_REQUEST
;
113 if (session
->internals
.resumable
== RESUME_FALSE
)
114 return GNUTLS_E_INVALID_SESSION
;
116 ret
= _gnutls_session_pack (session
, data
);
128 * gnutls_session_get_id:
129 * @session: is a #gnutls_session_t structure.
130 * @session_id: is a pointer to space to hold the session id.
131 * @session_id_size: is the session id's size, or it will be set by the function.
133 * Returns the current session id. This can be used if you want to
134 * check if the next session you tried to resume was actually
135 * resumed. This is because resumed sessions have the same sessionID
136 * with the original session.
138 * Session id is some data set by the server, that identify the
139 * current session. In TLS 1.0 and SSL 3.0 session id is always less
142 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise
143 * an error code is returned.
146 gnutls_session_get_id (gnutls_session_t session
,
147 void *session_id
, size_t * session_id_size
)
149 size_t given_session_id_size
= *session_id_size
;
151 *session_id_size
= session
->security_parameters
.session_id_size
;
153 /* just return the session size */
154 if (session_id
== NULL
)
159 if (given_session_id_size
< session
->security_parameters
.session_id_size
)
161 return GNUTLS_E_SHORT_MEMORY_BUFFER
;
164 memcpy (session_id
, &session
->security_parameters
.session_id
,
171 * gnutls_session_set_data:
172 * @session: is a #gnutls_session_t structure.
173 * @session_data: is a pointer to space to hold the session.
174 * @session_data_size: is the session's size
176 * Sets all session parameters, in order to resume a previously
177 * established session. The session data given must be the one
178 * returned by gnutls_session_get_data(). This function should be
179 * called before gnutls_handshake().
181 * Keep in mind that session resuming is advisory. The server may
182 * choose not to resume the session, thus a full handshake will be
185 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise
186 * an error code is returned.
189 gnutls_session_set_data (gnutls_session_t session
,
190 const void *session_data
, size_t session_data_size
)
193 gnutls_datum_t psession
;
195 psession
.data
= (uint8_t *) session_data
;
196 psession
.size
= session_data_size
;
198 if (session_data
== NULL
|| session_data_size
== 0)
201 return GNUTLS_E_INVALID_REQUEST
;
203 ret
= _gnutls_session_unpack (session
, &psession
);