Skip to content

Conversation

monam2
Copy link

@monam2 monam2 commented Aug 31, 2025

Description

Fixes #20681

Added support for multiple certificates in the resolveServerUrls function. Previously, only single certificates were supported, limiting HTTPS server configuration options.

  • Uses arraify to process certificate arrays and handle multiple certificates properly.
  • Added bufferify function for safe certificate conversion to Buffer format.
  • Implemented try-catch blocks to gracefully handle invalid certificates and prevent crashes.

All tests pass (unit, integration, and build tests all pass locally)


Test Coverage Added

  • No Certificate
  • Single Certificate
  • Multiple Certificates
  • IPv6 Support
  • Mixed Configurations (IPv4/IPv6 address families)
  • Invalid Certificate Handling

Note: Some test parameters use any types due to complex interface typing challenges. Type improvements are welcome.

@monam2
Copy link
Author

monam2 commented Sep 1, 2025

Sorry for the confusion in the test cases.
I've updated the multiple certs tests to use the same cert twice and removed the mixed IPv4/IPv6 test case since it's not directly related to this work.

Any feedback on the certificate or implementation setup would be welcome.

Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@sapphi-red sapphi-red added the p2-nice-to-have Not breaking anything but nice to have (priority) label Sep 13, 2025
@monam2
Copy link
Author

monam2 commented Sep 14, 2025

@sapphi-red Thanks for the suggestion — I’ve updated the code accordingly. I extracted the logic into a dedicated helper function and also renamed a few variables for clarity. PTAL.

@sapphi-red
Copy link
Member

Would you update the tests to use the new function you extracted?

@monam2
Copy link
Author

monam2 commented Sep 18, 2025

@sapphi-red Added cases for both single and multiple certificates.

bluwy
bluwy previously approved these changes Sep 20, 2025
bluwy
bluwy previously approved these changes Sep 21, 2025
@monam2 monam2 force-pushed the fix/multiple-certs-support branch from b4b27f9 to 6ef0e81 Compare September 23, 2025 06:26
@sapphi-red sapphi-red added this to the 7.2 milestone Sep 23, 2025
Copy link

@EmperorArthur EmperorArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really appreciate you taking the time to work on this.

Here are a few small things that you might want to consider tweaking. It's up to you and the maintainers of course, but thought I could try to contribute a little bit.

try {
return new crypto.X509Certificate(cert)
} catch {
return null

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we log a warning instead of completely ignoring an invalid cert?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the error would be shown when starting the server. Since this is an optional feature, I think it's fine to ignore the error here.

}
})
.flatMap((cert) =>
cert?.subjectAltName

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For whatever reason this took me a minute to parse.

Have you considered moving from the ternary .filter((cert) => Boolean(cert?.subjectAltName))?

Quick test to show that should cover all the cases:

let c = [{subjectAltName: 'asdf'}, {}, null, {subjectAltName: null}, {subjectAltName: ''}];
c.filter((cert) => Boolean(cert?.subjectAltName)).length === 1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeScript cannot infer the types with

    .filter((cert) => Boolean(cert?.subjectAltName))
    .flatMap((cert) => extractHostnamesFromSubjectAltName(cert.subjectAltName)) // cert may be null

so I think it's better to keep it as-is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p2-nice-to-have Not breaking anything but nice to have (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Extracting Hostnames From Multiple Certificates

4 participants