gnutls_priority.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation
00003  *
00004  * Author: Nikos Mavrogiannopoulos
00005  *
00006  * This file is part of GNUTLS.
00007  *
00008  * The GNUTLS library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation; either version 2.1 of
00011  * the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00021  * USA
00022  *
00023  */
00024 
00025 /* Here lies the code of the MHD_gnutls_*_set_priority() functions.
00026  */
00027 
00028 #include "gnutls_int.h"
00029 #include "gnutls_algorithms.h"
00030 #include "gnutls_errors.h"
00031 #include <gnutls_num.h>
00032 
00033 #define MAX_ELEMENTS 48
00034 
00035 static int
00036 _set_priority (MHD_gtls_priority_st * st, const int *list)
00037 {
00038   int num = 0;
00039 
00040   while ((list[num] != 0) && (num < MAX_ALGOS))
00041     num++;
00042   st->num_algorithms = num;
00043   memcpy (st->priority, list, num * sizeof (int));
00044   return 0;
00045 }
00046 
00047 static const int MHD_gtls_protocol_priority[] = { MHD_GNUTLS_PROTOCOL_TLS1_1,
00048   MHD_GNUTLS_PROTOCOL_TLS1_0,
00049   MHD_GNUTLS_PROTOCOL_SSL3,
00050   0
00051 };
00052 
00053 static const int MHD_gtls_cipher_priority_secure256[] =
00054   { MHD_GNUTLS_CIPHER_AES_256_CBC,
00055   0
00056 };
00057 
00058 static const int MHD_gtls_kx_priority_secure[] = { MHD_GNUTLS_KX_RSA,
00059   0
00060 };
00061 
00062 static const int MHD_gtls_mac_priority_secure[] = { MHD_GNUTLS_MAC_SHA1,
00063   0
00064 };
00065 
00066 static int MHD_gtls_cert_type_priority[] = { MHD_GNUTLS_CRT_X509,
00067   0
00068 };
00069 
00070 static const int MHD_gtls_comp_priority[] = { MHD_GNUTLS_COMP_NULL,
00071   0
00072 };
00073 
00085 int
00086 MHD__gnutls_priority_set (MHD_gtls_session_t session,
00087                           MHD_gnutls_priority_t priority)
00088 {
00089   if (priority == NULL)
00090     {
00091       MHD_gnutls_assert ();
00092       return GNUTLS_E_NO_CIPHER_SUITES;
00093     }
00094 
00095   memcpy (&session->internals.priorities, priority,
00096           sizeof (struct MHD_gtls_priority_st));
00097 
00098   return 0;
00099 }
00100 
00166 int
00167 MHD_tls_set_default_priority (MHD_gnutls_priority_t * priority_cache,
00168                               const char *priorities, const char **err_pos)
00169 {
00170   *priority_cache =
00171     MHD_gnutls_calloc (1, sizeof (struct MHD_gtls_priority_st));
00172   if (*priority_cache == NULL)
00173     {
00174       MHD_gnutls_assert ();
00175       return GNUTLS_E_MEMORY_ERROR;
00176     }
00177 
00178   /* set mode to "SECURE256" */
00179   _set_priority (&(*priority_cache)->protocol, MHD_gtls_protocol_priority);
00180   _set_priority (&(*priority_cache)->cipher,
00181                  MHD_gtls_cipher_priority_secure256);
00182   _set_priority (&(*priority_cache)->kx, MHD_gtls_kx_priority_secure);
00183   _set_priority (&(*priority_cache)->mac, MHD_gtls_mac_priority_secure);
00184   _set_priority (&(*priority_cache)->cert_type, MHD_gtls_cert_type_priority);
00185   _set_priority (&(*priority_cache)->compression, MHD_gtls_comp_priority);
00186 
00187   (*priority_cache)->no_padding = 0;
00188   return 0;
00189 }
00190 
00198 void
00199 MHD__gnutls_priority_deinit (MHD_gnutls_priority_t priority_cache)
00200 {
00201   MHD_gnutls_free (priority_cache);
00202 }
00203 
00218 int
00219 MHD__gnutls_priority_set_direct (MHD_gtls_session_t session,
00220                                  const char *priorities, const char **err_pos)
00221 {
00222   MHD_gnutls_priority_t prio;
00223   int ret;
00224 
00225   ret = MHD_tls_set_default_priority (&prio, priorities, err_pos);
00226   if (ret < 0)
00227     {
00228       MHD_gnutls_assert ();
00229       return ret;
00230     }
00231 
00232   ret = MHD__gnutls_priority_set (session, prio);
00233   if (ret < 0)
00234     {
00235       MHD_gnutls_assert ();
00236       return ret;
00237     }
00238 
00239   MHD__gnutls_priority_deinit (prio);
00240 
00241   return 0;
00242 }

Generated on Fri Feb 27 18:31:19 2009 for GNU libmicrohttpd by  doxygen 1.5.7.1