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"); } } }
public void ReadFromTpmBlob(TPMBlob blob) { _versionStruct = CapabilityDataCore.TPMVersionCore.CreateFromTPMBlob(blob); _sealInfo = new byte[blob.ReadUInt32()]; blob.Read(_sealInfo, 0, _sealInfo.Length); _encData = new byte[blob.ReadUInt32()]; blob.Read(_encData, 0, _encData.Length); }
public void ReadFromTpmBlob(TPMBlob blob) { _keyLength = blob.ReadUInt32(); _numPrimes = blob.ReadUInt32(); uint expoSize = blob.ReadUInt32(); _exponent = new byte[expoSize]; blob.Read(_exponent, 0, (int)expoSize); }
private uint ReadUInt32Response(TPMBlob response) { uint responseSize = response.ReadUInt32(); if (responseSize != 4) { throw new TPMResponseException(string.Format("Capability response size mismatch (should be 4, and is {0})", responseSize)); } return(response.ReadUInt32()); }
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)); }
public void ReadFromTpmBlob(TPMBlob blob) { _version = CapabilityDataCore.TPMVersionCore.CreateFromTPMBlob(blob); _keyUsage = (TPMKeyUsage)blob.ReadUInt16(); _keyFlags = (TPMKeyFlags)blob.ReadUInt32(); _authDataUsage = (TPMAuthDataUsage)blob.ReadByte(); _algorithmParams = TPMKeyParamsCore.CreateFromTPMBlob(blob); uint pcrInfoSize = blob.ReadUInt32(); /*byte[] pcrInfo =*/ blob.ReadBytes((int)pcrInfoSize); _pubKey = TPMStorePubkeyCore.CreateFromTpmBlob(blob); uint encDataSize = blob.ReadUInt32(); _encData = blob.ReadBytes((int)encDataSize); }
public void ReadFromTpmBlob(TPMBlob blob) { UInt16 handleCount = blob.ReadUInt16(); for (int i = 0; i < handleCount; i++) { _handles.Add(blob.ReadUInt32()); } }
/// <summary> /// Check a TPM reply blob /// </summary> /// <param name="reply">The tag type of this blob</param> public UInt16 CheckTpmReponse(TPMBlob reply) { if (reply.Length < 10) { throw new Exception(); } //throw new TpmCommandException("Short TPM response", reply); // Start from position zero reply.Position = 0; // Check the reply tag ushort replyTag = reply.ReadUInt16(); if (replyTag != TPMCmdTags.TPM_TAG_RSP_COMMAND && replyTag != TPMCmdTags.TPM_TAG_RSP_AUTH1_COMMAND && replyTag != TPMCmdTags.TPM_TAG_RSP_AUTH2_COMMAND) { throw new Exception(); //throw new TpmCommandException("Invalid TPM response tag", reply); } // Check the parameter size uint paramSize = reply.ReadUInt32(); if ((int)paramSize != reply.Length) { throw new Exception(); //throw new TpmCommandException("Bad TPM response paramSize", reply); } // Finally check the TPM result uint tpmResult = reply.ReadUInt32(); if (tpmResult != 0) { throw new TPMResponseException((Int64)tpmResult, TPMErrorCodeToMessage(tpmResult), reply); } return(replyTag); }
public void ReadFromTpmBlob(TPMBlob blob) { _pcrSelection = TPMPCRSelectionCore.CreateFromTPMBlob(blob); uint valueSize = blob.ReadUInt32(); _pcrValues = new byte[valueSize / 20][]; for (int i = 0; i < valueSize / 20; i++) { _pcrValues[i] = blob.ReadBytes(20); } }
public void ReadFromTpmBlob(TPMBlob blob) { _authHandle = blob.ReadUInt32(); _nonceEven = new byte[20]; blob.Read(_nonceEven, 0, _nonceEven.Length); if (_authType == AuthHandle.AuthType.OSAP) { _nonceEvenOSAP = new byte[20]; blob.Read(_nonceEvenOSAP, 0, _nonceEvenOSAP.Length); } }
public void ReadFromTpmBlob(TPMBlob blob) { /*uint responseSize = */ blob.ReadUInt32(); this._tag = blob.ReadUInt16(); this._version = new TPMVersionCore(blob); this._specLevel = blob.ReadUInt16(); this._errataRev = blob.ReadByte(); this._tpmVendorId = new byte[4]; blob.Read(_tpmVendorId, 0, _tpmVendorId.Length); ushort vendorSize = blob.ReadUInt16(); _vendorSpecific = blob.ReadBytes(vendorSize); }
public override TPMCommandResponse Process() { //We don't have any meaningful labeldata we could include, //so generate some random byte[] labelData = new byte[16]; Random r = new Random(); r.NextBytes(labelData); if (_params.IsDefined <ITPMHandle>("handle") == false) { return(new TPMCommandResponse(false, TPMCommandNames.TPM_CMD_SaveContext, new Parameters())); } ITPMHandle handle = _params.GetValueOf <ITPMHandle>("handle"); TPMBlob requestBlob = new TPMBlob(); requestBlob.WriteCmdHeader(TPMCmdTags.TPM_TAG_RQU_COMMAND, TPMOrdinals.TPM_ORD_SaveContext); requestBlob.WriteUInt32(handle.Handle); requestBlob.WriteUInt32((uint)handle.ResourceType); requestBlob.Write(labelData, 0, labelData.Length); TPMBlob responseBlob = TransmitMe(requestBlob); responseBlob.SkipHeader(); uint blobSize = responseBlob.ReadUInt32(); byte[] contextBlob = responseBlob.ReadBytes((int)blobSize); Parameters responseParams = new Parameters(); responseParams.AddPrimitiveType("context_blob", contextBlob); return(new TPMCommandResponse(true, TPMCommandNames.TPM_CMD_SaveContext, responseParams)); }
public void ReadFromTpmBlob(TPMBlob blob) { _structureTag = (TPMStructureTag)blob.ReadUInt16(); _label = blob.ReadBytes(4); _counterValue = blob.ReadUInt32(); }
public override TPMCommandResponse Process() { TPMBlob requestBlob = new TPMBlob(); requestBlob.WriteCmdHeader(TPMCmdTags.TPM_TAG_RQU_COMMAND, TPMOrdinals.TPM_ORD_GetCapability); requestBlob.WriteUInt32((uint)_capArea); switch (_capArea) { case CapabilityData.TPMCapabilityArea.TPM_CAP_VERSION_VAL: //Subcaps are ignored by TPM_CAP_VERSION_VAL requestBlob.WriteUInt32(0); break; case CapabilityData.TPMCapabilityArea.TPM_CAP_HANDLE: requestBlob.WriteUInt32(4); requestBlob.WriteUInt32((uint)_param.GetValueOf <TPMResourceType> ("handle_type")); break; case CapabilityData.TPMCapabilityArea.TPM_CAP_PROPERTY: CapabilityData.TPMSubCapProperty subCap = _param.GetValueOf <CapabilityData.TPMSubCapProperty> ("subCap"); //Size of subcap requestBlob.WriteUInt32(4); requestBlob.WriteUInt32((uint)subCap); break; case CapabilityData.TPMCapabilityArea.TPM_CAP_SELECT_SIZE: CapabilityDataCore.TPMSelectSizeCore tpmSelectSize = CapabilityDataCore.TPMSelectSizeCore.CreateVersion12(_param.GetValueOf <ushort>(CapabilityData.PARAM_PROP_SELECT_SIZE)); TPMBlobWriteableHelper.WriteITPMBlobWritableWithUIntSize(requestBlob, tpmSelectSize); break; default: throw new NotSupportedException("Defined cap or subcap are not supported"); } // if (_capArea == CapabilityData.TPMCapabilityArea.TPM_CAP_VERSION_VAL) // { // //Subcaps are ignored by TPM_CAP_VERSION_VAL // requestBlob.WriteUInt32 (0); // } // else if (_capArea == CapabilityData.TPMCapabilityArea.TPM_CAP_HANDLE) // { // requestBlob.WriteUInt32 (4); // requestBlob.WriteUInt32 ((uint)_param.GetValueOf<TPMResourceType> ("handle_type")); // } // else if (_capArea == CapabilityData.TPMCapabilityArea.TPM_CAP_PROPERTY) // { // CapabilityData.TPMSubCapProperty subCap = _param.GetValueOf<CapabilityData.TPMSubCapProperty> ("subCap"); // // //Size of subcap // requestBlob.WriteUInt32 (4); // requestBlob.WriteUInt32 ((uint)subCap); // } // else // throw new NotSupportedException ("Defined cap or subcap are not supported"); requestBlob.WriteCmdSize(); TPMBlob responseBlob = TransmitMe(requestBlob); responseBlob.SkipHeader(); Parameters parameters = new Parameters(); switch (_capArea) { case CapabilityData.TPMCapabilityArea.TPM_CAP_VERSION_VAL: CapabilityDataCore.TPMCapVersionInfoCore tpmVersionInfo = new CapabilityDataCore.TPMCapVersionInfoCore(responseBlob); parameters.AddValue(CapabilityData.PARAM_TPM_VERSION_INFO, tpmVersionInfo); break; case CapabilityData.TPMCapabilityArea.TPM_CAP_HANDLE: responseBlob.SkipHeader(); //Reads the response size, which is ignored responseBlob.ReadUInt32(); HandleListCore handleList = new HandleListCore(responseBlob, _param.GetValueOf <TPMResourceType> ("handle_type")); parameters.AddValue("handles", handleList); break; case CapabilityData.TPMCapabilityArea.TPM_CAP_PROPERTY: responseBlob.SkipHeader(); switch (_param.GetValueOf <CapabilityData.TPMSubCapProperty> ("subCap")) { case CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_PCR: parameters.AddPrimitiveType(CapabilityData.PARAM_PROP_PCR, ReadUInt32Response(responseBlob)); break; //case CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_DIR: // parameters.AddPrimitiveType (CapabilityData.PARAM_PROP_DIR, ReadUInt32Response (responseBlob)); // break; case CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_MANUFACTURER: parameters.AddPrimitiveType(CapabilityData.PARAM_PROP_MANUFACTURER, ReadUInt32Response(responseBlob)); break; case CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_KEYS: parameters.AddPrimitiveType(CapabilityData.PARAM_PROP_KEYS, ReadUInt32Response(responseBlob)); break; case CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_MAX_AUTHSESS: parameters.AddPrimitiveType(CapabilityData.PARAM_PROP_MAX_AUTHSESS, ReadUInt32Response(responseBlob)); break; case CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_MAX_TRANSESS: parameters.AddPrimitiveType(CapabilityData.PARAM_PROP_MAX_TRANSESS, ReadUInt32Response(responseBlob)); break; case CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_MAX_KEYS: parameters.AddPrimitiveType(CapabilityData.PARAM_PROP_MAX_KEYS, ReadUInt32Response(responseBlob)); break; case CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_MAX_SESSIONS: parameters.AddPrimitiveType(CapabilityData.PARAM_PROP_MAX_SESSIONS, ReadUInt32Response(responseBlob)); break; default: throw new NotSupportedException("Defined cap or subcap are not supported"); } break; case CapabilityData.TPMCapabilityArea.TPM_CAP_SELECT_SIZE: parameters.AddPrimitiveType(CapabilityData.PARAM_PROP_SELECT_SIZE, ReadBoolResponse(responseBlob)); break; } // if (_capArea == CapabilityData.TPMCapabilityArea.TPM_CAP_VERSION_VAL) // { // CapabilityDataCore.TPMCapVersionInfoCore tpmVersionInfo = new CapabilityDataCore.TPMCapVersionInfoCore (responseBlob); // parameters.AddValue (CapabilityData.PARAM_TPM_VERSION_INFO, tpmVersionInfo); // } // else if (_capArea == CapabilityData.TPMCapabilityArea.TPM_CAP_HANDLE) // { // responseBlob.SkipHeader (); // // //Reads the response size, which is ignored // responseBlob.ReadUInt32 (); // // HandleListCore handleList = new HandleListCore (responseBlob, _param.GetValueOf<TPMResourceType> ("handle_type")); // parameters.AddValue ("handles", handleList); // } // // // else if (_capArea == CapabilityData.TPMCapabilityArea.TPM_CAP_PROPERTY && // _param.GetValueOf<CapabilityData.TPMSubCapProperty> ("subCap") == CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_PCR) // { // responseBlob.SkipHeader (); // parameters.AddPrimitiveType (CapabilityData.PARAM_PROP_PCR, ReadUInt32Response (responseBlob)); // } // // else if (_capArea == CapabilityData.TPMCapabilityArea.TPM_CAP_PROPERTY && // _param.GetValueOf<CapabilityData.TPMSubCapProperty> ("subCap") == CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_MAX_AUTHSESS) // { // responseBlob.SkipHeader (); // parameters.AddPrimitiveType (CapabilityData.PARAM_PROP_MAX_AUTHSESS, ReadUInt32Response (responseBlob)); // } // // else if (_capArea == CapabilityData.TPMCapabilityArea.TPM_CAP_PROPERTY && // _param.GetValueOf<CapabilityData.TPMSubCapProperty> ("subCap") == CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_MAX_TRANSESS) // { // responseBlob.SkipHeader (); // parameters.AddPrimitiveType (CapabilityData.PARAM_PROP_MAX_TRANSESS, ReadUInt32Response (responseBlob)); // } // // else if (_capArea == CapabilityData.TPMCapabilityArea.TPM_CAP_PROPERTY && // _param.GetValueOf<CapabilityData.TPMSubCapProperty> ("subCap") == CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_MAX_SESSIONS) // { // responseBlob.SkipHeader (); // parameters.AddPrimitiveType (CapabilityData.PARAM_PROP_MAX_SESSIONS, ReadUInt32Response (responseBlob)); // } // else // throw new NotSupportedException("Defined cap or subcap are not supported"); return(new TPMCommandResponse(true, TPMCommandNames.TPM_CMD_GetCapability, parameters)); }
public void ReadFromTpmBlob(TPMBlob blob) { uint keyLength = blob.ReadUInt32(); _pubkey = blob.ReadBytes((int)keyLength); }