[gnutls-devel] GnuTLS | RFC7250 Raw public keys (!650)

Development of GNU's TLS library gnutls-devel at lists.gnutls.org
Sun Nov 25 13:32:59 CET 2018

Tom commented on a discussion on lib/auth/cert.c:

> +	int ret;
> +	gnutls_pcert_st *apr_cert_list;
> +	gnutls_privkey_t apr_pkey;
> +	int apr_cert_list_length;
> +
> +	// Retrieve the appropriate certificate
> +	if((ret = _gnutls_get_selected_cert(session, &apr_cert_list,
> +				       &apr_cert_list_length, &apr_pkey)) < 0)	{
> +			return gnutls_assert_val(ret);
> +	}
> +
> +	/* Since we are transmitting a raw public key with no additional
> +	 * certificate credentials attached to it, it doesn't make sense to
> +	 * have more than one certificate set (i.e. to have a certificate chain).
> +	 */
> +	if (apr_cert_list_length == 1) {

> it would have been simpler to return the error immediately if the list does not equal one

Isn't that a matter of coding style? I'm used to check for the condition that I need and then act on that. All other scenario's are then falsy. I find it a good approach, especially within the field of security. What's the advantage of checking the inverse condition and directly returning an error? Just to get rid of the else-statement and one level of indentiation?

> why don't you check that the certificate is of RAW type?

That is not necessary because this function will only be called when the certificate type is RAWPK. This is tested in `_gnutls_gen_cert_client_crt` and `_gnutls_gen_cert_server_crt`.

Reply to this email directly or view it on GitLab: https://gitlab.com/gnutls/gnutls/merge_requests/650#note_119837097
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gnupg.org/pipermail/gnutls-devel/attachments/20181125/8d260287/attachment-0001.html>

More information about the Gnutls-devel mailing list