Exemple #1
0
        /// <summary>
        /// Revokes a <see cref="VirgilCard"/> from Virgil Services.
        /// </summary>
        /// <param name="card">The card to be revoked.</param>
        public async Task RevokeAsync(VirgilCard card)
        {
            if ((this.context == null) || (this.context.Credentials == null) ||
                (this.context.Credentials.GetAppId() == null) ||
                (this.context.Credentials.GetAppKey(context.Crypto) == null))
            {
                throw new AppCredentialsException();
            }
            var revokeRequest = new RevokeCardRequest(card.Id, RevocationReason.Unspecified);

            var appId  = this.context.Credentials.GetAppId();
            var appKey = this.context.Credentials.GetAppKey(this.context.Crypto);


            var fingerprint = this.context.Crypto.CalculateFingerprint(revokeRequest.Snapshot);
            var signature   = this.context.Crypto.Sign(fingerprint.GetValue(), appKey);

            revokeRequest.AppendSignature(appId, signature);

            /* to_ask
             * var requestSigner = new RequestSigner(this.context.Crypto);
             * requestSigner.AuthoritySign(revokeRequest, appId, appKey); */

            await this.context.Client.RevokeCardAsync(revokeRequest);
        }
        public async Task AddOrDeleteRelationWithoutAuthoritySign_ExceptionShouldOccur()
        {
            const string identityType  = "member";
            var          crypto        = new VirgilCrypto();
            var          client        = PredefinedClient(crypto);
            var          requestSigner = new RequestSigner(crypto);

            var aliceKeys = crypto.GenerateKeys();
            var aliceExportedPublicKey = crypto.ExportPublicKey(aliceKeys.PublicKey);
            var aliceRequest           = new PublishCardRequest("alice", identityType, aliceExportedPublicKey);

            var bobKeys = crypto.GenerateKeys();
            var bobExportedPublicKey = crypto.ExportPublicKey(bobKeys.PublicKey);
            var bobRequest           = new PublishCardRequest("bob", identityType, bobExportedPublicKey);

            var appId  = ConfigurationManager.AppSettings["virgil:AppID"];
            var appKey = crypto.ImportPrivateKey(
                VirgilBuffer.FromFile(ConfigurationManager.AppSettings["virgil:AppKeyPath"]).GetBytes(),
                ConfigurationManager.AppSettings["virgil:AppKeyPassword"]);


            // publish cards
            requestSigner.SelfSign(aliceRequest, aliceKeys.PrivateKey);
            requestSigner.AuthoritySign(aliceRequest, appId, appKey);
            var aliceCardModel = await client
                                 .PublishCardAsync(aliceRequest).ConfigureAwait(false);

            requestSigner.SelfSign(bobRequest, bobKeys.PrivateKey);
            requestSigner.AuthoritySign(bobRequest, appId, appKey);
            var bobCardModel = await client
                               .PublishCardAsync(bobRequest).ConfigureAwait(false);

            aliceCardModel.Meta.Relations.Count.ShouldBeEquivalentTo(0);


            // add Bob's card to Alice's relations
            var addRelationRequest = new AddRelationRequest(bobCardModel.SnapshotModel);

            Assert.ThrowsAsync <Exceptions.RelationException>(() => client.AddRelationAsync(addRelationRequest));

            // Delete Bob's card from Alice's relations
            var deleteRelationRequest = new DeleteRelationRequest(bobCardModel.Id, RevocationReason.Unspecified);

            Assert.ThrowsAsync <Exceptions.RelationException>(() => client.DeleteRelationAsync(deleteRelationRequest));

            // delete cards
            var revokeBobRequest = new RevokeCardRequest(bobCardModel.Id, RevocationReason.Unspecified);

            requestSigner.AuthoritySign(revokeBobRequest, appId, appKey);
            await client.RevokeCardAsync(revokeBobRequest);

            var revokeAliceRequest = new RevokeCardRequest(aliceCardModel.Id, RevocationReason.Unspecified);

            requestSigner.AuthoritySign(revokeAliceRequest, appId, appKey);
            await client.RevokeCardAsync(revokeAliceRequest);
        }
        /// <summary>
        /// Revokes a <see cref="VirgilCard"/> from Virgil Services.
        /// </summary>
        /// <param name="card">The card to be revoked.</param>
        public async Task RevokeAsync(VirgilCard card)
        {
            var revokeRequest = new RevokeCardRequest(card.Id, RevocationReason.Unspecified);

            var appId  = this.context.Credentials.GetAppId();
            var appKey = this.context.Credentials.GetAppKey(this.context.Crypto);

            var fingerprint = this.context.Crypto.CalculateFingerprint(revokeRequest.Snapshot);
            var signature   = this.context.Crypto.Sign(fingerprint.GetValue(), appKey);

            revokeRequest.AppendSignature(appId, signature);

            await this.context.Client.RevokeCardAsync(revokeRequest);
        }
        public static async Task RevokeCard(string cardId)
        {
            var client        = GetVirgilClient();
            var crypto        = new VirgilCrypto();
            var requestSigner = new RequestSigner(crypto);

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

            var revokeRequest = new RevokeCardRequest(cardId, RevocationReason.Unspecified);

            requestSigner.AuthoritySign(revokeRequest, AppID, appKey);

            await client.RevokeCardAsync(revokeRequest);
        }
Exemple #5
0
 /// <summary>
 /// Revokes a <see cref="VirgilCard"/> by revocation request.
 /// </summary>
 public static async Task RevokeAsync(RevokeCardRequest request)
 {
     var client = VirgilConfig.GetService <VirgilClient>();
     await client.RevokeCardAsync(request).ConfigureAwait(false);
 }