private VirgilClient PredefinedClient(VirgilCrypto crypto)
        {
            var clientParams = new VirgilClientParams(ConfigurationManager.AppSettings["virgil:AppAccessToken"]);

            clientParams.SetCardsServiceAddress(ConfigurationManager.AppSettings["virgil:CardsServicesAddress"]);
            clientParams.SetIdentityServiceAddress(ConfigurationManager.AppSettings["virgil:IdentityServiceAddress"]);
            clientParams.SetRAServiceAddress(ConfigurationManager.AppSettings["virgil:RAServicesAddress"]);
            clientParams.SetReadCardsServiceAddress(ConfigurationManager.AppSettings["virgil:CardsReadServicesAddress"]);

            var validator = new CardValidator(crypto);

            // To use staging Verifier instead of default verifier
            var cardVerifier = new CardVerifierInfo
            {
                CardId        = ConfigurationManager.AppSettings["virgil:ServiceCardId"],
                PublicKeyData = VirgilBuffer.From(ConfigurationManager.AppSettings["virgil:ServicePublicKeyDerBase64"],
                                                  StringEncoding.Base64)
            };

            validator.AddVerifier(cardVerifier.CardId, cardVerifier.PublicKeyData.GetBytes());

            var client = new VirgilClient(clientParams);

            client.SetCardValidator(validator);

            return(client);
        }
Exemple #2
0
        public async Task CreateNewVirgilCard_SignatureValidation_ShouldPassValidation()
        {
            var crypto = new VirgilCrypto();
            var client = IntegrationHelper.GetVirgilClient();

            // CREATING A VIRGIL CARD

            var appKey = crypto.ImportPrivateKey(IntegrationHelper.AppKey, IntegrationHelper.AppKeyPassword);

            var aliceKeys         = crypto.GenerateKeys();
            var exportedPublicKey = crypto.ExportPublicKey(aliceKeys.PublicKey);

            var aliceIdentity = "alice-" + Guid.NewGuid();
            var request       = new PublishCardRequest(aliceIdentity, "member", exportedPublicKey);

            var requestSigner = new RequestSigner(crypto);

            requestSigner.SelfSign(request, aliceKeys.PrivateKey);
            requestSigner.AuthoritySign(request, IntegrationHelper.AppID, appKey);

            var aliceCard = await client.PublishCardAsync(request);

            // VALIDATING A VIRGIL CARD

            var appPublicKey         = crypto.ExtractPublicKey(appKey);
            var exportedAppPublicKey = crypto.ExportPublicKey(appPublicKey);

            var validator = new CardValidator(crypto);

            validator.AddVerifier(IntegrationHelper.AppID, exportedAppPublicKey);

            validator.Validate(aliceCard).Should().BeTrue();

            await IntegrationHelper.RevokeCard(aliceCard.Id);
        }
        private VirgilClient InitClient()
        {
            var client = this.ClientParams == null
                ? new VirgilClient(this.AccessToken)
                : new VirgilClient(this.ClientParams);

            var validator = new CardValidator(this.Crypto);

            if (this.CardVerifiers != null && this.CardVerifiers.Any())
            {
                foreach (var verifierInfo in this.CardVerifiers)
                {
                    validator.AddVerifier(verifierInfo.CardId, verifierInfo.PublicKeyData.GetBytes());
                }
            }

            client.SetCardValidator(validator);
            return(client);
        }