gnutls.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * OpenConnect (SSL + DTLS) VPN client
  3. *
  4. * Copyright © 2008-2015 Intel Corporation.
  5. *
  6. * Author: David Woodhouse <dwmw2@infradead.org>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public License
  10. * version 2.1, as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. */
  17. #ifndef __OPENCONNECT_GNUTLS_H__
  18. #define __OPENCONNECT_GNUTLS_H__
  19. #include "openconnect-internal.h"
  20. #include <gnutls/gnutls.h>
  21. #include <gnutls/pkcs12.h>
  22. #include <gnutls/abstract.h>
  23. int load_tpm1_key(struct openconnect_info *vpninfo, struct cert_info *certinfo,
  24. gnutls_datum_t *fdata, gnutls_privkey_t *pkey, gnutls_datum_t *pkey_sig);
  25. void release_tpm1_ctx(struct openconnect_info *info, struct cert_info *certinfo);
  26. int load_tpm2_key(struct openconnect_info *vpninfo, struct cert_info *certinfo,
  27. gnutls_datum_t *fdata, gnutls_privkey_t *pkey, gnutls_datum_t *pkey_sig);
  28. void release_tpm2_ctx(struct openconnect_info *info, struct cert_info *certinfo);
  29. int install_tpm2_key(struct openconnect_info *vpninfo, struct cert_info *certinfo,
  30. gnutls_privkey_t *pkey, gnutls_datum_t *pkey_sig,
  31. unsigned int parent, int emptyauth, int legacy,
  32. gnutls_datum_t *privdata, gnutls_datum_t *pubdata);
  33. int tpm2_rsa_sign_hash_fn(gnutls_privkey_t key, gnutls_sign_algorithm_t algo,
  34. void *_certinfo, unsigned int flags,
  35. const gnutls_datum_t *data, gnutls_datum_t *sig);
  36. int tpm2_ec_sign_hash_fn(gnutls_privkey_t key, gnutls_sign_algorithm_t algo,
  37. void *_certinfo, unsigned int flags,
  38. const gnutls_datum_t *data, gnutls_datum_t *sig);
  39. int oc_pad_rsasig(struct openconnect_info *vpninfo, gnutls_sign_algorithm_t algo,
  40. unsigned char *buf, int size, const gnutls_datum_t *data, int keybits);
  41. uint16_t tpm2_key_curve(struct openconnect_info *vpninfo, struct cert_info *certinfo);
  42. int tpm2_rsa_key_bits(struct openconnect_info *vpninfo, struct cert_info *certinfo);
  43. /* GnuTLS 3.6.0+ provides this. We have our own for older GnuTLS. There is
  44. * also _gnutls_encode_ber_rs_raw() in some older versions, but there were
  45. * zero-padding bugs in that, and some of the... less diligently maintained
  46. * distributions (like Ubuntu even in 18.04) don't have the fix yet, two
  47. * years later. */
  48. #if GNUTLS_VERSION_NUMBER < 0x030600
  49. #define gnutls_encode_rs_value oc_gnutls_encode_rs_value
  50. int oc_gnutls_encode_rs_value(gnutls_datum_t *sig_value, const gnutls_datum_t *r, const gnutls_datum_t *s);
  51. #endif
  52. char *get_gnutls_cipher(gnutls_session_t session);
  53. /* Compile-time optimisable GnuTLS version check. We should never be
  54. * run against a version of GnuTLS which is *older* than the one we
  55. * were built again, but we might be run against a version which is
  56. * newer. So some ancient compatibility code *can* be dropped at
  57. * compile time. Likewise, if building against GnuTLS 2.x then we
  58. * can never be running against a 3.x library — the soname changed.
  59. *
  60. * This macro was added upstream, gnutls_check_version_numeric,
  61. * in 3.5.0 (see https://gitlab.com/gnutls/gnutls/commit/c8b40aeb) */
  62. #define gtls_ver(a,b,c) ( GNUTLS_VERSION_MAJOR >= (a) && \
  63. (GNUTLS_VERSION_NUMBER >= ( ((a) << 16) + ((b) << 8) + (c) ) || \
  64. gnutls_check_version(#a "." #b "." #c)))
  65. #ifndef gnutls_check_version_numeric
  66. #define gnutls_check_version_numeric gtls_ver
  67. #endif
  68. #endif /* __OPENCONNECT_GNUTLS_H__ */