public override void Validate(System.Security.Cryptography.X509Certificates.X509Certificate2 certificate) { if (!String.IsNullOrEmpty(hash) && certificate.GetCertHashString() != hash) { throw new SecurityException("Server cannot be authenticated"); } }
public ExampleStorageEntity() { string CertPath = "../../../YOURCERTHERE.pfx"; var Cert = new System.Security.Cryptography.X509Certificates.X509Certificate2(CertPath); Uplink = new Connection("164.138.24.100", 5222, new JID("", "sandbox.clayster.com", ""), "", Cert, true, 30, 0); Uplink.Roster.OnSubscribe = Roster_OnSubscribe; Uplink.Roster.OnUnsubscribed = Roster_OnUnsubscribed; Uplink.OnConnectionStateChanged += Uplink_OnConnectionStateChanged; Uplink.Connect(); while (DataStorage == null) { Thread.Sleep(10); } // Set claim key string MyClaimKey = Cert.GetCertHashString(); var awaiter = DataStorage.SessionController.SetClaimKey(MyClaimKey); awaiter.Wait(); Console.WriteLine("Set claim key to {0} = {1}", awaiter.Result, MyClaimKey); CPUUsage = new LWTSD.ResourceTypes.ResourceInteger(); CPUUsage.Path = "meters/cpuusage"; CPUUsage.Displayname = "CPU%"; CPUUsage.SupportsRead = true; CPUUsage.SupportsWrite = false; CPUUsage.Unit = "percentage"; CPUUsage.Value = 0; AvailableMemory = new LWTSD.ResourceTypes.ResourceInteger(); AvailableMemory.Path = "meters/availablememory"; AvailableMemory.Displayname = "Available Memory"; AvailableMemory.SupportsRead = true; AvailableMemory.SupportsWrite = false; AvailableMemory.Unit = "MB"; AvailableMemory.Value = 0; ScratchPad = new LWTSD.ResourceTypes.ResourceString(); ScratchPad.Path = "misc/scratchpad"; ScratchPad.Displayname = "Scratchad"; ScratchPad.SupportsRead = true; ScratchPad.SupportsWrite = true; ScratchPad.Value = "Nothing"; DataStorage.AddResource(CPUUsage); DataStorage.AddResource(AvailableMemory); DataStorage.AddResource(ScratchPad); DataStorage.RegisterResources().Wait(); UpdateResourcesTimer = new System.Timers.Timer(1000.0); UpdateResourcesTimer.AutoReset = true; UpdateResourcesTimer.Elapsed += (sender, e) => { UpdateResources(); }; UpdateResourcesTimer.Start(); }