Author: David Woodhouse <[email protected]>
Description: Use TPM emulator if it's available and no hardware is.

diff -Naurp trousers.orig/src/include/tddl.h trousers/src/include/tddl.h
--- trousers.orig/src/include/tddl.h    2009-06-08 15:53:06.000000000 +0000
+++ trousers/src/include/tddl.h 2009-07-16 14:34:45.000000000 +0000
@@ -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;
diff -Naurp trousers.orig/src/tddl/tddl.c trousers/src/tddl/tddl.c
--- trousers.orig/src/tddl/tddl.c       2009-06-08 15:53:06.000000000 +0000
+++ trousers/src/tddl/tddl.c    2009-07-16 14:34:45.000000000 +0000
@@ -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;

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
TrouSerS-tech mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/trousers-tech

Reply via email to