summaryrefslogtreecommitdiff
path: root/lib/gnutls_priority.c
blob: 919a48d5998040083b0f6108900161884e00ab5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*
 *      Copyright (C) 2000 Nikos Mavroyanopoulos
 *
 * This file is part of GNUTLS.
 *
 *  The GNUTLS library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public   
 *  License as published by the Free Software Foundation; either 
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 *
 */

/* Here lies the code of the gnutls_*_set_priority() functions.
 */

#include "gnutls_int.h"
#include "gnutls_algorithms.h"
#include "gnutls_errors.h"
#include <gnutls_num.h>

/**
  * gnutls_cipher_set_priority - Sets the priority on the ciphers supported by gnutls.
  * @session: is a &gnutls_session structure.
  * @list: is a 0 terminated list of gnutls_cipher_algorithm elements.
  *
  * Sets the priority on the ciphers supported by gnutls.
  * Priority is higher for ciphers specified before others.
  * After specifying the ciphers you want, you should add 0.
  * Note that the priority is set on the client. The server does
  * not use the algorithm's priority except for disabling
  * algorithms that were not specified.
  **/
int gnutls_cipher_set_priority( gnutls_session session, const int* list) {
const int* _list = list;
int num=0, i;

	while( *_list != 0) {
		num++;
		++_list;
	} 

	num = GMIN( MAX_ALGOS, num);
	session->internals.cipher_algorithm_priority.algorithms = num;
	
	for (i=0;i<num;i++) {
		session->internals.cipher_algorithm_priority.priority[i] = list[i];
	}
	
	return 0;
}

/**
  * gnutls_kx_set_priority - Sets the priority on the key exchange algorithms supported by gnutls.
  * @session: is a &gnutls_session structure.
  * @list: is a 0 terminated list of gnutls_kx_algorithm elements.
  *
  * Sets the priority on the key exchange algorithms supported by gnutls.
  * Priority is higher for algorithms specified before others.
  * After specifying the algorithms you want, you should add 0.
  * Note that the priority is set on the client. The server does
  * not use the algorithm's priority except for disabling
  * algorithms that were not specified.
 **/
int gnutls_kx_set_priority( gnutls_session session, const int* list) {
const int* _list = list;
int num=0, i;

	while( *_list != 0) {
		num++;
		++_list;
	} 


	num = GMIN( MAX_ALGOS, num);
	session->internals.kx_algorithm_priority.algorithms = num;

	for (i=0;i<num;i++) {
		session->internals.kx_algorithm_priority.priority[i] = list[i];
	}

	return 0;
}

/**
  * gnutls_mac_set_priority - Sets the priority on the mac algorithms supported by gnutls.
  * @session: is a &gnutls_session structure.
  * @list: is a 0 terminated list of gnutls_mac_algorithm elements.
  *
  * Sets the priority on the mac algorithms supported by gnutls.
  * Priority is higher for algorithms specified before others.
  * After specifying the algorithms you want, you should add 0.
  * Note that the priority is set on the client. The server does
  * not use the algorithm's priority except for disabling
  * algorithms that were not specified.
  **/
int gnutls_mac_set_priority( gnutls_session session, const int* list) {
const int* _list = list;
int num=0, i;

	while( *_list != 0) {
		num++;
		++_list;
	} 

	
	num = GMIN( MAX_ALGOS, num);
	session->internals.mac_algorithm_priority.algorithms = num;

	for (i=0;i<num;i++) {
		session->internals.mac_algorithm_priority.priority[i] = list[i];
	}

	return 0;
}

/**
  * gnutls_compression_set_priority - Sets the priority on the compression algorithms supported by gnutls.
  * @session: is a &gnutls_session structure.
  * @list: is a 0 terminated list of gnutls_compression_method elements.
  *
  * Sets the priority on the compression algorithms supported by gnutls.
  * Priority is higher for algorithms specified before others.
  * After specifying the algorithms you want, you should add 0.
  * Note that the priority is set on the client. The server does
  * not use the algorithm's priority except for disabling
  * algorithms that were not specified.
  *
  * TLS 1.0 does not define any compression algorithms except
  * NULL. Other compression algorithms are to be considered
  * as gnutls extensions.
  *
  **/
int gnutls_compression_set_priority( gnutls_session session, const int* list) {
const int* _list = list;
int num=0, i;

	while( *_list != 0) {
		num++;
		++_list;
	} 
	
	num = GMIN( MAX_ALGOS, num);
	session->internals.compression_method_priority.algorithms = num;

	for (i=0;i<num;i++) {
		session->internals.compression_method_priority.priority[i] = list[i];
	}
	return 0;
}

/**
  * gnutls_protocol_set_priority - Sets the priority on the protocol versions supported by gnutls.
  * @session: is a &gnutls_session structure.
  * @list: is a 0 terminated list of gnutls_protocol_version elements.
  *
  * Sets the priority on the protocol versions supported by gnutls.
  * This function actually enables or disables protocols. Newer protocol
  * versions always have highest priority.
  *
  **/
int gnutls_protocol_set_priority( gnutls_session session, const int* list) {
const int* _list = list;
int num=0, i;

	while( *_list != 0) {
		num++;
		++_list;
	} 

	
	num = GMIN( MAX_ALGOS, num);
	session->internals.protocol_priority.algorithms = num;

	for (i=0;i<num;i++) {
		session->internals.protocol_priority.priority[i] = list[i];
	}

	/* set the current version to the first in the chain.
	 * This will be overriden later.
	 */
	if (num > 0)
		_gnutls_set_current_version( session, session->internals.protocol_priority.priority[0]);

	return 0;
}

/**
  * gnutls_certificate_type_set_priority - Sets the priority on the certificate types supported by gnutls.
  * @session: is a &gnutls_session structure.
  * @list: is a 0 terminated list of gnutls_certificate_type elements.
  *
  * Sets the priority on the certificate types supported by gnutls.
  * Priority is higher for types specified before others.
  * After specifying the types you want, you should add 0.
  * Note that the certificate type priority is set on the client. 
  * The server does not use the cert type priority except for disabling
  * types that were not specified.
  **/
int gnutls_certificate_type_set_priority( gnutls_session session, const int* list) {
#ifdef HAVE_LIBOPENCDK
const int* _list = list;
int num=0, i;


	while( *_list != 0) {
		num++;
		++_list;
	} 

	num = GMIN( MAX_ALGOS, num);
	session->internals.cert_type_priority.algorithms = num;

	for (i=0;i<num;i++) {
		session->internals.cert_type_priority.priority[i] = list[i];
	}

	return 0;

#endif

	return GNUTLS_E_UNIMPLEMENTED_FEATURE;

}