Exemplo n.º 1
0
        public override TPMCommandResponse Process()
        {
            byte[] nonce = NonceGenerator.GenerateByteNonce(20);

            TPMBlob requestBlob = new TPMBlob();

            requestBlob.WriteCmdHeader(TPMCmdTags.TPM_TAG_RQU_COMMAND, TPMOrdinals.TPM_ORD_ReadPubek);
            requestBlob.Write(nonce, 0, nonce.Length);
            requestBlob.WriteCmdSize();

            TPMBlob responseBlob = TransmitMe(requestBlob);

            responseBlob.SkipHeader();

            long          posStart = responseBlob.Position;
            TPMPubkeyCore pubkey   = TPMPubkeyCore.CreateFromTPMBlob(responseBlob);
            long          posEnd   = responseBlob.Position;

            Digest digest = new Digest(responseBlob, 20);

            if (digest.CompareTo(
                    new HashStreamDataProvider(responseBlob, posStart, posEnd - posStart, false),
                    new HashByteDataProvider(nonce)) == false)
            {
                throw new TPMResponseException("Local digest does not match remote digest");
            }

            Parameters responseParams = new Parameters();

            responseParams.AddValue(TPMPubkey.PARAM_TPM_PUBKEY, pubkey);

            return(new TPMCommandResponse(true, TPMCommandNames.TPM_CMD_ReadPubek, responseParams));
        }
Exemplo n.º 2
0
        protected override TPMCommandResponse InternalProcess()
        {
            TPMBlob requestBlob = new TPMBlob();

            requestBlob.WriteCmdHeader(TPMCmdTags.TPM_TAG_RQU_AUTH1_COMMAND, TPMOrdinals.TPM_ORD_GetPubKey);

            //If not loaded load now
            _keyManager.LoadKey(_params.GetValueOf <string>("key"));

            //KeyHandle To be inserted later
            requestBlob.WriteUInt32(0);

            //Blocking authorize, blocks till the user has entered the authorization data
            AuthorizeMe(requestBlob);

            using (_keyManager.AcquireLock())
            {
                //Write key handle to the first position after the header
                requestBlob.SkipHeader();
                requestBlob.WriteUInt32(_keyManager.IdentifierToHandle(_params.GetValueOf <string>("key")).Handle);

                _responseBlob = TransmitMe(requestBlob);
            }

            CheckResponseAuthInfo();

            _responseBlob.SkipHeader();

            TPMPubkeyCore pubKey = TPMPubkeyCore.CreateFromTPMBlob(_responseBlob);

            Parameters responseParams = new Parameters();

            responseParams.AddValue("pubkey", pubKey);

            return(new TPMCommandResponse(true, TPMCommandNames.TPM_CMD_GetPubKey, responseParams));
        }