~ubuntu-branches/ubuntu/utopic/trousers/utopic-proposed

« back to all changes in this revision

Viewing changes to src/tspi/tsp_transport.c

  • Committer: Package Import Robot
  • Author(s): Pierre Chifflier
  • Date: 2013-08-20 18:01:47 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20130820180147-ucz33jh8z2qx47ya
Tags: 0.3.11.2-1
* Imported Upstream version 0.3.11.2
* Upstream license changed to BSD
* Example tools are not shipped anymore
* Remove 05-gcc47.patch, not needed anymore
* Updated symbols file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/*
3
 
 * Licensed Materials - Property of IBM
4
 
 *
5
 
 * trousers - An open source TCG Software Stack
6
 
 *
7
 
 * (C) Copyright International Business Machines Corp. 2004-2007
8
 
 *
9
 
 */
10
 
 
11
 
 
12
 
#include <stdlib.h>
13
 
#include <stdio.h>
14
 
#include <string.h>
15
 
 
16
 
#include "trousers/tss.h"
17
 
#include "trousers/trousers.h"
18
 
#include "trousers_types.h"
19
 
#include "spi_utils.h"
20
 
#include "capabilities.h"
21
 
#include "tsplog.h"
22
 
#include "obj.h"
23
 
 
24
 
 
25
 
TSS_RESULT
26
 
Transport_LoadKeyByBlob(TSS_HCONTEXT     hContext,
27
 
                        TPM_COMMAND_CODE ordinal,
28
 
                        TSS_HKEY         hParentKey,
29
 
                        UINT32           ulBlobLength,
30
 
                        BYTE*            rgbBlobData,
31
 
                        TPM_AUTH*        pAuth,
32
 
                        TCS_KEY_HANDLE*  phKey,
33
 
                        TPM_KEY_HANDLE*  phSlot)
34
 
{
35
 
        TSS_RESULT result;
36
 
        UINT32 handleListSize, decLen;
37
 
        TCS_KEY_HANDLE hTCSParentKey;
38
 
        TCS_HANDLE *handleList;
39
 
        BYTE *dec = NULL;
40
 
        TPM_DIGEST pubKeyHash;
41
 
        Trspi_HashCtx hashCtx;
42
 
 
43
 
 
44
 
        if ((result = obj_context_transport_init(hContext)) == TSS_TSPATTRIB_DISABLE_TRANSPORT) {
45
 
                if ((result = obj_rsakey_get_tcs_handle(hParentKey, &hTCSParentKey)))
46
 
                        return result;
47
 
 
48
 
                return TCSP_LoadKeyByBlob(hContext, hTCSParentKey, ulBlobLength, rgbBlobData, pAuth,
49
 
                                          phKey, phSlot);
50
 
        } else if (result != TSS_TSPATTRIB_ENABLE_TRANSPORT)
51
 
                return result;
52
 
 
53
 
        LogDebugFn("Executing in a transport session");
54
 
 
55
 
        if ((result = obj_rsakey_get_transport_attribs(hParentKey, &hTCSParentKey, &pubKeyHash)))
56
 
                return result;
57
 
 
58
 
        result = Trspi_HashInit(&hashCtx, TSS_HASH_SHA1);
59
 
        result |= Trspi_Hash_DIGEST(&hashCtx, pubKeyHash.digest);
60
 
        if ((result |= Trspi_HashFinal(&hashCtx, pubKeyHash.digest)))
61
 
                return result;
62
 
 
63
 
        /* Call ExecuteTransport */
64
 
        handleListSize = 1;
65
 
        if ((handleList = malloc(sizeof(TCS_HANDLE))) == NULL) {
66
 
                LogError("malloc of %zd bytes failed", sizeof(TCS_HANDLE));
67
 
                return TSPERR(TSS_E_OUTOFMEMORY);
68
 
        }
69
 
 
70
 
        *handleList = hTCSParentKey;
71
 
 
72
 
        if ((result = obj_context_transport_execute(hContext, ordinal, ulBlobLength,
73
 
                                                    rgbBlobData, &pubKeyHash, &handleListSize,
74
 
                                                    &handleList, pAuth, NULL, &decLen, &dec))) {
75
 
                free(handleList);
76
 
                return result;
77
 
        }
78
 
 
79
 
        if (handleListSize == 1)
80
 
                *phKey = *(TCS_KEY_HANDLE *)handleList;
81
 
        else
82
 
                result = TSPERR(TSS_E_INTERNAL_ERROR);
83
 
 
84
 
        free(handleList);
85
 
        free(dec);
86
 
 
87
 
        return result;
88
 
}