2 * Copyright (C) 2000, 2003, 2004, 2005 Free Software Foundation
4 * Author: Nikos Mavroyanopoulos
6 * This file is part of GNUTLS.
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.
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
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,
24 #include "gnutls_int.h"
25 #include "gnutls_errors.h"
27 #include <gnutls_session_pack.h>
30 * gnutls_session_get_data - Returns all session parameters.
31 * @session: is a #gnutls_session_t structure.
32 * @session_data: is a pointer to space to hold the session.
33 * @session_data_size: is the session_data's size, or it will be set by the function.
35 * Returns all session parameters, in order to support resuming.
36 * The client should call this, and keep the returned session, if he wants to
37 * resume that current version later by calling gnutls_session_set_data()
38 * This function must be called after a successful handshake.
40 * Resuming sessions is really useful and speedups connections after a succesful one.
43 gnutls_session_get_data (gnutls_session_t session
,
44 void *session_data
, size_t * session_data_size
)
47 gnutls_datum_t psession
;
50 if (session
->internals
.resumable
== RESUME_FALSE
)
51 return GNUTLS_E_INVALID_SESSION
;
53 psession
.data
= session_data
;
55 ret
= _gnutls_session_pack (session
, &psession
);
61 *session_data_size
= psession
.size
;
63 if (psession
.size
> *session_data_size
)
64 return GNUTLS_E_SHORT_MEMORY_BUFFER
;
66 if (session_data
!= NULL
)
67 memcpy (session_data
, psession
.data
, psession
.size
);
73 * gnutls_session_get_data2 - Returns all session parameters.
74 * @session: is a #gnutls_session_t structure.
75 * @session_data: is a pointer to a datum that will hold the session.
77 * Returns all session parameters, in order to support resuming.
78 * The client should call this, and keep the returned session, if he wants to
79 * resume that current version later by calling gnutls_session_set_data()
80 * This function must be called after a successful handshake. The returned
81 * datum must be freed with gnutls_free().
83 * Resuming sessions is really useful and speedups connections after a succesful one.
86 gnutls_session_get_data2 (gnutls_session_t session
, gnutls_datum
* data
)
93 return GNUTLS_E_INVALID_REQUEST
;
96 if (session
->internals
.resumable
== RESUME_FALSE
)
97 return GNUTLS_E_INVALID_SESSION
;
99 ret
= _gnutls_session_pack (session
, data
);
111 * gnutls_session_get_id - Returns session id.
112 * @session: is a #gnutls_session_t structure.
113 * @session_id: is a pointer to space to hold the session id.
114 * @session_id_size: is the session id's size, or it will be set by the function.
116 * Returns the current session id. This can be used if you want to check if
117 * the next session you tried to resume was actually resumed.
118 * This is because resumed sessions have the same sessionID with the
121 * Session id is some data set by the server, that identify the current session.
122 * In TLS 1.0 and SSL 3.0 session id is always less than 32 bytes.
124 * Returns zero on success.
127 gnutls_session_get_id (gnutls_session_t session
,
128 void *session_id
, size_t * session_id_size
)
130 size_t given_session_id_size
= *session_id_size
;
132 *session_id_size
= session
->security_parameters
.session_id_size
;
134 /* just return the session size */
135 if (session_id
== NULL
)
140 if (given_session_id_size
< session
->security_parameters
.session_id_size
)
142 return GNUTLS_E_SHORT_MEMORY_BUFFER
;
145 memcpy (session_id
, &session
->security_parameters
.session_id
,
152 * gnutls_session_set_data - Sets all session parameters
153 * @session: is a #gnutls_session_t structure.
154 * @session_data: is a pointer to space to hold the session.
155 * @session_data_size: is the session's size
157 * Sets all session parameters, in order to resume a previously established
158 * session. The session data given must be the one returned by gnutls_session_get_data().
159 * This function should be called before gnutls_handshake().
161 * Keep in mind that session resuming is advisory. The server may
162 * choose not to resume the session, thus a full handshake will be
165 * Returns a negative value on error.
169 gnutls_session_set_data (gnutls_session_t session
,
170 const void *session_data
, size_t session_data_size
)
173 gnutls_datum_t psession
;
175 psession
.data
= (opaque
*) session_data
;
176 psession
.size
= session_data_size
;
178 if (session_data
== NULL
|| session_data_size
== 0)
181 return GNUTLS_E_INVALID_REQUEST
;
183 ret
= _gnutls_session_unpack (session
, &psession
);