Beispiel #1
0
        public async Task Decrypt_Fails_When_Wrong_Decryption_Certificate_Is_Given()
        {
            // Arrange
            AS4Message as4Message = await GetEncryptedMessageAsync();

            var certificate = new StubCertificateRepository().GetStubCertificate();

            // Act&Assert
            Assert.ThrowsAny <Exception>(() => as4Message.Decrypt(certificate));
        }
Beispiel #2
0
        public async Task Decrypt_Unmarks_SecurityHeader_As_Encrypted()
        {
            // Arrange
            AS4Message as4Message = await GetEncryptedMessageAsync();

            X509Certificate2 decryptCertificate = GetDecryptCertificate();

            Assert.True(as4Message.SecurityHeader.IsEncrypted);

            // Act
            as4Message.Decrypt(decryptCertificate);

            Assert.False(as4Message.SecurityHeader.IsEncrypted);
        }
Beispiel #3
0
        public async Task Decrypt_Sets_Compressed_ContentType_For_Payloads_Afterwards()
        {
            // Arrange
            AS4Message as4Message = await GetEncryptedCompressedMessageAsync();

            X509Certificate2 decryptCert = GetDecryptCertificate();

            // Act
            as4Message.Decrypt(decryptCert);

            // Assert
            Assert.All(
                as4Message.Attachments,
                a => Assert.Equal("application/gzip", a.ContentType));
        }
Beispiel #4
0
        public async Task Decrypt_Multiple_Image_Payloads_Correctly()
        {
            // Arrange
            AS4Message as4Message = await GetEncryptedMessageAsync();

            X509Certificate2 decryptCertificate = GetDecryptCertificate();

            // Act
            as4Message.Decrypt(decryptCertificate);

            // Assert
            Assert.Equal(
                new [] { flower1, flower2 },
                as4Message.Attachments.Select(GetAttachmentContents));
            Assert.All(
                as4Message.Attachments,
                a => Assert.Equal("image/jpeg", a.ContentType));
        }
Beispiel #5
0
        public async Task Decrypt_Removes_Encryption_Elements_From_SecurityHeader()
        {
            // Arrange
            AS4Message as4Message = await GetEncryptedMessageAsync();

            X509Certificate2 decryptCertificate = GetDecryptCertificate();

            // Act
            as4Message.Decrypt(decryptCertificate);

            // Assert
            var encryptedKeyNode = as4Message.SecurityHeader.GetXml().SelectSingleNode("//*[local-name()='EncryptedKey']");

            Assert.Null(encryptedKeyNode);

            var encryptedDatas = as4Message.SecurityHeader.GetXml().SelectNodes("//*[local-name()='EncryptedData']");

            Assert.True(encryptedDatas == null || encryptedDatas.Count == 0);
        }
Beispiel #6
0
        public async Task Decrypts_IssuerSerial_Signed_AS4Message()
        {
            // Arrange
            const string contentType =
                "multipart/related; boundary=\"MIMEBoundary_416ba07b9ac392cc88fdb1c2ed23ba5e2e6d64fdf13325f1\"; type=\"application/soap+xml\"; start=\"<*****@*****.**>\"";

            AS4Message encrypted = await SerializerProvider
                                   .Default
                                   .Get(contentType)
                                   .DeserializeAsync(new MemoryStream(as4_encrypted_signed_issuerserial), contentType);

            // Act
            encrypted.Decrypt(
                new X509Certificate2(
                    AccessPointB_pfx,
                    AccessPointB_password,
                    X509KeyStorageFlags.Exportable));

            // Assert
            Assert.False(encrypted.IsEncrypted);
        }