Example usage for io.netty.handler.ssl.util SelfSignedCertificate SelfSignedCertificate

List of usage examples for io.netty.handler.ssl.util SelfSignedCertificate SelfSignedCertificate

Introduction

In this page you can find the example usage for io.netty.handler.ssl.util SelfSignedCertificate SelfSignedCertificate.

Prototype

public SelfSignedCertificate(String fqdn) throws CertificateException 

Source Link

Document

Creates a new instance.

Usage

From source file:org.neo4j.bolt.security.ssl.TestSslCertificateFactory.java

License:Open Source License

@Test
public void shouldLoadPEMPrivateKey() throws Throwable {
    // Given/*  www . ja  v  a  2s. c  o m*/
    SelfSignedCertificate cert = new SelfSignedCertificate("example.com");
    Certificates certs = new Certificates();

    File privateKey = cert.privateKey();

    // When
    PrivateKey pk = certs.loadPrivateKey(privateKey);

    // Then
    assertNotNull(pk);
}

From source file:org.neo4j.bolt.security.ssl.TestSslCertificateFactory.java

License:Open Source License

/**
 * For backwards-compatibility reasons, we support both PEM-encoded certificates *and* raw binary files containing
 * the certificate data./*  w ww. j a v a2  s .c o m*/
 *
 * @throws Throwable
 */
@Test
public void shouldLoadBinaryCertificates() throws Throwable {
    // Given
    SelfSignedCertificate cert = new SelfSignedCertificate("example.com");
    Certificates certs = new Certificates();

    File cPath = tmpDir.newFile("certificate");
    byte[] raw = certs.loadCertificates(cert.certificate())[0].getEncoded();

    try (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));
}

From source file:org.neo4j.bolt.security.ssl.TestSslCertificateFactory.java

License:Open Source License

/**
 * For backwards-compatibility reasons, we support both PEM-encoded private keys *and* raw binary files containing
 * the private key data/*from   ww w .jav  a2 s . c  om*/
 *
 * @throws Throwable
 */
@Test
public void shouldLoadBinaryPrivateKey() throws Throwable {
    // Given
    SelfSignedCertificate cert = new SelfSignedCertificate("example.com");
    Certificates certs = new Certificates();

    File keyFile = tmpDir.newFile("certificate");
    byte[] raw = certs.loadPrivateKey(cert.privateKey()).getEncoded();

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

    // When
    PrivateKey pk = certs.loadPrivateKey(keyFile);

    // Then
    assertNotNull(pk);
}