예제 #1
0
파일: TPMContext.cs 프로젝트: deveck/doTSS
 public TPMContext(string deviceName, TPMWrapper tpm)
 {
     _deviceName = deviceName;
     _tpm = tpm;
     _authHandleManager = new AuthHandleManager(this);
     _keyManager = new KeyManager(this);
 }
예제 #2
0
        public override void Init(Parameters param, TPMProvider tpmProvider, TPMWrapper tpmWrapper)
        {
            base.Init (param, tpmProvider, tpmWrapper);

            _param = param;
            _capArea = param.GetValueOf<CapabilityData.TPMCapabilityArea> ("capArea");
        }
예제 #3
0
        /// <summary>
        /// Reads the configured tpm devices from the configuration and
        /// sets up the corresponding tpm contexts
        /// </summary>
        private void SetupTPMContexts()
        {
            IConnectionsConfiguration connectionConfig = (IConnectionsConfiguration)ConfigurationManager.GetSection ("connections");

            foreach (Iaik.Tc.TPM.Configuration.DotNetConfiguration.TPMDevice device in connectionConfig.TpmDevices)
            {
                try
                {
                    _logger.InfoFormat ("Setting up tpm context '{0}'", device.TPMName);
                    TPMWrapper tpmDevice = new TPMWrapper ();
                    tpmDevice.Init (device.TPMType, device.Parameters);
                    TPMContext tpmContext = new TPMContext (device.TPMName, tpmDevice);
                    _tpmContexts.Add (device.TPMName, tpmContext);

                    _logger.InfoFormat ("Flushing device '{0}'", device.TPMName);
                    foreach (TPMResourceType resourceType in new TPMResourceType[] {
                        TPMResourceType.TPM_RT_AUTH, TPMResourceType.TPM_RT_KEY})
                    {
                        Parameters listLoadedHandlesParameters = new Parameters ();
                        listLoadedHandlesParameters.AddPrimitiveType ("capArea", CapabilityData.TPMCapabilityArea.TPM_CAP_HANDLE);
                        listLoadedHandlesParameters.AddPrimitiveType ("handle_type", resourceType);
                        TPMCommandRequest listLoadedHandlesRequest = new TPMCommandRequest (TPMCommandNames.TPM_CMD_GetCapability,
                            listLoadedHandlesParameters);
                        TPMCommandResponse response = tpmDevice.Process (listLoadedHandlesRequest);

                        if (response.Status == false)
                            throw new Exception ("An unknown tpm exception while flushing occured");

                        foreach (uint handle in response.Parameters.GetValueOf<HandleList> ("handles"))
                        {
                            Parameters flushParameters = new Parameters ();
                            flushParameters.AddValue ("handle", HandleFactory.Create (resourceType, handle));
                            TPMCommandRequest flushRequest = new TPMCommandRequest (TPMCommandNames.TPM_CMD_FlushSpecific, flushParameters);
                            TPMCommandResponse flushResponse = tpmDevice.Process (flushRequest);

                            if (flushResponse.Status == false)
                                throw new Exception ("Something went wrong while flushing");

                        }
                    }

                    _logger.InfoFormat ("Successfully setup tpm context '{0}' with type '{1}'", device.TPMName, device.TPMType);
                }
                catch (Exception ex)
                {
                    _logger.FatalFormat ("Error setting up tpm device '{0}', the device will not be available ({1})", device.TPMName, ex);
                }

                ///Set the Assembly search order for incoming Parameters so that core classes are always at first
                Parameters.AssemblySearchOrder = new Assembly[]{
                    typeof(TPMWrapper).Assembly, //lib core
                    typeof(ITypedParameter).Assembly};	//lib common

            }
        }
예제 #4
0
 public TpmKeymanager(TPMWrapper tpm)
 {
     _tpm = tpm;
 }
예제 #5
0
파일: TPM_PCRRead.cs 프로젝트: deveck/doTSS
 public override void Init(Parameters param, TPMProvider provider, TPMWrapper tpmWrapper)
 {
     base.Init(param, provider, tpmWrapper);
     _register = param.GetValueOf<UInt32>("pcrnum");
 }
예제 #6
0
파일: Main.cs 프로젝트: deveck/doTSS
        private static void ReadPCRs(TPMWrapper tpm)
        {
            uint i = 0;

            ILog log = LogManager.GetLogger("ReadPCRs");

            Parameters param = new Parameters();
            param.AddPrimitiveType("capArea", CapabilityData.TPMCapabilityArea.TPM_CAP_PROPERTY);
            param.AddPrimitiveType("subCap", CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_PCR);
            TPMCommandRequest request = new TPMCommandRequest(TPMCommandNames.TPM_CMD_GetCapability, param);
            TPMCommandResponse response = tpm.Process(request);

            uint maxPcrs = response.Parameters.GetValueOf<uint>(CapabilityData.PARAM_PROP_PCR);

            for(i=0; i<maxPcrs; ++i){

                param = new Parameters();
                param.AddPrimitiveType("pcrnum", i);
                TPMCommandRequest req = new TPMCommandRequest(TPMCommandNames.TPM_CMD_PCRRead,param);
                TPMCommandResponse resp = tpm.Process(req);

                byte[] val = resp.Parameters.GetValueOf<byte[]>("value");

                log.InfoFormat("Answer for PCR {0} is: 0x{1}", resp.Parameters.GetValueOf<UInt32>("pcrnum"),
                               ByteHelper.ByteArrayToHexString(val));
            }

            //			TPMCommandRequest req = new TPMCommandRequest(TPMCommandNames.TPM_CMD_PCRRead, null);
            //			TPMCommand com = TPMCommandFactory.Create(req);
            //			com.Init(param, tpm);
            //			com.Process();
            //Console.WriteLine ("Hello World!");
        }
