xref: /netbsd-src/crypto/external/cpl/trousers/dist/src/include/tcsd.h (revision af56d1fe9956bd7c616e18c1b7f025f464618471)
1 
2 /*
3  * Licensed Materials - Property of IBM
4  *
5  * trousers - An open source TCG Software Stack
6  *
7  * (C) Copyright International Business Machines Corp. 2004
8  *
9  */
10 
11 
12 #ifndef _TCSD_H_
13 #define _TCSD_H_
14 
15 #include <signal.h>
16 
17 #include "rpc_tcstp.h"
18 
19 /* Platform Class structures */
20 struct platform_class
21 {
22 	unsigned int simpleID;	/* Platform specific spec identifier */
23 	unsigned int classURISize;	/* Size of the classURI */
24 	char *classURI;	/* Specific spec. Can be NULL */
25 	struct platform_class *next;
26 };
27 
28 /* config structures */
29 struct tcsd_config
30 {
31 	int port;		/* port the TCSD will listen on */
32 	unsigned int num_threads;	/* max number of threads the TCSD allows simultaneously */
33 	char *system_ps_dir;	/* the directory the system PS file sits in */
34 	char *system_ps_file;	/* the name of the system PS file */
35 	char *firmware_log_file;/* the name of the firmware PCR event file */
36 	char *kernel_log_file;	/* the name of the kernel PCR event file */
37 	unsigned int kernel_pcrs;	/* bitmask of PCRs the kernel controls */
38 	unsigned int firmware_pcrs;	/* bitmask of PCRs the firmware controls */
39 	char *platform_cred;		/* location of the platform credential */
40 	char *conformance_cred;		/* location of the conformance credential */
41 	char *endorsement_cred;		/* location of the endorsement credential */
42 	int remote_ops[TCSD_MAX_NUM_ORDS];	/* array of ordinals executable by remote hosts */
43 	unsigned int unset;	/* bitmask of options which are still unset */
44 	int exclusive_transport; /* allow applications to open exclusive transport sessions with
45 				    the TPM and enforce their exclusivity (possible DOS issue) */
46 	struct platform_class *host_platform_class; /* Host platform class of this TCS System */
47 	struct platform_class *all_platform_classes;	/* List of platform classes
48 							of this TCS System */
49 };
50 
51 #define TCSD_DEFAULT_CONFIG_FILE	ETC_PREFIX "/tcsd.conf"
52 extern char *tcsd_config_file;
53 
54 #ifdef __NetBSD__
55 #define TSS_USER_NAME		"_tss"
56 #define TSS_GROUP_NAME		"_tss"
57 #else
58 #define TSS_USER_NAME		"tss"
59 #define TSS_GROUP_NAME		"tss"
60 #endif
61 
62 #define TCSD_DEFAULT_MAX_THREADS	10
63 #define TCSD_DEFAULT_SYSTEM_PS_FILE	VAR_PREFIX "/lib/tpm/system.data"
64 #define TCSD_DEFAULT_SYSTEM_PS_DIR	VAR_PREFIX "/lib/tpm"
65 #define TCSD_DEFAULT_FIRMWARE_LOG_FILE	"/sys/kernel/security/tpm0/binary_bios_measurements"
66 #define TCSD_DEFAULT_KERNEL_LOG_FILE	"/sys/kernel/security/ima/binary_runtime_measurements"
67 #define TCSD_DEFAULT_FIRMWARE_PCRS	0x00000000
68 #define TCSD_DEFAULT_KERNEL_PCRS	0x00000000
69 
70 /* This will change when a system with more than 32 PCR's exists */
71 #define TCSD_MAX_PCRS			32
72 
73 /* this is the 2nd param passed to the listen() system call */
74 #define TCSD_MAX_SOCKETS_QUEUED		50
75 #define TCSD_TXBUF_SIZE			1024
76 
77 /* The Available Tcs Platform Classes */
78 struct tcg_platform_spec {
79 	char *name;
80 	TPM_PLATFORM_SPECIFIC specNo;
81 	char *specURI;
82 };
83 
84 /* The Specific URI's for the platforms specs on TCG website */
85 #define TPM_PS_PC_11_URI	"https://www.trustedcomputinggroup.org/groups/pc_client/TCG_PCSpecificSpecification_v1_1.pdf"
86 #define TPM_PS_PC_12_URI	"https://www.trustedcomputinggroup.org/specs/PCClient/TCG_PCClientImplementationforBIOS_1-20_1-00.pdf"
87 #define TPM_PS_PDA_12_URI	"https://www.trustedcomputinggroup.org/specs/mobilephone/tcg-mobile-reference-architecture-1.0.pdf"
88 #define TPM_PS_Server_12_URI	"https://www.trustedcomputinggroup.org/specs/Server/TCG_Generic_Server_Specification_v1_0_rev0_8.pdf"
89 #define TPM_PS_Mobile_12_URI	"https://www.trustedcomputinggroup.org/specs/mobilephone/tcg-mobile-reference-architecture-1.0.pdf"
90 
91 /* for detecting whether an option has been set */
92 #define TCSD_OPTION_PORT		0x0001
93 #define TCSD_OPTION_MAX_THREADS		0x0002
94 #define TCSD_OPTION_FIRMWARE_PCRS	0x0004
95 #define TCSD_OPTION_KERNEL_PCRS		0x0008
96 #define TCSD_OPTION_SYSTEM_PSFILE	0x0010
97 #define TCSD_OPTION_KERNEL_LOGFILE	0x0020
98 #define TCSD_OPTION_FIRMWARE_LOGFILE	0x0040
99 #define TCSD_OPTION_PLATFORM_CRED	0x0080
100 #define TCSD_OPTION_CONFORMANCE_CRED	0x0100
101 #define TCSD_OPTION_ENDORSEMENT_CRED	0x0200
102 #define TCSD_OPTION_REMOTE_OPS		0x0400
103 #define TCSD_OPTION_EXCLUSIVE_TRANSPORT	0x0800
104 #define TCSD_OPTION_HOST_PLATFORM_CLASS	0x1000
105 
106 #define TSS_TCP_RPC_MAX_DATA_LEN	1048576
107 #define TSS_TCP_RPC_BAD_PACKET_TYPE	0x10000000
108 
109 enum tcsd_config_option_code {
110 	opt_port = 1,
111 	opt_max_threads,
112 	opt_system_ps_file,
113 	opt_firmware_log,
114 	opt_kernel_log,
115 	opt_firmware_pcrs,
116 	opt_kernel_pcrs,
117 	opt_platform_cred,
118 	opt_conformance_cred,
119 	opt_endorsement_cred,
120 	opt_remote_ops,
121 	opt_exclusive_transport,
122 	opt_host_platform_class,
123 	opt_all_platform_classes
124 };
125 
126 struct tcsd_config_options {
127 	char *name;
128 	enum tcsd_config_option_code option;
129 };
130 
131 extern struct tcsd_config tcsd_options;
132 
133 TSS_RESULT conf_file_init(struct tcsd_config *);
134 void	   conf_file_final(struct tcsd_config *);
135 TSS_RESULT ps_dirs_init();
136 void	   tcsd_signal_handler(int);
137 
138 /* threading structures */
139 struct tcsd_thread_data
140 {
141 	int sock;
142 	UINT32 context;
143 	THREAD_TYPE *thread_id;
144 	char *hostname;
145 	struct tcsd_comm_data comm;
146 };
147 
148 struct tcsd_thread_mgr
149 {
150 	MUTEX_DECLARE(lock);
151 	struct tcsd_thread_data *thread_data;
152 
153 	int shutdown;
154 	UINT32 num_active_threads;
155 	UINT32 max_threads;
156 };
157 
158 TSS_RESULT tcsd_threads_init();
159 TSS_RESULT tcsd_threads_final();
160 TSS_RESULT tcsd_thread_create(int, char *);
161 void	   *tcsd_thread_run(void *);
162 void	   thread_signal_init();
163 
164 /* signal handling */
165 struct sigaction tcsd_sa_int;
166 struct sigaction tcsd_sa_chld;
167 
168 #endif
169