2 * Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation
4 * Author: Nikos Mavroyanopoulos
6 * This file is part of GNUTLS.
8 * The GNUTLS library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25 /* This file contains the code the Certificate Type TLS extension.
26 * This extension is currently gnutls specific.
29 #include "gnutls_int.h"
30 #include "gnutls_errors.h"
31 #include "gnutls_num.h"
32 #include "ext_cert_type.h"
33 #include <gnutls_state.h>
34 #include <gnutls_num.h>
36 inline static int _gnutls_num2cert_type (int num
);
37 inline static int _gnutls_cert_type2num (int record_size
);
40 * In case of a server: if a CERT_TYPE extension type is received then it stores
41 * into the session security parameters the new value. The server may use gnutls_session_certificate_type_get(),
44 * In case of a client: If a cert_types have been specified then we send the extension.
49 _gnutls_cert_type_recv_params (gnutls_session_t session
,
50 const opaque
* data
, size_t _data_size
)
52 int new_type
= -1, ret
, i
;
53 ssize_t data_size
= _data_size
;
55 if (session
->security_parameters
.entity
== GNUTLS_CLIENT
)
62 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH
;
65 new_type
= _gnutls_num2cert_type (data
[0]);
73 /* Check if we support this cert_type */
75 _gnutls_session_cert_type_supported (session
, new_type
)) < 0)
81 _gnutls_session_cert_type_set (session
, new_type
);
85 { /* SERVER SIDE - we must check if the sent cert type is the right one
92 DECR_LEN (data_size
, len
);
94 for (i
= 0; i
< len
; i
++)
96 new_type
= _gnutls_num2cert_type (data
[i
+ 1]);
101 /* Check if we support this cert_type */
103 _gnutls_session_cert_type_supported (session
,
117 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER
;
121 _gnutls_session_cert_type_supported (session
, new_type
)) < 0)
124 /* The peer has requested unsupported certificate
125 * types. Instead of failing, procceed normally.
126 * (the ciphersuite selection would fail, or a
127 * non certificate ciphersuite will be selected).
132 _gnutls_session_cert_type_set (session
, new_type
);
141 /* returns data_size or a negative number on failure
144 _gnutls_cert_type_send_params (gnutls_session_t session
, opaque
* data
,
149 /* this function sends the client extension data (dnsname) */
150 if (session
->security_parameters
.entity
== GNUTLS_CLIENT
)
153 if (session
->internals
.cert_type_priority
.algorithms
> 0)
156 len
= session
->internals
.cert_type_priority
.algorithms
;
159 session
->internals
.cert_type_priority
.priority
[0] ==
162 /* We don't use this extension if X.509 certificates
168 if (data_size
< len
+ 1)
171 return GNUTLS_E_SHORT_MEMORY_BUFFER
;
176 data
[0] = (uint8_t) len
;
178 for (i
= 0; i
< len
; i
++)
180 data
[i
+ 1] = _gnutls_cert_type2num (session
->internals
.
190 if (session
->security_parameters
.cert_type
!= DEFAULT_CERT_TYPE
)
196 return GNUTLS_E_SHORT_MEMORY_BUFFER
;
200 _gnutls_cert_type2num (session
->security_parameters
.cert_type
);
210 /* Maps numbers to record sizes according to the
214 _gnutls_num2cert_type (int num
)
219 return GNUTLS_CRT_X509
;
221 return GNUTLS_CRT_OPENPGP
;
223 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER
;
227 /* Maps record size to numbers according to the
231 _gnutls_cert_type2num (int cert_type
)
235 case GNUTLS_CRT_X509
:
237 case GNUTLS_CRT_OPENPGP
:
240 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER
;