//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldLoadPEMPrivateKey() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldLoadPEMPrivateKey() { // Given SelfSignedCertificate cert = new SelfSignedCertificate("example.com"); PkiUtils certs = new PkiUtils(); File privateKey = cert.privateKey(); // When PrivateKey pk = certs.LoadPrivateKey(privateKey); // Then assertNotNull(pk); }
//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)); }
//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()); }
/// <summary> /// For backwards-compatibility reasons, we support both PEM-encoded private keys *and* raw binary files containing /// the private key data /// </summary> //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldLoadBinaryPrivateKey() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldLoadBinaryPrivateKey() { // Given SelfSignedCertificate cert = new SelfSignedCertificate("example.com"); PkiUtils certs = new PkiUtils(); File keyFile = _testDirectory.file("certificate"); assertTrue(keyFile.createNewFile()); sbyte[] raw = certs.LoadPrivateKey(cert.privateKey()).Encoded; using (FileChannel ch = FileChannel.open(keyFile.toPath(), WRITE)) { FileUtils.writeAll(ch, ByteBuffer.wrap(raw)); } // When PrivateKey pk = certs.LoadPrivateKey(keyFile); // Then assertNotNull(pk); }
/// <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)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void createSelfSignedCertificateWithCorrectPermissions() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void CreateSelfSignedCertificateWithCorrectPermissions() { assumeTrue(!SystemUtils.IS_OS_WINDOWS); PkiUtils certificates = new PkiUtils(); certificates.CreateSelfSignedCertificate(TestDirectory.file("certificate"), TestDirectory.file("privateKey"), "localhost"); PosixFileAttributes certificateAttributes = Files.getFileAttributeView(TestDirectory.file("certificate").toPath(), typeof(PosixFileAttributeView)).readAttributes(); assertTrue(certificateAttributes.permissions().contains(PosixFilePermission.OWNER_READ)); assertTrue(certificateAttributes.permissions().contains(PosixFilePermission.OWNER_WRITE)); assertFalse(certificateAttributes.permissions().contains(PosixFilePermission.OWNER_EXECUTE)); assertFalse(certificateAttributes.permissions().contains(PosixFilePermission.GROUP_READ)); assertFalse(certificateAttributes.permissions().contains(PosixFilePermission.GROUP_WRITE)); assertFalse(certificateAttributes.permissions().contains(PosixFilePermission.GROUP_EXECUTE)); assertFalse(certificateAttributes.permissions().contains(PosixFilePermission.OTHERS_READ)); assertFalse(certificateAttributes.permissions().contains(PosixFilePermission.OTHERS_WRITE)); assertFalse(certificateAttributes.permissions().contains(PosixFilePermission.OTHERS_EXECUTE)); PosixFileAttributes privateKey = Files.getFileAttributeView(TestDirectory.file("privateKey").toPath(), typeof(PosixFileAttributeView)).readAttributes(); assertTrue(privateKey.permissions().contains(PosixFilePermission.OWNER_READ)); assertTrue(privateKey.permissions().contains(PosixFilePermission.OWNER_WRITE)); assertFalse(privateKey.permissions().contains(PosixFilePermission.OWNER_EXECUTE)); assertFalse(privateKey.permissions().contains(PosixFilePermission.GROUP_READ)); assertFalse(privateKey.permissions().contains(PosixFilePermission.GROUP_WRITE)); assertFalse(privateKey.permissions().contains(PosixFilePermission.GROUP_EXECUTE)); assertFalse(privateKey.permissions().contains(PosixFilePermission.OTHERS_READ)); assertFalse(privateKey.permissions().contains(PosixFilePermission.OTHERS_WRITE)); assertFalse(privateKey.permissions().contains(PosixFilePermission.OTHERS_EXECUTE)); }