示例#1
0
        public int ReadPublicKey(KeyBlob keyBlob, ulong handle)
        {
            int rc = wolfTPM2_ReadPublicKey(device, keyBlob.keyblob, handle);

            if (rc != (int)Status.TPM_RC_SUCCESS &&
                rc != (int)Status.TPM_RC_HANDLE)
            {
                throw new WolfTpm2Exception(
                          "wolfTPM2_ReadPublicKey", rc);
            }
            return(rc);
        }
示例#2
0
        public int StoreKey(KeyBlob keyBlob, ulong primaryHandle, ulong persistentHandle)
        {
            int rc = wolfTPM2_NVStoreKey(device, primaryHandle, keyBlob.keyblob,
                                         persistentHandle);

            if (rc != (int)Status.TPM_RC_SUCCESS &&
                rc != (int)Status.TPM_RC_NV_UNAVAILABLE)
            {
                throw new WolfTpm2Exception(
                          "wolfTPM2_NVStoreKey", rc);
            }
            return(rc);
        }
示例#3
0
        public int LoadKey(KeyBlob keyBlob,
                           Key parent)
        {
            int rc = wolfTPM2_LoadKey(device, keyBlob.keyblob,
                                      parent.GetHandle());

            if (rc != (int)Status.TPM_RC_SUCCESS)
            {
                throw new WolfTpm2Exception(
                          "wolfTPM2_LoadKey", rc);
            }
            return(rc);
        }
示例#4
0
        public int MakeAndSign(Device device,
                               KeyBlob keyBlob,
                               X509_Format outputFormat,
                               byte[] output)
        {
            int rc = wolfTPM2_CSR_MakeAndSign(device.Ref, csr,
                                              keyBlob.keyblob, (int)outputFormat, output, output.Length);

            /* positive return code is length of resulting output */
            if (rc < 0)
            {
                throw new WolfTpm2Exception(
                          "wolfTPM2_CSR_MakeAndSign", rc);
            }
            return(rc);
        }
示例#5
0
        public int MakeAndSign(Device device,
                               KeyBlob keyBlob,
                               X509_Format outputFormat,
                               byte[] output,
                               int sigType,
                               int selfSign)
        {
            int rc = wolfTPM2_CSR_MakeAndSign_ex(device.Ref, csr,
                                                 keyBlob.keyblob, (int)outputFormat, output, output.Length,
                                                 sigType, selfSign, Device.INVALID_DEVID);

            if (rc != (int)Status.TPM_RC_SUCCESS)
            {
                throw new WolfTpm2Exception(
                          "wolfTPM2_CSR_MakeAndSign_ex", rc);
            }
            return(rc);
        }
示例#6
0
        public int CreateKey(KeyBlob keyBlob,
                             Key parent,
                             Template publicTemplate,
                             string auth)
        {
            int rc = wolfTPM2_CreateKey(device,
                                        keyBlob.keyblob,
                                        parent.GetHandle(),
                                        publicTemplate.template,
                                        auth,
                                        auth.Length);

            if (rc != (int)Status.TPM_RC_SUCCESS)
            {
                throw new WolfTpm2Exception(
                          "wolfTPM2_CreateKey", rc);
            }
            return(rc);
        }
示例#7
0
        public int GenerateCSR(
            KeyBlob keyBlob,
            string subject,
            string keyUsage,
            X509_Format outputFormat,
            byte[] output)
        {
            int rc = wolfTPM2_CSR_Generate(
                device,
                keyBlob.keyblob,
                subject,
                keyUsage,
                (int)outputFormat,
                output, output.Length);

            /* positive return code is length of resulting output */
            if (rc < 0)
            {
                throw new WolfTpm2Exception(
                          "wolfTPM2_CSR_Generate", rc);
            }
            return(rc);
        }
示例#8
0
 public int UnloadHandle(KeyBlob keyBlob)
 {
     return(wolfTPM2_UnloadHandle(device, keyBlob.GetHandle()));
 }