Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: src/tspi/ps/tspps.c

Issue 3581012: Upgrade from trousers 0.3.3 to 0.3.6 and from testsuite 0.2 to 0.3. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/trousers.git
Patch Set: git cl push Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/tspi/obj_rsakey.c ('k') | src/tspi/rpc/hosttable.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Licensed Materials - Property of IBM 3 * Licensed Materials - Property of IBM
4 * 4 *
5 * trousers - An open source TCG Software Stack 5 * trousers - An open source TCG Software Stack
6 * 6 *
7 * (C) Copyright International Business Machines Corp. 2004-2006 7 * (C) Copyright International Business Machines Corp. 2004-2006
8 * 8 *
9 */ 9 */
10 10
11 11
12 #include <stdio.h> 12 #include <stdio.h>
13 #include <stdlib.h> 13 #include <stdlib.h>
14 #include <string.h> 14 #include <string.h>
15 #include <unistd.h> 15 #include <unistd.h>
16 #include <errno.h> 16 #include <errno.h>
17 #include <pwd.h> 17 #include <pwd.h>
18 #include <sys/types.h> 18 #include <sys/types.h>
19 #include <sys/file.h> 19 #include <sys/file.h>
20 #include <sys/stat.h> 20 #include <sys/stat.h>
21 #include <assert.h> 21 #include <assert.h>
22 #include <fcntl.h>
23 #include <limits.h>
24 #include <netdb.h>
25 #if defined (HAVE_BYTEORDER_H)
26 #include <sys/byteorder.h>
27 #elif defined(HAVE_ENDIAN_H)
28 #include <endian.h>
29 #define LE_16 htole16
30 #define LE_32 htole32
31 #define LE_64 htole64
32 #else
33 #define LE_16(x) (x)
34 #define LE_32(x) (x)
35 #define LE_64(x) (x)
36 #endif
22 37
23 #include "trousers/tss.h" 38 #include "trousers/tss.h"
24 #include "trousers/trousers.h" 39 #include "trousers/trousers.h"
25 #include "trousers_types.h" 40 #include "trousers_types.h"
26 #include "tcs_tsp.h" 41 #include "tcs_tsp.h"
27 #include "spi_utils.h" 42 #include "spi_utils.h"
28 #include "tspps.h" 43 #include "tspps.h"
29 #include "tsplog.h" 44 #include "tsplog.h"
30 45
31 static int user_ps_fd = -1; 46 static int user_ps_fd = -1;
32 static MUTEX_DECLARE_INIT(user_ps_lock); 47 static MUTEX_DECLARE_INIT(user_ps_lock);
33 #if (defined (__FreeBSD__) || defined (__OpenBSD__)) 48 #if (defined (__FreeBSD__) || defined (__OpenBSD__))
34 static MUTEX_DECLARE_INIT(user_ps_path); 49 static MUTEX_DECLARE_INIT(user_ps_path);
35 #endif 50 #endif
51 #if defined (SOLARIS)
52 static struct flock fl = {
53 0,
54 0,
55 0,
56 0,
57 0,
58 0,
59 {0, 0, 0, 0}
60 };
61 #endif
36 62
37 63
38 /* 64 /*
39 * Determine the default path to the persistent storage file and create it if it doesn't exist. 65 * Determine the default path to the persistent storage file and create it if it doesn't exist.
40 */ 66 */
41 TSS_RESULT 67 TSS_RESULT
42 get_user_ps_path(char **file) 68 get_user_ps_path(char **file)
43 { 69 {
44 TSS_RESULT result; 70 TSS_RESULT result;
45 char *file_name = NULL, *home_dir = NULL; 71 char *file_name = NULL, *home_dir = NULL;
46 struct passwd *pwp; 72 struct passwd *pwp;
47 #if (defined (__linux) || defined (linux)) 73 #if (defined (__linux) || defined (linux) || defined(__GLIBC__))
48 struct passwd pw; 74 struct passwd pw;
49 #endif 75 #endif
50 struct stat stat_buf; 76 struct stat stat_buf;
51 char buf[PASSWD_BUFSIZE]; 77 char buf[PASSWD_BUFSIZE];
52 uid_t euid; 78 uid_t euid;
53 int rc; 79 int rc;
54 80
55 if ((file_name = getenv("TSS_USER_PS_FILE"))) { 81 if ((file_name = getenv("TSS_USER_PS_FILE"))) {
56 *file = strdup(file_name); 82 *file = strdup(file_name);
57 return (*file) ? TSS_SUCCESS : TSPERR(TSS_E_OUTOFMEMORY); 83 return (*file) ? TSS_SUCCESS : TSPERR(TSS_E_OUTOFMEMORY);
58 } 84 }
59 #if (defined (__FreeBSD__) || defined (__OpenBSD__)) 85 #if (defined (__FreeBSD__) || defined (__OpenBSD__))
60 MUTEX_LOCK(user_ps_path); 86 MUTEX_LOCK(user_ps_path);
61 #endif 87 #endif
62 88
63 euid = geteuid(); 89 euid = geteuid();
64 90
91 #if defined (SOLARIS)
92 /*
93 * Solaris keeps user PS in a local directory instead of
94 * in the user's home directory, which may be shared
95 * by multiple systems.
96 *
97 * The directory path on Solaris is /var/tpm/userps/[EUID]/
98 */
99 rc = snprintf(buf, sizeof (buf), "%s/%d", TSS_USER_PS_DIR, euid);
100 #else
65 setpwent(); 101 setpwent();
66 while (1) { 102 while (1) {
67 #if (defined (__linux) || defined (linux)) 103 #if (defined (__linux) || defined (linux) || defined(__GLIBC__))
68 rc = getpwent_r(&pw, buf, PASSWD_BUFSIZE, &pwp); 104 rc = getpwent_r(&pw, buf, PASSWD_BUFSIZE, &pwp);
69 if (rc) { 105 if (rc) {
70 LogDebugFn("USER PS: Error getting path to home director y: getpwent_r: %s", 106 LogDebugFn("USER PS: Error getting path to home director y: getpwent_r: %s",
71 strerror(rc)); 107 strerror(rc));
72 endpwent(); 108 endpwent();
73 return TSPERR(TSS_E_INTERNAL_ERROR); 109 return TSPERR(TSS_E_INTERNAL_ERROR);
74 } 110 }
75 111
76 #elif (defined (__FreeBSD__) || defined (__OpenBSD__)) 112 #elif (defined (__FreeBSD__) || defined (__OpenBSD__))
77 if ((pwp = getpwent()) == NULL) { 113 if ((pwp = getpwent()) == NULL) {
78 LogDebugFn("USER PS: Error getting path to home director y: getpwent: %s", 114 LogDebugFn("USER PS: Error getting path to home director y: getpwent: %s",
79 strerror(rc)); 115 strerror(rc));
80 endpwent(); 116 endpwent();
81 MUTEX_UNLOCK(user_ps_path); 117 MUTEX_UNLOCK(user_ps_path);
82 return TSPERR(TSS_E_INTERNAL_ERROR); 118 return TSPERR(TSS_E_INTERNAL_ERROR);
83 } 119 }
84 #endif 120 #endif
85 if (euid == pwp->pw_uid) { 121 if (euid == pwp->pw_uid) {
86 home_dir = strdup(pwp->pw_dir); 122 home_dir = strdup(pwp->pw_dir);
87 break; 123 break;
88 } 124 }
89 } 125 }
90 endpwent(); 126 endpwent();
91 127
92 if (!home_dir) 128 if (!home_dir)
93 return TSPERR(TSS_E_OUTOFMEMORY); 129 return TSPERR(TSS_E_OUTOFMEMORY);
94 130
95 /* Tack on TSS_USER_PS_DIR and see if it exists */ 131 /* Tack on TSS_USER_PS_DIR and see if it exists */
96 » rc = snprintf(buf, PASSWD_BUFSIZE, "%s/%s", home_dir, TSS_USER_PS_DIR); 132 » rc = snprintf(buf, sizeof (buf), "%s/%s", home_dir, TSS_USER_PS_DIR);
97 » if (rc == PASSWD_BUFSIZE) { 133 #endif /* SOLARIS */
134 » if (rc == sizeof (buf)) {
98 LogDebugFn("USER PS: Path to file too long! (> %d bytes)", PASSW D_BUFSIZE); 135 LogDebugFn("USER PS: Path to file too long! (> %d bytes)", PASSW D_BUFSIZE);
99 result = TSPERR(TSS_E_INTERNAL_ERROR); 136 result = TSPERR(TSS_E_INTERNAL_ERROR);
100 goto done; 137 goto done;
101 } 138 }
102 139
103 errno = 0; 140 errno = 0;
104 if ((rc = stat(buf, &stat_buf)) == -1) { 141 if ((rc = stat(buf, &stat_buf)) == -1) {
105 if (errno == ENOENT) { 142 if (errno == ENOENT) {
106 errno = 0; 143 errno = 0;
107 » » » /* Create the base directory, $HOME/.trousers */ 144 » » » /* Create the user's ps directory if it is not there. */
108 if ((rc = mkdir(buf, 0700)) == -1) { 145 if ((rc = mkdir(buf, 0700)) == -1) {
109 LogDebugFn("USER PS: Error creating dir: %s: %s" , buf, 146 LogDebugFn("USER PS: Error creating dir: %s: %s" , buf,
110 strerror(errno)); 147 strerror(errno));
111 result = TSPERR(TSS_E_INTERNAL_ERROR); 148 result = TSPERR(TSS_E_INTERNAL_ERROR);
112 goto done; 149 goto done;
113 } 150 }
114 } else { 151 } else {
115 LogDebugFn("USER PS: Error stating dir: %s: %s", buf, st rerror(errno)); 152 LogDebugFn("USER PS: Error stating dir: %s: %s", buf, st rerror(errno));
116 result = TSPERR(TSS_E_INTERNAL_ERROR); 153 result = TSPERR(TSS_E_INTERNAL_ERROR);
117 goto done; 154 goto done;
118 } 155 }
119 } 156 }
120 157
121 /* Directory exists or has been created, return the path to the file */ 158 /* Directory exists or has been created, return the path to the file */
122 » rc = snprintf(buf, PASSWD_BUFSIZE, "%s/%s/%s", home_dir, TSS_USER_PS_DIR , 159 #if defined (SOLARIS)
160 » rc = snprintf(buf, sizeof (buf), "%s/%d/%s", TSS_USER_PS_DIR, euid,
123 TSS_USER_PS_FILE); 161 TSS_USER_PS_FILE);
124 » if (rc == PASSWD_BUFSIZE) { 162 #else
125 » » LogDebugFn("USER PS: Path to file too long! (> %d bytes)", PASSW D_BUFSIZE); 163 » rc = snprintf(buf, sizeof (buf), "%s/%s/%s", home_dir, TSS_USER_PS_DIR,
164 » » TSS_USER_PS_FILE);
165 #endif
166 » if (rc == sizeof (buf)) {
167 » » LogDebugFn("USER PS: Path to file too long! (> %d bytes)", sizeo f (buf));
126 } else 168 } else
127 *file = strdup(buf); 169 *file = strdup(buf);
128 170
129 result = (*file) ? TSS_SUCCESS : TSPERR(TSS_E_OUTOFMEMORY); 171 result = (*file) ? TSS_SUCCESS : TSPERR(TSS_E_OUTOFMEMORY);
130 done: 172 done:
131 free(home_dir); 173 free(home_dir);
132 return result; 174 return result;
133 } 175 }
134 176
135 TSS_RESULT 177 TSS_RESULT
136 get_file(int *fd) 178 get_file(int *fd)
137 { 179 {
138 TSS_RESULT result; 180 TSS_RESULT result;
139 int rc = 0; 181 int rc = 0;
140 char *file_name = NULL; 182 char *file_name = NULL;
141 183
142 MUTEX_LOCK(user_ps_lock); 184 MUTEX_LOCK(user_ps_lock);
143 185
144 /* check the global file handle first. If it exists, lock it and return */ 186 /* check the global file handle first. If it exists, lock it and return */
145 if (user_ps_fd != -1) { 187 if (user_ps_fd != -1) {
188 #if defined (SOLARIS)
189 fl.l_type = F_WRLCK;
190 if ((rc = fcntl(user_ps_fd, F_SETLKW, &fl))) {
191 #else
146 if ((rc = flock(user_ps_fd, LOCK_EX))) { 192 if ((rc = flock(user_ps_fd, LOCK_EX))) {
193 #endif /* SOLARIS */
147 LogDebug("USER PS: failed to lock file: %s", strerror(er rno)); 194 LogDebug("USER PS: failed to lock file: %s", strerror(er rno));
148 MUTEX_UNLOCK(user_ps_lock); 195 MUTEX_UNLOCK(user_ps_lock);
149 return TSPERR(TSS_E_INTERNAL_ERROR); 196 return TSPERR(TSS_E_INTERNAL_ERROR);
150 } 197 }
151
152 *fd = user_ps_fd; 198 *fd = user_ps_fd;
153 return TSS_SUCCESS; 199 return TSS_SUCCESS;
154 } 200 }
155 201
156 /* open and lock the file */ 202 /* open and lock the file */
157 if ((result = get_user_ps_path(&file_name))) { 203 if ((result = get_user_ps_path(&file_name))) {
158 LogDebugFn("USER PS: error getting file path"); 204 LogDebugFn("USER PS: error getting file path");
159 MUTEX_UNLOCK(user_ps_lock); 205 MUTEX_UNLOCK(user_ps_lock);
160 return result; 206 return result;
161 } 207 }
162 208
163 user_ps_fd = open(file_name, O_CREAT|O_RDWR, 0600); 209 user_ps_fd = open(file_name, O_CREAT|O_RDWR, 0600);
164 if (user_ps_fd < 0) { 210 if (user_ps_fd < 0) {
165 LogDebug("USER PS: open of %s failed: %s", file_name, strerror(e rrno)); 211 LogDebug("USER PS: open of %s failed: %s", file_name, strerror(e rrno));
166 free(file_name); 212 free(file_name);
167 MUTEX_UNLOCK(user_ps_lock); 213 MUTEX_UNLOCK(user_ps_lock);
168 return TSPERR(TSS_E_INTERNAL_ERROR); 214 return TSPERR(TSS_E_INTERNAL_ERROR);
169 } 215 }
170 216 #if defined (SOLARIS)
217 » fl.l_type = F_WRLCK;
218 » if ((rc = fcntl(user_ps_fd, F_SETLKW, &fl))) {
219 #else
171 if ((rc = flock(user_ps_fd, LOCK_EX))) { 220 if ((rc = flock(user_ps_fd, LOCK_EX))) {
221 #endif /* SOLARIS */
172 LogDebug("USER PS: failed to get lock of %s: %s", file_name, str error(errno)); 222 LogDebug("USER PS: failed to get lock of %s: %s", file_name, str error(errno));
173 free(file_name); 223 free(file_name);
174 close(user_ps_fd); 224 close(user_ps_fd);
175 user_ps_fd = -1; 225 user_ps_fd = -1;
176 MUTEX_UNLOCK(user_ps_lock); 226 MUTEX_UNLOCK(user_ps_lock);
177 return TSPERR(TSS_E_INTERNAL_ERROR); 227 return TSPERR(TSS_E_INTERNAL_ERROR);
178 } 228 }
179 229
180 *fd = user_ps_fd; 230 *fd = user_ps_fd;
181 free(file_name); 231 free(file_name);
182 return TSS_SUCCESS; 232 return TSS_SUCCESS;
183 } 233 }
184 234
185 int 235 int
186 put_file(int fd) 236 put_file(int fd)
187 { 237 {
188 int rc = 0; 238 int rc = 0;
189 239
190 fsync(fd); 240 fsync(fd);
191 241
192 /* release the file lock */ 242 /* release the file lock */
243 #if defined (SOLARIS)
244 fl.l_type = F_UNLCK;
245 if ((rc = fcntl(fd, F_SETLKW, &fl))) {
246 #else
193 if ((rc = flock(fd, LOCK_UN))) { 247 if ((rc = flock(fd, LOCK_UN))) {
248 #endif /* SOLARIS */
194 LogDebug("USER PS: failed to unlock file: %s", strerror(errno)); 249 LogDebug("USER PS: failed to unlock file: %s", strerror(errno));
195 rc = -1; 250 rc = -1;
196 } 251 }
197 252
198 MUTEX_UNLOCK(user_ps_lock); 253 MUTEX_UNLOCK(user_ps_lock);
199 return rc; 254 return rc;
200 } 255 }
201 256
202 void 257 void
203 psfile_close(int fd) 258 psfile_close(int fd)
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 if (rc == ((off_t)-1)) { 413 if (rc == ((off_t)-1)) {
359 LogDebug("lseek: %s", strerror(errno)); 414 LogDebug("lseek: %s", strerror(errno));
360 return TSPERR(TSS_E_INTERNAL_ERROR); 415 return TSPERR(TSS_E_INTERNAL_ERROR);
361 } 416 }
362 417
363 rc = read(fd, &num_keys, sizeof(UINT32)); 418 rc = read(fd, &num_keys, sizeof(UINT32));
364 if (rc != sizeof(UINT32)) { 419 if (rc != sizeof(UINT32)) {
365 LogDebug("read of %zd bytes: %s", sizeof(UINT32), strerror(errno )); 420 LogDebug("read of %zd bytes: %s", sizeof(UINT32), strerror(errno ));
366 return TSPERR(TSS_E_INTERNAL_ERROR); 421 return TSPERR(TSS_E_INTERNAL_ERROR);
367 } 422 }
423 num_keys = LE_32(num_keys);
368 424
369 if (increment) 425 if (increment)
370 num_keys++; 426 num_keys++;
371 else 427 else
372 num_keys--; 428 num_keys--;
373 429
374 rc = lseek(fd, TSSPS_NUM_KEYS_OFFSET, SEEK_SET); 430 rc = lseek(fd, TSSPS_NUM_KEYS_OFFSET, SEEK_SET);
375 if (rc == ((off_t)-1)) { 431 if (rc == ((off_t)-1)) {
376 LogDebug("lseek: %s", strerror(errno)); 432 LogDebug("lseek: %s", strerror(errno));
377 return TSPERR(TSS_E_INTERNAL_ERROR); 433 return TSPERR(TSS_E_INTERNAL_ERROR);
378 } 434 }
379 435
436 num_keys = LE_32(num_keys);
380 if ((result = write_data(fd, (void *)&num_keys, sizeof(UINT32)))) { 437 if ((result = write_data(fd, (void *)&num_keys, sizeof(UINT32)))) {
381 LogDebug("%s", __FUNCTION__); 438 LogDebug("%s", __FUNCTION__);
382 return result; 439 return result;
383 } 440 }
384 441
385 return TSS_SUCCESS; 442 return TSS_SUCCESS;
386 } 443 }
387 444
388 /* Write the initial header (number of keys and PS version) to initialize a new file */ 445 /* Write the initial header (number of keys and PS version) to initialize a new file */
389 TSS_RESULT 446 TSS_RESULT
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 goto done; 548 goto done;
492 } 549 }
493 550
494 /* [TSS_UUID uuid_parent0 ] yes */ 551 /* [TSS_UUID uuid_parent0 ] yes */
495 if ((result = write_data(fd, (void *)parent_uuid, sizeof(TSS_UUID)))) { 552 if ((result = write_data(fd, (void *)parent_uuid, sizeof(TSS_UUID)))) {
496 LogDebug("%s", __FUNCTION__); 553 LogDebug("%s", __FUNCTION__);
497 goto done; 554 goto done;
498 } 555 }
499 556
500 /* [UINT16 pub_data_size0 ] yes */ 557 /* [UINT16 pub_data_size0 ] yes */
558 pub_key_size = LE_16(pub_key_size);
501 if ((result = write_data(fd, &pub_key_size, sizeof(UINT16)))) { 559 if ((result = write_data(fd, &pub_key_size, sizeof(UINT16)))) {
502 LogDebug("%s", __FUNCTION__); 560 LogDebug("%s", __FUNCTION__);
503 goto done; 561 goto done;
504 } 562 }
563 pub_key_size = LE_16(pub_key_size);
505 564
506 /* [UINT16 blob_size0 ] yes */ 565 /* [UINT16 blob_size0 ] yes */
566 key_blob_size = LE_16(key_blob_size);
507 if ((result = write_data(fd, &key_blob_size, sizeof(UINT16)))) { 567 if ((result = write_data(fd, &key_blob_size, sizeof(UINT16)))) {
508 LogDebug("%s", __FUNCTION__); 568 LogDebug("%s", __FUNCTION__);
509 goto done; 569 goto done;
510 } 570 }
571 key_blob_size = LE_16(key_blob_size);
511 572
512 /* [UINT32 vendor_data_size0 ] yes */ 573 /* [UINT32 vendor_data_size0 ] yes */
513 if ((result = write_data(fd, &zero, sizeof(UINT32)))) { 574 if ((result = write_data(fd, &zero, sizeof(UINT32)))) {
514 LogDebug("%s", __FUNCTION__); 575 LogDebug("%s", __FUNCTION__);
515 goto done; 576 goto done;
516 } 577 }
517 578
518 /* [UINT16 cache_flags0 ] yes */ 579 /* [UINT16 cache_flags0 ] yes */
580 cache_flags = LE_16(cache_flags);
519 if ((result = write_data(fd, &cache_flags, sizeof(UINT16)))) { 581 if ((result = write_data(fd, &cache_flags, sizeof(UINT16)))) {
520 LogDebug("%s", __FUNCTION__); 582 LogDebug("%s", __FUNCTION__);
521 goto done; 583 goto done;
522 } 584 }
585 cache_flags = LE_16(cache_flags);
523 586
524 /* [BYTE[] pub_data0 ] no */ 587 /* [BYTE[] pub_data0 ] no */
525 if ((result = write_data(fd, (void *)key.pubKey.key, pub_key_size))) { 588 if ((result = write_data(fd, (void *)key.pubKey.key, pub_key_size))) {
526 LogDebug("%s", __FUNCTION__); 589 LogDebug("%s", __FUNCTION__);
527 goto done; 590 goto done;
528 } 591 }
529 592
530 /* [BYTE[] blob0 ] no */ 593 /* [BYTE[] blob0 ] no */
531 if ((result = write_data(fd, (void *)key_blob, key_blob_size))) { 594 if ((result = write_data(fd, (void *)key_blob, key_blob_size))) {
532 LogDebug("%s", __FUNCTION__); 595 LogDebug("%s", __FUNCTION__);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 if ((result = read_data(fd, &tmp[i].parent_uuid, sizeof(TSS_UUID )))) { 741 if ((result = read_data(fd, &tmp[i].parent_uuid, sizeof(TSS_UUID )))) {
679 LogDebug("%s", __FUNCTION__); 742 LogDebug("%s", __FUNCTION__);
680 goto err_exit; 743 goto err_exit;
681 } 744 }
682 745
683 /* pub data size */ 746 /* pub data size */
684 if ((result = read_data(fd, &tmp[i].pub_data_size, sizeof(UINT16 )))) { 747 if ((result = read_data(fd, &tmp[i].pub_data_size, sizeof(UINT16 )))) {
685 LogDebug("%s", __FUNCTION__); 748 LogDebug("%s", __FUNCTION__);
686 goto err_exit; 749 goto err_exit;
687 } 750 }
751 tmp[i].pub_data_size = LE_16(tmp[i].pub_data_size);
688 752
689 DBG_ASSERT(tmp[i].pub_data_size <= 2048); 753 DBG_ASSERT(tmp[i].pub_data_size <= 2048);
690 754
691 /* blob size */ 755 /* blob size */
692 if ((result = read_data(fd, &tmp[i].blob_size, sizeof(UINT16)))) { 756 if ((result = read_data(fd, &tmp[i].blob_size, sizeof(UINT16)))) {
693 LogDebug("%s", __FUNCTION__); 757 LogDebug("%s", __FUNCTION__);
694 goto err_exit; 758 goto err_exit;
695 } 759 }
760 tmp[i].blob_size = LE_16(tmp[i].blob_size);
696 761
697 DBG_ASSERT(tmp[i].blob_size <= 4096); 762 DBG_ASSERT(tmp[i].blob_size <= 4096);
698 763
699 /* vendor data size */ 764 /* vendor data size */
700 if ((result = read_data(fd, &tmp[i].vendor_data_size, sizeof(UIN T32)))) { 765 if ((result = read_data(fd, &tmp[i].vendor_data_size, sizeof(UIN T32)))) {
701 LogDebug("%s", __FUNCTION__); 766 LogDebug("%s", __FUNCTION__);
702 goto err_exit; 767 goto err_exit;
703 } 768 }
769 tmp[i].vendor_data_size = LE_32(tmp[i].vendor_data_size);
704 770
705 /* cache flags */ 771 /* cache flags */
706 if ((result = read_data(fd, &tmp[i].flags, sizeof(UINT16)))) { 772 if ((result = read_data(fd, &tmp[i].flags, sizeof(UINT16)))) {
707 LogDebug("%s", __FUNCTION__); 773 LogDebug("%s", __FUNCTION__);
708 goto err_exit; 774 goto err_exit;
709 } 775 }
776 tmp[i].flags = LE_16(tmp[i].flags);
710 777
711 /* fast forward over the pub key */ 778 /* fast forward over the pub key */
712 offset = lseek(fd, tmp[i].pub_data_size, SEEK_CUR); 779 offset = lseek(fd, tmp[i].pub_data_size, SEEK_CUR);
713 if (offset == ((off_t)-1)) { 780 if (offset == ((off_t)-1)) {
714 LogDebug("lseek: %s", strerror(errno)); 781 LogDebug("lseek: %s", strerror(errno));
715 result = TSPERR(TSS_E_INTERNAL_ERROR); 782 result = TSPERR(TSS_E_INTERNAL_ERROR);
716 goto err_exit; 783 goto err_exit;
717 } 784 }
718 785
719 /* fast forward over the blob */ 786 /* fast forward over the blob */
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 } 1091 }
1025 1092
1026 rc = read(fd, &num_keys, sizeof(UINT32)); 1093 rc = read(fd, &num_keys, sizeof(UINT32));
1027 if (rc < 0) { 1094 if (rc < 0) {
1028 LogDebug("read of %zd bytes: %s", sizeof(UINT32), strerror(errno )); 1095 LogDebug("read of %zd bytes: %s", sizeof(UINT32), strerror(errno ));
1029 return 0; 1096 return 0;
1030 } else if ((unsigned)rc < sizeof(UINT32)) { 1097 } else if ((unsigned)rc < sizeof(UINT32)) {
1031 num_keys = 0; 1098 num_keys = 0;
1032 } 1099 }
1033 1100
1101 /* The system PS file is written in little-endian */
1102 num_keys = LE_32(num_keys);
1034 return num_keys; 1103 return num_keys;
1035 } 1104 }
1036 1105
1037 /* 1106 /*
1038 * disk store format: 1107 * disk store format:
1039 * 1108 *
1040 * TrouSerS 0.2.1+ 1109 * TrouSerS 0.2.1+
1041 * Version 1: cached? 1110 * Version 1: cached?
1042 * [BYTE PS version = '\1'] 1111 * [BYTE PS version = '\1']
1043 * [UINT32 num_keys_on_disk ] 1112 * [UINT32 num_keys_on_disk ]
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 LogDebug("lseek: %s", strerror(errno)); 1171 LogDebug("lseek: %s", strerror(errno));
1103 return TSPERR(TSS_E_INTERNAL_ERROR); 1172 return TSPERR(TSS_E_INTERNAL_ERROR);
1104 } 1173 }
1105 } 1174 }
1106 1175
1107 /* pub data size */ 1176 /* pub data size */
1108 if ((result = read_data(fd, &c->pub_data_size, sizeof(UINT16)))) { 1177 if ((result = read_data(fd, &c->pub_data_size, sizeof(UINT16)))) {
1109 LogDebug("%s", __FUNCTION__); 1178 LogDebug("%s", __FUNCTION__);
1110 return result; 1179 return result;
1111 } 1180 }
1112 1181 » » c->pub_data_size = LE_16(c->pub_data_size);
1113 DBG_ASSERT(c->pub_data_size <= 2048 && c->pub_data_size > 0); 1182 DBG_ASSERT(c->pub_data_size <= 2048 && c->pub_data_size > 0);
1114 1183
1115 /* blob size */ 1184 /* blob size */
1116 if ((result = read_data(fd, &c->blob_size, sizeof(UINT16)))) { 1185 if ((result = read_data(fd, &c->blob_size, sizeof(UINT16)))) {
1117 LogDebug("%s", __FUNCTION__); 1186 LogDebug("%s", __FUNCTION__);
1118 return result; 1187 return result;
1119 } 1188 }
1120 1189 » » c->blob_size = LE_16(c->blob_size);
1121 DBG_ASSERT(c->blob_size <= 4096 && c->blob_size > 0); 1190 DBG_ASSERT(c->blob_size <= 4096 && c->blob_size > 0);
1122 1191
1123 /* vendor data size */ 1192 /* vendor data size */
1124 if ((result = read_data(fd, &c->vendor_data_size, sizeof(UINT32) ))) { 1193 if ((result = read_data(fd, &c->vendor_data_size, sizeof(UINT32) ))) {
1125 LogDebug("%s", __FUNCTION__); 1194 LogDebug("%s", __FUNCTION__);
1126 return result; 1195 return result;
1127 } 1196 }
1197 c->vendor_data_size = LE_32(c->vendor_data_size);
1128 1198
1129 /* cache flags */ 1199 /* cache flags */
1130 if ((result = read_data(fd, &c->flags, sizeof(UINT16)))) { 1200 if ((result = read_data(fd, &c->flags, sizeof(UINT16)))) {
1131 LogDebug("%s", __FUNCTION__); 1201 LogDebug("%s", __FUNCTION__);
1132 return result; 1202 return result;
1133 } 1203 }
1204 c->flags = LE_16(c->flags);
1134 1205
1135 /* fast forward over the pub key */ 1206 /* fast forward over the pub key */
1136 offset = lseek(fd, c->pub_data_size, SEEK_CUR); 1207 offset = lseek(fd, c->pub_data_size, SEEK_CUR);
1137 if (offset == ((off_t)-1)) { 1208 if (offset == ((off_t)-1)) {
1138 LogDebug("lseek: %s", strerror(errno)); 1209 LogDebug("lseek: %s", strerror(errno));
1139 return TSPERR(TSS_E_INTERNAL_ERROR); 1210 return TSPERR(TSS_E_INTERNAL_ERROR);
1140 } 1211 }
1141 1212
1142 /* fast forward over the blob */ 1213 /* fast forward over the blob */
1143 offset = lseek(fd, c->blob_size, SEEK_CUR); 1214 offset = lseek(fd, c->blob_size, SEEK_CUR);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 LogDebug("%s", __FUNCTION__); 1262 LogDebug("%s", __FUNCTION__);
1192 return result; 1263 return result;
1193 } 1264 }
1194 1265
1195 /* pub data size */ 1266 /* pub data size */
1196 if ((result = read_data(fd, &c->pub_data_size, sizeof(UINT16)))) { 1267 if ((result = read_data(fd, &c->pub_data_size, sizeof(UINT16)))) {
1197 LogDebug("%s", __FUNCTION__); 1268 LogDebug("%s", __FUNCTION__);
1198 return result; 1269 return result;
1199 } 1270 }
1200 1271
1272 c->pub_data_size = LE_16(c->pub_data_size);
1201 DBG_ASSERT(c->pub_data_size <= 2048 && c->pub_data_size > 0); 1273 DBG_ASSERT(c->pub_data_size <= 2048 && c->pub_data_size > 0);
1202 1274
1203 /* blob size */ 1275 /* blob size */
1204 if ((result = read_data(fd, &c->blob_size, sizeof(UINT16)))) { 1276 if ((result = read_data(fd, &c->blob_size, sizeof(UINT16)))) {
1205 LogDebug("%s", __FUNCTION__); 1277 LogDebug("%s", __FUNCTION__);
1206 return result; 1278 return result;
1207 } 1279 }
1208 1280
1281 c->blob_size = LE_16(c->blob_size);
1209 DBG_ASSERT(c->blob_size <= 4096 && c->blob_size > 0); 1282 DBG_ASSERT(c->blob_size <= 4096 && c->blob_size > 0);
1210 1283
1211 /* vendor data size */ 1284 /* vendor data size */
1212 if ((result = read_data(fd, &c->vendor_data_size, sizeof(UINT32) ))) { 1285 if ((result = read_data(fd, &c->vendor_data_size, sizeof(UINT32) ))) {
1213 LogDebug("%s", __FUNCTION__); 1286 LogDebug("%s", __FUNCTION__);
1214 return result; 1287 return result;
1215 } 1288 }
1289 c->vendor_data_size = LE_32(c->vendor_data_size);
1216 1290
1217 /* cache flags */ 1291 /* cache flags */
1218 if ((result = read_data(fd, &c->flags, sizeof(UINT16)))) { 1292 if ((result = read_data(fd, &c->flags, sizeof(UINT16)))) {
1219 LogDebug("%s", __FUNCTION__); 1293 LogDebug("%s", __FUNCTION__);
1220 return result; 1294 return result;
1221 } 1295 }
1296 c->flags = LE_16(c->flags);
1222 1297
1223 if (c->pub_data_size == pub_size) { 1298 if (c->pub_data_size == pub_size) {
1224 /* read in the pub key */ 1299 /* read in the pub key */
1225 if ((result = read_data(fd, blob, c->pub_data_size))) { 1300 if ((result = read_data(fd, blob, c->pub_data_size))) {
1226 LogDebug("%s", __FUNCTION__); 1301 LogDebug("%s", __FUNCTION__);
1227 return result; 1302 return result;
1228 } 1303 }
1229 1304
1230 if (!memcmp(blob, pub, pub_size)) 1305 if (!memcmp(blob, pub, pub_size))
1231 break; 1306 break;
1232 } 1307 }
1233 1308
1234 /* fast forward over the blob */ 1309 /* fast forward over the blob */
1235 offset = lseek(fd, c->blob_size, SEEK_CUR); 1310 offset = lseek(fd, c->blob_size, SEEK_CUR);
1236 if (offset == ((off_t)-1)) { 1311 if (offset == ((off_t)-1)) {
1237 LogDebug("lseek: %s", strerror(errno)); 1312 LogDebug("lseek: %s", strerror(errno));
1238 return TSPERR(TSS_E_INTERNAL_ERROR); 1313 return TSPERR(TSS_E_INTERNAL_ERROR);
1239 } 1314 }
1240 1315
1241 /* ignore vendor data */ 1316 /* ignore vendor data */
1242 } 1317 }
1243 1318
1244 return TSS_SUCCESS; 1319 return TSS_SUCCESS;
1245 } 1320 }
OLDNEW
« no previous file with comments | « src/tspi/obj_rsakey.c ('k') | src/tspi/rpc/hosttable.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698