예제 #1
0
        public override IPermission Intersect(IPermission target)
        {
            StrongNameIdentityPermission snip = (target as StrongNameIdentityPermission);

            if ((snip == null) || IsEmpty())
            {
                return(null);
            }
            if (snip.IsEmpty())
            {
                return(new StrongNameIdentityPermission(PermissionState.None));
            }
            if (!Match(snip.Name))
            {
                return(null);
            }

            string n = ((Name.Length < snip.Name.Length) ? Name : snip.Name);

            if (!Version.Equals(snip.Version))
            {
                return(null);
            }
            if (!PublicKey.Equals(snip.PublicKey))
            {
                return(null);
            }

            return(new StrongNameIdentityPermission(this.PublicKey, n, this.Version));
        }
예제 #2
0
        public Signature Sign(PrivateKey privateKey, Keccak message)
        {
            if (!Proxy.VerifyPrivateKey(privateKey.KeyBytes))
            {
                throw new ArgumentException("Invalid private key", nameof(privateKey));
            }

            byte[] signatureBytes = Proxy.SignCompact(message.Bytes, privateKey.KeyBytes, out int recoveryId);

            //// https://bitcoin.stackexchange.com/questions/59820/sign-a-tx-with-low-s-value-using-openssl

            //byte[] sBytes = signatureBytes.Slice(32, 32);
            //BigInteger s = sBytes.ToUnsignedBigInteger();
            //if (s > MaxLowS)
            //{
            //    s = LowSTransform - s;
            //    byte[] newSBytes = s.ToBigEndianByteArray();
            //    for (int i = 0; i < 32; i++)
            //    {
            //        signatureBytes[32 + 1] = newSBytes[i];
            //    }
            //}

            Signature signature = new(signatureBytes, recoveryId);

#if DEBUG
            PublicKey address = RecoverPublicKey(signature, message);
            if (!address.Equals(privateKey.PublicKey))
            {
                throw new InvalidOperationException("After signing recovery returns different address than ecdsa's");
            }
#endif

            return(signature);
        }
        bool IReportMatchMembershipCondition.Check(Evidence evidence, out object usedEvidence)
        {
            usedEvidence = null;

            if (evidence == null)
            {
                return(false);
            }

            StrongName name = evidence.GetDelayEvaluatedHostEvidence <StrongName>();

            if (name != null)
            {
                bool publicKeyMatch = PublicKey != null && PublicKey.Equals(name.PublicKey);
                bool nameMatch      = Name == null || (name.Name != null && StrongName.CompareNames(name.Name, Name));
                bool versionMatch   = (object)Version == null || ((object)name.Version != null && name.Version.CompareTo(Version) == 0);

                if (publicKeyMatch && nameMatch && versionMatch)
                {
                    // Note that we explicitly do not want to mark the strong name evidence as used at
                    // this point, since we could be a child code group where our parent provides more
                    // trust than we do.  For instance, if we're in a setup like this:
                    //
                    //   AllCode -> FullTrust
                    //     StrongName -> FullTrust
                    //
                    // the StrongName code group didn't add anything to the final grant set and therefore
                    // does not need to be evaluated.
                    usedEvidence = name;
                    return(true);
                }
            }

            return(false);
        }
예제 #4
0
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            StrongNameIdentityPermission snip = (target as StrongNameIdentityPermission);

            if (snip == null)
            {
                throw new ArgumentException(Locale.GetText("Wrong permission type."));
            }
            if (IsEmpty() || snip.IsEmpty())
            {
                return(null);
            }
            if (!Match(snip.Name))
            {
                return(null);
            }

            string n = ((Name.Length < snip.Name.Length) ? Name : snip.Name);

            if (!Version.Equals(snip.Version))
            {
                return(null);
            }
            if (!PublicKey.Equals(snip.PublicKey))
            {
                return(null);
            }

            return(new StrongNameIdentityPermission(this.PublicKey, n, this.Version));
        }
 /// <summary>
 /// Two DnsResourceDataHostIdentityProtocol are equal iff their host identity tag, public key algorithm, public key and rendezvous servers fields
 /// are equal.
 /// </summary>
 public bool Equals(DnsResourceDataHostIdentityProtocol other)
 {
     return(other != null &&
            HostIdentityTag.Equals(other.HostIdentityTag) &&
            PublicKeyAlgorithm.Equals(other.PublicKeyAlgorithm) &&
            PublicKey.Equals(other.PublicKey) &&
            RendezvousServers.SequenceEqual(RendezvousServers));
 }
예제 #6
0
        public bool Equals(UserPublicKey other)
        {
            if (Object.ReferenceEquals(other, null) || GetType() != other.GetType())
            {
                return(false);
            }

            return(Email == other.Email && PublicKey != null && PublicKey.Equals(other.PublicKey));
        }
예제 #7
0
 /// <summary>
 /// Two DnsResourceDataDnsKey are equal iff their zone key, revoke, secure entry point, protocol, algorithm and public key fields are equal.
 /// </summary>
 public bool Equals(DnsResourceDataDnsKey other)
 {
     return(other != null &&
            ZoneKey.Equals(other.ZoneKey) &&
            Revoke.Equals(other.Revoke) &&
            SecureEntryPoint.Equals(other.SecureEntryPoint) &&
            Protocol.Equals(other.Protocol) &&
            Algorithm.Equals(other.Algorithm) &&
            PublicKey.Equals(other.PublicKey));
 }
