Imported Upstream version 2.3.1
[platform/upstream/gpg2.git] / tpm2d / tpm2daemon.h
1 /* tpm2daemon.h - Global definitions for the TPM2D
2  * Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
3  * Copyright (C) 2021 James Bottomley <James.Bottomley@HansenPartnership.com>
4  *
5  * This file is part of GnuPG.
6  *
7  * GnuPG is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * GnuPG is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, see <https://www.gnu.org/licenses/>.
19  * SPDX-License-Identifier: GPL-3.0-or-later
20  */
21
22 #ifndef TPM2DAEMON_H
23 #define TPM2DAEMON_H
24
25 #ifdef GPG_ERR_SOURCE_DEFAULT
26 #error GPG_ERR_SOURCE_DEFAULT already defined
27 #endif
28 /* FIXME: Replace this hard coded value as soon as we require a newer
29  *        libgpg-error.  */
30 #define GPG_ERR_SOURCE_DEFAULT  16 /* GPG_ERR_SOURCE_TPM2 */
31 #include <gpg-error.h>
32
33 #include <time.h>
34 #include <gcrypt.h>
35 #include "../common/util.h"
36 #include "../common/sysutils.h"
37
38 /* Maximum length of a digest.  */
39 #define MAX_DIGEST_LEN 64
40
41
42
43 /* A large struct name "opt" to keep global flags. */
44 EXTERN_UNLESS_MAIN_MODULE
45 struct
46 {
47   unsigned int debug; /* Debug flags (DBG_foo_VALUE). */
48   int verbose;        /* Verbosity level. */
49   int quiet;          /* Be as quiet as possible. */
50   unsigned long parent;       /* TPM parent */
51 } opt;
52
53
54 #define DBG_MPI_VALUE     2     /* debug mpi details */
55 #define DBG_CRYPTO_VALUE  4     /* debug low level crypto */
56 #define DBG_IPC_VALUE     1024
57
58 #define DBG_CRYPTO  (opt.debug & DBG_CRYPTO_VALUE)
59 #define DBG_MEMORY  (opt.debug & DBG_MEMORY_VALUE)
60
61 struct server_local_s;
62
63 struct server_control_s
64 {
65   /* Private data used to fire up the connection thread.  We use this
66      structure do avoid an extra allocation for just a few bytes. */
67   struct {
68     gnupg_fd_t fd;
69   } thread_startup;
70
71   /* Local data of the server; used only in command.c. */
72   struct server_local_s *server_local;
73
74   /* The application context used with this connection or NULL if none
75      associated.  Note that this is shared with the other connections:
76      All connections accessing the same reader are using the same
77      application context. */
78   struct assuan_context_s *ctx;
79
80   /* Helper to store the value we are going to sign */
81   struct
82   {
83     unsigned char *value;
84     int valuelen;
85   } in_data;
86 };
87
88 typedef struct app_ctx_s *app_t;
89
90 /*-- tpm2daemon.c --*/
91 void tpm2d_exit (int rc);
92
93 /*-- command.c --*/
94 gpg_error_t initialize_module_command (void);
95 int  tpm2d_command_handler (ctrl_t, int);
96 void send_client_notifications (app_t app, int removal);
97 void tpm2d_kick_the_loop (void);
98 int get_active_connection_count (void);
99
100 #endif /*TPM2DAEMON_H*/