/// <inheritdoc /> public override void InjectReferenceValue(X509Certificate2 value) { Certificate = value; Asn1Object exValue = GetExtensionValue(value); if (exValue == null) { if (IsRequired()) { throw new PolicyRequiredException("Extention " + ExtentionIdentifier.Display + " is marked as required by is not present."); } PolicyValue = new PolicyValue <IList <string> >(new List <string>()); return; } ExtendedKeyUsage usages = ExtendedKeyUsage.GetInstance(exValue); IList purposeList = usages.GetAllUsages(); var usageList = new List <string>(); foreach (DerObjectIdentifier purpose in purposeList) { usageList.Add(purpose.Id); } PolicyValue = new PolicyValue <IList <string> >(usageList); }
public void Playout(Board state) { TreeNode node = root; while (!node.IsLeaf()) { object[] selectResult = node.Select(c_puct); node = (TreeNode)selectResult[1]; state.DoMove((int)selectResult[0]); } PolicyValue policyValue = policy.PolicyValueFn(state); float leafValue = policyValue.V; object[] var = state.GameEnd(); bool end = (bool)var[0]; int winner = (int)var[1]; if (!end) { node.Expand(policyValue.actionPs); } else { if (winner == -1) { leafValue = 0; } else { leafValue = (winner == state.GetCurrentPlayer() ? 1f : -1f); } } node.UpdateRecursive(-leafValue); }
/// <inheritdoc /> public override void InjectReferenceValue(X509Certificate2 value) { Certificate = value; Asn1Object exValue = GetExtensionValue(value); if (exValue == null) { if (IsRequired()) { throw new PolicyRequiredException("Extention " + ExtentionIdentifier.Display + " is marked as required by is not present."); } var emptyList = new List <string>(); PolicyValue = new PolicyValue <IList <String> >(emptyList); return; } var retVal = new List <String>(); var seq = exValue.ToAsn1Object() as Asn1Sequence; if (seq != null) { var pols = seq.GetEnumerator(); while (pols.MoveNext()) { PolicyInformation pol = PolicyInformation.GetInstance(pols.Current); retVal.Add(pol.PolicyIdentifier.Id); } } //TODO: PolicyInformation is only storing the ID. There other intersting info items in here that we may want //maybe not for rules but for when things go wrong... logging info. PolicyValue = new PolicyValue <IList <String> >(retVal); }
/// <inheritdoc /> public override void InjectReferenceValue(X509Certificate2 value) { Certificate = value; Asn1Object exValue = GetExtensionValue(value); if (exValue == null) { if (IsRequired()) { throw new PolicyRequiredException("Extention " + ExtentionIdentifier.Display + " is marked as required by is not present."); } PolicyValue = new PolicyValue <string>(String.Empty); return; } var aki = AuthorityKeyIdentifier.GetInstance(exValue); byte[] keyId = aki.GetKeyIdentifier(); if (keyId == null) { if (IsRequired()) { throw new PolicyRequiredException("Extention " + ExtentionIdentifier.Display + " is marked as required by is not present."); } PolicyValue = new PolicyValue <string>(String.Empty); } PolicyValue = new PolicyValue <string>(PolicyUtils.CreateByteStringRep(keyId)); }
public SignatureLevelEPES(IAdvancedSignature signature, SignatureValidationResult levelReached) : base (levelReached) { if (signature != null) { signaturePolicy = signature.PolicyId; } }
/// <summary>The default constructor for SignatureLevelBES.</summary> /// <remarks>The default constructor for SignatureLevelBES.</remarks> /// <param name="name"></param> /// <param name="signature"></param> /// <param name="levelReached"></param> public SignatureLevelEPES(AdvancedSignature signature, Result levelReached) : base (levelReached) { if (signature != null) { signaturePolicy = signature.GetPolicyId(); } }
/// <inheritdoc /> public override String ToString() { if (PolicyValue == null) { return("Unevaluated TBS field: " + Name); } return(PolicyValue.ToString()); }
protected internal virtual SignatureLevelEPES VerifyLevelEPES(IAdvancedSignature signature, DateTime referenceTime, IValidationContext ctx) { try { PolicyValue policyValue = signature.PolicyId; SignatureValidationResult levelReached = new SignatureValidationResult(policyValue != null); return(new SignatureLevelEPES(signature, levelReached)); } catch (Exception) { return(new SignatureLevelEPES(signature, new SignatureValidationResult(ResultStatus.INVALID, "$UI_Signatures_ValidationText_ExceptionWhileVerifying"))); } }
/// <inheritdoc /> public override void InjectReferenceValue(X509Certificate2 value) { Certificate = value; var extensionIdentifier = Certificate.GetExtensionIdentifier <X509BasicConstraintsExtension>(ExtentionIdentifier.Id); if (extensionIdentifier == null) { if (IsRequired()) { throw new PolicyRequiredException("Extention " + ExtentionIdentifier.Display + " is marked as required by is not present."); } PolicyValue = new PolicyValue <bool>(false); return; } PolicyValue = new PolicyValue <Boolean>(extensionIdentifier.CertificateAuthority); }
/// <inheritdoc /> public override void InjectReferenceValue(X509Certificate2 value) { Certificate = value; Asn1Object exValue = GetExtensionValue(value); if (exValue == null) { if (IsRequired()) { throw new PolicyRequiredException("Extention " + ExtentionIdentifier.Display + " is marked as required by is not present."); } var emptyList = new List <string>(); PolicyValue = new PolicyValue <IList <string> >(emptyList); return; } var retVal = new List <String>(); var seq = exValue.ToAsn1Object() as Asn1Sequence; if (seq != null) { var pols = seq.GetEnumerator(); while (pols.MoveNext()) { PolicyInformation pol = PolicyInformation.GetInstance(pols.Current); if (pol.PolicyQualifiers != null) { var polInfos = pol.PolicyQualifiers.GetEnumerator(); while (polInfos.MoveNext()) { // The PolicyQualifier object is not exposed nicely in the BouncyCastle API where Java is. var derseq = polInfos.Current as DerSequence; if (derseq.Id().Equals(PolicyQualifierID.IdQtCps)) { retVal.Add(derseq.Value()); } } } } } PolicyValue = new PolicyValue <IList <string> >(retVal); }
public void TestExecute_Intersection_StringConversion_AssertResults() { IPolicyValue <IList <String> > op1 = PolicyValueFactory.GetInstance <IList <String> >(new List <string> { "A", "B", "C", "D" }); IPolicyValue <String> op2 = new PolicyValue <string>("A,B,E"); IEnumerable <string> resultList = PolicyOperator <IList <string>, string, IEnumerable <string> > .INTERSECT.Execute( op1.GetPolicyValue(), op2.GetPolicyValue()); var result = resultList.ToList(); result.Count().Should().Be(2); result.Contains("A").Should().BeTrue(); result.Contains("B").Should().BeTrue(); op1 = PolicyValueFactory.GetInstance <IList <String> >(new List <string> { "A", "B", "C" }); op2 = new PolicyValue <string>("D,E,F"); resultList = PolicyOperator <IList <string>, string, IEnumerable <string> > .INTERSECT.Execute( op1.GetPolicyValue(), op2.GetPolicyValue()); resultList.Any().Should().BeFalse(); op1 = PolicyValueFactory.GetInstance <IList <String> >(new List <string> { "D", "C", "B", "A" }); op2 = new PolicyValue <string>("A,E,B"); resultList = PolicyOperator <IList <string>, string, IEnumerable <string> > .INTERSECT.Execute( op1.GetPolicyValue(), op2.GetPolicyValue()); result = resultList.ToList(); result.Count().Should().Be(2); result.Contains("A").Should().BeTrue(); result.Contains("B").Should().BeTrue(); }
/// <inheritdoc /> public override void InjectReferenceValue(X509Certificate2 value) { Certificate = value; Asn1Object exValue = GetExtensionValue(value); if (exValue == null) { if (IsRequired()) { throw new PolicyRequiredException("Extention " + ExtentionIdentifier.Display + " is marked as required by is not present."); } var emptyList = new List <string>(); PolicyValue = new PolicyValue <IList <string> >(emptyList); return; } CrlDistPoint distPoints = CrlDistPoint.GetInstance(exValue); IList <String> retVal = new List <String>(); foreach (var distPoint in distPoints.GetDistributionPoints()) { if (distPoint.DistributionPointName != null && distPoint.DistributionPointName.PointType == DistributionPointName.FullName) { GeneralNames names = GeneralNames.GetInstance(distPoint.DistributionPointName.Name); foreach (var generalName in names.GetNames()) { retVal.Add(generalName.Name.ToString()); } } } if (!retVal.Any() && IsRequired()) { throw new PolicyRequiredException("Extention " + ExtentionIdentifier.Display + " is marked as required by is not present."); } PolicyValue = new PolicyValue <IList <string> >(retVal); }
/// <inheritdoc /> public override void InjectReferenceValue(X509Certificate2 value) { int retVal = 0; Certificate = value; try { PublicKey pubKey = Certificate.PublicKey; if (pubKey.Key is RSACryptoServiceProvider || pubKey.Key is DSACryptoServiceProvider) { retVal = pubKey.Key.KeySize; } } catch (NotSupportedException) { retVal = 0; } PolicyValue = new PolicyValue <int>(retVal); }
/// <inheritdoc /> public override void InjectReferenceValue(X509Certificate2 value) { Certificate = value; Asn1Object exValue = GetExtensionValue(value); if (exValue == null) { if (IsRequired()) { throw new PolicyRequiredException("Extention " + ExtentionIdentifier.Display + " is marked as required but is not present."); } var emptyList = new List <string>(); PolicyValue = new PolicyValue <IList <string> >(emptyList); return; } AuthorityInformationAccess aia = AuthorityInformationAccess.GetInstance(exValue); IList <String> retVal = new List <String>(); foreach (var accessDescription in aia.GetAccessDescriptions()) { string accessMethod = Standard.AuthorityInfoAccessMethodIdentifier.FromId( accessDescription.AccessMethod.ToString()).Name; retVal.Add(accessMethod + ":" + accessDescription.AccessLocation.Name); } if (!retVal.Any() && IsRequired()) { throw new PolicyRequiredException("Extention " + ExtentionIdentifier.Display + " is marked as required by is not present."); } PolicyValue = new PolicyValue <IList <string> >(retVal); }
public void ShowHint(PolicyValue policyValue, Transform[] actionTransforms) { HideHint(); if (policyValue == null) { return; } valueText.text = "局面评估\n" + policyValue.V; valueText.gameObject.SetActive(true); float maxP = 0.01f; foreach (ActionP actionP in policyValue.actionPs) { if (actionP.P > maxP) { maxP = actionP.P; } } maxP = maxP * 4f / 3f; foreach (ActionP actionP in policyValue.actionPs) { //if (actionP.P < 0.01) continue; if (!actionTextDictionary.ContainsKey(actionP.action)) { GameObject actionPolicyText = Instantiate(actionPolicyTextPrefab, transform); actionTextDictionary.Add(actionP.action, actionPolicyText); } Text actionText = actionTextDictionary[actionP.action].GetComponent <Text>(); actionText.text = (actionP.P * 100f).ToString("F2") + "%"; actionText.color = new Color(1, 0, 0, 0.25f + actionP.P / maxP); actionTextDictionary[actionP.action].transform.position = Camera.main.WorldToScreenPoint(actionTransforms[actionP.action].position); actionTextDictionary[actionP.action].SetActive(true); } showing = true; }
/// <inheritdoc /> public override void InjectReferenceValue(X509Certificate2 value) { Certificate = value; DerBitString derBitString = GetExtensionValue(value) as DerBitString; if (derBitString == null) { if (IsRequired()) { throw new PolicyRequiredException("Extention " + ExtentionIdentifier.Display + " is marked as required by is not present."); } PolicyValue = new PolicyValue <int>(0); return; } var keyUsage = new KeyUsage(derBitString.IntValue); byte[] data = keyUsage.GetBytes(); int intValue = (data.Length == 1) ? data[0] & 0xff : (data[1] & 0xff) << 8 | (data[0] & 0xff); PolicyValue = new PolicyValue <int>(intValue); }
public void TestExecute_Intersection_StringConversion_AssertResults() { IPolicyValue<IList<String>> op1 = PolicyValueFactory.GetInstance<IList<String>>(new List<string> {"A", "B", "C", "D"}); IPolicyValue<String> op2 = new PolicyValue<string>("A,B,E"); IEnumerable<string> resultList = PolicyOperator<IList<string>, string, IEnumerable<string>>.INTERSECT.Execute( op1.GetPolicyValue(), op2.GetPolicyValue()); var result = resultList.ToList(); result.Count().Should().Be(2); result.Contains("A").Should().BeTrue(); result.Contains("B").Should().BeTrue(); op1 = PolicyValueFactory.GetInstance<IList<String>>(new List<string> { "A", "B", "C" }); op2 = new PolicyValue<string>("D,E,F"); resultList = PolicyOperator<IList<string>, string, IEnumerable<string>>.INTERSECT.Execute( op1.GetPolicyValue(), op2.GetPolicyValue()); resultList.Any().Should().BeFalse(); op1 = PolicyValueFactory.GetInstance<IList<String>>(new List<string> { "D", "C", "B", "A" }); op2 = new PolicyValue<string>("A,E,B"); resultList = PolicyOperator<IList<string>, string, IEnumerable<string>>.INTERSECT.Execute( op1.GetPolicyValue(), op2.GetPolicyValue()); result = resultList.ToList(); result.Count().Should().Be(2); result.Contains("A").Should().BeTrue(); result.Contains("B").Should().BeTrue(); }