Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /**
  2.  * \file ssl_cache.h
  3.  *
  4.  * \brief SSL session cache implementation
  5.  *
  6.  *  Copyright (C) 2006-2012, Brainspark B.V.
  7.  *
  8.  *  This file is part of PolarSSL (http://www.polarssl.org)
  9.  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
  10.  *
  11.  *  All rights reserved.
  12.  *
  13.  *  This program is free software; you can redistribute it and/or modify
  14.  *  it under the terms of the GNU General Public License as published by
  15.  *  the Free Software Foundation; either version 2 of the License, or
  16.  *  (at your option) any later version.
  17.  *
  18.  *  This program is distributed in the hope that it will be useful,
  19.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  *  GNU General Public License for more details.
  22.  *
  23.  *  You should have received a copy of the GNU General Public License along
  24.  *  with this program; if not, write to the Free Software Foundation, Inc.,
  25.  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  26.  */
  27. #ifndef POLARSSL_SSL_CACHE_H
  28. #define POLARSSL_SSL_CACHE_H
  29.  
  30. #include "ssl.h"
  31.  
  32. #define SSL_CACHE_DEFAULT_TIMEOUT       86400   /*!< 1 day  */
  33. #define SSL_CACHE_DEFAULT_MAX_ENTRIES      50   /*!< Maximum entries in cache */
  34.  
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38.  
  39. typedef struct _ssl_cache_context ssl_cache_context;
  40. typedef struct _ssl_cache_entry ssl_cache_entry;
  41.  
  42. /**
  43.  * \brief   This structure is used for storing cache entries
  44.  */
  45. struct _ssl_cache_entry
  46. {
  47.     time_t timestamp;           /*!< entry timestamp    */
  48.     ssl_session session;        /*!< entry session      */
  49.     x509_buf peer_cert;         /*!< entry peer_cert    */
  50.     ssl_cache_entry *next;      /*!< chain pointer      */
  51. };
  52.  
  53. /**
  54.  * \brief Cache context
  55.  */
  56. struct _ssl_cache_context
  57. {
  58.     ssl_cache_entry *chain;     /*!< start of the chain     */
  59.     int timeout;                /*!< cache entry timeout    */
  60.     int max_entries;            /*!< maximum entries        */
  61. };
  62.  
  63. /**
  64.  * \brief          Initialize an SSL cache context
  65.  *
  66.  * \param cache    SSL cache context
  67.  */
  68. void ssl_cache_init( ssl_cache_context *cache );
  69.  
  70. /**
  71.  * \brief          Cache get callback implementation
  72.  *
  73.  * \param data     SSL cache context
  74.  * \param session  session to retrieve entry for
  75.  */
  76. int ssl_cache_get( void *data, ssl_session *session );
  77.  
  78. /**
  79.  * \brief          Cache set callback implementation
  80.  *
  81.  * \param data     SSL cache context
  82.  * \param session  session to store entry for
  83.  */
  84. int ssl_cache_set( void *data, const ssl_session *session );
  85.  
  86. /**
  87.  * \brief          Set the cache timeout
  88.  *                 (Default: SSL_CACHE_DEFAULT_TIMEOUT (1 day))
  89.  *
  90.  *                 A timeout of 0 indicates no timeout.
  91.  *
  92.  * \param cache    SSL cache context
  93.  * \param timeout  cache entry timeout
  94.  */
  95. void ssl_cache_set_timeout( ssl_cache_context *cache, int timeout );
  96.  
  97. /**
  98.  * \brief          Set the cache timeout
  99.  *                 (Default: SSL_CACHE_DEFAULT_MAX_ENTRIES (50))
  100.  *
  101.  * \param cache    SSL cache context
  102.  * \param max      cache entry maximum
  103.  */
  104. void ssl_cache_set_max_entries( ssl_cache_context *cache, int max );
  105.  
  106. /**
  107.  * \brief          Free referenced items in a cache context and clear memory
  108.  *
  109.  * \param cache    SSL cache context
  110.  */
  111. void ssl_cache_free( ssl_cache_context *cache );
  112.  
  113. #ifdef __cplusplus
  114. }
  115. #endif
  116.  
  117. #endif /* ssl_cache.h */
  118.