Example #1
0
        protected override TPMCommandResponse InternalProcess()
        {
            byte[] ownerAuth = _params.GetValueOf <byte[]> (PARAM_OWNERAUTH);
            byte[] srkAuth   = _params.GetValueOf <byte[]> (PARAM_SRKAUTH);


            TPMBlob requestBlob = new TPMBlob();

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

            requestBlob.WriteUInt16((ushort)TPMProtocolId.TPM_PID_OWNER);

            requestBlob.WriteUInt32((uint)ownerAuth.Length);
            requestBlob.Write(ownerAuth, 0, ownerAuth.Length);

            requestBlob.WriteUInt32((uint)srkAuth.Length);
            requestBlob.Write(srkAuth, 0, srkAuth.Length);

            _tpmKey.WriteToTpmBlob(requestBlob);

            _responseBlob = AuthorizeMeAndTransmit(requestBlob);

            CheckResponseAuthInfo();

            return(new TPMCommandResponse(true, TPMCommandNames.TPM_CMD_TakeOwnership, new Parameters()));
        }
 public void WriteAuthorizationInfo(TPMBlob target, AuthorizationInfo authInfo)
 {
     target.WriteUInt32(authInfo.Handle.Handle);
     target.Write(authInfo.Handle.NonceOdd, 0, authInfo.Handle.NonceOdd.Length);
     target.WriteBool(authInfo.ContinueAuthSession);
     target.Write(authInfo.AuthData, 0, authInfo.AuthData.Length);
 }
Example #3
0
        public override TPMCommandResponse Process()
        {
            ITPMHandle handle = _params.GetValueOf <ITPMHandle> ("handle");

            TPMBlob requestBlob = new TPMBlob();

            requestBlob.WriteCmdHeader(TPMCmdTags.TPM_TAG_RQU_COMMAND, TPMOrdinals.TPM_ORD_FlushSpecific);
            requestBlob.WriteUInt32(handle.Handle);
            requestBlob.WriteUInt32((uint)handle.ResourceType);

            requestBlob.WriteCmdSize();

            try
            {
                TransmitMe(requestBlob);
            }
            catch (Exception)
            {
                if (!_params.GetValueOf <bool>("ignore_tpm_error", false))
                {
                    throw;
                }
            }

            return(new TPMCommandResponse(true, TPMCommandNames.TPM_CMD_FlushSpecific, new Parameters()));
        }
Example #4
0
 public void WriteToTpmBlob(TPMBlob blob)
 {
     blob.WriteByte(_major);
     blob.WriteByte(_minor);
     blob.WriteByte(_revMajor);
     blob.WriteByte(_revMinor);
 }
Example #5
0
 public void ReadFromTpmBlob(TPMBlob blob)
 {
     _major    = blob.ReadByte();
     _minor    = blob.ReadByte();
     _revMajor = blob.ReadByte();
     _revMinor = blob.ReadByte();
 }
Example #6
0
            public static TPMVersionCore CreateFromTPMBlob(TPMBlob blob)
            {
                TPMVersionCore version = new TPMVersionCore();

                version.ReadFromTpmBlob(blob);
                return(version);
            }
Example #7
0
        public static TPMStorePubkeyCore CreateFromTpmBlob(TPMBlob blob)
        {
            TPMStorePubkeyCore pubkey = new TPMStorePubkeyCore();

            pubkey.ReadFromTpmBlob(blob);
            return(pubkey);
        }
Example #8
0
        public static TPMPCRInfoCore CreateFromTPMBlob(TPMBlob blob)
        {
            TPMPCRInfoCore pcrInfo = new TPMPCRInfoCore();

            pcrInfo.ReadFromTpmBlob(blob);
            return(pcrInfo);
        }
Example #9
0
 public ResponseAuthHandleInfoCore(TPMBlob blob, long startIndex)
 {
     blob.Seek(startIndex, SeekOrigin.Begin);
     _nonceEven           = blob.ReadBytes(20);
     _continueAuthSession = blob.ReadBool();
     _tpmAuthData         = blob.ReadBytes(20);
 }
Example #10
0
 public void WriteToTpmBlob(TPMBlob blob)
 {
     blob.WriteUInt32((uint)_algorithmId);
     blob.WriteUInt16((ushort)_encScheme);
     blob.WriteUInt16((ushort)_sigScheme);
     TPMBlobWriteableHelper.WriteITPMBlobWritableWithUIntSize(blob, (ITPMBlobWritable)_params);
 }
