than password files.
- Added the function gnutls_openpgp_set_recv_key_function()
which can be used to set a callback, to get OpenPGP keys.
+- Added the new functions:
+ gnutls_get_malloc_function()
+ gnutls_get_free_function()
+ to be used in callbacks.
Version 0.5.11 (5/11/2002)
- Some fixes in 'gnutls-cli' client program to prevent some segmentation
Current list:
+ Add ability to read PKCS-12 structures (certificate and private key)
* Convert documentation to texinfo format
+* Provide the callbacks with a malloc() and a free() like functions.
* Add support for certificate CRLs in certificate verification
* Audit the code
* Add GPGSM certificate manager support
appendix.tex x509cert.xml.tex pgpcert.xml.tex \
programs.tex library.tex certificate.tex record_weaknesses.tex \
tlsintro.tex compression.tex $(EXAMPLE_OBJECTS) \
- tls_extensions.tex srp.tex preparation.tex
+ tls_extensions.tex srp.tex preparation.tex callbacks.tex
gnutls.html: $(TEX_OBJECTS)
-latex2html gnutls.tex -no_navigation -split 0 \
--- /dev/null
+\section{Callback functions}
+\index{Callback functions}
+
+There are several cases where \gnutls{} may need some out of band input from
+your program. This is now implemented using some callback functions,
+which your program is expected to register.
+
+An example of this type of functions are the push and pull callbacks
+which are used to specify the functions that will retrieve and send
+data to the transport layer.
+\begin{itemize}
+\item \printfunc{gnutls_transport_set_push_function}{gnutls\_transport\_set\_push\_function}
+\item \printfunc{gnutls_transport_set_pull_function}{gnutls\_transport\_set\_pull\_function}
+\end{itemize}
+
+Other callback functions such as the one set by
+\printfunc{gnutls_srp_set_server_credentials_function}{gnutls\_srp\_set\_server\_credentials\_function},
+may require more complicated input, including data to be allocated.
+These callbacks should use the following function to get a malloc()
+and a free() like functions, to allocate data.
+\begin{itemize}
+\item \printfunc{gnutls_global_get_malloc_function}{gnutls\_global\_get\_malloc\_function}
+\item \printfunc{gnutls_global_get_free_function}{gnutls\_global\_get\_free\_function}
+\end{itemize}
\input{errors}
\input{memory}
+
+\input{callbacks}
int gnutls_global_init(void);
void gnutls_global_deinit(void);
+typedef void* (*gnutls_alloc_function)(size_t);
+typedef void (*gnutls_free_function)(void*);
+typedef void* (*gnutls_realloc_function)(void*, size_t);
+
void gnutls_global_set_mem_functions(
- void *(*gnutls_alloc_func)(size_t), void* (*gnutls_secure_alloc_func)(size_t),
- int (*gnutls_is_secure_func)(const void*), void *(*gnutls_realloc_func)(void *, size_t),
- void (*gnutls_free_func)(void*));
+ gnutls_alloc_function, gnutls_alloc_function,
+ int (*gnutls_is_secure_func)(const void*), gnutls_realloc_function,
+ gnutls_free_function);
+
+/* For use in callbacks */
+gnutls_alloc_function* gnutls_global_get_malloc_function(void);
+gnutls_free_function* gnutls_global_get_free_function(void);
typedef void (*gnutls_log_func)( const char*);
void gnutls_global_set_log_function( gnutls_log_func log_func);
int _gnutls_set_datum_m( gnutls_datum* dat, const void* data, int data_size,
- ALLOC_FUNC galloc_func) {
+ gnutls_alloc_function galloc_func) {
dat->data = galloc_func(data_size);
if (dat->data==NULL) return GNUTLS_E_MEMORY_ERROR;
}
int _gnutls_datum_append_m( gnutls_datum* dst, const void* data, int data_size,
- REALLOC_FUNC grealloc_func) {
+ gnutls_realloc_function grealloc_func) {
dst->data = grealloc_func(dst->data, data_size+dst->size);
if (dst->data==NULL) return GNUTLS_E_MEMORY_ERROR;
return 0;
}
-void _gnutls_free_datum_m( gnutls_datum* dat, FREE_FUNC gfree_func) {
+void _gnutls_free_datum_m( gnutls_datum* dat, gnutls_free_function gfree_func) {
if (dat->data!=NULL && dat->size!=0)
gfree_func( dat->data);
void _gnutls_write_datum8( opaque* dest, gnutls_datum dat);
int _gnutls_set_datum_m( gnutls_datum* dat, const void* data, int data_size,
- ALLOC_FUNC);
+ gnutls_alloc_function);
#define _gnutls_set_datum( x, y, z) _gnutls_set_datum_m(x,y,z, gnutls_malloc)
#define _gnutls_sset_datum( x, y, z) _gnutls_set_datum_m(x,y,z, gnutls_secure_malloc)
int _gnutls_datum_append_m( gnutls_datum* dat, const void* data, int data_size,
- REALLOC_FUNC);
+ gnutls_realloc_function);
#define _gnutls_datum_append(x,y,z) _gnutls_datum_append_m(x,y,z, gnutls_realloc)
void _gnutls_free_datum_m( gnutls_datum* dat,
- FREE_FUNC);
+ gnutls_free_function);
#define _gnutls_free_datum(x) _gnutls_free_datum_m(x, gnutls_free)
* sessions database. This function must return a gnutls_datum containing the
* data on success, or a gnutls_datum containing null and 0 on failure.
*
+ * The datum's data must be allocated using the function returned by
+ * gnutls_get_malloc_function().
+ *
* The first argument to store_function() will be null unless gnutls_db_set_ptr()
* has been called.
*
gnutls_assert();
return ret;
}
-
- /* Note: Data is not allocated with gnutls_malloc
- */
- free(data.data);
+
+ gnutls_free(data.data);
return 0;
}
if (session->internals.db_remove_func!=NULL)
ret = session->internals.db_remove_func( session->internals.db_ptr, session_id);
-
return (ret == 0 ? ret : GNUTLS_E_DB_ERROR);
}
#endif
}
-extern ALLOC_FUNC gnutls_secure_malloc;
-extern ALLOC_FUNC gnutls_malloc;
-extern FREE_FUNC gnutls_free;
+extern gnutls_alloc_function gnutls_secure_malloc;
+extern gnutls_alloc_function gnutls_malloc;
+extern gnutls_free_function gnutls_free;
extern int (*_gnutls_is_secure_memory)(const void*);
-extern REALLOC_FUNC gnutls_realloc;
+extern gnutls_realloc_function gnutls_realloc;
extern char* (*gnutls_strdup)(const char*);
extern void* (*gnutls_calloc)(size_t, size_t);
return NULL;
}
+/**
+ * gnutls_global_get_malloc_function - Returns a malloc() like function
+ * @session: is a &gnutls_session structure.
+ *
+ * This function will return a malloc() compatible function to be
+ * used by callbacks.
+ *
+ **/
+gnutls_alloc_function gnutls_global_get_malloc_function()
+{
+ return gnutls_malloc;
+}
+
+/**
+ * gnutls_global_get_free_function - Returns a free() like function
+ * @session: is a &gnutls_session structure.
+ *
+ * This function will return a free() compatible function to be
+ * used by callbacks.
+ *
+ **/
+gnutls_alloc_function gnutls_global_get_free_function()
+{
+ return gnutls_free;
+}
+
#include <gnutls_errors.h>
#include <gnutls_num.h>
-ALLOC_FUNC gnutls_secure_malloc = malloc;
-ALLOC_FUNC gnutls_malloc = malloc;
-FREE_FUNC gnutls_free = free;
-REALLOC_FUNC gnutls_realloc = realloc;
+gnutls_alloc_function gnutls_secure_malloc = malloc;
+gnutls_alloc_function gnutls_malloc = malloc;
+gnutls_free_function gnutls_free = free;
+gnutls_realloc_function gnutls_realloc = realloc;
void* (*gnutls_calloc)(size_t, size_t) = calloc;
char* (*gnutls_strdup)(const char*) = strdup;
# define gnutls_afree gnutls_free
#endif /* HAVE_ALLOCA */
-typedef void* (*ALLOC_FUNC)(size_t);
-typedef void (*FREE_FUNC)(void*);
-typedef void* (*REALLOC_FUNC)(void*, size_t);
+typedef void* (*gnutls_alloc_function)(size_t);
+typedef void (*gnutls_free_function)(void*);
+typedef void* (*gnutls_realloc_function)(void*, size_t);
-extern ALLOC_FUNC gnutls_secure_malloc;
-extern ALLOC_FUNC gnutls_malloc;
-extern FREE_FUNC gnutls_free;
+extern gnutls_alloc_function gnutls_secure_malloc;
+extern gnutls_alloc_function gnutls_malloc;
+extern gnutls_free_function gnutls_free;
extern int (*_gnutls_is_secure_memory)(const void*);
-extern REALLOC_FUNC gnutls_realloc;
+extern gnutls_realloc_function gnutls_realloc;
extern void* (*gnutls_calloc)(size_t, size_t);
extern char* (*gnutls_strdup)( const char*);
int gnutls_record_get_direction(gnutls_session session) {
return session->internals.direction;
}
+
}
}
-void _gnutls_string_init( gnutls_string* str, ALLOC_FUNC alloc_func,
- REALLOC_FUNC realloc_func,
- FREE_FUNC free_func)
+void _gnutls_string_init( gnutls_string* str, gnutls_alloc_function alloc_func,
+ gnutls_realloc_function realloc_func,
+ gnutls_free_function free_func)
{
str->data = NULL;
str->max_length = 0;
opaque * data;
size_t max_length;
size_t length;
- REALLOC_FUNC realloc_func;
- ALLOC_FUNC alloc_func;
- FREE_FUNC free_func;
+ gnutls_realloc_function realloc_func;
+ gnutls_alloc_function alloc_func;
+ gnutls_free_function free_func;
} gnutls_string;
-void _gnutls_string_init( gnutls_string*, ALLOC_FUNC, REALLOC_FUNC, FREE_FUNC);
+void _gnutls_string_init( gnutls_string*, gnutls_alloc_function, gnutls_realloc_function, gnutls_free_function);
void _gnutls_string_clear( gnutls_string*);
/* Beware, do not clear the string, after calling this
if (cred->pwd_callback != NULL) {
ret = cred->pwd_callback( state, username, &entry->salt,
&entry->v, &entry->g, &entry->n);
- entry->malloced = 1;
if (ret < 0) {
gnutls_assert();
}
void _gnutls_srp_entry_free( SRP_PWD_ENTRY * entry) {
- if (entry->malloced) {
- free( entry->v.data); entry->v.data = NULL;
- free( entry->g.data); entry->g.data = NULL;
- free( entry->n.data); entry->n.data = NULL;
- free( entry->salt.data); entry->salt.data = NULL;
- } else {
- _gnutls_free_datum(&entry->v);
- _gnutls_free_datum(&entry->g);
- _gnutls_free_datum(&entry->n);
- _gnutls_free_datum(&entry->salt);
- }
+ _gnutls_free_datum(&entry->v);
+ _gnutls_free_datum(&entry->g);
+ _gnutls_free_datum(&entry->n);
+ _gnutls_free_datum(&entry->salt);
gnutls_free(entry->username);
gnutls_free(entry);
gnutls_datum v;
gnutls_datum g;
gnutls_datum n;
-
- int malloced; /* if non zero, use free() instead of gnutls_free()
- */
-
} SRP_PWD_ENTRY;
/* this is localy alocated. It should be freed using the provided function */
* 'username' contains the actual username.
*
* The 'salt', 'verifier', 'generator' and 'prime' must be filled
- * in (using malloc).
+ * in using the malloc returned by gnutls_get_malloc_function().
*
* In case the callback returned a negative number then gnutls will
* assume that the username does not exist.
#define DEFAULT_PGP_CERTFILE "openpgp/cli_pub.asc"
#define DEFAULT_PGP_KEYRING "openpgp/cli_ring.gpg"
-#define DEFAULT_SRP_USERNAME "test"
-#define DEFAULT_SRP_PASSWD "test"
-
/* initializes a gnutls_session with some defaults.
*/
static gnutls_session init_tls_session( const char* hostname)
if (info.srp_passwd != NULL)
srp_passwd = info.srp_passwd;
- else
- srp_passwd = DEFAULT_SRP_PASSWD;
if (info.srp_username != NULL)
srp_username = info.srp_username;
- else
- srp_username = DEFAULT_SRP_USERNAME;
#else
srp_username = info.srp_username;
srp_passwd = info.srp_passwd;
if (gnutls_srp_allocate_client_credentials(&cred) < 0) {
fprintf(stderr, "SRP authentication error\n");
}
- gnutls_srp_set_client_credentials(cred, srp_username, srp_passwd);
+
+ if ((ret=gnutls_srp_set_client_credentials(cred, srp_username, srp_passwd)) < 0) {
+ fprintf(stderr, "SRP credentials set error [%d]\n", ret);
+ }
}
/* ANON stuff */
#include <config.h>
#include <list.h>
+#define ENA 1
+#if ENA
+
+#include <opencdk.h>
+
+
+int
+recv_openpgp_key(gnutls_session session, const unsigned char *keyfpr,
+ unsigned int keyfpr_length, gnutls_datum * key)
+{
+static const char *hostname = "hkp://wwwkeys.pgp.net";
+static const short port = 11371;
+ int rc;
+ CDK_KBNODE knode = NULL;
+
+ /* The key fingerprint should be 20 bytes
+ * in v4 keys.
+ */
+ if (keyfpr_length != 20)
+ return -1;
+
+ rc = cdk_keyserver_recv_key( hostname, port, keyfpr,
+ CDK_DBSEARCH_FPR, &knode );
+
+ if( !rc ) {
+ size_t len;
+
+ cdk_kbnode_write_to_mem( knode, NULL, &len);
+
+ key->data = malloc( len);
+ if (key->data==NULL) {
+ rc = -1;
+ goto finish;
+ }
+
+ cdk_kbnode_write_to_mem( knode, key->data, &len);
+
+ rc = 0; /* success */
+
+ } else {
+ rc = -1;
+ }
+
+ finish:
+
+ cdk_kbnode_release( knode );
+ return rc;
+
+}
+
+
+#endif
+
/* konqueror cannot handle sending the page in multiple
* pieces.
*/
*/
gnutls_handshake_set_private_extensions( session, 1);
+#if ENA
+gnutls_openpgp_set_recv_key_function( session, recv_openpgp_key);
+#endif
+
if (nodb==0) {
gnutls_db_set_retrieve_function( session, wrap_db_fetch);
gnutls_db_set_remove_function( session, wrap_db_delete);
fprintf(stderr, "Error while setting SRP parameters\n");
}
-
gnutls_anon_allocate_server_credentials(&dh_cred);
if (generate != 0)
gnutls_anon_set_server_dh_params(dh_cred, dh_params);