public async Task SearchForVirgilCards_ValidationWithServiceKey_ShouldPassValidation() { var crypto = new VirgilCrypto(); var client = IntergrationHelper.GetVirgilClient(); client.SetCardValidator(new CardValidator(crypto)); // CREATING A VIRGIL CARD var appKey = crypto.ImportPrivateKey(IntergrationHelper.AppKey, IntergrationHelper.AppKeyPassword); var aliceKeys = crypto.GenerateKeys(); var exportedPublicKey = crypto.ExportPublicKey(aliceKeys.PublicKey); var aliceIdentity = "alice-" + Guid.NewGuid(); var request = new CreateCardRequest(aliceIdentity, "member", exportedPublicKey); var requestSigner = new RequestSigner(crypto); requestSigner.SelfSign(request, aliceKeys.PrivateKey); requestSigner.AuthoritySign(request, IntergrationHelper.AppID, appKey); var aliceCard = await client.CreateCardAsync(request); // VALIDATING A VIRGIL CARD var cards = await client.SearchCardsAsync(SearchCriteria.ByIdentity(aliceIdentity)); aliceCard.ShouldBeEquivalentTo(cards.Single()); await IntergrationHelper.RevokeCard(aliceCard.Id); }
public async Task GetSignleVirgilCard_ByGivenId_ShouldReturnVirgilCard() { var crypto = new VirgilCrypto(); var client = IntergrationHelper.GetVirgilClient(); var requestSigner = new RequestSigner(crypto); var appKey = crypto.ImportPrivateKey(IntergrationHelper.AppKey, IntergrationHelper.AppKeyPassword); // Prepare Requests var aliceIdentity = "alice-" + Guid.NewGuid(); var aliceKeys = crypto.GenerateKeys(); var alicePublicKey = crypto.ExportPublicKey(aliceKeys.PublicKey); var aliceRequest = new CreateCardRequest(aliceIdentity, "member", alicePublicKey); requestSigner.SelfSign(aliceRequest, aliceKeys.PrivateKey); requestSigner.AuthoritySign(aliceRequest, IntergrationHelper.AppID, appKey); var aliceCard = await client.CreateCardAsync(aliceRequest); var foundAliceCard = await client.GetCardAsync(aliceCard.Id); aliceCard.ShouldBeEquivalentTo(foundAliceCard); await IntergrationHelper.RevokeCard(aliceCard.Id); }
public async Task CreateNewVirgilCard_SignatureValidation_ShouldPassValidation() { var crypto = new VirgilCrypto(); var client = IntergrationHelper.GetVirgilClient(); // CREATING A VIRGIL CARD var appKey = crypto.ImportPrivateKey(IntergrationHelper.AppKey, IntergrationHelper.AppKeyPassword); var aliceKeys = crypto.GenerateKeys(); var exportedPublicKey = crypto.ExportPublicKey(aliceKeys.PublicKey); var aliceIdentity = "alice-" + Guid.NewGuid(); var request = new CreateCardRequest(aliceIdentity, "member", exportedPublicKey); var requestSigner = new RequestSigner(crypto); requestSigner.SelfSign(request, aliceKeys.PrivateKey); requestSigner.AuthoritySign(request, IntergrationHelper.AppID, appKey); var aliceCard = await client.CreateCardAsync(request); // VALIDATING A VIRGIL CARD var appPublicKey = crypto.ExtractPublicKey(appKey); var exportedAppPublicKey = crypto.ExportPublicKey(appPublicKey); var validator = new CardValidator(crypto); validator.AddVerifier(IntergrationHelper.AppID, exportedAppPublicKey); validator.Validate(aliceCard).Should().BeTrue(); await IntergrationHelper.RevokeCard(aliceCard.Id); }
public async Task CreateNewVirgilCard_IdentityAndPublicKeyGiven_ShouldBeFoundByIdentity() { var crypto = new VirgilCrypto(); var client = IntergrationHelper.GetVirgilClient(); var appKey = crypto.ImportPrivateKey(IntergrationHelper.AppKey, IntergrationHelper.AppKeyPassword); var aliceKeys = crypto.GenerateKeys(); var exportedPublicKey = crypto.ExportPublicKey(aliceKeys.PublicKey); var aliceIdentity = "alice-" + Guid.NewGuid(); var request = new CreateCardRequest(aliceIdentity, "member", exportedPublicKey); var requestSigner = new RequestSigner(crypto); requestSigner.SelfSign(request, aliceKeys.PrivateKey); requestSigner.AuthoritySign(request, IntergrationHelper.AppID, appKey); var newCard = await client.CreateCardAsync(request); var cards = await client.SearchCardsAsync(new SearchCriteria { Identities = new[] { aliceIdentity } }); cards.Should().HaveCount(1); var foundCard = cards.Single(); newCard.ShouldBeEquivalentTo(foundCard); }
public async Task SearchForTheVirgilCards_MultipleIdentitiesGiven_ShouldReturnVirgilCards() { // Initialization var crypto = new VirgilCrypto(); var client = IntergrationHelper.GetVirgilClient(); var requestSigner = new RequestSigner(crypto); var appKey = crypto.ImportPrivateKey(IntergrationHelper.AppKey, IntergrationHelper.AppKeyPassword); // Prepare Requests var aliceIdentity = "alice-" + Guid.NewGuid(); var aliceKeys = crypto.GenerateKeys(); var alicePublicKey = crypto.ExportPublicKey(aliceKeys.PublicKey); var bobIdentity = "bob-" + Guid.NewGuid(); var bobKeys = crypto.GenerateKeys(); var bobPublicKey = crypto.ExportPublicKey(bobKeys.PublicKey); var aliceRequest = new CreateCardRequest(aliceIdentity, "member", alicePublicKey); var bobRequest = new CreateCardRequest(bobIdentity, "member", bobPublicKey); requestSigner.SelfSign(aliceRequest, aliceKeys.PrivateKey); requestSigner.AuthoritySign(aliceRequest, IntergrationHelper.AppID, appKey); requestSigner.SelfSign(bobRequest, bobKeys.PrivateKey); requestSigner.AuthoritySign(bobRequest, IntergrationHelper.AppID, appKey); // Publish Virgil Cards var aliceCard = await client.CreateCardAsync(aliceRequest); var bobCard = await client.CreateCardAsync(bobRequest); // Search for the Virgil Cards var foundCards = await client.SearchCardsAsync(new SearchCriteria { Identities = new[] { bobIdentity, aliceIdentity } }); // Assertions foundCards.Should().HaveCount(2); foundCards.Single(it => it.Id == aliceCard.Id).ShouldBeEquivalentTo(aliceCard); foundCards.Single(it => it.Id == bobCard.Id).ShouldBeEquivalentTo(bobCard); await IntergrationHelper.RevokeCard(aliceCard.Id); await IntergrationHelper.RevokeCard(bobCard.Id); }
public async Task CreateNewVirgilCard_DuplicateCardCreation_ShouldThrowException() { var crypto = new VirgilCrypto(); var client = IntergrationHelper.GetVirgilClient(); var appKey = crypto.ImportPrivateKey(IntergrationHelper.AppKey, IntergrationHelper.AppKeyPassword); var aliceKeys = crypto.GenerateKeys(); var exportedPublicKey = crypto.ExportPublicKey(aliceKeys.PublicKey); var aliceIdentity = "alice-" + Guid.NewGuid(); var request = new CreateCardRequest(aliceIdentity, "member", exportedPublicKey); var requestSigner = new RequestSigner(crypto); requestSigner.SelfSign(request, aliceKeys.PrivateKey); requestSigner.AuthoritySign(request, IntergrationHelper.AppID, appKey); var virgilCard = await client.CreateCardAsync(request); Assert.ThrowsAsync <VirgilClientException>(async() => await client.CreateCardAsync(request)); }