Example #11
0
        public static TPMStoredDataCore CreateFromTPMBlob(TPMBlob blob)
        {
            TPMStoredDataCore storedData = new TPMStoredDataCore();

            storedData.ReadFromTpmBlob(blob);
            return(storedData);
        }
Example #12
0
        public static TPMKeyParamsCore CreateFromTPMBlob(TPMBlob blob)
        {
            TPMKeyParamsCore keyParams = new TPMKeyParamsCore();

            keyParams.ReadFromTpmBlob(blob);
            return(keyParams);
        }
Example #13
0
        public void ReadFromTpmBlob(TPMBlob blob)
        {
            _algorithmId = (TPMAlgorithmId)blob.ReadUInt32();
            _encScheme   = (TPMEncScheme)blob.ReadUInt16();
            _sigScheme   = (TPMSigScheme)blob.ReadUInt16();

            UInt32 paramsSize = blob.ReadUInt32();

            byte[] paramsData = new byte[paramsSize];

            blob.Read(paramsData, 0, paramsData.Length);

            using (TPMBlob paramSrc = new TPMBlob(paramsData))
            {
                if (_algorithmId == TPMAlgorithmId.TPM_ALG_RSA)
                {
                    _params = TPMRSAKeyParamsCore.CreateFromTPMBlob(paramSrc);
                }
                else if (_algorithmId == TPMAlgorithmId.TPM_ALG_AES128 ||
                         _algorithmId == TPMAlgorithmId.TPM_ALG_AES192 ||
                         _algorithmId == TPMAlgorithmId.TPM_ALG_AES256)
                {
                    //TODO
                    throw new NotImplementedException("Symmetric key params not implemented");
                }
            }
        }
Example #14
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));
        }
Example #15
0
        public override TPMCommandResponse Process()
        {
            if (_params.IsDefined <ITPMHandle>("handle") == false ||
                _params.IsDefined <byte[]>("context_blob") == false)
            {
                return(new TPMCommandResponse(false, TPMCommandNames.TPM_CMD_LoadContext, new Parameters()));
            }

            ITPMHandle handle = _params.GetValueOf <ITPMHandle>("handle");


            TPMBlob blob = new TPMBlob();

            blob.WriteCmdHeader(TPMCmdTags.TPM_TAG_RQU_COMMAND, TPMOrdinals.TPM_ORD_LoadContext);
            blob.WriteUInt32(handle.Handle);
            blob.WriteBool(handle.ForceHandle);
            blob.WriteUInt32((uint)handle.ContextBlob.Length);
            blob.Write(handle.ContextBlob, 0, handle.ContextBlob.Length);

            TPMBlob responseBlob = TransmitMe(blob);

            responseBlob.SkipHeader();
            handle.Handle = responseBlob.ReadUInt32();

            Parameters responseParameters = new Parameters();

            responseParameters.AddValue("handle", handle);

            return(new TPMCommandResponse(true, TPMCommandNames.TPM_CMD_LoadContext, responseParameters));
        }
Example #16
0
 /// <summary>
 /// Transmit a blob to the given network stream
 /// </summary>
 /// <param name="stm"></param>
 /// <param name="tpmBlob"></param>
 public static void SendBlob(Stream stm, TPMBlob tpmBlob)
 {
     // We need to have a valid size when working over the network
     // Disabled for now - tpmBlob.WriteCmdSize();
     //tpmBlob.WriteCmdSize();
     RawSendBlob(stm, tpmBlob.GetBuffer(), (int)tpmBlob.Length);
 }
Example #17
0
        public static TPMPCRSelectionCore CreateFromTPMBlob(TPMBlob blob)
        {
            TPMPCRSelectionCore pcrSelection = new TPMPCRSelectionCore();

            pcrSelection.ReadFromTpmBlob(blob);
            return(pcrSelection);
        }
Example #18
0
        /// <summary>
        /// Transmit and check the given TPM blob.
        /// </summary>
        /// <param name="blob"></param>
        /// <returns></returns>
        public TPMBlob TransmitAndCheck(TPMBlob blob, bool writeSize)
        {
            ushort expected_rsp_tag;

            // Determine the expected RSP tag
            blob.Position = 0;
            switch (blob.ReadUInt16())
            {
            case TPMCmdTags.TPM_TAG_RQU_COMMAND:
                expected_rsp_tag = TPMCmdTags.TPM_TAG_RSP_COMMAND;
                break;

            case TPMCmdTags.TPM_TAG_RQU_AUTH1_COMMAND:
                expected_rsp_tag = TPMCmdTags.TPM_TAG_RSP_AUTH1_COMMAND;
                break;

            case TPMCmdTags.TPM_TAG_RQU_AUTH2_COMMAND:
                expected_rsp_tag = TPMCmdTags.TPM_TAG_RSP_AUTH2_COMMAND;
                break;

            default:
                throw new Exception();
                //throw new TpmCommandException("Unsupported TPM request tag", blob);
            }

            // Do the actual transaction
            TPMBlob rsp = Transmit(blob, writeSize);

            // Check the response
            CheckTpmReponse(rsp, expected_rsp_tag);

            return(rsp);
        }
