]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Removed the gdbm backend for resuming TLS sessions. Program gnutls-serv was modified...
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 15 Jun 2002 09:46:27 +0000 (09:46 +0000)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 15 Jun 2002 09:46:27 +0000 (09:46 +0000)
16 files changed:
NEWS
configure.in
doc/TODO
doc/tex/handshake.tex
doc/tex/serv1.tex
lib/defines.h
lib/gnutls.h.in.in
lib/gnutls_db.c
lib/gnutls_handshake.c
lib/gnutls_int.h
lib/gnutls_int_compat.c
lib/gnutls_state.c
lib/x509_xml.c
src/Makefile.am
src/common.c
src/serv.c

diff --git a/NEWS b/NEWS
index 036786f2ee649cd048b69d840990f4f90f008224..728629301a6a461bb148f01d591ce925eec2e236 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,7 +8,10 @@ Version ?.?.?
   and compression algorithms.
 - Added check for C99 macro support by the compiler.
 - Added functions gnutls_b64_encode_fmt2() and gnutls_b64_decode_fmt2()
-- Added the new libasn1 library.
+- Added the new libtasn1 library.
+- Removed the gdbm backend. Applications are now responsible for the
+  session resuming backend. The gnutls-serv application contains an
+  simple example on how to use gdbm for resuming.
 
 Version 0.4.3 (23/05/2002)
 - The gnutls-extra library now compiles fine, if the opencdk library is