예제 #8
0
 public bool Equals(Validator other)
 {
     return(PublicKey.Equals(other.PublicKey) &&
            WithdrawalCredentials.Equals(other.WithdrawalCredentials) &&
            EffectiveBalance.Equals(other.EffectiveBalance) &&
            IsSlashed == other.IsSlashed &&
            ActivationEligibilityEpoch.Equals(other.ActivationEligibilityEpoch) &&
            ActivationEpoch.Equals(other.ActivationEpoch) &&
            ExitEpoch.Equals(other.ExitEpoch) &&
            WithdrawableEpoch.Equals(other.WithdrawableEpoch));
 }
 public static bool TryRemoveKey(PublicKey key)
 {
     foreach (var existing in _keys)
     {
         if (key.Equals(existing.PublicKey))
         {
             return(_keys.Remove(existing));
         }
     }
     return(false);
 }
 public bool Equals(IAsymmetricKeyPair other)
 {
     if ((object)other == null)
     {
         return(false);
     }
     if (Object.ReferenceEquals(PrivateKey, null))
     {
         return(Object.ReferenceEquals(other.PrivateKey, null));
     }
     return(PrivateKey.Equals(other.PrivateKey) && PublicKey.Equals(other.PublicKey));
 }
예제 #11
0
        public bool Equals(FidoDeviceRegistration other)
        {
            if (other == null)
            {
                return(false);
            }

            return
                (Counter == other.Counter &&
                 Certificate.Equals(other.Certificate) &&
                 KeyHandle.Equals(other.KeyHandle) &&
                 PublicKey.Equals(other.PublicKey));
        }
예제 #12
0
        public override IPermission Union(IPermission target)
        {
            StrongNameIdentityPermission snip = Cast(target);

            if ((snip == null) || snip.IsEmpty())
            {
                return(Copy());
            }

            if (IsEmpty())
            {
                return(snip.Copy());
            }

            if (!PublicKey.Equals(snip.PublicKey))
            {
                return(null);
            }

            string n = Name;

            if ((n == null) || (n.Length == 0))
            {
                n = snip.Name;
            }
            else if (Match(snip.Name))
            {
                n = ((Name.Length > snip.Name.Length) ? Name : snip.Name);
            }
            else if ((snip.Name != null) && (snip.Name.Length > 0) && (n != snip.Name))
            {
                return(null);
            }

            Version v = Version;

            if (v == null)
            {
                v = snip.Version;
            }
            else if ((snip.Version != null) && (v != snip.Version))
            {
                return(null);
            }

            return(new StrongNameIdentityPermission(PublicKey, n, v));
        }
예제 #13
0
        public override bool Equals(object o)
        {
            StrongName sn = (o as StrongName);

            if (sn == null)
            {
                return(false);
            }
            if (name != sn.Name)
            {
                return(false);
            }
            if (!Version.Equals(sn.Version))
            {
                return(false);
            }
            return(PublicKey.Equals(sn.PublicKey));
        }
예제 #14
0
 /// <summary>
 /// Two DnsResourceDataKey are equal iff their authentication prohibited, confidentiality prohibited, experimental, user associated, IPSec, email,
 /// name type, signatory, protocol, algorithm, flags extension and public key fields are equal.
 /// </summary>
 public bool Equals(DnsResourceDataKey other)
 {
     return(other != null &&
            AuthenticationProhibited.Equals(other.AuthenticationProhibited) &&
            ConfidentialityProhibited.Equals(other.ConfidentialityProhibited) &&
            Experimental.Equals(other.Experimental) &&
            UserAssociated.Equals(other.UserAssociated) &&
            IpSec.Equals(other.IpSec) &&
            Email.Equals(other.Email) &&
            NameType.Equals(other.NameType) &&
            Signatory.Equals(other.Signatory) &&
            Protocol.Equals(other.Protocol) &&
            Algorithm.Equals(other.Algorithm) &&
            (FlagsExtension.HasValue
                 ? other.FlagsExtension.HasValue && FlagsExtension.Value.Equals(other.FlagsExtension.Value)
                 : !other.FlagsExtension.HasValue) &&
            PublicKey.Equals(other.PublicKey));
 }
예제 #15
0
        /// <summary>
        /// Tests for equality between the specified identity and this identity.
        /// This method should be overriden by subclasses to test for equality.
        /// The default behavior is to return true if the names and public keys
        /// are equal.
        /// </summary>
        /// <param name="identity"> the identity to test for equality with this identity.
        /// </param>
        /// <returns> true if the identities are considered equal, false
        /// otherwise.
        /// </returns>
        /// <seealso cref= #equals </seealso>
        protected internal virtual bool IdentityEquals(Identity identity)
        {
            if (!Name_Renamed.EqualsIgnoreCase(identity.Name_Renamed))
            {
                return(Principal_Fields.False);
            }

            if ((PublicKey_Renamed == null) ^ (identity.PublicKey_Renamed == null))
            {
                return(Principal_Fields.False);
            }

            if (PublicKey_Renamed != null && identity.PublicKey_Renamed != null)
            {
                if (!PublicKey_Renamed.Equals(identity.PublicKey_Renamed))
                {
                    return(Principal_Fields.False);
                }
            }

            return(true);
        }