跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[Java] 为什么在 TSS. Java 项目中使用 tpm.EvictControl()方法运行出错,并显示以下消息:{NO_SESSIONS},有没有了解的进来提点提点

发表于

用的是微软的 TSS.java 开发工具包,做个 TPM 可信模块开发,遇到的问题,源码如下:

public static void main(String[] args) throws IOException {
        Tpm tpm = TpmFactory.platformTpm();
        byte[] nullVec = new byte[0];
        byte[] aesKey = Helpers.RandomBytes(16);
        TPMT_PUBLIC aesTemplate = new TPMT_PUBLIC(TPM_ALG_ID.SHA256, new TPMA_OBJECT(new TPMA_OBJECT[]{TPMA_OBJECT.decrypt, TPMA_OBJECT.sign, TPMA_OBJECT.fixedParent, TPMA_OBJECT.fixedTPM, TPMA_OBJECT.userWithAuth}), new byte[0], new TPMS_SYMCIPHER_PARMS(new TPMT_SYM_DEF_OBJECT(TPM_ALG_ID.AES, 128, TPM_ALG_ID.CFB)), new TPM2B_DIGEST_SYMCIPHER());
        TPMS_SENSITIVE_CREATE sensCreate = new TPMS_SENSITIVE_CREATE(nullVec, aesKey);
        CreatePrimaryResponse aesPrimary = tpm.CreatePrimary(tpm._OwnerHandle, sensCreate, aesTemplate, nullVec, new TPMS_PCR_SELECTION[0]);
        TPM_HANDLE aesHandle = aesPrimary.handle;
        byte[] toEncrypt = new byte[]{1, 2, 3, 4, 5, 4, 3, 2, 12, 3, 4, 5};
        byte[] iv = new byte[16];
        EncryptDecryptResponse encrypted = tpm.EncryptDecrypt(aesHandle, (byte) 0, TPM_ALG_ID.CFB, iv, toEncrypt);
        EncryptDecryptResponse decrypted = tpm.EncryptDecrypt(aesHandle, (byte) 1, TPM_ALG_ID.CFB, iv, encrypted.outData);
        System.out.println("AES128 encryption with key = " + Helpers.toHex(aesKey));
        System.out.println("    Input     data:" + Helpers.toHex(toEncrypt));
        System.out.println("    encrypted data:" + Helpers.toHex(encrypted.outData));
        System.out.println("    decrypted data:" + Helpers.toHex(decrypted.outData));


        // persistent handle
        TPM_HANDLE persistentHandle = TPM_HANDLE.persistent(0x81010001);
        tpm.EvictControl(TPM_HANDLE.from(TPM_RH.OWNER), aesHandle, persistentHandle);
        if (!Helpers.arraysAreEqual(toEncrypt, decrypted.outData)) {
            throw new RuntimeException("encrypt/decrypt failed!");
        } else {
            tpm.FlushContext(aesHandle);
        }
        // clean object
        if (!Helpers.arraysAreEqual(toEncrypt, decrypted.outData)) {
            throw new RuntimeException("encrypt/decrypt failed!");
        } else {
            tpm.FlushContext(aesHandle);
        }
    }

错误信息如下:

Exception in thread "main" tss.TpmException: Unexpected response tag {NO_SESSIONS}  
at tss.TpmBase.DispatchCommand(TpmBase.java:391)    
at tss.Tpm.EvictControl(Tpm.java:1930)  
at com.xxx.assist.XXXX.main(XXXX.java:12)

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.