OLD | NEW |
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 <sys/types.h> | 17 #include <sys/types.h> |
18 #include <sys/file.h> | 18 #include <sys/file.h> |
19 #include <sys/stat.h> | 19 #include <sys/stat.h> |
| 20 #if defined (HAVE_BYTEORDER_H) |
| 21 #include <sys/byteorder.h> |
| 22 #elif defined (HAVE_ENDIAN_H) |
| 23 #include <endian.h> |
| 24 #define LE_16 htole16 |
| 25 #define LE_32 htole32 |
| 26 #define LE_64 htole64 |
| 27 #else |
| 28 #define LE_16(x) (x) |
| 29 #define LE_32(x) (x) |
| 30 #define LE_64(x) (x) |
| 31 #endif |
20 #include <assert.h> | 32 #include <assert.h> |
21 #include <fcntl.h> | 33 #include <fcntl.h> |
22 #include <limits.h> | 34 #include <limits.h> |
23 | 35 |
24 #include "trousers/tss.h" | 36 #include "trousers/tss.h" |
25 #include "trousers_types.h" | 37 #include "trousers_types.h" |
26 #include "tcsps.h" | 38 #include "tcsps.h" |
27 #include "tcs_tsp.h" | 39 #include "tcs_tsp.h" |
28 #include "tcs_utils.h" | 40 #include "tcs_utils.h" |
29 #include "capabilities.h" | 41 #include "capabilities.h" |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 goto done; | 597 goto done; |
586 } | 598 } |
587 | 599 |
588 /* [TSS_UUID uuid_parent0 ] yes */ | 600 /* [TSS_UUID uuid_parent0 ] yes */ |
589 if ((rc = write_data(fd, (void *)parent_uuid, sizeof(TSS_UUID)))) { | 601 if ((rc = write_data(fd, (void *)parent_uuid, sizeof(TSS_UUID)))) { |
590 LogError("%s", __FUNCTION__); | 602 LogError("%s", __FUNCTION__); |
591 goto done; | 603 goto done; |
592 } | 604 } |
593 | 605 |
594 /* [UINT16 pub_data_size0 ] yes */ | 606 /* [UINT16 pub_data_size0 ] yes */ |
| 607 pub_key_size = LE_16(pub_key_size); |
595 if ((rc = write_data(fd, &pub_key_size, sizeof(UINT16)))) { | 608 if ((rc = write_data(fd, &pub_key_size, sizeof(UINT16)))) { |
596 LogError("%s", __FUNCTION__); | 609 LogError("%s", __FUNCTION__); |
597 goto done; | 610 goto done; |
598 } | 611 } |
| 612 /* Swap it back for later */ |
| 613 pub_key_size = LE_16(pub_key_size); |
599 | 614 |
600 /* [UINT16 blob_size0 ] yes */ | 615 /* [UINT16 blob_size0 ] yes */ |
| 616 key_blob_size = LE_16(key_blob_size); |
601 if ((rc = write_data(fd, &key_blob_size, sizeof(UINT16)))) { | 617 if ((rc = write_data(fd, &key_blob_size, sizeof(UINT16)))) { |
602 LogError("%s", __FUNCTION__); | 618 LogError("%s", __FUNCTION__); |
603 goto done; | 619 goto done; |
604 } | 620 } |
| 621 /* Swap it back for later */ |
| 622 key_blob_size = LE_16(key_blob_size); |
605 | 623 |
606 /* [UINT32 vendor_data_size0 ] yes */ | 624 /* [UINT32 vendor_data_size0 ] yes */ |
| 625 vendor_size = LE_32(vendor_size); |
607 if ((rc = write_data(fd, &vendor_size, sizeof(UINT32)))) { | 626 if ((rc = write_data(fd, &vendor_size, sizeof(UINT32)))) { |
608 LogError("%s", __FUNCTION__); | 627 LogError("%s", __FUNCTION__); |
609 goto done; | 628 goto done; |
610 } | 629 } |
| 630 /* Swap it back for later */ |
| 631 vendor_size = LE_32(vendor_size); |
611 | 632 |
612 /* [UINT16 cache_flags0 ] yes */ | 633 /* [UINT16 cache_flags0 ] yes */ |
| 634 cache_flags = LE_16(cache_flags); |
613 if ((rc = write_data(fd, &cache_flags, sizeof(UINT16)))) { | 635 if ((rc = write_data(fd, &cache_flags, sizeof(UINT16)))) { |
614 LogError("%s", __FUNCTION__); | 636 LogError("%s", __FUNCTION__); |
615 goto done; | 637 goto done; |
616 } | 638 } |
| 639 /* Swap it back for later */ |
| 640 cache_flags = LE_16(cache_flags); |
617 | 641 |
618 /* [BYTE[] pub_data0 ] no */ | 642 /* [BYTE[] pub_data0 ] no */ |
619 if ((rc = write_data(fd, (void *)key.pubKey.key, pub_key_size))) { | 643 if ((rc = write_data(fd, (void *)key.pubKey.key, pub_key_size))) { |
620 LogError("%s", __FUNCTION__); | 644 LogError("%s", __FUNCTION__); |
621 goto done; | 645 goto done; |
622 } | 646 } |
623 | 647 |
624 /* [BYTE[] blob0 ] no */ | 648 /* [BYTE[] blob0 ] no */ |
625 if ((rc = write_data(fd, (void *)key_blob, key_blob_size))) { | 649 if ((rc = write_data(fd, (void *)key_blob, key_blob_size))) { |
626 LogError("%s", __FUNCTION__); | 650 LogError("%s", __FUNCTION__); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 | 752 |
729 /* we succeeded in removing a key from the disk. Decrement the number | 753 /* we succeeded in removing a key from the disk. Decrement the number |
730 * of keys in the file */ | 754 * of keys in the file */ |
731 rc = lseek(fd, TSSPS_NUM_KEYS_OFFSET, SEEK_SET); | 755 rc = lseek(fd, TSSPS_NUM_KEYS_OFFSET, SEEK_SET); |
732 if (rc == ((off_t) - 1)) { | 756 if (rc == ((off_t) - 1)) { |
733 LogError("lseek: %s", strerror(errno)); | 757 LogError("lseek: %s", strerror(errno)); |
734 return TCSERR(TSS_E_INTERNAL_ERROR); | 758 return TCSERR(TSS_E_INTERNAL_ERROR); |
735 } | 759 } |
736 | 760 |
737 rc = read(fd, &num_keys, sizeof(UINT32)); | 761 rc = read(fd, &num_keys, sizeof(UINT32)); |
| 762 num_keys = LE_32(num_keys); |
738 if (rc != sizeof(UINT32)) { | 763 if (rc != sizeof(UINT32)) { |
739 LogError("read of %zd bytes: %s", sizeof(UINT32), strerror(errno
)); | 764 LogError("read of %zd bytes: %s", sizeof(UINT32), strerror(errno
)); |
740 return TCSERR(TSS_E_INTERNAL_ERROR); | 765 return TCSERR(TSS_E_INTERNAL_ERROR); |
741 } | 766 } |
742 | 767 |
743 rc = lseek(fd, TSSPS_NUM_KEYS_OFFSET, SEEK_SET); | 768 rc = lseek(fd, TSSPS_NUM_KEYS_OFFSET, SEEK_SET); |
744 if (rc == ((off_t) - 1)) { | 769 if (rc == ((off_t) - 1)) { |
745 LogError("lseek: %s", strerror(errno)); | 770 LogError("lseek: %s", strerror(errno)); |
746 return TCSERR(TSS_E_INTERNAL_ERROR); | 771 return TCSERR(TSS_E_INTERNAL_ERROR); |
747 } | 772 } |
748 | 773 |
749 /* decrement, then write back out to disk */ | 774 /* decrement, then write back out to disk */ |
750 num_keys--; | 775 num_keys--; |
751 | 776 |
| 777 num_keys = LE_32(num_keys); |
752 if ((result = write_data(fd, (void *)&num_keys, sizeof(UINT32)))) { | 778 if ((result = write_data(fd, (void *)&num_keys, sizeof(UINT32)))) { |
753 LogError("%s", __FUNCTION__); | 779 LogError("%s", __FUNCTION__); |
754 return result; | 780 return result; |
755 } | 781 } |
756 | 782 |
757 return TSS_SUCCESS; | 783 return TSS_SUCCESS; |
758 } | 784 } |
OLD | NEW |