int _gnutls_server_restore_session(gnutls_session_t session, uint8_t * session_id, int session_id_size) { gnutls_datum_t data; gnutls_datum_t key; int ret; if (session_id == NULL || session_id_size == 0) { gnutls_assert(); return GNUTLS_E_INVALID_REQUEST; } if (session->internals.premaster_set != 0) { /* hack for CISCO's DTLS-0.9 */ if (session_id_size == session->internals.resumed_security_parameters. session_id_size && memcmp(session_id, session->internals. resumed_security_parameters.session_id, session_id_size) == 0) return 0; } key.data = session_id; key.size = session_id_size; if (db_func_is_ok(session) != 0) { gnutls_assert(); return GNUTLS_E_INVALID_SESSION; } data = session->internals.db_retrieve_func(session->internals.db_ptr, key); if (data.data == NULL) { gnutls_assert(); return GNUTLS_E_INVALID_SESSION; } /* expiration check is performed inside */ ret = gnutls_session_set_data(session, data.data, data.size); gnutls_free(data.data); if (ret < 0) { gnutls_assert(); return ret; } ret = _gnutls_check_resumed_params(session); if (ret < 0) return gnutls_assert_val(ret); return 0; }
/* Stores session data to the db backend. */ static int store_session(gnutls_session_t session, gnutls_datum_t session_id, gnutls_datum_t session_data) { int ret = 0; if (db_func_is_ok(session) != 0) { return GNUTLS_E_DB_ERROR; } if (session_data.data == NULL || session_data.size == 0) { gnutls_assert(); return GNUTLS_E_INVALID_SESSION; } /* if we can't read why bother writing? */ ret = session->internals.db_store_func(session->internals.db_ptr, session_id, session_data); return (ret == 0 ? ret : GNUTLS_E_DB_ERROR); }