예제 #1
0
        public override TPMCommandResponse Process()
        {
            TPMBlob requestBlob = new TPMBlob();

            requestBlob.WriteCmdHeader(TPMCmdTags.TPM_TAG_RQU_COMMAND, TPMOrdinals.TPM_ORD_OIAP);
            requestBlob.WriteCmdSize();

            _commandAuthHelper.EnsureFreeSlot();
            TPMBlob responseBlob = TransmitMe(requestBlob);

            responseBlob.SkipHeader();
            AuthHandleCore authHandle = new AuthHandleCore(AuthHandle.AuthType.OIAP, responseBlob);

            _responseParameters = new Parameters();
            _responseParameters.AddValue("auth_handle", authHandle);
            return(new TPMCommandResponse(true, TPMCommandNames.TPM_CMD_OIAP, _responseParameters));
        }
예제 #2
0
        public override TPMCommandResponse Process()
        {
            TPMEntityTypeLSB entityLSB  = _params.GetValueOf <TPMEntityTypeLSB>("entity_lsb");
            TPMEntityTypeMSB entityMSB  = _params.GetValueOf <TPMEntityTypeMSB>("entity_msb");
            string           identifier = _params.GetValueOf <string>("entity_value");


            if (entityLSB != TPMEntityTypeLSB.TPM_ET_KEYHANDLE &&
                entityLSB != TPMEntityTypeLSB.TPM_ET_SRK &&
                entityLSB != TPMEntityTypeLSB.TPM_ET_OWNER)
            {
                throw new ArgumentException("TPM_OSAP does currently not support entityType: " + entityLSB.ToString());
            }

            if (entityMSB != TPMEntityTypeMSB.TPM_ET_XOR)
            {
                throw new ArgumentException(string.Format("TPM_OSAP does currently not support '{0}' EncAuth encryption", entityMSB));
            }


            if (entityLSB == TPMEntityTypeLSB.TPM_ET_KEYHANDLE ||
                entityLSB == TPMEntityTypeLSB.TPM_ET_SRK)
            {
                //We now know that the current identifier is a key identifier (maybe srk, but then the value is ignored by TPM_OSAP).
                //So we invoke the key manager to load the key with the specified identifier and establish an OSAP session
                _keyManager.LoadKey(identifier);
            }

            //handle is not known yet
            AuthHandle authHandle = new AuthHandle(AuthHandle.AuthType.OSAP, 0);

            authHandle.EntityType = entityLSB;
            authHandle.NewNonceOddOSAP();


            using (_keyManager.AcquireLock())
            {
                TPMBlob requestBlob = new TPMBlob();
                requestBlob.WriteCmdHeader(TPMCmdTags.TPM_TAG_RQU_COMMAND, TPMOrdinals.TPM_ORD_OSAP);
                requestBlob.WriteUInt16((ushort)(((ushort)entityMSB << 8) | (ushort)entityLSB));

                if (entityLSB == TPMEntityTypeLSB.TPM_ET_KEYHANDLE ||
                    entityLSB == TPMEntityTypeLSB.TPM_ET_SRK)
                {
                    if (identifier == KeyHandle.KEY_SRK)
                    {
                        requestBlob.WriteUInt32((uint)TPMKeyHandles.TPM_KH_SRK);
                        authHandle.EntityValue = (uint)TPMKeyHandles.TPM_KH_SRK;
                    }
                    else
                    {
                        KeyHandle keyHandle = _keyManager.IdentifierToHandle(identifier);
                        requestBlob.WriteUInt32(keyHandle.Handle);
                        authHandle.EntityValue = keyHandle.Handle;
                    }
                }
                else if (entityLSB == TPMEntityTypeLSB.TPM_ET_OWNER)
                {
                    requestBlob.WriteUInt32((uint)TPMKeyHandles.TPM_KH_OWNER);
                    authHandle.EntityValue = (uint)TPMKeyHandles.TPM_KH_OWNER;
                }

                requestBlob.Write(authHandle.NonceOddOSAP, 0, authHandle.NonceOddOSAP.Length);
                requestBlob.WriteCmdSize();

                _commandAuthHelper.EnsureFreeSlot();
                _responseBlob = TransmitMe(requestBlob);
            }

            _responseBlob.SkipHeader();
            AuthHandleCore receivedAuthHandle = new AuthHandleCore(AuthHandle.AuthType.OSAP, _responseBlob);

            authHandle.UpdateFromOtherAuthHandle(receivedAuthHandle);


            _responseParameters = new Parameters();
            _responseParameters.AddValue("auth_handle", authHandle);
            return(new TPMCommandResponse(true, TPMCommandNames.TPM_CMD_OSAP, _responseParameters));
        }