Esempio n. 1
0
        public async Task ValidateCertificateExisting()
        {
            using (var dirServer = TempDirectory.Create("Server"))
                using (var dirClient = TempDirectory.Create("Client"))
                {
                    var storeServer = new DirectoryStore(dirServer.Name, createLocalCertificateIfNotExist: true);
                    var storeClient = new DirectoryStore(dirClient.Name, acceptAllRemoteCertificates: false);

                    var server = new ApplicationDescription
                    {
                        ApplicationUri = "http://hostname/server",
                    };

                    // First we create a certificate
                    var(cert, _) = await storeServer.GetLocalCertificateAsync(server);

                    CopyAll(dirServer.Name + @"/own/certs", dirClient.Name + @"/trusted");

                    // The certificate is now in the expected directory
                    // hence it should be accepted
                    var ret = await storeClient.ValidateRemoteCertificateAsync(cert);

                    ret
                    .Should().BeTrue();
                }
        }
Esempio n. 2
0
        public async Task ValidateCertificateNotExisting()
        {
            using (var dirServer = TempDirectory.Create("Server"))
                using (var dirClient = TempDirectory.Create("Client", false))
                {
                    var storeServer = new DirectoryStore(dirServer.Name, createLocalCertificateIfNotExist: true);
                    var storeClient = new DirectoryStore(dirClient.Name, acceptAllRemoteCertificates: false);

                    var server = new ApplicationDescription
                    {
                        ApplicationUri = "http://hostname/server",
                    };

                    // First we create a certificate
                    var(cert, _) = await storeServer.GetLocalCertificateAsync(server);

                    // The certificate is not in the expected directory
                    // hence it should not be accepted
                    var ret = await storeClient.ValidateRemoteCertificateAsync(cert);

                    ret
                    .Should().BeFalse();

                    Directory.EnumerateFiles(dirClient.Name + @"/rejected")
                    .Should().HaveCount(1);
                }
        }
Esempio n. 3
0
        public async Task LoadCertificate()
        {
            using (var dir = TempDirectory.Create())
            {
                var store = new DirectoryStore(dir.Name, createLocalCertificateIfNotExist: true);

                var app = new ApplicationDescription
                {
                    ApplicationUri = "urn:hostname:appname",
                };

                var(cert1, key1) = await store.GetLocalCertificateAsync(app);

                var(cert2, key2) = await store.GetLocalCertificateAsync(app);

                cert1
                .Should().Be(cert2);

                key1
                .Should().Be(key2);
            }
        }
Esempio n. 4
0
        public async Task CreateNoCertificate()
        {
            var store = new DirectoryStore("nocert", createLocalCertificateIfNotExist: false);

            var app = new ApplicationDescription
            {
                ApplicationUri = "http://hostname/appname",
            };

            var(cert, key) = await store.GetLocalCertificateAsync(app);

            cert
            .Should().BeNull();
            key
            .Should().BeNull();
        }
Esempio n. 5
0
        public async Task CertificateDirectoryStructure()
        {
            using (var dir = TempDirectory.Create())
            {
                var store = new DirectoryStore(dir.Name, createLocalCertificateIfNotExist: true);

                var app = new ApplicationDescription
                {
                    ApplicationUri = "http://hostname/appname",
                };

                await store.GetLocalCertificateAsync(app);

                Directory.EnumerateFiles(dir.Name + @"/own/certs")
                .Should().HaveCount(1);

                Directory.EnumerateFiles(dir.Name + @"/own/private")
                .Should().HaveCount(1);
            }
        }
Esempio n. 6
0
        public async Task CreateCertificate()
        {
            using (var dir = TempDirectory.Create())
            {
                var store = new DirectoryStore(dir.Name, createLocalCertificateIfNotExist: true);

                var app = new ApplicationDescription
                {
                    ApplicationUri = "http://hostname/appname",
                };

                var(cert, key) = await store.GetLocalCertificateAsync(app);

                cert
                .Should().NotBeNull();
                key
                .Should().NotBeNull();

                cert.SubjectDN.ToString()
                .Should().Be("CN=appname,DC=hostname");
            }
        }