gnutls.h 3.07 KB
Newer Older
Ted Zlatanov's avatar
Ted Zlatanov committed
1
/* GnuTLS glue for GNU Emacs.
Paul Eggert's avatar
Paul Eggert committed
2
   Copyright (C) 2010-2019 Free Software Foundation, Inc.
Ted Zlatanov's avatar
Ted Zlatanov committed
3 4 5 6 7

This file is part of GNU Emacs.

GNU Emacs is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
8 9
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
Ted Zlatanov's avatar
Ted Zlatanov committed
10 11 12 13 14 15 16

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
17
along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
Ted Zlatanov's avatar
Ted Zlatanov committed
18 19 20 21 22 23

#ifndef EMACS_GNUTLS_DEFINED
#define EMACS_GNUTLS_DEFINED

#ifdef HAVE_GNUTLS
#include <gnutls/gnutls.h>
24
#include <gnutls/x509.h>
Ted Zlatanov's avatar
Ted Zlatanov committed
25

26 27 28 29 30
#if 0x030000 <= GNUTLS_VERSION_NUMBER
# define HAVE_GNUTLS3
# include <gnutls/crypto.h>
#endif

31 32
#include "lisp.h"

33 34 35
/* This limits the attempts to handshake per process (connection).  It
   should work out to about one minute in asynchronous cases. */
#define GNUTLS_EMACS_HANDSHAKES_LIMIT 6000
36

Ted Zlatanov's avatar
Ted Zlatanov committed
37 38 39 40 41 42
typedef enum
{
  /* Initialization stages.  */
  GNUTLS_STAGE_EMPTY = 0,
  GNUTLS_STAGE_CRED_ALLOC,
  GNUTLS_STAGE_FILES,
43
  GNUTLS_STAGE_CALLBACKS,
Ted Zlatanov's avatar
Ted Zlatanov committed
44 45 46 47 48 49 50 51 52
  GNUTLS_STAGE_INIT,
  GNUTLS_STAGE_PRIORITY,
  GNUTLS_STAGE_CRED_SET,

  /* Handshake stages.  */
  GNUTLS_STAGE_HANDSHAKE_CANDO = GNUTLS_STAGE_CRED_SET,
  GNUTLS_STAGE_TRANSPORT_POINTERS_SET,
  GNUTLS_STAGE_HANDSHAKE_TRIED,

Paul Eggert's avatar
Paul Eggert committed
53
  GNUTLS_STAGE_READY
Ted Zlatanov's avatar
Ted Zlatanov committed
54 55
} gnutls_initstage_t;

56
#define GNUTLS_EMACS_ERROR_NOT_LOADED (GNUTLS_E_APPLICATION_ERROR_MIN + 1)
Ted Zlatanov's avatar
Ted Zlatanov committed
57 58 59 60
#define GNUTLS_EMACS_ERROR_INVALID_TYPE GNUTLS_E_APPLICATION_ERROR_MIN

#define GNUTLS_INITSTAGE(proc) (XPROCESS (proc)->gnutls_initstage)

61 62
#define GNUTLS_PROCESS_USABLE(proc) \
  (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_READY)
Ted Zlatanov's avatar
Ted Zlatanov committed
63

64 65 66 67
#define GNUTLS_LOG(level, max, string)				\
  do {								\
    if ((level) <= (max))					\
      gnutls_log_function (level, "(Emacs) " string);		\
68
  } while (false)
69

70 71 72 73
#define GNUTLS_LOG2(level, max, string, extra)			\
  do {								\
    if ((level) <= (max))					\
      gnutls_log_function2 (level, "(Emacs) " string, extra);	\
74
  } while (false)
75

76 77 78
#define GNUTLS_LOG2i(level, max, string, extra)			\
  do {								\
    if ((level) <= (max))					\
79
      message ("gnutls.c: [%d] %s %d", level, string, extra);	\
80
  } while (false)
81

82 83 84 85
extern ptrdiff_t
emacs_gnutls_write (struct Lisp_Process *proc, const char *buf, ptrdiff_t nbyte);
extern ptrdiff_t
emacs_gnutls_read (struct Lisp_Process *proc, char *buf, ptrdiff_t nbyte);
Ted Zlatanov's avatar
Ted Zlatanov committed
86

87
extern ptrdiff_t emacs_gnutls_record_check_pending (gnutls_session_t state);
88
#ifdef WINDOWSNT
89
extern void emacs_gnutls_transport_set_errno (gnutls_session_t state, int err);
90
extern int w32_gnutls_rnd (gnutls_rnd_level_t, void *, size_t);
91
#endif
92
extern Lisp_Object emacs_gnutls_deinit (Lisp_Object);
93
extern Lisp_Object emacs_gnutls_global_init (void);
94
extern int gnutls_try_handshake (struct Lisp_Process *p);
95
extern Lisp_Object gnutls_verify_boot (Lisp_Object proc, Lisp_Object proplist);
96

97
#endif
Ted Zlatanov's avatar
Ted Zlatanov committed
98

Ted Zlatanov's avatar
Ted Zlatanov committed
99 100
extern void syms_of_gnutls (void);

Ted Zlatanov's avatar
Ted Zlatanov committed
101
#endif