Example #19
0
        public static TPMPCRCompositeCore CreateFromTPMBlob(TPMBlob blob)
        {
            TPMPCRCompositeCore pcrComposite = new TPMPCRCompositeCore();

            pcrComposite.ReadFromTpmBlob(blob);
            return(pcrComposite);
        }
Example #20
0
        public static TPMCounterValueCore CreateFromTPMBlob(TPMBlob blob)
        {
            TPMCounterValueCore counterValue = new TPMCounterValueCore();

            counterValue.ReadFromTpmBlob(blob);
            return(counterValue);
        }
Example #21
0
        public static TPMPubkeyCore CreateFromTPMBlob(TPMBlob src)
        {
            TPMPubkeyCore pubkey = new TPMPubkeyCore();

            pubkey.ReadFromTpmBlob(src);
            return(pubkey);
        }
Example #22
0
 public void WriteToTpmBlob(TPMBlob blob)
 {
     ((ITPMBlobWritable)_version).WriteToTpmBlob(blob);
     blob.Write(_fixed, 0, _fixed.Length);
     blob.Write(_compositeHash, 0, _compositeHash.Length);
     blob.Write(_nonce, 0, _nonce.Length);
 }
Example #23
0
 public void WriteToTpmBlob(TPMBlob blob)
 {
     ((ITPMBlobWritable)_versionStruct).WriteToTpmBlob(blob);
     blob.WriteUInt32((uint)_sealInfo.Length);
     blob.Write(_sealInfo, 0, _sealInfo.Length);
     blob.WriteUInt32((uint)_encData.Length);
     blob.Write(_encData, 0, _encData.Length);
 }
Example #24
0
        public void WriteToTpmBlob(TPMBlob blob)
        {
            blob.WriteUInt32(_keyLength);
            blob.WriteUInt32(_numPrimes);

            blob.WriteUInt32((uint)_exponent.Length);
            blob.Write(_exponent, 0, _exponent.Length);
        }
Example #25
0
        public void ReadFromTpmBlob(TPMBlob blob)
        {
            uint size = blob.ReadUInt16();

            byte[] selectionBits = new byte[size];
            blob.Read(selectionBits, 0, (int)size);
            _pcrSelection = new BitMap(selectionBits);
        }
Example #26
0
        public HashTPMBlobWritableDataProvider(ITPMBlobWritable blobWritable)
        {
            TPMBlob tempBlob = new TPMBlob();

            blobWritable.WriteToTpmBlob(tempBlob);

            _subDataProvider = new HashStreamDataProvider(tempBlob, null, null, true);
        }
Example #27
0
        /// <summary>
        /// TPM response check with tag test
        /// </summary>
        /// <param name="rsp"></param>
        /// <param name="p"></param>
        public void CheckTpmReponse(TPMBlob rsp, ushort expected_tag)
        {
            ushort currentTag = CheckTpmReponse(rsp);

            if (currentTag != expected_tag)
            {
                throw new TPMResponseException(-1, string.Format("TPM response tag does not match request tag, received: {0}, expected: {1}", currentTag, expected_tag), rsp);
            }
        }
Example #28
0
        public void ReadFromTpmBlob(TPMBlob blob)
        {
            UInt16 handleCount = blob.ReadUInt16();

            for (int i = 0; i < handleCount; i++)
            {
                _handles.Add(blob.ReadUInt32());
            }
        }
Example #29
0
        public void ReadFromTpmBlob(TPMBlob blob)
        {
            _pcrSelection = TPMPCRSelectionCore.CreateFromTPMBlob(blob);
            byte[] digestAtRelease  = new byte[20];
            byte[] digestAtCreation = new byte[20];

            blob.Read(digestAtRelease, 0, 20);
            blob.Read(digestAtCreation, 0, 20);
        }
Example #30
0
        public void WriteToTpmBlob(TPMBlob blob)
        {
            ((ITPMBlobWritable)_pcrSelection).WriteToTpmBlob(blob);
            blob.WriteUInt32((uint)_pcrValues.Length * 20);

            foreach (byte[] pcrValue in _pcrValues)
            {
                blob.Write(pcrValue, 0, pcrValue.Length);
            }
        }