Home / Function/ newSelfSignedCertificate() — netty Function Reference

newSelfSignedCertificate() — netty Function Reference

Architecture documentation for the newSelfSignedCertificate() function in SelfSignedCertificate.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  3e521991_ebab_34c6_6bc0_ff49eab101aa["newSelfSignedCertificate()"]
  3f71414d_6bbb_ccc1_3eec_bdf61bb53618["SelfSignedCertificate"]
  3e521991_ebab_34c6_6bc0_ff49eab101aa -->|defined in| 3f71414d_6bbb_ccc1_3eec_bdf61bb53618
  b6d34d94_3591_0c0e_1e18_5c1881831df7["safeClose()"]
  3e521991_ebab_34c6_6bc0_ff49eab101aa -->|calls| b6d34d94_3591_0c0e_1e18_5c1881831df7
  c38a1d9f_c49f_d3d0_cf58_d5aa3ad6dac6["safeDelete()"]
  3e521991_ebab_34c6_6bc0_ff49eab101aa -->|calls| c38a1d9f_c49f_d3d0_cf58_d5aa3ad6dac6
  style 3e521991_ebab_34c6_6bc0_ff49eab101aa fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

handler/src/main/java/io/netty/handler/ssl/util/SelfSignedCertificate.java lines 286–356

    static String[] newSelfSignedCertificate(
            String fqdn, PrivateKey key, X509Certificate cert) throws IOException, CertificateEncodingException {
        // Encode the private key into a file.
        ByteBuf wrappedBuf = Unpooled.wrappedBuffer(key.getEncoded());
        ByteBuf encodedBuf;
        final String keyText;
        try {
            encodedBuf = Base64.encode(wrappedBuf, true);
            try {
                keyText = "-----BEGIN PRIVATE KEY-----\n" +
                        encodedBuf.toString(CharsetUtil.US_ASCII) +
                        "\n-----END PRIVATE KEY-----\n";
            } finally {
                encodedBuf.release();
            }
        } finally {
            wrappedBuf.release();
        }

        // Change all asterisk to 'x' for file name safety.
        fqdn = fqdn.replaceAll("[^\\w.-]", "x");

        File keyFile = PlatformDependent.createTempFile("keyutil_" + fqdn + '_', ".key", null);
        keyFile.deleteOnExit();

        OutputStream keyOut = new FileOutputStream(keyFile);
        try {
            keyOut.write(keyText.getBytes(CharsetUtil.US_ASCII));
            keyOut.close();
            keyOut = null;
        } finally {
            if (keyOut != null) {
                safeClose(keyFile, keyOut);
                safeDelete(keyFile);
            }
        }

        wrappedBuf = Unpooled.wrappedBuffer(cert.getEncoded());
        final String certText;
        try {
            encodedBuf = Base64.encode(wrappedBuf, true);
            try {
                // Encode the certificate into a CRT file.
                certText = "-----BEGIN CERTIFICATE-----\n" +
                        encodedBuf.toString(CharsetUtil.US_ASCII) +
                        "\n-----END CERTIFICATE-----\n";
            } finally {
                encodedBuf.release();
            }
        } finally {
            wrappedBuf.release();
        }

        File certFile = PlatformDependent.createTempFile("keyutil_" + fqdn + '_', ".crt", null);
        certFile.deleteOnExit();

        OutputStream certOut = new FileOutputStream(certFile);
        try {
            certOut.write(certText.getBytes(CharsetUtil.US_ASCII));
            certOut.close();
            certOut = null;
        } finally {
            if (certOut != null) {
                safeClose(certFile, certOut);
                safeDelete(certFile);
                safeDelete(keyFile);
            }
        }

        return new String[] { certFile.getPath(), keyFile.getPath() };
    }

Domain

Subdomains

Frequently Asked Questions

What does newSelfSignedCertificate() do?
newSelfSignedCertificate() is a function in the netty codebase, defined in handler/src/main/java/io/netty/handler/ssl/util/SelfSignedCertificate.java.
Where is newSelfSignedCertificate() defined?
newSelfSignedCertificate() is defined in handler/src/main/java/io/netty/handler/ssl/util/SelfSignedCertificate.java at line 286.
What does newSelfSignedCertificate() call?
newSelfSignedCertificate() calls 2 function(s): safeClose, safeDelete.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free