Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: res.connection.getPeerCertificate is not a function #15731

Open
isaced opened this issue Dec 12, 2024 · 0 comments
Open

TypeError: res.connection.getPeerCertificate is not a function #15731

isaced opened this issue Dec 12, 2024 · 0 comments
Labels
bug Something isn't working node:http

Comments

@isaced
Copy link

isaced commented Dec 12, 2024

What version of Bun is running?

1.1.38+bf2f153f5

What platform is your computer?

Darwin 23.6.0 arm64 arm

What steps can reproduce the bug?

The code snippet fetch-ssl.ts attempts to retrieve the peer's SSL certificate information using res.connection.getPeerCertificate(). However, when running the script with Bun (bun run fetch-ssl.ts), an error occurs:

get ssl info error:  7 |             port: 443,
 8 |             method: 'GET',
 9 |             rejectUnauthorized: false
10 |         };
11 |         const req = https.request(options, (res) => {
12 |             const data = res.connection.getPeerCertificate();
                                             ^
TypeError: res.connection.getPeerCertificate is not a function. (In 'res.connection.getPeerCertificate()', 'res.connection.getPeerCertificate' is undefined)
      at /Users/isaced/Downloads/network-test/fetch-ssl.js:12:41
      at onceWrapper (node:events:165:55)
      at emit (node:events:73:22)
      at node:http:1006:60

This error indicates that the getPeerCertificate method is not available on the connection property of the response object (res) in the Bun environment.

On the other hand, running the same code with Node.js (node fetch-ssl.js) produces the expected output, retrieving the certificate information:

ssl info: {
  subject: [Object: null prototype] { CN: 'www.google.com' },
  issuer: [Object: null prototype] {
    C: 'US',
    O: 'Google Trust Services',
    CN: 'WR2'
  },
  subjectaltname: 'DNS:www.google.com',
  infoAccess: [Object: null prototype] {
...

Code:

const https = require('https');

function getCertificateInfo(hostname) {
    return new Promise((resolve, reject) => {
        const options = {
            hostname,
            port: 443,
            method: 'GET',
            rejectUnauthorized: false
        };
        const req = https.request(options, (res) => {
            const data = res.connection.getPeerCertificate();
            resolve(data);
        });
        req.on('error', (error) => {
            reject(error);
        });
        req.end();
    });
}

getCertificateInfo('www.google.com')
    .then(info => {
        console.log('ssl info:', info);
    })
    .catch(error => {
        console.error('get ssl info error:', error);
    }); 

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

@isaced isaced added bug Something isn't working needs triage labels Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working node:http
Projects
None yet
Development

No branches or pull requests

2 participants