using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Security.Cryptography; using System.Management.Automation; using System.Management.Automation.Provider; using Intel.Management.Mei; using Intel.Management.Wsman; using Intel.Management.PSModule.Amt; namespace Intel.Management.PSModule.Heci { /// /// ME Setup Services (Local and Remove) /// /// Local control mode supported on AMT 6.2 and above, Remote TLS setup supported by all class SetupService : DriveContainer { public SetupService(DriveItem parent) : base("Config", parent) { } public override void GetChildItems(ChildWriter writer) { writer.Add(new EtcService(this)); writer.Add(new LocalSetup(this)); writer.Add(new RemoteSetup(this)); } public override object GetReturnObject() { return new NameValuePairItem(Name, Value); } class RemoteSetup : DriveContainer { public RemoteSetup(DriveItem parent) : base("Remote", parent) { } public override void GetChildItems(ChildWriter writer) { HECIClass heci = ((HeciRoot)GetRoot()).Heci; heci.Init(); try { bool ztcEnabled; if (heci.GetZeroTouchEnabled(out ztcEnabled)) writer.Add(new DriveEntry("ZtcEnabled", ztcEnabled, this)); else writer.Add(new DriveEntry("ZtcEnabled", false, this)); HECIClass.ProvisioningState state; if (heci.GetProvisioningState(out state)) { writer.Add( new DriveEntry("Status",ValueMap.Create(state.ToString(), ValueList.ConfigurationState),this)); } HECIClass.AuditRecord record; if (heci.GetAuditRecord(out record)) { writer.Add(new RemoteLog(record,this)); } } finally { heci.DeInit(); } } public override object GetReturnObject() { return new NameValuePairItem(Name, Value); } } class RemoteLog : DriveContainer { HECIClass.AuditRecord _record; public RemoteLog(HECIClass.AuditRecord record, DriveItem parent) : base("Log", parent) { _record = record; } public override void GetChildItems(ChildWriter writer) { writer.Add(new DriveEntry("AdditionalCaSerialNums", _record.AdditionalCaSerialNums, this)); writer.Add(new DriveEntry("CaCertificateSerials", _record.CaCertificateSerials, this)); writer.Add(new DriveEntry("SetupServer", _record.ProvServerFQDN, this)); writer.Add(new DriveEntry("SetupServerIp", _record.ProvServerIP, this)); writer.Add(new DriveEntry("CertificateHash", _record.HashData, this)); writer.Add(new DriveEntry("HashAlgorithm", _record.HashAlgorithm, this)); writer.Add(new DriveEntry("HashIsOemDefault", _record.HashIsOemDefault, this)); //writer.Add(new DriveEntry("SecureDNS", record.SecureDNS, this)); writer.Add(new DriveEntry("Timestamp", _record.Timestamp, this)); } }//End RemoteLog class LocalSetup : SettingsContainer { public LocalSetup(DriveItem parent) : base("Local", parent) { } public override void GetChildItems(ChildWriter writer) { IWsmanConnection conn = ((HeciRoot)GetRoot()).Connection; if (conn == null) return; _refToSettings = conn.NewReference("SELECT * FROM IPS_HostBasedSetupService"); _settingsObj = _refToSettings.Get(); //allowed modes bool adminMode = false; bool clientMode = false; foreach (IWsmanItem item in _settingsObj.GetProperty("AllowedControlModes")) { if (item.ToString().Equals("1")) clientMode = true; else if (item.ToString().Equals("2")) adminMode = true; } List list = new List(); list.Add("Unconfigured"); if (clientMode) list.Add("ClientMode"); if (adminMode) list.Add("AdminMode"); writer.Add(new DriveEntry("AllowedModes",list.ToArray(), this)); if (HasSetting("CertChainStatus")) { string status = string.Empty; status = _settingsObj.GetProperty("CertChainStatus").ToString(); if (status.Equals("0")) status="Not Started"; else if (status.Equals("1")) status="In-Progress"; else if (status.Equals("2")) status="Complete"; writer.Add(new DriveEntry("CertChainStatus",status, this)); } if (HasSetting("ConfigurationNonce")) writer.Add(new DriveEntry("ConfigurationNonce", _settingsObj.GetProperty("ConfigurationNonce").ToString(), this)); writer.Add(new ControlModeItem(this)); writer.Add(new LocalLog(this)); } } // end local setup class ControlModeItem : SettingsItem { public ControlModeItem(SettingsContainer parent) : base("CurrentMode", parent) { } public override object Value { get { SettingsContainer settings = _parent as SettingsContainer; string mode = settings.GetSetting("CurrentControlMode"); _value = mode; if (mode.Equals("0")) mode = "Unconfigured"; else if (mode.Equals("1")) mode = "ClientMode"; else if (mode.Equals("2")) mode = "AdminMode"; return mode; } } public override void SetItem(object values, DriveProvider provider) { SettingsContainer settings = _parent as SettingsContainer; //string mode = settings.get //_value. } } class LocalLog : SettingsContainer { public LocalLog(SettingsContainer parent) : base("Log", parent) { } public override void GetChildItems(ChildWriter writer) { IWsmanConnection conn = ((HeciRoot)GetRoot()).Connection; foreach (IWsmanItem item in conn.ExecQuery("SELECT * FROM IPS_ProvisioningAuditRecord")) { SetupRecord record = new SetupRecord(item.Object); writer.Add(new DriveEntry("AdditionalCaSerialNums", record.AdditionalCaSerialNums,this)); writer.Add(new DriveEntry("CaCertificateSerials", record.CaCertificateSerials, this)); writer.Add(new DriveEntry("CertificateCN", record.CertificateCN, this)); writer.Add(new DriveEntry("CertificateHash", record.CertificateHash, this)); writer.Add(new DriveEntry("HashAlgorithm", record.HashAlgorithm, this)); writer.Add(new DriveEntry("HashIsOemDefault", record.HashIsOemDefault, this)); writer.Add(new DriveEntry("LogName", record.LogName, this)); writer.Add(new DriveEntry("RecordID", record.RecordID, this)); writer.Add(new DriveEntry("SecureDNS", record.SecureDNS, this)); writer.Add(new DriveEntry("Timestamp", record.Timestamp, this)); break; } } } }// End Setup class }//namespace