public void HasDataTest() { CertPolicy target = new CertPolicy(); Assert.False(target.HasData); target.Data = Encoding.UTF8.GetBytes("somerandomstring"); Assert.True(target.HasData); }
public void GetPolicyByName() { CertPolicyManager mgr = CreateManager(); CertPolicy policy = mgr.Get("Policy1"); policy.Name.Should().BeEquivalentTo("Policy1"); }
//--------------------------------------- // // Implementation details // //--------------------------------------- internal void PushPolicy(string name, string policyText, string description, bool checkForDupes) { try { if (!checkForDupes || !Client.Contains(name)) { CertPolicy certPolicy = new CertPolicy(name, description, policyText.ToBytesUtf8()); Client.AddPolicy(certPolicy); WriteLine("Added {0}", certPolicy.Name); } else { WriteLine("Exists {0}", name); } } catch (FaultException <ConfigStoreFault> ex) { if (ex.Detail.Error == ConfigStoreError.UniqueConstraint) { WriteLine("Exists {0}", name); } else { throw; } } }
/// <summary> /// Remove the certificate for the specified host. /// </summary> /// <param name="host">The host the certificate belongs to.</param> public static void RemoveCertificate(string host) { string uriHost = GetHostFromUri(host); log.Debug("removing for host : {0}", uriHost); CertPolicy.RemoveCertificate(uriHost); log.Debug("removed for host : {0}", uriHost); // also remove it from store , if any Store store = Store.GetStore(); Domain domain = store.GetDomain(store.LocalDomain); // Check for an existing cert in the store. Node cn = null; ICSList nodeList = domain.Search(hostProperty, uriHost, SearchOp.Equal); foreach (ShallowNode sn in nodeList) { cn = new Node(domain, sn); if (cn.IsType(CertType)) { Property myprop = cn.Properties.GetSingleProperty(certificateProperty); if (myprop != null) { domain.Commit(domain.Delete(cn)); log.Debug("committed the deletion of certtype node for :{0} ", uriHost); } } } }
public void IDTest() { CertPolicy target = new CertPolicy(); long expected = new Random().Next(1, 10); target.ID = expected; long actual = target.ID; Assert.Equal(expected, actual); }
public void CreateDateTest() { CertPolicy target = new CertPolicy(); DateTime expected = DateTime.UtcNow; target.CreateDate = expected; DateTime actual = target.CreateDate; Assert.Equal(expected, actual); }
public void DataTest() { CertPolicy target = new CertPolicy(); byte[] expected = Encoding.UTF8.GetBytes("somerandomstring"); target.Data = expected; byte[] actual = target.Data; Assert.Equal(expected, actual); }
public void AddCertPolicyGroupTest() { CertPolicy target = new CertPolicy(); target.ID = 99; CertPolicyGroupMap targetChild = new CertPolicyGroupMap(); target.CertPolicyGroupMap.Add(targetChild); }
public void DeletePolicyTest() { CertPolicyManager mgr = CreateManager(); CertPolicy policy = mgr.Get("Policy2"); mgr.Remove(policy.ID); mgr.Get("Policy2").Should().BeNull(); }
public void Print(CertPolicy policy) { CommandUI.Print("ID", policy.ID); CommandUI.Print("Name", policy.Name); CommandUI.Print("Description", policy.Description); CommandUI.Print("CreateDate", policy.CreateDate); CommandUI.Print("Data", policy.Data.ToUtf8String()); CommandUI.Print("# of Groups", policy.CertPolicyGroups == null ? 0 : policy.CertPolicyGroups.Count); }
/// <summary> /// Get the Certificate for the specified store. /// </summary> /// <param name="host">The host who owns the certificate.</param> /// <returns>The certificate as a byte array.</returns> public static byte[] GetCertificate(string host) { CertPolicy.CertificateState cs = CertPolicy.GetCertificate(GetHostFromUri(host)); if (cs != null) { return(cs.Certificate.GetRawCertData()); } return(null); }
public static bool Contains(this CertPolicyStoreClient client, string name) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("value was null or empty", "name"); } CertPolicy policy = client.GetPolicyByName(name); return(policy != null); }
private void button1_Click(object sender, EventArgs e) { pol = new CertPolicy() { Oid = tbOid.Text, Name = tbName.Text, Cps = tbCps.Text, Unotice = tbNotice.Text }; }
private CertPolicy GetCertPolicy(string name) { CertPolicy certPolicy = Client.GetPolicyByName(name); if (certPolicy == null) { throw new ArgumentException(string.Format("CertPolicy {0} not found", name)); } return(certPolicy); }
public void NameTest() { CertPolicy target = new CertPolicy(); string expected = "Policy_1"; target.Name = expected; string actual = target.Name; Assert.Equal(expected, actual); }
/// <summary> /// Get the Certificate for the specified store. /// </summary> /// <param name="recoveryAgnt">The host who owns the certificate.</param> /// <returns>The certificate as a byte array.</returns> public static byte[] GetRACertificate(string recoveryAgnt) { log.Debug("In Get RA Certificate in certificate store"); CertPolicy.CertificateState cs = CertPolicy.GetRACertificate(recoveryAgnt); if (cs != null) { return(cs.Certificate.GetRawCertData()); } return(null); }
public void UpdatePolicyAttributes(CertPolicy policy) { try { Store.CertPolicies.Update(policy); } catch (Exception ex) { throw CreateFault("UpdatePolicyAttributes", ex); } }
public void RemoveTest() { certificatePolicies target = new certificatePolicies(testData1); CertPolicy Policy = new CertPolicy() { Oid = "1.2.860.0.1311.1.3", Cps = "", Name = "", Unotice = "" }; target.Remove(Policy); Assert.AreEqual("CertificatePolicies: 1.2.860.0.1311.1.1", target.CertificatePolicies.ToString()); }
public CertPolicy AddPolicy(CertPolicy policy) { try { CertPolicy certPolicy = new CertPolicy(policy); return(Store.CertPolicies.Add(certPolicy)); } catch (Exception ex) { throw CreateFault("AddPolicy", ex); } }
/// <summary> /// Check for trust failure /// </summary> /// <param name="host">Host name</param> /// <param name="we">WebException occured</param> static void IsTrustFailure(string host, WebException we) { if (we.Status == WebExceptionStatus.TrustFailure) { throw we; } CertPolicy.CertificateState cs = CertPolicy.GetCertificate(host); if (cs != null && !cs.Accepted) { // BUGBUG this is here to work around a mono bug. throw new WebException(we.Message, we, WebExceptionStatus.TrustFailure, we.Response); } }
public void AddPolicy() { CertPolicyManager mgr = CreateManager(); CertPolicy expectedPolicy = new CertPolicy("UnitTestPolicy", "", "1 = 1".ToBytesUtf8()); mgr.Add(expectedPolicy); CertPolicy actualCertPolicy = mgr.Get("UnitTestPolicy"); expectedPolicy.Name.Should().BeEquivalentTo("UnitTestPolicy"); expectedPolicy.CreateDate.Should().BeCloseTo(actualCertPolicy.CreateDate); }
/// <summary> /// Get the Certificate for the specified store along with Problem. /// </summary> /// <param name="host">The host who owns the certificate.</param> /// <param name="Problem"></param> /// <returns>The certificate as a byte array.</returns> public static byte[] GetCertificate(string host, out CertPolicy.CertificateProblem Problem) { CertPolicy.CertificateState cs = CertPolicy.GetCertificate(GetHostFromUri(host)); if (cs != null) { Problem = cs.Problem; if (cs.Certificate.GetRawCertData().Length == 0) { log.Info("GetCertificate either null or empty"); } return(cs.Certificate.GetRawCertData()); } Problem = CertPolicy.CertificateProblem.CertOK; return(null); }
/// <summary> /// Store the certificate for the specified host. /// </summary> /// <param name="certificate">The certificate to store.</param> /// <param name="host">The host the certificate belongs to.</param> /// <param name="domainID">the domainID to which host belongs</param> /// <param name="persist">If true save in store.</param> public static void StoreDomainCertificate(byte[] certificate, string host, string domainID, bool persist) { // this function is neither tested nor used string uriHost = GetHostFromUri(host); log.Debug("storing certificate for host : {0}", uriHost); CertPolicy.StoreCertificate(certificate, uriHost); //try //{ if (persist) { // Save the cert in the store. Store store = Store.GetStore(); Domain domain = store.GetDomain(domainID); // Check for an existing cert in the store. Node cn = null; ICSList nodeList = domain.Search(hostProperty, uriHost, SearchOp.Equal); foreach (ShallowNode sn in nodeList) { cn = new Node(domain, sn); if (!cn.IsType(CertType)) { cn = null; continue; } break; } if (cn == null) { // The cert doesn't exist ... create it. //cn=new Node(" cn = new Node("Certificate for " + uriHost); domain.SetType(cn, CertType); cn.Properties.ModifyNodeProperty(new Property(hostProperty, uriHost)); } Property myprop = new Property(certificateProperty, Convert.ToBase64String(certificate)); myprop.LocalProperty = true; cn.Properties.ModifyNodeProperty(myprop); //cn.Properties.ModifyNodeProperty(new Property(certificateProperty, Convert.ToBase64String(certificate))); log.Debug("committed the storage of certificate"); domain.Commit(cn); } //}catch(Exception ex){} }
private void updateDataSet(CertPolicy pol, int index) { dr = ds.Tables["policies"].NewRow(); dr["#"] = (index + 1).ToString(); dr["OID"] = pol.Oid; dr["Name"] = pol.Name; dr["CPS"] = pol.Cps; dr["Notice"] = pol.Unotice; ds.Tables["policies"].Rows.Add(dr); // Seems to be a bug in the .Net dgv code that throws an exception in some circumstances try { dgv.Columns[0].Width = 20; } catch (NullReferenceException) { } }
public void UpdatePolicyDataTest() { CertPolicyManager mgr = CreateManager(); CertPolicy newCertPolicy = new CertPolicy("UnitTestPolicy", "UnitTest Policy Description", "1 = 1".ToBytesUtf8()); mgr.Add(newCertPolicy); CertPolicy actualCertPolicy = mgr.Get("UnitTestPolicy"); actualCertPolicy.Should().NotBeNull(); actualCertPolicy.Data = "1 != 1".ToBytesUtf8(); mgr.Update(actualCertPolicy); CertPolicy updatedCertPolicy = mgr.Get("UnitTestPolicy"); updatedCertPolicy.Data.ToUtf8String().ShouldAllBeEquivalentTo("1 != 1"); }
public void UpdatePolicyDescriptionTest() { CertPolicyManager mgr = CreateManager(); CertPolicy newCertPolicy = new CertPolicy("UnitTestPolicy", "UnitTest Policy Description", "1 = 1".ToBytesUtf8()); mgr.Add(newCertPolicy); CertPolicy actualCertPolicy = mgr.Get("UnitTestPolicy"); actualCertPolicy.Should().NotBeNull(); actualCertPolicy.Description = "blank"; mgr.Update(actualCertPolicy); CertPolicy updatedCertPolicy = mgr.Get("UnitTestPolicy"); updatedCertPolicy.Description.ShouldBeEquivalentTo("blank"); }
public void AssociatePolicyToGroupSessionTest() { InitCertPolicyRecords(); InitCertPolicyGroupRecords(); using (ConfigDatabase db = CreateConfigDatabase(CertPolicyGroupManager.DataLoadOptions)) { CertPolicyGroupManager mgr = CreateManager(); CertPolicyGroup policyGroup = mgr.Get(db, "PolicyGroup1"); policyGroup.CertPolicies.Count.Should().Be(0); CertPolicyManager policyMgr = CreatePolicyManager(); CertPolicy certPolicy = policyMgr.Get("Policy1"); policyGroup.CertPolicies.Add(certPolicy); db.SubmitChanges(); policyGroup = mgr.Get("PolicyGroup1"); policyGroup.CertPolicies.Count.Should().Be(1); } }
public void AddPolicyToGroup(string policyName, string groupName, CertPolicyUse policyUse, bool incoming, bool outgoing) { try { CertPolicy certPolicy = Store.CertPolicies.Get(policyName); if (certPolicy == null) { throw new ConfigStoreException(ConfigStoreError.InvalidCertPolicyName); } Store.CertPolicyGroups.AddPolicyUse(policyName, groupName, policyUse, incoming, outgoing); } catch (FaultException faultEx) { throw faultEx; } catch (Exception ex) { throw CreateFault("AddPolicyToGroup", ex); } }
public void DeletePolicyWithAssociations() { CertPolicyGroupManager groupMgr = CreatePolicyGroupManager(); CertPolicyGroup policyGroup = groupMgr.Get("PolicyGroup1"); policyGroup.CertPolicies.Count.Should().Be(0); CertPolicyManager policyMgr = CreateManager(); policyMgr.Get("Policy1").Should().NotBeNull(); groupMgr.AddPolicyUse("Policy1", "PolicyGroup1", CertPolicyUse.PRIVATE_RESOLVER, true, true); policyGroup = groupMgr.Get("PolicyGroup1"); policyGroup.CertPolicies.Count.Should().Be(1); CertPolicyManager mgr = CreateManager(); CertPolicy policy = mgr.Get("Policy1"); mgr.Remove(policy.ID); policyMgr.Get("Policy1").Should().BeNull(); }
/// <summary> /// Remove the certificate for the specified host. /// </summary> /// /// <param name="domainID">the domainid for this host</param> /// <param name="host">The host the certificate belongs to.</param> public static void RemoveDomainCertificate(string domainID, string host) { // this API is yet to be tested , and has not been used. string uriHost = GetHostFromUri(host); log.Debug("removing for host : {0}", uriHost); CertPolicy.RemoveCertificate(uriHost); log.Debug("removed for host : {0}", uriHost); // also remove it from store , if any Store store = Store.GetStore(); Domain domain = store.GetDomain(domainID); // check for the cert Node cn = null; ICSList nodelist = domain.Search(hostProperty, "*", SearchOp.Equal); //domain.GetNodesByType(CertType); if (nodelist == null) { log.Debug("returned null for hostproperty * "); } foreach (ShallowNode sn in nodelist) { cn = new Node(domain, sn); if (!cn.IsType(CertType)) { log.Debug("returned non null but this node is not of type CertType"); continue; } if (cn != null) { // cert type is found domain.Commit(domain.Delete(cn)); log.Debug("committed the deletion of certtype node for :{0} ", uriHost); } } }
public void ValidateHasDataTest() { CertPolicy target = new CertPolicy(); try { target.ValidateHasData(); Assert.True(false); } catch { Assert.True(true); } target.Data = Encoding.UTF8.GetBytes("somerandomstring"); try { target.ValidateHasData(); Assert.True(true); } catch { Assert.True(false); } }