예제 #7
0
파일: Main.cs 프로젝트: deveck/doTSS
 private static void ReadCapabilities(TPMWrapper tpm)
 {
     ILog log = LogManager.GetLogger("ReadCapabilities");
     // Read out each capability property
     foreach(CapabilityData.TPMSubCapProperty subCap in Enum.GetValues(typeof(CapabilityData.TPMSubCapProperty)))
     {
         Parameters param = new Parameters();
         param.AddPrimitiveType("capArea", CapabilityData.TPMCapabilityArea.TPM_CAP_PROPERTY);
         param.AddPrimitiveType("subCap", subCap);
         TPMCommandRequest request = new TPMCommandRequest(TPMCommandNames.TPM_CMD_GetCapability, param);
         TPMCommandResponse response = tpm.Process(request);
         switch(subCap)
         {
         case CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_PCR:
             log.InfoFormat("Number of PCRs is {0}", response.Parameters.GetValueOf<uint>(CapabilityData.PARAM_PROP_PCR));
             break;
         //case CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_DIR:
         //    log.InfoFormat("Number of DIR is {0} and should be 1 because command is deprecated", response.Parameters.GetValueOf<uint>(CapabilityData.PARAM_PROP_DIR));
         //    break;
         case CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_MANUFACTURER:
             log.InfoFormat("Manufacturer ID is {0}", response.Parameters.GetValueOf<uint>(CapabilityData.PARAM_PROP_MANUFACTURER));
             break;
         case CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_KEYS:
             log.InfoFormat("Number of free keyslots is {0}", response.Parameters.GetValueOf<uint>(CapabilityData.PARAM_PROP_KEYS));
             break;
         case CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_MAX_AUTHSESS:
             log.InfoFormat("Number of max Auth Sessions is {0}", response.Parameters.GetValueOf<uint>(CapabilityData.PARAM_PROP_MAX_AUTHSESS));
             break;
         case CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_MAX_TRANSESS:
             log.InfoFormat("Number of max Trans Sessions is {0}", response.Parameters.GetValueOf<uint>(CapabilityData.PARAM_PROP_MAX_TRANSESS));
             break;
         case CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_MAX_KEYS:
             log.InfoFormat("Number of max keys (without EK and SRK) is {0}", response.Parameters.GetValueOf<uint>(CapabilityData.PARAM_PROP_MAX_KEYS));
             break;
         case CapabilityData.TPMSubCapProperty.TPM_CAP_PROP_MAX_SESSIONS:
             log.InfoFormat("Number of max Sessions is {0}", response.Parameters.GetValueOf<uint>(CapabilityData.PARAM_PROP_MAX_SESSIONS));
             break;
         default:
             throw new NotSupportedException("Defined cap or subcap are not supported");
         }
     }
 }
예제 #8
0
파일: Main.cs 프로젝트: deveck/doTSS
        private static AuthHandle EstablishOIAP(TPMWrapper tpm)
        {
            ILog log = LogManager.GetLogger ("EstablishOIAP");

            for (int i = 0; i < 2; i++)
            {
                TPMCommandRequest request = new TPMCommandRequest (TPMCommandNames.TPM_CMD_OIAP, new Parameters ());
                TPMCommandResponse response = tpm.Process (request);

                AuthHandle myAuthHandle = response.Parameters.GetValueOf<AuthHandle> ("auth_handle");

            //				Parameters parameters = new Parameters ();
                //				parameters.AddValue ("handle", myAuthHandle);
                //				TPMCommandRequest requestFlush = new TPMCommandRequest (TPMCommandNames.TPM_CMD_FLUSH_SPECIFIC, parameters);
                //				tpm.Process (requestFlush);

            //return myAuthHandle;
            }

            Parameters listHandlesParameters = new Parameters ();
            listHandlesParameters.AddPrimitiveType ("capArea", CapabilityData.TPMCapabilityArea.TPM_CAP_HANDLE);
            listHandlesParameters.AddPrimitiveType ("handle_type", TPMResourceType.TPM_RT_AUTH);

            TPMCommandRequest listHandlesRequest = new TPMCommandRequest (TPMCommandNames.TPM_CMD_GetCapability, listHandlesParameters);
            TPMCommandResponse listHandlesResponse = tpm.Process (listHandlesRequest);

            HandleList loadedKeyHandles = listHandlesResponse.Parameters.GetValueOf<HandleList> ("handles");

            return null;
        }