Git Product home page Git Product logo

Comments (1)

cirospaciari avatar cirospaciari commented on July 22, 2024

using nodejs we match the same result with the code:

import fs from "fs";
import { createServer } from "https";
createServer(
  {
    key: fs.readFileSync("/tmp/server-key.pem"),
    cert: fs.readFileSync("/tmp/server-cert.pem"),
    ca: fs.readFileSync("/tmp/ca-cert.pem"),
    requestCert: true,
    rejectUnauthorized: true,
  },
  (req, res) => {
    res.end("pong");
  },
).listen(1234);
cirospaciari@Ciros-MBP ~ % curl -v -k https://127.0.0.1:1234
*   Trying 127.0.0.1:1234...
* Connected to 127.0.0.1 (127.0.0.1) port 1234
* ALPN: curl offers h2,http/1.1
* (304) (OUT), TLS handshake, Client hello (1):
* (304) (IN), TLS handshake, Server hello (2):
* (304) (IN), TLS handshake, Unknown (8):
* (304) (IN), TLS handshake, Request CERT (13):
* (304) (IN), TLS handshake, Certificate (11):
* (304) (IN), TLS handshake, CERT verify (15):
* (304) (IN), TLS handshake, Finished (20):
* (304) (OUT), TLS handshake, Certificate (11):
* (304) (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / AEAD-CHACHA20-POLY1305-SHA256 / [blank] / UNDEF
* ALPN: server did not agree on a protocol. Uses default.
* Server certificate:
*  subject: CN=127.0.0.1
*  start date: Jul  9 00:24:26 2024 GMT
*  expire date: Jun  1 00:24:26 2161 GMT
*  issuer: CN=127.0.0.1
*  SSL certificate verify result: self signed certificate (18), continuing anyway.
* using HTTP/1.x
> GET / HTTP/1.1
> Host: 127.0.0.1:1234
> User-Agent: curl/8.6.0
> Accept: */*
> 
* LibreSSL SSL_read: LibreSSL/3.3.6: error:1404C45C:SSL routines:ST_OK:reason(1116), errno 0
* Closing connection
curl: (56) LibreSSL SSL_read: LibreSSL/3.3.6: error:1404C45C:SSL routines:ST_OK:reason(1116), errno 0

If we use rejectUnauthorized: false at the server we will not auto close the connection:

const s = Bun.serve({
  fetch: () => new Response("pong"),
  port: 1234,
  tls: {
    key: Bun.file("/tmp/server-key.pem"),
    cert: Bun.file("/tmp/server-cert.pem"),
    ca: Bun.file("/tmp/ca-cert.pem"),
    rejectUnauthorized: false,
  },
});

nodejs equivalent:

import fs from "fs";
import { createServer } from "https";
createServer(
  {
    key: fs.readFileSync("/tmp/server-key.pem"),
    cert: fs.readFileSync("/tmp/server-cert.pem"),
    ca: fs.readFileSync("/tmp/ca-cert.pem"),
    requestCert: true,
    rejectUnauthorized: false,
  },
  (req, res) => {
    res.end("pong");
  },
).listen(1234);
cirospaciari@Ciros-MBP ~ % curl -v -k https://127.0.0.1:1234
*   Trying 127.0.0.1:1234...
* Connected to 127.0.0.1 (127.0.0.1) port 1234
* ALPN: curl offers h2,http/1.1
* (304) (OUT), TLS handshake, Client hello (1):
* (304) (IN), TLS handshake, Server hello (2):
* (304) (IN), TLS handshake, Unknown (8):
* (304) (IN), TLS handshake, Request CERT (13):
* (304) (IN), TLS handshake, Certificate (11):
* (304) (IN), TLS handshake, CERT verify (15):
* (304) (IN), TLS handshake, Finished (20):
* (304) (OUT), TLS handshake, Certificate (11):
* (304) (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / AEAD-CHACHA20-POLY1305-SHA256 / [blank] / UNDEF
* ALPN: server did not agree on a protocol. Uses default.
* Server certificate:
*  subject: CN=127.0.0.1
*  start date: Jul  9 00:24:26 2024 GMT
*  expire date: Jun  1 00:24:26 2161 GMT
*  issuer: CN=127.0.0.1
*  SSL certificate verify result: self signed certificate (18), continuing anyway.
* using HTTP/1.x
> GET / HTTP/1.1
> Host: 127.0.0.1:1234
> User-Agent: curl/8.6.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< content-type: text/plain;charset=utf-8
< Date: Tue, 09 Jul 2024 00:41:25 GMT
< Content-Length: 4
< 
* Connection #0 to host 127.0.0.1 left intact
pong% 

from bun.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.