gnutls_priority.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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 }