trousers/trousers-0.3.1-use-tpm-emu.patch
2008-12-16 23:19:45 +00:00

81 lines
2.3 KiB
Diff

--- trousers-0.3.1/src/tddl/tddl.c~ 2006-06-08 20:23:34.000000000 +0100
+++ trousers-0.3.1/src/tddl/tddl.c 2008-09-27 10:12:27.000000000 +0100
@@ -15,6 +15,8 @@
#include <errno.h>
#include <string.h>
#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
#include "trousers/tss.h"
#include "trousers_types.h"
@@ -22,14 +24,16 @@
#include "tcslog.h"
#include "tddl.h"
-struct tpm_device_node tpm_device_nodes[] = {
- {"/dev/tpm0", TDDL_UNDEF, TDDL_UNDEF},
- {"/udev/tpm0", TDDL_UNDEF, TDDL_UNDEF},
- {"/dev/tpm", TDDL_UNDEF, TDDL_UNDEF},
- {NULL, 0, 0}
+static struct tpm_device_node tpm_device_nodes[] = {
+ {"/dev/tpm0", TDDL_TYPE_FILE, TDDL_UNDEF, TDDL_UNDEF},
+ {"/udev/tpm0", TDDL_TYPE_FILE, TDDL_UNDEF, TDDL_UNDEF},
+ {"/dev/tpm", TDDL_TYPE_FILE, TDDL_UNDEF, TDDL_UNDEF},
+ {"/var/run/tpm/tpmd_socket:0", TDDL_TYPE_SOCKET, TDDL_TRANSMIT_RW,
+ TDDL_UNDEF},
+ {NULL, 0, 0, 0}
};
-struct tpm_device_node *opened_device = NULL;
+static struct tpm_device_node *opened_device = NULL;
BYTE txBuffer[TDDL_TXBUF_SIZE];
@@ -40,12 +44,30 @@ open_device(void)
/* tpm_device_paths is filled out in tddl.h */
for (i = 0; tpm_device_nodes[i].path != NULL; i++) {
+ int fd = -1;
errno = 0;
- if ((tpm_device_nodes[i].fd = open(tpm_device_nodes[i].path, O_RDWR)) < 0)
+
+ if (tpm_device_nodes[i].type == TDDL_TYPE_FILE)
+ fd = open(tpm_device_nodes[i].path, O_RDWR);
+ else if (tpm_device_nodes[i].type == TDDL_TYPE_SOCKET) {
+ struct sockaddr_un addr;
+
+ fd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (fd >= 0) {
+ addr.sun_family = AF_UNIX;
+ strncpy(addr.sun_path, tpm_device_nodes[i].path,
+ sizeof(addr.sun_path));
+ if (connect(fd, (void *)&addr, sizeof(addr)) < 0) {
+ close(fd);
+ fd = -1;
+ }
+ }
+ }
+ if (fd < 0)
continue;
-
+ tpm_device_nodes[i].fd = fd;
opened_device = &(tpm_device_nodes[i]);
- return opened_device->fd;
+ return fd;
}
return -1;
--- trousers-0.3.1/src/include/tddl.h~ 2005-10-25 04:01:07.000000000 +0100
+++ trousers-0.3.1/src/include/tddl.h 2008-09-27 10:00:20.000000000 +0100
@@ -14,6 +14,9 @@
struct tpm_device_node {
char *path;
+#define TDDL_TYPE_FILE 1
+#define TDDL_TYPE_SOCKET 2
+ int type;
#define TDDL_TRANSMIT_IOCTL 1
#define TDDL_TRANSMIT_RW 2
int transmit;