~mrooney/ecryptfs/nautilus-integration

« back to all changes in this revision

Viewing changes to src/key_mod/ecryptfs_key_mod_tspi.c

  • Committer: Dustin Kirkland
  • Date: 2009-02-03 08:18:53 UTC
  • Revision ID: git-v1:b0090ac8d4f626339d7f8ca5681934d5e68dac3e
make most of the code compatible with -Werror

Thanks to Michal Hlavinka for the patch.  This has been on my
to-do list for a while now!

Patch retrieved from:
https://bugzilla.redhat.com/show_bug.cgi?id=479762

Signed-off-by: Dustin Kirkland <kirkland@canonical.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 * 02111-1307, USA.
20
20
 */
21
21
 
 
22
#include "config.h"
22
23
#include <sys/types.h>
23
24
#include <sys/stat.h>
24
25
#include <fcntl.h>
30
31
#include <unistd.h>
31
32
#include <errno.h>
32
33
#include <trousers/tss.h>
33
 
#include "config.h"
 
34
#include <trousers/trousers.h>
 
35
#include <openssl/sha.h>
34
36
#include "../include/ecryptfs.h"
35
37
#include "../include/decision_graph.h"
36
38
 
82
84
static int ecryptfs_tspi_generate_signature(char *sig, BYTE *n, uint32_t nbytes)
83
85
{
84
86
        int len, i;
85
 
        char hash[SHA1_DIGEST_LENGTH];
86
 
        char *data = NULL;
 
87
        unsigned char hash[SHA1_DIGEST_LENGTH];
 
88
        unsigned char *data = NULL;
87
89
        BYTE e[] = { 1, 0, 1 }; /* The e for all TPM RSA keys */
88
90
        int rc = 0;
89
91
 
95
97
        }
96
98
        i = 0;
97
99
        data[i++] = '\x99';
98
 
        data[i++] = (char)(len >> 8);
99
 
        data[i++] = (char)len;
 
100
        data[i++] = (len >> 8);
 
101
        data[i++] = len;
100
102
        data[i++] = '\x04';
101
103
        data[i++] = '\00';
102
104
        data[i++] = '\00';
103
105
        data[i++] = '\00';
104
106
        data[i++] = '\00';
105
107
        data[i++] = '\02';
106
 
        data[i++] = (char)((nbytes * 8) >> 8);
107
 
        data[i++] = (char)(nbytes * 8);
 
108
        data[i++] = ((nbytes * 8) >> 8);
 
109
        data[i++] = (nbytes * 8);
108
110
        memcpy(&data[i], n, nbytes);
109
111
        i += nbytes;
110
 
        data[i++] = (char)((sizeof(e) * 8) >> 8);
111
 
        data[i++] = (char)(sizeof(e) * 8);
 
112
        data[i++] = ((sizeof(e) * 8) >> 8);
 
113
        data[i++] = (sizeof(e) * 8);
112
114
        memcpy(&data[i], e, sizeof(e));
113
115
        i += sizeof(e);
114
116
        SHA1(data, len + 3, hash);
115
 
        ecryptfs_tspi_to_hex(sig, hash, ECRYPTFS_SIG_SIZE);
 
117
        ecryptfs_tspi_to_hex(sig, (char *)hash, ECRYPTFS_SIG_SIZE);
116
118
        sig[ECRYPTFS_SIG_SIZE_HEX] = '\0';
117
119
out:
118
120
        free(data);
125
127
        int rc = 0;
126
128
 
127
129
        memcpy(&tspi_data->uuid, blob, sizeof(TSS_UUID));
128
 
out:
 
130
 
129
131
        return rc;
130
132
}
131
133
 
164
166
                rc = -EIO;
165
167
                goto out;
166
168
        }
167
 
        rc = ecryptfs_tspi_generate_signature(sig, n, size_n);
 
169
        rc = ecryptfs_tspi_generate_signature((char *)sig, n, size_n);
168
170
out:
169
171
        return rc;
170
172
}
369
371
                rc = -EIO;
370
372
                goto out;
371
373
        }
372
 
        if ((result = Tspi_Data_Seal(h_encdata, hKey, from_size, from, 0))
 
374
        if ((result = Tspi_Data_Seal(h_encdata, hKey, from_size, 
 
375
                                     (unsigned char *)from, 0))
373
376
            != TSS_SUCCESS) {
374
377
                syslog(LOG_ERR, "Tspi_Data_Seal failed: [%s]\n",
375
378
                       Trspi_Error_String(result));
544
547
        for (i = 0; i < (sizeof(TSS_UUID) * 2);
545
548
             i += (sizeof(unsigned long) * 2)) {
546
549
                memcpy(tmp, &str[i], sizeof(unsigned long) * 2);
547
 
                l = strtoul(tmp, NULL, 16);
 
550
                l = strtoul((char *)tmp, NULL, 16);
548
551
                l = htonl(l);
549
552
                memcpy(&((BYTE *)uuid)[i/2], &l, sizeof(unsigned long));
550
553
        }