2 * Copyright (C) 2000, 2003, 2004, 2005, 2007, 2008 Free Software Foundation
4 * Author: Nikos Mavrogiannopoulos
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>
28 #include <gnutls_datum.h>
31 * gnutls_session_get_data - Returns all session parameters.
32 * @session: is a #gnutls_session_t structure.
33 * @session_data: is a pointer to space to hold the session.
34 * @session_data_size: is the session_data's size, or it will be set by the function.
36 * Returns all session parameters, in order to support resuming. The
37 * client should call this, and keep the returned session, if he
38 * wants to resume that current version later by calling
39 * gnutls_session_set_data() This function must be called after a
40 * successful handshake.
42 * Resuming sessions is really useful and speedups connections after
45 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise
46 * an error code is returned.
49 gnutls_session_get_data (gnutls_session_t session
,
50 void *session_data
, size_t * session_data_size
)
53 gnutls_datum_t psession
;
56 if (session
->internals
.resumable
== RESUME_FALSE
)
57 return GNUTLS_E_INVALID_SESSION
;
59 psession
.data
= session_data
;
61 ret
= _gnutls_session_pack (session
, &psession
);
67 *session_data_size
= psession
.size
;
69 if (psession
.size
> *session_data_size
)
71 ret
= GNUTLS_E_SHORT_MEMORY_BUFFER
;
75 if (session_data
!= NULL
)
76 memcpy (session_data
, psession
.data
, psession
.size
);
81 _gnutls_free_datum( &psession
);
86 * gnutls_session_get_data2 - Returns all session parameters.
87 * @session: is a #gnutls_session_t structure.
88 * @session_data: is a pointer to a datum that will hold the session.
90 * Returns all session parameters, in order to support resuming.
91 * The client should call this, and keep the returned session, if he wants to
92 * resume that current version later by calling gnutls_session_set_data()
93 * This function must be called after a successful handshake. The returned
94 * datum must be freed with gnutls_free().
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 - Returns session 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 - Sets all session parameters
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
= (opaque
*) 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
);