Hi,

On Wed, Jan 9, 2013 at 3:02 AM, guohang.bao <[email protected]> wrote:
> CODE HERE:
> int main(int argc, char *argv) {
>     TSS_RESULT result;
>     TSS_HTPM hTPM;
>     TSS_HCONTEXT hContext;
>     TSS_HPOLICY hownerpolicy, hSRKPolicy, hNVPolicy;
>     TSS_HKEY hSRK, hstoragekey;
>     TSS_UUID SRK_UUID = TSS_UUID_SRK;
>     TSS_HNVSTORE hNVStore;
>     TSS_FLAG initFlags = TSS_KEY_TYPE_STORAGE | TSS_KEY_SIZE_2048 |
> TSS_KEY_NO_AUTHORIZATION; //密钥标记
>
>     int keyBlobLen, pubKeySize = 284;
>     BYTE* pubKey, keyBlob;
>
>     result = Tspi_Context_Create(&hContext);
>     if (result != TSS_SUCCESS) {
>         printf("Context_Create ERROR:%s(%04x)\n", get_error(result),
> result);
>     }
>     result = Tspi_Context_Connect(hContext, NULL);
>     if (result != TSS_SUCCESS) {
>         printf("Context_Connect ERROR:%s(%04x)\n", get_error(result),
> result);
>     }
> //
> //
> //    result = Tspi_Context_GetTpmObject(hContext, &hTPM);
> //    if (result != TSS_SUCCESS) {
> //        printf("Tspi_Context_GetTpmObject ERROR:%s(%04x)\n",
> get_error(result), result);
> //    }
> //    result = Tspi_GetPolicyObject(hTPM, TSS_POLICY_USAGE,
> &hownerpolicy);
> //    if (result != TSS_SUCCESS) {
> //        printf("Tspi_GetPolicyObject ERROR:%s(%04x)\n",
> get_error(result), result);
> //    }
> ////    result = Tspi_Policy_SetSecret(hownerpolicy,
> TSS_SECRET_MODE_PLAIN, 20, (BYTE*) "00000000000000000000");
> //    result = Tspi_Policy_SetSecret(hownerpolicy, TSS_SECRET_MODE_NONE,
> 0, NULL);
> //    if (result != TSS_SUCCESS) {
> //        printf("Tspi_Policy_SetSecret ERROR:%s(%04x)\n",
> get_error(result), result);
> //    }
>
>     result = Tspi_Context_LoadKeyByUUID(hContext, TSS_PS_TYPE_SYSTEM,
> SRK_UUID, &hSRK);
>     if (result != TSS_SUCCESS) {
>         printf("Tspi_Context_LoadKeyByUUID ERROR:%s(%04x)\n",
> get_error(result), result);
>     }
>
>     result = Tspi_GetPolicyObject(hSRK, TSS_POLICY_USAGE, &hSRKPolicy);
> //    if (result != TSS_SUCCESS) {
> //        printf("Tspi_GetPolicyObject ERROR:%s(%04x)\n",
> get_error(result), result);
> //    }
> //
> //    result = Tspi_Policy_SetSecret(hSRKPolicy, TSS_SECRET_MODE_NONE,
> 0, NULL);
>     result = Tspi_Policy_SetSecret(hSRKPolicy, TSS_SECRET_MODE_PLAIN, 5,
> (BYTE*) "admin");
> //    result = Tspi_Policy_SetSecret(hSRKPolicy, TSS_SECRET_MODE_POPUP,
> 0, NULL);
>     if (result != TSS_SUCCESS) {
>         printf("Tspi_Policy_SetSecret ERROR:%s(%04x)\n",
> get_error(result), result);
>     }
>
>     result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_RSAKEY,
> initFlags, &hstoragekey);
>
>     result = Tspi_SetAttribUint32(hstoragekey, TSS_TSPATTRIB_KEY_INFO,
> TSS_TSPATTRIB_KEYINFO_ENCSCHEME, TSS_ES_RSAESOAEP_SHA1_MGF1);
>
>     result = Tspi_Key_CreateKey(hstoragekey, hSRK, 0);
>
>     result = Tspi_Key_LoadKey(hstoragekey, hSRK);
>
>     result = Tspi_Key_GetPubKey(hstoragekey, &pubKeySize, &pubKey);
> //
>     result = Tspi_GetAttribData(hstoragekey, TSS_TSPATTRIB_KEY_BLOB,
> TSS_TSPATTRIB_KEYBLOB_BLOB, (UINT32 *) & keyBlobLen,
>             (BYTE **) & keyBlob);
>     result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_NV, 0,
> &hNVStore);
>
>     result = Tspi_SetAttribUint32(hNVStore, TSS_TSPATTRIB_NV_INDEX, 0,
> 0x00011680);

  Your NV index looks suspect here. If you check the spec, you'll
notice that this index is reserved for GPIO pins. See the TPM main
spec, part 2 structures, section 19.1.2.

Kent

>     /* Set the permission for the index. */
>     result = Tspi_SetAttribUint32(hNVStore,
> TSS_TSPATTRIB_NV_PERMISSIONS, 0, 0x2000);
>
>     /* Set the data size to be defined. */
>     result = Tspi_SetAttribUint32(hNVStore, TSS_TSPATTRIB_NV_DATASIZE,
> 0, 559);
>     /*Define NV space*/
>     result = Tspi_NV_DefineSpace(hNVStore, 0, 0);
>
> //    result =
> Tspi_NV_WriteValue(hNVStore, /*offset*/0, /*datalength*/559, &keyBlob);
>     printf("%s\n", get_error(result));
>     Tspi_Context_Close(hContext);
>     return 0;
> }
>
>
>
> ------------------------------------------------------------------------------
> Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
> and much more. Keep your Java skills current with LearnJavaNow -
> 200+ hours of step-by-step video tutorials by Java experts.
> SALE $49.99 this month only -- learn more at:
> http://p.sf.net/sfu/learnmore_122612
> _______________________________________________
> TrouSerS-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/trousers-users

------------------------------------------------------------------------------
Master SQL Server Development, Administration, T-SQL, SSAS, SSIS, SSRS
and more. Get SQL Server skills now (including 2012) with LearnDevNow -
200+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only - learn more at:
http://p.sf.net/sfu/learnmore_122512
_______________________________________________
TrouSerS-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/trousers-users

Reply via email to