GNUTLS_CERTIFICATE_SET_RETRIEVE_FUNCTION(3)

πŸ’– NAME πŸ’–

gnutls_certificate_set_retrieve_function β€” bestie, it's an API function, and it's the one that tells gnutls who to ask when it needs a certificate mid-handshake πŸŽ€

This page lives in the gnutls manual, and we're serving it up fresh ✨


🌸 SYNOPSIS 🌸

#include <gnutls/gnutls.h>

void
gnutls_certificate_set_retrieve_function(gnutls_certificate_credentials_t
cred, gnutls_certificate_retrieve_function * func);

✨ ARGUMENTS ✨

  • gnutls_certificate_credentials_t cred β€” okay so this is a gnutls_certificate_credentials_t type. That's the whole lore, she's just the creds babe πŸ’…
  • gnutls_certificate_retrieve_function * func β€” and this one? It's the callback function. The main character of this whole story πŸ‘‘

πŸ¦‹ DESCRIPTION πŸ¦‹

So the way this works: this function sets a callback that gets called to retrieve the certificate that's gonna be used in the handshake. Not me hyping up a callback but honestly? Iconic behavior ✨

The callback will take control only if a certificate is requested by the peer. No request, no callback, that's the rule bestie.

And listen β€” you are advised to use gnutls_certificate_set_retrieve_function2() instead, because it is much more efficient in the processing it requires from gnutls. Lowkey that's a glow-up, take the hint πŸ™ˆ

The callback's function prototype is:

int (*callback)(gnutls_session_t,
   const gnutls_datum_t* req_ca_dn,
   int nreqs,
   const gnutls_pk_algorithm_t* pk_algos,
   int pk_algos_length,
   gnutls_retr2_st* st);

Let's break down the cast of characters, because they all matter:

  • req_ca_dn is only used in X.509 certificates. It contains a list with the CA names that the server considers trusted. This is a hint, and typically the client should send a certificate that is signed by one of these CAs. These names, when available, are DER encoded. To get a more meaningful value, use the function gnutls_x509_rdn_get() πŸŽ€
  • pk_algos contains a list with the server's acceptable public key algorithms. The certificate you return should support the server's given algorithms β€” no cap, she's picky about who she talks to πŸ’…
  • st should contain the certificates and private keys πŸ”‘

If the callback function is provided, then gnutls will call it, in the handshake, after the certificate request message has been received. Timing is everything bestie ⏰

In server side, pk_algos and req_ca_dn are NULL. Yeah, they just ghost you over there 😭

Now the rules of the game:

  • The callback function should set the certificate list to be sent, and return 0 on success βœ…
  • If no certificate was selected, then the number of certificates should be set to zero
  • The value (-1) indicates error, and the handshake will be terminated 🚨 (so like, be careful, that's the dramatic one)
  • If both certificates are set in the credentials and a callback is available, the callback takes predence. Callback wins, she ate and left no crumbs πŸ‘‘

⭐ SINCE ⭐

3.0 β€” she's been around, she's a classic, respect the elders 🫢


🌈 REPORTING BUGS 🌈

Found a bug? Tell the people, they wanna know fr fr:


Copyright Β© 2001-2023 Free Software Foundation, Inc., and others.

Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. That's the deal, and honestly? Generous queen behavior πŸ‘‘


πŸ“ SEE ALSO πŸ“

The full documentation for gnutls is maintained as a Texinfo manual. If the /usr/share/doc/gnutls/ directory does not contain the HTML form, visit

https://www.gnutls.org/manual/

And that's the whole page bestie, you're officially fluent in certificate retrieve callbacks πŸ’…βœ¨

This little masterpiece came from the gnutls manual, version 3.8.13 β€” go forth, set your callbacks, and slay πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from