index 4db53d737315d48f977e562d81d57a62d9d88532..571033d000b33f6d3e48ee78aaddf52c5003ba1f 100644 (file)
@@ -252,7 +252,7 @@ AC_ARG_WITH( ext-libraries, [  --without-ext-libraries disable external librarie
 
 if test x$ac_ext_libraries != xno; then
  AC_MSG_RESULT(yes)
- AC_CHECK_LIB(gdbm, gdbm_open,, AC_MSG_WARN(
+ AC_CHECK_LIB(gdbm, gdbm_open, SERV_LIBS="-lgdbm", AC_MSG_WARN(
 *** 
 *** GDBM was not found. You will not be able to use the default gdbm session resumption backend.))
  AC_CHECK_LIB(z, compress,,AC_MSG_WARN(
@@ -329,6 +329,8 @@ LIBGNUTLS_CFLAGS="$LIBGCRYPT_CFLAGS -I${includedir}"
 AC_SUBST(LIBGNUTLS_LIBS)
 AC_SUBST(LIBGNUTLS_CFLAGS)
 
+SERV_LIBS="$LIBS $SERV_LIBS"
+AC_SUBST(SERV_LIBS)
 
 LIBGNUTLS_EXTRA_LIBS="-L${libdir} -lgnutls-extra -lgnutls $LIBOPENCDK_LIBS"
 LIBGNUTLS_EXTRA_CFLAGS="$LIBOPENCDK_CFLAGS -I${includedir}"
index f23d2d6f07db5774f53cd930f40a794b39b8e91f..c993347caf7ae656a8100ae98915461deb2c9834 100644 (file)
--- a/doc/TODO
+++ b/doc/TODO
@@ -5,7 +5,6 @@ in order to avoid having people working on the same thing.
 Current list:
 * Audit the code
 * Add function(s) to get the DHE/A parameters
-* Add function(s) to extract the certificate key's parameters
 * Add PKCS-12 support
 * Convert documentation to texinfo format
 * Merge common stuff in DHE and DHA key exchange
index 022f1609742b3a13cc2d240de657134ef8bf43bc..d63a01c7737b1849c75d52d42e7a1d64154c9ce4 100644 (file)
@@ -39,11 +39,7 @@ feature of the {\bf TLS} protocol which allows a client to connect to a server,
 after a successful handshake, without the expensive calculations. This is
 achieved by using the previously
 established keys. \gnutls{} supports this feature, and the
-example \hyperref{resume client}{resume client (see Section }{)}{resume-example} illustrates a typical use of it.
-\par
-Servers only need to use the
-\hyperref{gnutls\_db\_set\_name()}{gnutls\_db\_set\_name() (see Section }{)}{gnutls_db_set_name} function if they want to use the gdbm
-backend to store sessions. 
+example \hyperref{resume client}{resume client (see section }{)}{resume-example} illustrates a typical use of it.
 \par
 Keep in mind that sessions are expired after some time, for security reasons, thus
 it may be normal for a server not to resume a session even if you requested that.
@@ -57,49 +53,24 @@ order to be able to resume sessions. The gnutls approach is, in case of a
 client, to leave all the burden of resuming to the client. Ie. copy and keep the
 nesessary parameters. See the functions:
 \begin{itemize}
-\item \hyperref{gnutls\_session\_get\_data()}
-{gnutls\_session\_get\_data() on section }{}{gnutls_session_get_data}
-\item \hyperref{gnutls\_session\_get\_id()}
-{gnutls\_session\_get\_id() on section }{}{gnutls_session_get_id}
-\item \hyperref{gnutls\_session\_set\_data()}
-{gnutls\_session\_set\_data() on section }{}{gnutls_session_set_data}
+\item \printfunc{gnutls_session_get_data}{gnutls\_session\_get\_data}
+\item \printfunc{gnutls_session_get_id}{gnutls\_session\_get\_id}
+\item \printfunc{gnutls_session_set_data}{gnutls\_session\_set\_data}
 \end{itemize}
 
 \par
-The server side is different.
-Here the server only specifies a DB file, using 
-\hyperref{gnutls\_db\_set\_name()}{gnutls\_db\_set\_name() (see Section }{)}{gnutls_db_set_name}.
-This DB file is used to store the sessions' required parameters for
-resuming. This means that this file contains very sensitive information,
-such as encryption keys. In a multi-threaded application every thread can
-read from the DB file and access all previously established sessions, but
-only one thread can write at a time. The current behaviour of gnutls is
-not to block to wait for the DB to be ready for writing, but continue the
-process normally (and do not save the parameters).  
-\par
-The default behaviour is not efficient in servers where many connections
-per second arrive. Thus
- \gnutls{} provides the following callback functions:
+The server side is different. A server has to specify some callback functions
+which store, retrieve and delete session data. These can be registered with:
 \begin{itemize}
-\item \hyperref{gnutls\_db\_set\_remove\_function()}{gnutls\_db\_set\_remove\_function() (see Section }{)}
-{gnutls_db_set_remove_function}
-\item \hyperref{gnutls\_db\_set\_store\_function()}{gnutls\_db\_set\_store\_function() (see Section }{)}
-{gnutls_db_set_store_function}
-\item \hyperref{gnutls\_db\_set\_retrieve\_function()}{gnutls\_db\_set\_retrieve\_function() (see Section }{)
-}{gnutls_db_set_retrieve_function}
-\item \hyperref{gnutls\_db\_set\_ptr()}{gnutls\_db\_set\_ptr() (see Section }{)}
-{gnutls_db_set_ptr}
+\item \printfunc{gnutls_db_set_remove_function}{gnutls\_db\_set\_remove\_function}
+\item \printfunc{gnutls_db_set_store_function}{gnutls\_db\_set\_store\_function}
+\item \printfunc{gnutls_db_set_retrieve_function}{gnutls\_db\_set\_retrieve\_function}
+\item \printfunc{gnutls_db_set_ptr}{gnutls\_db\_set\_ptr}
 \end{itemize}
 
-These callback functions are required in order to use a session
-storage method, other than the default gdbm backend. 
 \par
-If an alternative backend is in use, it might be usefull to be able to check
-for expired sessions in order to remove them, and save space. This is what
-\hyperref{gnutls\_db\_clean()}{gnutls\_db\_clean() (see Section }{)}
-{gnutls_db_clean} does for the gdbm backend. 
-\gnutls{} provides the function
-\hyperref{gnutls\_db\_check\_entry()}{gnutls\_db\_check\_entry() (see Section }{)
-}{gnutls_db_check_entry}, which takes as input session data, and
-returns a negative value if the data are to be removed.
+It might also be usefull to be able to check for expired sessions in order to remove 
+them, and save space. The function
+\printfunc{gnutls_db_check_entry}{gnutls\_db\_check\_entry} is provided for that
+reason.
 
index 26fe76c46f417e6d5cb9f0b55dc1bb33a400c824..c45f6eec0080e28fd71bc8dfa0cebda656135496 100644 (file)
@@ -47,11 +47,6 @@ GNUTLS_STATE initialize_state()
 
    gnutls_init(&state, GNUTLS_SERVER);
 
-   /* in order to support session resuming:
-    */
-   if ((ret = gnutls_db_set_name(state, "gnutls-rsm.db")) < 0)
-      fprintf(stderr, "*** DB error (%d)\n\n", ret);
-
    gnutls_protocol_set_priority(state, protocol_priority);
    gnutls_cipher_set_priority(state, cipher_priority);
    gnutls_compression_set_priority(state, comp_priority);
index d71afaa64a14865b480cfa8a868afb6ca23e005a..dd918865d725d994f52e66057452cf8e0694f6bc 100644 (file)
@@ -66,10 +66,6 @@ typedef long ptrdiff_t;
 # include <sys/types.h>
 #endif
 
-#ifdef HAVE_LIBGDBM
-# include <gdbm.h>
-#endif
-
 #ifdef HAVE_SYS_STAT_H
 # include <sys/stat.h>
 #endif
index 89ed3493c9bb73af754a47064fa11e2363d4ba52..39e5a475840274fc8b0152ac09eee0adcb57570c 100644 (file)
@@ -188,9 +188,7 @@ typedef gnutls_datum (*GNUTLS_DB_RETR_FUNC)(void*, gnutls_datum key);
 
 void gnutls_db_set_cache_expiration( GNUTLS_STATE state, int seconds);
 
-int  gnutls_db_set_name( GNUTLS_STATE state, const char* filename);    
-int  gnutls_db_clean( GNUTLS_STATE state);
-void  gnutls_db_remove_session( GNUTLS_STATE state);
+void gnutls_db_remove_session( GNUTLS_STATE state);
 void gnutls_db_set_retrieve_func( GNUTLS_STATE, GNUTLS_DB_RETR_FUNC);
 void gnutls_db_set_remove_func( GNUTLS_STATE, GNUTLS_DB_REMOVE_FUNC);
 void gnutls_db_set_store_func( GNUTLS_STATE, GNUTLS_DB_STORE_FUNC);
index a7405932ea7dccf886a66bc650c061b1dcac96b4..5650379a42593dbf2ff2fa7ec74c2ee30083ba27 100644 (file)
 
 #define GNUTLS_DBNAME state->gnutls_internals.db_name
 
-#ifdef HAVE_LIBGDBM
-# define GNUTLS_DBF state->gnutls_internals.db_reader
-# define GNUTLS_REOPEN_DB() if (GNUTLS_DBF!=NULL) \
-       gdbm_close( GNUTLS_DBF); \
-       GNUTLS_DBF = gdbm_open(GNUTLS_DBNAME, 0, GDBM_READER, 0600, NULL);
-#endif
-
 /**
-  * gnutls_db_set_retrieve_function - Sets the function that will be used to get data
+  * gnutls_db_set_retrieve_func - Sets the function that will be used to get data
   * @state: is a &GNUTLS_STATE structure.
   * @retr_func: is the function.
   *
   * has been called.
   *
   **/
-void gnutls_db_set_retrieve_function( GNUTLS_STATE state, GNUTLS_DB_RETR_FUNC retr_func) {
+void gnutls_db_set_retrieve_func( GNUTLS_STATE state, GNUTLS_DB_RETR_FUNC retr_func) {
        state->gnutls_internals.db_retrieve_func = retr_func;
 }
 
 /**
-  * gnutls_db_set_remove_function - Sets the function that will be used to remove data
+  * gnutls_db_set_remove_func - Sets the function that will be used to remove data
   * @state: is a &GNUTLS_STATE structure.
   * @rem_func: is the function.
   *
@@ -71,12 +64,12 @@ void gnutls_db_set_retrieve_function( GNUTLS_STATE state, GNUTLS_DB_RETR_FUNC re
   * has been called.
   *
   **/
-void gnutls_db_set_remove_function( GNUTLS_STATE state, GNUTLS_DB_REMOVE_FUNC rem_func) {
+void gnutls_db_set_remove_func( GNUTLS_STATE state, GNUTLS_DB_REMOVE_FUNC rem_func) {
        state->gnutls_internals.db_remove_func = rem_func;
 }
 
 /**
-  * gnutls_db_set_store_function - Sets the function that will be used to put data
+  * gnutls_db_set_store_func - Sets the function that will be used to put data
   * @state: is a &GNUTLS_STATE structure.
   * @store_func: is the function
   *
@@ -89,7 +82,7 @@ void gnutls_db_set_remove_function( GNUTLS_STATE state, GNUTLS_DB_REMOVE_FUNC re
   * has been called.
   *
   **/
-void gnutls_db_set_store_function( GNUTLS_STATE state, GNUTLS_DB_STORE_FUNC store_func) {
+void gnutls_db_set_store_func( GNUTLS_STATE state, GNUTLS_DB_STORE_FUNC store_func) {
        state->gnutls_internals.db_store_func = store_func;
 }
 
@@ -130,60 +123,11 @@ void gnutls_db_set_cache_expiration( GNUTLS_STATE state, int seconds) {
        state->gnutls_internals.expire_time = seconds;
 }
 
-/**
-  * gnutls_db_set_name - Sets the name of the database that holds TLS sessions.
-  * @state: is a &GNUTLS_STATE structure.
-  * @filename: is the filename for the database
-  *
-  * Sets the name of the (gdbm) database to be used to keep
-  * the sessions to be resumed. This function also creates the database
-  * - if it does not exist - and opens it for reading.
-  * You should not call this function if using an other backend
-  * than gdbm (ie. called function gnutls_db_set_store_func() etc.)
-  *
-  **/
-int gnutls_db_set_name( GNUTLS_STATE state, const char* filename) {
-#ifdef HAVE_LIBGDBM
-GDBM_FILE dbf;
-
-       if (filename==NULL) return 0;
-
-       /* deallocate previous name */
-       if (GNUTLS_DBNAME!=NULL)
-               gnutls_free(GNUTLS_DBNAME);
-
-       /* set name */
-       GNUTLS_DBNAME = gnutls_strdup(filename);
-       if (GNUTLS_DBNAME==NULL) return GNUTLS_E_MEMORY_ERROR;
-
-       /* open for reader */
-       GNUTLS_DBF = gdbm_open(GNUTLS_DBNAME, 0, GDBM_READER, 0600, NULL);
-       if (GNUTLS_DBF==NULL) {
-               /* maybe it does not exist - so try to
-                * create it.
-                */
-               dbf = gdbm_open( (char*)filename, 0, GDBM_WRCREAT, 0600, NULL);
-               if (dbf==NULL) return GNUTLS_E_DB_ERROR;
-               gdbm_close(dbf);
-
-               /* try to open again */
-               GNUTLS_DBF = gdbm_open(GNUTLS_DBNAME, 0, GDBM_READER, 0600, NULL);
-       }
-       if (GNUTLS_DBF==NULL)
-               return GNUTLS_E_DB_ERROR;
-
-       return 0;
-#else
-       return GNUTLS_E_UNIMPLEMENTED_FEATURE;
-#endif
-}
-
 /**
   * gnutls_db_check_entry - checks if the given db entry has expired
   * @state: is a &GNUTLS_STATE structure.
   * @session_entry: is the session data (not key)
   *
-  * This function should only be used if not using the gdbm backend.
   * This function returns GNUTLS_E_EXPIRED, if the database entry
   * has expired or 0 otherwise. This function is to be used when
   * you want to clear unnesessary session which occupy space in your
@@ -202,59 +146,6 @@ time_t timestamp;
        return 0;
 }
 
-/**
-  * gnutls_db_clean - removes expired and invalid sessions from the database
-  * @state: is a &GNUTLS_STATE structure.
-  *
-  * This function Deletes all expired records in the resumed sessions' database. 
-  * This database may become huge if this function is not called.
-  * This function is also quite expensive. This function should only
-  * be called if using the gdbm backend.
-  *
-  **/
-int gnutls_db_clean( GNUTLS_STATE state) {
-#ifdef HAVE_LIBGDBM
-GDBM_FILE dbf;
-int ret;
-datum key;
-time_t timestamp;
-gnutls_datum _key;
-
-       if (GNUTLS_DBF==NULL) return GNUTLS_E_DB_ERROR;
-       if (GNUTLS_DBNAME==NULL) return GNUTLS_E_DB_ERROR;
-
-       dbf = gdbm_open(GNUTLS_DBNAME, 0, GDBM_WRITER, 0600, NULL);
-       if (dbf==NULL) return GNUTLS_E_AGAIN;
-       key = gdbm_firstkey(dbf);
-
-       timestamp = time(0);
-
-       _key.data = key.dptr;
-       _key.size = key.dsize;
-       while( _key.data != NULL) {
-
-               if ( gnutls_db_check_entry( state, _key)==GNUTLS_E_EXPIRED) {
-                   /* delete expired entry */
-                   gdbm_delete( dbf, key);
-               }
-               
-               free(key.dptr);
-               key = gdbm_nextkey(dbf, key);
-       }
-       ret = gdbm_reorganize(dbf);
-       
-       gdbm_close(dbf);
-       GNUTLS_REOPEN_DB();
-       
-       if (ret!=0) return GNUTLS_E_DB_ERROR;
-               
-       return 0;
-#else
-       return GNUTLS_E_UNIMPLEMENTED_FEATURE;
-#endif
-
-}
-
 /* The format of storing data is:
  * (forget it). Check gnutls_session_pack.c
  */
@@ -356,11 +247,6 @@ gnutls_datum key = { session_id, session_id_size };
  */
 int _gnutls_store_session( GNUTLS_STATE state, gnutls_datum session_id, gnutls_datum session_data)
 {
-#ifdef HAVE_LIBGDBM
-GDBM_FILE dbf;
-datum key = { session_id.data, session_id.size };
-datum content = {session_data.data, session_data.size};
-#endif
 int ret = 0;
 
        if (state->gnutls_internals.resumable==RESUME_FALSE) {
@@ -383,29 +269,8 @@ int ret = 0;
        }
        /* if we can't read why bother writing? */
 
-#ifdef HAVE_LIBGDBM
-       if (GNUTLS_DBF!=NULL) { /* use gdbm */
-               dbf = gdbm_open(GNUTLS_DBNAME, 0, GDBM_WRITER, 0600, NULL);
-               if (dbf==NULL) {
-                       /* cannot open db for writing. This may happen if multiple
-                        * instances try to write. 
-                        */
-                       gnutls_assert();
-                       return GNUTLS_E_AGAIN;
-               }
-               ret = gdbm_store( dbf, key, content, GDBM_INSERT);
-               if (ret<0) {
-                       gnutls_assert();
-               }
-               gdbm_close(dbf);
-
-               return 0; /*GNUTLS_E_UNIMPLEMENTED_FEATURE;*/
-       }
-       else 
-#endif
-               if (state->gnutls_internals.db_store_func!=NULL)
-                       ret = state->gnutls_internals.db_store_func( state->gnutls_internals.db_ptr, session_id, session_data);
-
+       if (state->gnutls_internals.db_store_func!=NULL)
+               ret = state->gnutls_internals.db_store_func( state->gnutls_internals.db_ptr, session_id, session_data);
 
        return (ret == 0 ? ret : GNUTLS_E_DB_ERROR);
 
@@ -415,10 +280,6 @@ int ret = 0;
  */
 gnutls_datum _gnutls_retrieve_session( GNUTLS_STATE state, gnutls_datum session_id)
 {
-#ifdef HAVE_LIBGDBM
-datum key = { session_id.data, session_id.size };
-datum content;
-#endif
 gnutls_datum ret = { NULL, 0 };
 
        if (session_id.data==NULL || session_id.size==0) {
@@ -426,16 +287,8 @@ gnutls_datum ret = { NULL, 0 };
                return ret;
        }
        
-       /* if we can't read why bother writing? */
-#ifdef HAVE_LIBGDBM
-       if (GNUTLS_DBF!=NULL) { /* use gdbm */
-               content = gdbm_fetch( GNUTLS_DBF, key);
-               ret.data = content.dptr;
-               ret.size = content.dsize;
-       } else
-#endif
-               if (state->gnutls_internals.db_retrieve_func!=NULL)
-                       ret = state->gnutls_internals.db_retrieve_func( state->gnutls_internals.db_ptr, session_id);
+       if (state->gnutls_internals.db_retrieve_func!=NULL)
+               ret = state->gnutls_internals.db_retrieve_func( state->gnutls_internals.db_ptr, session_id);
 
        return ret;
 
@@ -445,10 +298,6 @@ gnutls_datum ret = { NULL, 0 };
  */
 int _gnutls_remove_session( GNUTLS_STATE state, gnutls_datum session_id)
 {
-#ifdef HAVE_LIBGDBM
-GDBM_FILE dbf;
-datum key = { session_id.data, session_id.size };
-#endif
 int ret = 0;
 
        if (GNUTLS_DBNAME==NULL && _gnutls_db_func_is_ok(state)!=0) {
@@ -459,23 +308,8 @@ int ret = 0;
                return GNUTLS_E_INVALID_SESSION;
 
        /* if we can't read why bother writing? */
-#ifdef HAVE_LIBGDBM
-       if (GNUTLS_DBF!=NULL) { /* use gdbm */
-
-               dbf = gdbm_open(GNUTLS_DBNAME, 0, GDBM_WRITER, 0600, NULL);
-               if (dbf==NULL) {
-                       /* cannot open db for writing. This may happen if multiple
-                        * instances try to write. 
-                        */
-                       return GNUTLS_E_AGAIN;
-               }
-               ret = gdbm_delete( dbf, key);
-
-               gdbm_close(dbf);
-       } else
-#endif
-               if (state->gnutls_internals.db_remove_func!=NULL)
-                       ret = state->gnutls_internals.db_remove_func( state->gnutls_internals.db_ptr, session_id);
+       if (state->gnutls_internals.db_remove_func!=NULL)
+               ret = state->gnutls_internals.db_remove_func( state->gnutls_internals.db_ptr, session_id);
 
 
        return (ret == 0 ? ret : GNUTLS_E_DB_ERROR);
index e64d50341f7ed2c6ee01d685a8cf47986cc7792b..533e57cd351c1cfb34ff4a1fb4524af453668be8 100644 (file)
@@ -302,7 +302,6 @@ int _gnutls_read_client_hello(GNUTLS_STATE state, opaque * data,
 
        if (ret == 0) {         /* resumed! */
                resume_copy_required_values(state);
-
                state->gnutls_internals.resumed = RESUME_TRUE;
                return 0;
        } else {
index 738a70462a48b79663440b3105d37261c6595256..f7cfb796ebe9d1a6f29db3c3109ce3ca0d4c0bc7 100644 (file)
@@ -473,9 +473,6 @@ typedef struct {
        int                             v2_hello; /* 0 if the client hello is v3+.
                                                   * non-zero if we got a v2 hello.
                                                   */
-#ifdef HAVE_LIBGDBM
-       GDBM_FILE                       db_reader;
-#endif
        /* keeps the headers of the handshake packet 
         */
        HANDSHAKE_HEADER_BUFFER         handshake_header_buffer;
index 37a44adbdac3c0361fa94a9780fe0835245b3773..cf97cb7113efcbb0bae52f49e1848e421dd3f54e 100644 (file)
@@ -14,6 +14,14 @@ int gnutls_x509_extract_subject_alt_name( const gnutls_datum *
        return gnutls_x509_extract_certificate_subject_alt_name( cert, seq, ret, ret_size);
 }
 
+int gnutls_db_set_name( GNUTLS_STATE state, const char* filename) {
+       return GNUTLS_E_UNIMPLEMENTED_FEATURE;
+}
+
+int gnutls_db_clean( GNUTLS_STATE state) {
+       return GNUTLS_E_UNIMPLEMENTED_FEATURE;
+}
+
 /* nothing here */
 
 #endif /* GNUTLS_BACKWARDS_COMPATIBLE */
index 75a8192c994053242b0940c7711feb3194c62594..90861913025b7da30aadb4e12cdd1edaab8ac53f 100644 (file)
@@ -220,12 +220,6 @@ void gnutls_deinit(GNUTLS_STATE state)
        /* remove auth info firstly */
        _gnutls_free_auth_info(state );
 
-#ifdef HAVE_LIBGDBM
-       /* close the database - resuming sessions */
-       if ( state->gnutls_internals.db_reader != NULL)
-               gdbm_close(state->gnutls_internals.db_reader);
-#endif
-
        _gnutls_handshake_io_buffer_clear( state);
 
        gnutls_sfree_datum(&state->connection_state.read_mac_secret);
index 93dd5abcb5fac6c902c092fde013d4cc0aa61535..5666b988461904577a7e094c43ea14d7d9f2b054 100644 (file)
@@ -428,10 +428,10 @@ _gnutls_asn1_get_structure_xml(ASN1_TYPE structure, char *name,
   * gnutls_x509_get_certificate_xml - This function parses an RDN sequence
   * @cert: should contain a DER encoded certificate
   * @res: The datum that will hold the result
-  * @detail: The detail level (unused for now)
+  * @detail: The detail level (must be 0 for now)
   *
   * This function will return the XML structures of the given X.509 certificate.
-  * The XML structures are allocated internaly and stored into res.
+  * The XML structures are allocated internaly (with malloc) and stored into res.
   * Returns a negative error code in case of an error.
   *
   **/
index 6d1ff21f9cb6497efb44cd22b1123908ef61559c..ba32877bfd2b145cd5259424bdd8c4d34904cadc 100644 (file)
@@ -7,7 +7,7 @@ INCLUDES = -I../lib -I../libtasn1/lib
 
 bin_PROGRAMS = gnutls-serv gnutls-cli gnutls-srpcrypt gnutls-cli-debug
 gnutls_serv_SOURCES = serv-gaa.c serv.c common.c
-gnutls_serv_LDADD = ../lib/libgnutls.la ../libextra/libgnutls-extra.la  $(LIBGCRYPT_LIBS) $(LIBOPENCDK_LIBS)
+gnutls_serv_LDADD = ../lib/libgnutls.la ../libextra/libgnutls-extra.la $(LIBGCRYPT_LIBS) $(LIBOPENCDK_LIBS) #$(SERV_LIBS)
 gnutls_srpcrypt_SOURCES = crypt-gaa.c crypt.c
 gnutls_srpcrypt_LDADD = ../lib/libgnutls.la ../libextra/libgnutls-extra.la  $(LIBGCRYPT_LIBS) $(LIBOPENCDK_LIBS)
 gnutls_cli_SOURCES = cli-gaa.c cli.c common.c 
index 029bf491105dd31569f8106370f1b0fe0d7e4756..d69bd475b0f1021b91faac86866e0491ddda33f9 100644 (file)
@@ -47,7 +47,6 @@ void print_x509_info(GNUTLS_STATE state)
        if (cert_list_size <= 0)
                return;
 
-
        printf(" - Certificate info:\n");
 
        printf(" # Certificate is valid since: %s", my_ctime( &activet));
index 79aa8d664e6896ba54fd34ef89688c8dfe64c47d..b79b71b589edbcfc917b14c1eb193704a3be23ab 100644 (file)
@@ -32,7 +32,7 @@
 #include "common.h"
 #include <signal.h>
 #include "serv-gaa.h"
-
+#include <config.h>
 
 /* konqueror cannot handle sending the page in multiple
  * pieces.
@@ -85,6 +85,27 @@ GNUTLS_ANON_SERVER_CREDENTIALS dh_cred;
 GNUTLS_CERTIFICATE_SERVER_CREDENTIALS cert_cred;
 
 
+#ifdef HAVE_LIBGDBM
+
+# include <gdbm.h>
+
+ typedef struct {
+       GDBM_FILE read_dbf;
+ } DBF;
+
+ static DBF dbf;
+
+# define DB_FILE "gnutls-rsm.db"
+
+ static void wrap_gdbm_init(void);
+ static void wrap_gdbm_deinit(void);
+ static int wrap_gdbm_store( DBF* dbf, gnutls_datum key, gnutls_datum data);
+ static gnutls_datum wrap_gdbm_fetch( DBF* dbf, gnutls_datum key);
+ static int wrap_gdbm_delete( DBF* dbf, gnutls_datum key);
+
+#endif
+
+
 #define DEFAULT_PRIME_BITS 1024
 
 /* we use primes up to 1024 in this server.
@@ -150,7 +171,6 @@ int cert_type_priority[16] = { GNUTLS_CRT_X509, GNUTLS_CRT_OPENPGP, 0 };
 GNUTLS_STATE initialize_state(void)
 {
    GNUTLS_STATE state;
-   int ret;
 
    gnutls_init(&state, GNUTLS_SERVER);
 
@@ -158,10 +178,12 @@ GNUTLS_STATE initialize_state(void)
     */
    gnutls_handshake_set_private_extensions( state, 1);
 
-   if ((ret = gnutls_db_set_name(state, "gnutls-rsm.db")) < 0)
-      fprintf(stderr,
-             "*** DB error (%d). Resuming will not be possible.\n\n",
-             ret);
+#ifdef HAVE_LIBGDBM
+   gnutls_db_set_retrieve_func( state, wrap_gdbm_fetch);
+   gnutls_db_set_remove_func( state, wrap_gdbm_delete);
+   gnutls_db_set_store_func( state, wrap_gdbm_store);
+   gnutls_db_set_ptr( state, &dbf);
+#endif
 
    /* null cipher is here only for debuging 
     * purposes.
@@ -330,6 +352,10 @@ int main(int argc, char **argv)
 
    gaa_parser(argc, argv);
 
+#ifdef HAVE_LIBGDBM
+   wrap_gdbm_init();
+#endif
+
    if (http == 1) {
       strcpy(name, "HTTP Server");
    } else {
@@ -554,6 +580,9 @@ int main(int argc, char **argv)
    gnutls_srp_free_server_sc(srp_cred);
    gnutls_anon_free_server_sc(dh_cred);
 
+#ifdef HAVE_LIBGDBM
+   wrap_gdbm_deinit();
+#endif
    gnutls_global_deinit();
 
    return 0;
@@ -723,12 +752,93 @@ void gaa_parser(int argc, char **argv)
       }
       comp_priority[j] = 0;
    }
-
-
-
 }
 
 void serv_version(void) {
        fprintf(stderr, "GNU TLS test server, ");
        fprintf(stderr, "version %s.\n", LIBGNUTLS_VERSION);
 }
+
+#ifdef HAVE_LIBGDBM
+
+static void wrap_gdbm_init(void) {
+       GDBM_FILE tmpdbf;
+       
+       /* create db */
+       tmpdbf = gdbm_open(DB_FILE, 0, GDBM_NEWDB, 0600, NULL);
+       if (tmpdbf==NULL) {
+               fprintf(stderr, "Error opening gdbm database\n");
+               exit(1);
+       }
+       gdbm_close( tmpdbf);
+
+       dbf.read_dbf = gdbm_open(DB_FILE, 0, GDBM_READER, 0600, NULL);
+       if (dbf.read_dbf==NULL) {
+               fprintf(stderr, "Error opening gdbm database\n");
+               exit(1);
+       }
+}
+
+static void wrap_gdbm_deinit(void) {
+       gdbm_close( dbf.read_dbf);
+}
+
+static int wrap_gdbm_store( DBF* dbf, gnutls_datum key, gnutls_datum data) {
+       datum _key, _data;
+       int res;
+       GDBM_FILE write_dbf;
+
+       write_dbf = gdbm_open(DB_FILE, 0, GDBM_WRITER, 0600, NULL);
+       if (write_dbf==NULL) {
+               fprintf(stderr, "Error opening gdbm database\n");
+               exit(1);
+       }
+       
+       _key.dptr = key.data;
+       _key.dsize = key.size;
+
+       _data.dptr = data.data;
+       _data.dsize = data.size;
+       
+       res = gdbm_store( write_dbf, _key, _data, GDBM_INSERT);
+
+       gdbm_close( write_dbf);
+       return res;
+}
+
+static gnutls_datum wrap_gdbm_fetch( DBF* dbf, gnutls_datum key) {
+       datum _key, _res;
+       gnutls_datum res2;
+       
+       _key.dptr = key.data;
+       _key.dsize = key.size;
+       
+       _res = gdbm_fetch( dbf->read_dbf, _key);
+
+       res2.data = _res.dptr;
+       res2.size = _res.dsize;
+
+       return res2;
+}
+
+static int wrap_gdbm_delete( DBF* dbf, gnutls_datum key) {
+       datum _key;
+       int res;
+       GDBM_FILE write_dbf;
+
+       write_dbf = gdbm_open(DB_FILE, 0, GDBM_WRITER, 0600, NULL);
+       if (write_dbf==NULL) {
+               fprintf(stderr, "Error opening gdbm database\n");
+               exit(1);
+       }
+       
+       _key.dptr = key.data;
+       _key.dsize = key.size;
+       
+       res = gdbm_delete( write_dbf, _key);
+       gdbm_close( write_dbf);
+
+       return res;
+}
+
+#endif /* HAVE LIBGDBM */