// //////////////////////////////////////////////////////////////////////////////////////////// // Sign support public async Task <BlockChain> Sign(BlockChain blockChain, CancellationToken token) { SignRequest request = blockChain.GetPrincipleDigests().ToSignRequest(); if (request.PrincipleDigests.Count == 0) { return(blockChain); } SignRequestResponse signedDigests = await _signingClient.Sign(request, token); return(blockChain.Sign(signedDigests.PrincipleDigests)); }
public async Task GivenIdentityEntry_WhenSigned_WillVerify() { const string issuer = "*****@*****.**"; IdentityClient client = TestApplication.GetIdentityClient(); SigningClient signClient = TestApplication.GetSigningClient(); var documentId = new DocumentId("identity:test/unit-tests-identity/identity1"); var query = new QueryParameter() { Filter = "test/unit-tests-identity", Recursive = false, }; IReadOnlyList <DatalakePathItem> search = (await client.Search(query).ReadNext()).Records; bool isInsearch = search.Any(x => x.Name == documentId.Path); bool deleted = await client.Delete(documentId); (isInsearch == deleted).Should().BeTrue(); var request = new IdentityEntryRequest { DirectoryId = (string)documentId, Issuer = issuer }; bool success = await client.Create(request); success.Should().BeTrue(); var signRequest = new SignRequest { PrincipleDigests = new[] { new PrincipleDigest { PrincipleId = (string)documentId, Digest = Guid.NewGuid().ToString() } } }; SignRequestResponse signedJwt = await signClient.Sign(signRequest); signedJwt.Should().NotBeNull(); (signedJwt.Errors == null || signedJwt.Errors.Count == 0).Should().BeTrue(); signedJwt.PrincipleDigests.Count.Should().Be(1); var validateRequest = new ValidateRequest { PrincipleDigests = new[] { new PrincipleDigest { PrincipleId = (string)documentId, Digest = signRequest.PrincipleDigests[0].Digest, JwtSignature = signedJwt.PrincipleDigests.First().JwtSignature, } } }; bool jwtValidated = await signClient.Validate(validateRequest); jwtValidated.Should().BeTrue(); await client.Delete(documentId); search = (await client.Search(query).ReadNext()).Records; search.Any(x => x.Name == (string)documentId).Should().BeFalse(); }