Exemplo n.º 1
0
        private void VerifyWif(UserInfo user)
        {
            var pkBytes = Secp256K1Manager.GetPublicKey(user.ActiveKeys[0], true);
            var pk      = new PublicKeyType(pkBytes, SbdSymbol);

            Assert.True(pk.Data.SequenceEqual(user.Account.Active.KeyAuths[0].Key.Data));
        }
Exemplo n.º 2
0
 public WitnessUpdateOperation(string owner, string url, PublicKeyType blockSigningKey, LegacyChainProperties props, Asset fee)
 {
     Owner           = owner;
     Url             = url;
     BlockSigningKey = blockSigningKey;
     Props           = props;
     Fee             = fee;
 }
Exemplo n.º 3
0
        public static string Translate(this PublicKeyType type, Translator translator)
        {
            switch (type)
            {
            case PublicKeyType.OpenPGP:
                return(translator.Get("Enum.PublicKeyType.OpenPGP", "OpenPGP value in the public key type enum", "OpenPGP"));

            default:
                throw new NotSupportedException();
            }
        }
Exemplo n.º 4
0
        public void get_key_references()
        {
            var pubKey = new PublicKeyType("STM6C8GjDBAHrfSqaNRn4FnLLUdCfw3WgjY3td1cC4T7CKpb32YM6");

            var args = new GetKeyReferencesArgs()
            {
                Keys = new[] { pubKey }
            };
            var resp = Api.GetKeyReferences(args, CancellationToken.None);

            WriteLine(resp);
            Assert.IsFalse(resp.IsError);
        }
Exemplo n.º 5
0
        public async Task get_key_references()
        {
            var pubKey = new PublicKeyType(Config.KeyPrefix + "6C8GjDBAHrfSqaNRn4FnLLUdCfw3WgjY3td1cC4T7CKpb32YM6");

            var args = new GetKeyReferencesArgs
            {
                Keys = new[] { pubKey }
            };
            var resp = await Api.GetKeyReferencesAsync(args, CancellationToken.None).ConfigureAwait(false);

            WriteLine(resp);
            Assert.IsFalse(resp.IsError);
        }
Exemplo n.º 6
0
        public static PublicKey Decode(IByteReader stream)
        {
            PublicKey decodedPublicKey = new PublicKey();

            decodedPublicKey.Discriminant = PublicKeyType.Decode(stream);
            switch (decodedPublicKey.Discriminant.InnerValue)
            {
            case PublicKeyType.PublicKeyTypeEnum.PUBLIC_KEY_TYPE_ED25519:
                decodedPublicKey.Ed25519 = Uint256.Decode(stream);
                break;
            }
            return(decodedPublicKey);
        }
Exemplo n.º 7
0
        public static PublicKey Decode(XdrDataInputStream stream)
        {
            var decodedPublicKey = new PublicKey();
            var discriminant     = PublicKeyType.Decode(stream);

            decodedPublicKey.Discriminant = discriminant;
            switch (decodedPublicKey.Discriminant.InnerValue)
            {
            case PublicKeyType.PublicKeyTypeEnum.PUBLIC_KEY_TYPE_ED25519:
                decodedPublicKey.Ed25519 = Uint256.Decode(stream);
                break;
            }
            return(decodedPublicKey);
        }
Exemplo n.º 8
0
        public async Task EvaluateEmptyPublicKeyProducesCorrectMessage()
        {
            PublicKeyData publicKeyData = new PublicKeyData("");
            PublicKeyType publicKeyType = new PublicKeyType("", KeyType.Rsa);

            DkimRecord dkimRecord = new DkimRecord(null, new List <Tag> {
                publicKeyData, publicKeyType
            });

            List <EvaluationError> result = await _selectorShouldBeWellConfigured.Evaluate(dkimRecord);

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(Guid.Parse("7150fec3-0464-4cd5-b774-d1d7bcff7ec5"), result[0].Id);
        }
        public EvaluationResult <Tag> Parse(string value)
        {
            KeyType keyType = GetPublicKeyType(value);

            PublicKeyType publicKeyType = new PublicKeyType(value, keyType);

            if (keyType == KeyType.Unknown)
            {
                EvaluationError error = new EvaluationError(Id, EvaluationErrorType.Error,
                                                            string.Format(DKimEvaluatorParsersResources.InvalidPublicTypeErrorMessage, value ?? "null"),
                                                            string.Format(DKimEvaluatorParsersMarkdownResources.InvalidPublicTypeErrorMessage, value ?? "null"));

                return(new EvaluationResult <Tag>(publicKeyType, error));
            }

            return(new EvaluationResult <Tag>(publicKeyType));
        }
        public void PublicKeyTypeParserStrategy(string tokenValue, KeyType keyType, string errorMessageStartsWith, EvaluationErrorType?type)
        {
            PublicKeyTypeParserStrategy publicKeyTypeParserStrategy = new PublicKeyTypeParserStrategy();
            EvaluationResult <Tag>      publicKeyTypeResult         = publicKeyTypeParserStrategy.Parse(tokenValue);

            PublicKeyType publicKeyType = (PublicKeyType)publicKeyTypeResult.Item;

            if (errorMessageStartsWith == null)
            {
                Assert.That(publicKeyTypeResult.Errors, Is.Empty);
                Assert.That(publicKeyType.Value, Is.EqualTo(tokenValue));
                Assert.That(publicKeyType.KeyType, Is.EqualTo(keyType));
            }
            else
            {
                Assert.That(publicKeyTypeResult.Errors.Count, Is.EqualTo(1));
                Assert.That(publicKeyTypeResult.Errors[0].Message.StartsWith(errorMessageStartsWith), Is.EqualTo(true));
                Assert.That(publicKeyTypeResult.Errors[0].ErrorType, Is.EqualTo(type));
                Assert.That(publicKeyType.Value, Is.EqualTo(tokenValue));
                Assert.That(publicKeyType.KeyType, Is.EqualTo(keyType));
            }
        }
