circu.js
    Preparing search index...

    Namespace CModuleSSL

    USAGE EXAMPLES

    // Example 1: HTTPS Server with Pipe
    const { Context, Pipe } = import.meta.use('ssl');
    const { TCP } = import.meta.use('streams');

    const Context = new Context({
    mode: "server",
    cert: certPem,
    key: keyPem,
    alpn: ["h2", "http/1.1"]
    });

    const server = new TCP();
    server.bind("0.0.0.0", 8443);
    server.listen(128);

    server.accept().then(conn => {
    const pipe = new Pipe(Context);

    conn.read().then(data => {
    pipe.feed(data);
    pipe.handshake();

    const output = pipe.getOutput();
    if (output) conn.write(output);
    });
    });

    // Example 2: HTTPS Client
    const { Context, Pipe } = import.meta.use('ssl');
    const { TCP } = import.meta.use('streams');

    const Context2 = new Context({
    mode: "client",
    verify: true,
    ca: caPem
    });

    const conn2 = new TCP();
    await conn2.connect("example.com", 443);

    const pipe2 = new Pipe(Context2, { servername: "example.com" });

    // Start handshake
    pipe2.handshake();
    const handshake2 = pipe2.getOutput();
    if (handshake2) await conn2.write(handshake2);

    // Complete handshake
    while (!pipe2.handshakeComplete) {
    const response2 = await conn2.read();
    pipe2.feed(response2);
    pipe2.handshake();

    const output2 = pipe2.getOutput();
    if (output2) await conn2.write(output2);
    }

    // Send HTTP request
    const request2 = new TextEncoder().encode("GET / HTTP/1.1\r\nHost: example.com\r\n\r\n");
    pipe2.write(request2);
    const encrypted2 = pipe2.getOutput();
    await conn2.write(encrypted2);

    // Example 3: Generate Self-Signed Certificate
    const { Context, Pipe } = import.meta.use('ssl');
    const { TCP } = import.meta.use('streams');

    const { cert, key } = createSelfSignedCert({
    commonName: "localhost",
    days: 365
    });

    const context3 = new Context({
    mode: "server",
    cert,
    key
    });

    // Example 4: Inspect Peer Certificate
    const pipe4 = new Pipe(clientContext, { servername: "example.com" });
    // ... perform handshake ...

    if (pipe4.handshakeComplete) {
    const cert4 = pipe4.certificate;
    console.log("Subject:", cert4.subject);
    console.log("Issuer:", cert4.issuer);
    console.log("Valid:", cert4.validFrom, "to", cert4.validTo);
    console.log("SANs:", cert4.subjectAltNames);
    console.log("Fingerprint:", cert4.fingerprint256);

    const verify4 = pipe4.verifyResult;
    if (!verify4.ok) {
    console.error("Certificate verification failed:", verify4.error);
    }
    }

    // Example 5: Advanced SSL Context Configuration
    import { Context } from "@tjs/ssl";

    const context5 = new Context({
    mode: "server",
    cert: certPem,
    key: keyPem,
    minVersion: "TLSv1.2",
    maxVersion: "TLSv1.3",
    ciphers: "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384",
    alpn: ["h2", "http/1.1"],
    sessionTickets: true,
    sessionCache: true,
    compression: false,
    dhparam: "dhparam.pem",
    ecdhCurve: "prime256v1"
    });

    Classes

    Context
    Pipe

    Interfaces

    CertificateInfo
    CipherInfo
    ContextOptions
    PEMInfo
    PipeOptions
    SelfSignedCertOptions
    SelfSignedCertResult
    VerifyResult

    Variables

    ciphers
    version

    Functions

    createSelfSignedCert
    loadPEM