2
* Licensed Materials - Property of IBM
4
* trousers - An open source TCG Software Stack
6
* (C) Copyright International Business Machines Corp. 2006
15
#include "trousers/tss.h"
16
#include "spi_internal_types.h"
17
#include "spi_utils.h"
19
// #include "tcslog.h"
21
#include "daa_parameter.h"
24
static char *DEFAULT_FILENAME = "issuer.txt";
25
static char *DEFAULT_ISSUER = "IBM-Issuer";
27
static const int DEFAULT_ISSUER_ATTRIBUTES = 2; // A1 A2
28
static const int DEFAULT_RECEIVER_ATTRIBUTES = 3; // A3 A4 A5
30
int print_usage(char *cmd) {
31
fprintf(stderr, "usage: %s\n", cmd);
32
fprintf(stderr, " \t-npa,\t--nb_platform_attr\tnumber of attributes that the\
33
Platform can choose and which will not be visible to the Issuer (default: %d)\n",
34
DEFAULT_ISSUER_ATTRIBUTES);
35
fprintf(stderr, " \t-nia,\t--nb_issuer_attr\tnumber of attributes that the issuer\
36
can choose and which will be visible to both the Platform and the Issuer(default: %d)\n",
37
DEFAULT_RECEIVER_ATTRIBUTES);
38
fprintf(stderr, " \t-if,\t--issuer_file\tthe file that will contain all key pair\
39
and proof to be used by the issuer (default: %s)\n",
41
fprintf(stderr, " \t-i,\t--issuer\tissuer identity (default: %s)\n",
46
int main(int argc, char *argv[]) {
47
int nb_platform_attr = DEFAULT_ISSUER_ATTRIBUTES;
48
int nb_issuer_attr = DEFAULT_RECEIVER_ATTRIBUTES;
49
char *filename = DEFAULT_FILENAME;
50
char *issuer = DEFAULT_ISSUER;
53
TSS_HCONTEXT hContext;
54
TSS_DAA_KEY_PAIR *key_pair;
55
TSS_DAA_PK_PROOF *public_keyproof;
58
TSS_DAA_PK_PROOF_internal *public_keyproof_internal;
59
TSS_DAA_PK_internal *pk;
60
TSS_DAA_PRIVATE_KEY *private_key;
61
DAA_PRIVATE_KEY_internal *private_key_internal;
62
KEY_PAIR_WITH_PROOF_internal *key_pair_with_proof;
64
printf("Issuer Setup (%s:%s,%s)\n", argv[0], __DATE__, __TIME__);
68
if ( strcmp( param, "-if") == 0 || strcmp( param, "--issuer_file")) {
70
if( i == argc) return print_usage( argv[0]);
72
} else if( strcmp( param, "-npa") == 0 || strcmp( param, "--nb_platform_attr")) {
74
if( i == argc) return print_usage( argv[0]);
75
nb_platform_attr = atoi( argv[i]);
76
} else if( strcmp( param, "-nia") == 0 || strcmp( param, "--nb_issuer_attr")) {
78
if( i == argc) return print_usage( argv[0]);
79
nb_issuer_attr = atoi(argv[i]);
80
} else if( strcmp( param, "-i") == 0 || strcmp( param, "--issuer")) {
82
if( i == argc) return print_usage( argv[0]);
85
fprintf(stderr, "%s:unrecognized option `%s'\n", argv[0], param);
86
return print_usage( argv[0]);
92
printf("Create Context\n");
93
result = Tspi_Context_Create( &hContext );
94
if ( result != TSS_SUCCESS )
96
fprintf( stderr, "Tspi_Context_Create %d\n", result );
100
// Connect to Context
101
printf("Connect to the context\n");
102
result = Tspi_Context_Connect( hContext, NULL );
103
if ( result != TSS_SUCCESS )
105
fprintf( stderr, "Tspi_Context_Connect error:%d\n", result );
106
Tspi_Context_FreeMemory( hContext, NULL );
107
Tspi_Context_Close( hContext );
111
result = obj_daa_add( hContext, &hDAA);
112
if (result != TSS_SUCCESS) {
115
result = Tspi_DAA_IssueSetup(
117
strlen( issuer), // in
118
(BYTE *)issuer, // in
119
nb_platform_attr, // in
120
nb_issuer_attr, // in
121
(TSS_HKEY *)&key_pair, // out
122
&public_keyproof); // out
123
if( result != TSS_SUCCESS) goto close;
125
// TSS_DAA_KEY_PAIR_internal *key_pair_internal = DAA_KEY_PAIR_2_internal( key_pair);
126
public_keyproof_internal = e_2_i_TSS_DAA_PK_PROOF( public_keyproof);
127
pk = e_2_i_TSS_DAA_PK( key_pair->public_key);
128
private_key = key_pair->private_key;
129
private_key_internal = e_2_i_TSS_DAA_PRIVATE_KEY( private_key);
130
key_pair_with_proof =
131
(KEY_PAIR_WITH_PROOF_internal *)malloc( sizeof(KEY_PAIR_WITH_PROOF_internal));
132
if( key_pair_with_proof == NULL) {
133
fprintf("malloc of %d bytes failed", sizeof(KEY_PAIR_WITH_PROOF_internal));
136
key_pair_with_proof->pk = pk;
137
key_pair_with_proof->private_key = private_key_internal;
138
key_pair_with_proof->proof = public_keyproof_internal;
140
printf("Saving key pair with proof -> \'%s\'", filename);
141
FILE *file = fopen( filename, "w");
143
fprintf( stderr, "%s: Error when saving \'%s\': %s\n",
149
if( save_KEY_PAIR_WITH_PROOF( file, key_pair_with_proof) != 0) {
150
fprintf( stderr, "%s: Error when saving \'%s\': %s\n",
159
obj_daa_remove( hDAA, hContext);
160
printf("Closing the context\n");
161
Tspi_Context_FreeMemory( hContext, NULL );
162
Tspi_Context_Close( hContext );
164
printf("Result: %d", result);