Exemplo n.º 11
0
    public override int GetHashCode()
    {
        int hash = 1;

        if (PublicKey.Length != 0)
        {
            hash ^= PublicKey.GetHashCode();
        }
        if (PublicKeyType != 0)
        {
            hash ^= PublicKeyType.GetHashCode();
        }
        if (EntityType != 0)
        {
            hash ^= EntityType.GetHashCode();
        }
        if (EntityHash.Length != 0)
        {
            hash ^= EntityHash.GetHashCode();
        }
        if (EntityHashSignature.Length != 0)
        {
            hash ^= EntityHashSignature.GetHashCode();
        }
        if (ValidFrom != 0)
        {
            hash ^= ValidFrom.GetHashCode();
        }
        if (ValidTo != 0)
        {
            hash ^= ValidTo.GetHashCode();
        }
        if (_unknownFields != null)
        {
            hash ^= _unknownFields.GetHashCode();
        }
        return(hash);
    }
Exemplo n.º 12
0
 public static void Encode(IByteWriter stream, PublicKeyType value)
 {
     XdrEncoding.EncodeInt32((int)value.InnerValue, stream);
 }
Exemplo n.º 13
0
 public AccountUpdateOperation(string account, PublicKeyType memoKey, string jsonMetadata)
 {
     Account      = account;
     MemoKey      = memoKey;
     JsonMetadata = jsonMetadata;
 }
Exemplo n.º 14
0
        public Task <List <EvaluationError> > Evaluate(DkimRecord record)
        {
            PublicKeyData publicKeyData = record.Tags.OfType <PublicKeyData>().FirstOrDefault();
            PublicKeyType publicKeyType = record.Tags.OfType <PublicKeyType>().FirstOrDefault();

            List <EvaluationError> errors = new List <EvaluationError>();

            if (publicKeyData != null && publicKeyType != null && !string.IsNullOrEmpty(publicKeyData.Value))
            {
                if (publicKeyType.KeyType != KeyType.Unknown)
                {
                    switch (publicKeyType.KeyType)
                    {
                    case KeyType.Ed25519:
                        break;

                    case KeyType.Rsa:
                        string key = publicKeyData.Value.TrimEnd(';');


                        if (!_publicKeyEvaluator.TryGetKeyLengthSize(key, out int keyLength))
                        {
                            Guid Error3Id = Guid.Parse("21B09D43-685C-4CAE-989E-7194CA093863");

                            errors.Add(new EvaluationError(Error3Id, EvaluationErrorType.Error,
                                                           DKimEvaluatorRulesResources.CorruptPublicKeyErrorMessage,
                                                           DKimEvaluatorRulesMarkdownResources.CorruptPublicKeyErrorMessage));
                        }
                        else if (keyLength < 2048)
                        {
                            if (keyLength < 1024)
                            {
                                Guid Error1Id = Guid.Parse("C740A1B0-394B-4397-A4E6-178C3137A84D");

                                errors.Add(new EvaluationError(Error1Id, EvaluationErrorType.Error,
                                                               string.Format(DKimEvaluatorRulesResources.PublicKeyIsToShortErrorMessage,
                                                                             keyLength),
                                                               string.Empty));
                            }
                            else if (keyLength >= 1024 && keyLength < 2048)
                            {
                                Guid Error2Id = Guid.Parse("D16BE8D5-8ED6-4DD0-A8AA-C8F1380A8D3C");

                                errors.Add(new EvaluationError(Error2Id, EvaluationErrorType.Warning,
                                                               string.Format(
                                                                   DKimEvaluatorRulesResources.PublicKeyIsToShortUseLongerErrorMessage,
                                                                   keyLength),
                                                               string.Empty));
                            }
                        }
                        break;
                    }
                }
                else
                {
                    Guid Error3Id = Guid.Parse("FF2380B4-8DE6-4B97-B69A-F3382EBF3DE2");

                    errors.Add(new EvaluationError(Error3Id, EvaluationErrorType.Error,
                                                   DKimEvaluatorRulesResources.IncorrectPublicKeyConfigured,
                                                   DKimEvaluatorRulesMarkdownResources.IncorrectPublicKeyConfigured));
                }
            }
            else
            {
                Guid Error3Id = Guid.Parse("7150FEC3-0464-4CD5-B774-D1D7BCFF7EC5");

                errors.Add(new EvaluationError(Error3Id, EvaluationErrorType.Info,
                                               DKimEvaluatorRulesResources.NullPublicKeyConfigured,
                                               DKimEvaluatorRulesMarkdownResources.NullPublicKeyConfigured));
            }

            return(Task.FromResult(errors));
        }
Exemplo n.º 15
0
 public NamedIntViewModel(Translator translator, PublicKeyType type, bool selected)
     : this((int)type, type.Translate(translator), selected)
 {
 }