From: Nikos Mavrogiannopoulos Date: Tue, 29 Jan 2002 16:09:52 +0000 (+0000) Subject: CertificateType is now accesible from the API. X-Git-Tag: gnutls_0_3_90~148 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1de7d6cfbf0d83eb12d7d8bc3c96189730e5e893;p=thirdparty%2Fgnutls.git CertificateType is now accesible from the API. --- diff --git a/lib/auth_cert.c b/lib/auth_cert.c index a04fd02ffc..7ed3eccf9f 100644 --- a/lib/auth_cert.c +++ b/lib/auth_cert.c @@ -282,7 +282,7 @@ static int _gnutls_find_acceptable_client_cert(GNUTLS_STATE state, pk_algos, pk_algos_length, cred->cert_list[i][0].subject_pk_algorithm)==0) && (cred->cert_list[i][0].cert_type == - _gnutls_state_cert_type_get( state))) { + gnutls_cert_type_get( state))) { indx = i; break; } @@ -315,7 +315,7 @@ static int _gnutls_find_acceptable_client_cert(GNUTLS_STATE state, /* put the requested DNs to req_dn, only in case * of X509 certificates. */ - if ( _gnutls_state_cert_type_get(state) == GNUTLS_CRT_X509) { + if ( gnutls_cert_type_get(state) == GNUTLS_CRT_X509) { data = _data; data_size = _data_size; count = 0; /* holds the number of given CA's DN */ @@ -362,7 +362,7 @@ static int _gnutls_find_acceptable_client_cert(GNUTLS_STATE state, */ for (j = i = 0; i < cred->ncerts; i++) { if ( (cred->cert_list[i][0].cert_type == - _gnutls_state_cert_type_get( state)) && + gnutls_cert_type_get( state)) && (_gnutls_check_pk_algo_in_list( pk_algos, pk_algos_length, cred->cert_list[i][0].subject_pk_algorithm)==0)) { @@ -867,7 +867,7 @@ int _gnutls_gen_x509_server_cert_req(GNUTLS_STATE state, opaque ** data) return GNUTLS_E_INSUFICIENT_CRED; } - size = CERTTYPE_SIZE + 2; /* 2 for CertType + 2 for size of rdn_seq + size = CERTTYPE_SIZE + 2; /* 2 for CertificateType + 2 for size of rdn_seq */ size += cred->x509_rdn_sequence.size; @@ -1483,7 +1483,7 @@ int _gnutls_server_find_x509_cert_list_index(GNUTLS_STATE state, requested_algo==cred->cert_list[i][0].subject_pk_algorithm) { /* if cert type matches */ - if ( _gnutls_state_cert_type_get( state) == + if ( gnutls_cert_type_get( state) == cred->cert_list[i][0].cert_type) { index = i; @@ -1513,7 +1513,7 @@ int _gnutls_server_find_x509_cert_list_index(GNUTLS_STATE state, requested_algo==cred->cert_list[i][0].subject_pk_algorithm) { /* if cert type matches */ - if ( _gnutls_state_cert_type_get( state) == + if ( gnutls_cert_type_get( state) == cred->cert_list[i][0].cert_type) { ij_map[j] = i; diff --git a/lib/gnutls.h.in.in b/lib/gnutls.h.in.in index 36ff3ee8a8..b6acc467f4 100644 --- a/lib/gnutls.h.in.in +++ b/lib/gnutls.h.in.in @@ -66,6 +66,10 @@ typedef enum GNUTLS_CloseRequest { GNUTLS_SHUT_RDWR=0, GNUTLS_SHUT_WR=1 } GNUTLS typedef enum GNUTLS_Version { GNUTLS_SSL3=1, GNUTLS_TLS1 } GNUTLS_Version; +typedef enum GNUTLS_CertificateType { GNUTLS_CRT_X509=1, GNUTLS_CRT_OPENPGP +} GNUTLS_CertificateType; + + /* If you want to change this, then also change the * define in gnutls_int.h, and recompile. */ @@ -97,10 +101,11 @@ int gnutls_alert_send( GNUTLS_STATE, GNUTLS_AlertLevel, GNUTLS_AlertDescripti int gnutls_alert_send_appropriate( GNUTLS_STATE state, int err); /* get information on the current state */ -GNUTLS_BulkCipherAlgorithm gnutls_cipher_get( GNUTLS_STATE state); -GNUTLS_KXAlgorithm gnutls_kx_get( GNUTLS_STATE state); -GNUTLS_MACAlgorithm gnutls_mac_get( GNUTLS_STATE state); -GNUTLS_CompressionMethod gnutls_compression_get( GNUTLS_STATE state); +GNUTLS_BulkCipherAlgorithm gnutls_cipher_get( GNUTLS_STATE state); +GNUTLS_KXAlgorithm gnutls_kx_get( GNUTLS_STATE state); +GNUTLS_MACAlgorithm gnutls_mac_get( GNUTLS_STATE state); +GNUTLS_CompressionMethod gnutls_compression_get( GNUTLS_STATE state); +GNUTLS_CertificateType gnutls_cert_type_get( GNUTLS_STATE state); /* the name of the specified algorithms */ const char *gnutls_cipher_get_name( GNUTLS_BulkCipherAlgorithm); diff --git a/lib/gnutls_cert.h b/lib/gnutls_cert.h index eacf51c157..00ea31e8cd 100644 --- a/lib/gnutls_cert.h +++ b/lib/gnutls_cert.h @@ -52,7 +52,7 @@ typedef struct gnutls_cert { /* holds the type (PGP, X509) */ - CertType cert_type; + CertificateType cert_type; gnutls_datum raw; /* the raw certificate */ } gnutls_cert; diff --git a/lib/gnutls_int.h b/lib/gnutls_int.h index d8ed09906a..cd29c2ca5d 100644 --- a/lib/gnutls_int.h +++ b/lib/gnutls_int.h @@ -180,9 +180,9 @@ typedef enum KXAlgorithm { GNUTLS_KX_RSA=1, GNUTLS_KX_DHE_DSS, } KXAlgorithm; #define GNUTLS_KXAlgorithm KXAlgorithm -typedef enum CertType { GNUTLS_CRT_X509=1, GNUTLS_CRT_OPENPGP -} CertType; -#define GNUTLS_CertType CertType +typedef enum CertificateType { GNUTLS_CRT_X509=1, GNUTLS_CRT_OPENPGP +} CertificateType; +#define GNUTLS_CertificateType CertificateType typedef enum CredType { GNUTLS_CRD_CERTIFICATE=1, GNUTLS_CRD_ANON, GNUTLS_CRD_SRP } CredType; @@ -348,7 +348,7 @@ typedef struct { TLSExtensions extensions; uint16 max_record_size; /* holds the negotiated certificate type */ - CertType cert_type; + CertificateType cert_type; GNUTLS_Version version; /* moved here */ } SecurityParameters; diff --git a/lib/gnutls_record.c b/lib/gnutls_record.c index 3a2effab57..e018be37ba 100644 --- a/lib/gnutls_record.c +++ b/lib/gnutls_record.c @@ -989,45 +989,6 @@ ssize_t gnutls_recv_int( GNUTLS_STATE state, ContentType type, HandshakeType hty return ret; } -/** - * gnutls_cipher_get - Returns the currently used cipher. - * @state: is a &GNUTLS_STATE structure. - * - * Returns the currently used cipher. - **/ -GNUTLS_BulkCipherAlgorithm gnutls_cipher_get( GNUTLS_STATE state) { - return state->security_parameters.read_bulk_cipher_algorithm; -} - -/** - * gnutls_kx_get - Returns the key exchange algorithm. - * @state: is a &GNUTLS_STATE structure. - * - * Returns the key exchange algorithm used in the last handshake. - **/ -GNUTLS_KXAlgorithm gnutls_kx_get( GNUTLS_STATE state) { - return state->security_parameters.kx_algorithm; -} - -/** - * gnutls_mac_get - Returns the currently used mac algorithm. - * @state: is a &GNUTLS_STATE structure. - * - * Returns the currently used mac algorithm. - **/ -GNUTLS_MACAlgorithm gnutls_mac_get( GNUTLS_STATE state) { - return state->security_parameters.read_mac_algorithm; -} - -/** - * gnutls_compression_get - Returns the currently used compression algorithm. - * @state: is a &GNUTLS_STATE structure. - * - * Returns the currently used compression method. - **/ -GNUTLS_CompressionMethod gnutls_compression_get( GNUTLS_STATE state) { - return state->security_parameters.read_compression_algorithm; -} /* Taken from libgcrypt */ diff --git a/lib/gnutls_record.h b/lib/gnutls_record.h index 58a7bd589e..a9bf8ea64d 100644 --- a/lib/gnutls_record.h +++ b/lib/gnutls_record.h @@ -1,4 +1,3 @@ -KXAlgorithm gnutls_kx_get( GNUTLS_STATE state); ssize_t gnutls_send_int( GNUTLS_STATE state, ContentType type, HandshakeType htype, const void* data, size_t sizeofdata); ssize_t gnutls_recv_int( GNUTLS_STATE state, ContentType type, HandshakeType, char* data, size_t sizeofdata); ssize_t _gnutls_send_change_cipher_spec( GNUTLS_STATE state, int again); diff --git a/lib/gnutls_state.c b/lib/gnutls_state.c index 7dc12269c6..8e21420813 100644 --- a/lib/gnutls_state.c +++ b/lib/gnutls_state.c @@ -19,11 +19,66 @@ */ #include +#include +#include -CertType _gnutls_state_cert_type_get( GNUTLS_STATE state) { +#define CHECK_AUTH(auth, ret) if (gnutls_auth_get_type(state) != auth) { \ + gnutls_assert(); \ + return ret; \ + } + +void _gnutls_state_cert_type_set( GNUTLS_STATE state, CertificateType ct) { + state->security_parameters.cert_type = ct; +} + +/** + * gnutls_cipher_get - Returns the currently used cipher. + * @state: is a &GNUTLS_STATE structure. + * + * Returns the currently used cipher. + **/ +GNUTLS_BulkCipherAlgorithm gnutls_cipher_get( GNUTLS_STATE state) { + return state->security_parameters.read_bulk_cipher_algorithm; +} + +/** + * gnutls_cert_type_get - Returns the currently used certificate type. + * @state: is a &GNUTLS_STATE structure. + * + * Returns the currently used certificate type. The certificate type + * is by default X.509, unless it is negotiated as a TLS extension. + * + **/ +GNUTLS_CertificateType gnutls_cert_type_get( GNUTLS_STATE state) { return state->security_parameters.cert_type; } -void _gnutls_state_cert_type_set( GNUTLS_STATE state, CertType ct) { - state->security_parameters.cert_type = ct; +/** + * gnutls_kx_get - Returns the key exchange algorithm. + * @state: is a &GNUTLS_STATE structure. + * + * Returns the key exchange algorithm used in the last handshake. + **/ +GNUTLS_KXAlgorithm gnutls_kx_get( GNUTLS_STATE state) { + return state->security_parameters.kx_algorithm; +} + +/** + * gnutls_mac_get - Returns the currently used mac algorithm. + * @state: is a &GNUTLS_STATE structure. + * + * Returns the currently used mac algorithm. + **/ +GNUTLS_MACAlgorithm gnutls_mac_get( GNUTLS_STATE state) { + return state->security_parameters.read_mac_algorithm; +} + +/** + * gnutls_compression_get - Returns the currently used compression algorithm. + * @state: is a &GNUTLS_STATE structure. + * + * Returns the currently used compression method. + **/ +GNUTLS_CompressionMethod gnutls_compression_get( GNUTLS_STATE state) { + return state->security_parameters.read_compression_algorithm; } diff --git a/lib/gnutls_state.h b/lib/gnutls_state.h index 1305e9b4cd..3138ed9701 100644 --- a/lib/gnutls_state.h +++ b/lib/gnutls_state.h @@ -3,8 +3,9 @@ #include -CertType _gnutls_state_cert_type_get( GNUTLS_STATE state); -void _gnutls_state_cert_type_set( GNUTLS_STATE state, CertType); +void _gnutls_state_cert_type_set( GNUTLS_STATE state, CertificateType); +KXAlgorithm gnutls_kx_get( GNUTLS_STATE state); +CertificateType gnutls_cert_type_get( GNUTLS_STATE state); #endif