Example #1
0
        /// <summary>
        /// For backwards-compatibility reasons, we support both PEM-encoded certificates *and* raw binary files containing
        /// the certificate data.
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldLoadBinaryCertificates() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldLoadBinaryCertificates()
        {
            // Given
            SelfSignedCertificate cert = new SelfSignedCertificate("example.com");
            PkiUtils certs             = new PkiUtils();

            File cPath = _testDirectory.file("certificate");

            assertTrue(cPath.createNewFile());
            sbyte[] raw = certs.LoadCertificates(cert.certificate())[0].Encoded;

            using (FileChannel ch = FileChannel.open(cPath.toPath(), WRITE))
            {
                FileUtils.writeAll(ch, ByteBuffer.wrap(raw));
            }

            // When
            Certificate[] certificates = certs.LoadCertificates(cPath);

            // Then
            assertThat(certificates.Length, equalTo(1));
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldLoadPEMCertificates() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldLoadPEMCertificates()
        {
            // Given
            SelfSignedCertificate cert = new SelfSignedCertificate("example.com");
            PkiUtils certs             = new PkiUtils();

            File pemCertificate = cert.certificate();

            // When
            Certificate[] certificates = certs.LoadCertificates(pemCertificate);

            // Then
            assertThat(certificates.Length, equalTo(1));
        }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldCreateASelfSignedCertificate() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldCreateASelfSignedCertificate()
        {
            // Given
            PkiUtils sslFactory = new PkiUtils();
            File     cPath      = new File(_testDirectory.directory(), "certificate");
            File     pkPath     = new File(_testDirectory.directory(), "key");

            // When
            sslFactory.CreateSelfSignedCertificate(cPath, pkPath, "myhost");

            // Then
            // Attempt to load certificate
            Certificate[] certificates = sslFactory.LoadCertificates(cPath);
            assertThat(certificates.Length, @is(greaterThan(0)));

            // Attempt to load private key
            PrivateKey pk = sslFactory.LoadPrivateKey(pkPath);

            assertThat(pk, notNullValue());
        }