feat: adds possibility to specify cert serial number#274
Conversation
WalkthroughAn optional Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
ts/src/sdk/provider/auth/mtls/CertificateManager.ts (2)
82-82: Consider validating thatserialis a positive integer.X.509 serial numbers must be positive integers per RFC 5280. If a caller passes
0, a negative number, or a non-integer, the generated certificate would be non-compliant. Since this is a public API, defensive validation would prevent subtle bugs.🛡️ Suggested validation
Add validation at the start of
generatePEM:async generatePEM(address: string, options?: ValidityRangeOptions): Promise<CertificatePem> { + if (options?.serial !== undefined && (!Number.isInteger(options.serial) || options.serial <= 0)) { + throw new Error("Certificate serial number must be a positive integer"); + } const rs = await getRSASignLib();🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ts/src/sdk/provider/auth/mtls/CertificateManager.ts` at line 82, The generatePEM method in CertificateManager.ts must validate the options.serial value to ensure X.509 compliance: check the provided serial (in generatePEM) is a finite integer greater than zero (reject 0, negative, non-integer, NaN, or non-number); if absent use the existing default Math.floor(Date.now() * 1000); on invalid input throw a clear error (e.g., RangeError or TypeError) with a concise message mentioning "serial" so callers can correct it. Ensure the check runs before constructing the serial field so serial: { int: ... } always receives a valid positive integer.
28-32: Add JSDoc for the newserialfield.The other fields (
validFrom,validTo) don't have inline docs either, but since this is a new addition, consider documenting the expected constraints: the serial should be a positive integer per X.509/RFC 5280 requirements.📝 Suggested documentation
/** * Options for specifying the validity range of a certificate. */ export interface ValidityRangeOptions { + /** + * Custom serial number for the certificate. Must be a positive integer. + * Defaults to a time-based value if not provided. + */ serial?: number; validFrom?: Date; validTo?: Date; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ts/src/sdk/provider/auth/mtls/CertificateManager.ts` around lines 28 - 32, Add JSDoc comments to the ValidityRangeOptions interface documenting the new serial field and expected constraints: annotate serial as a positive integer (per X.509 / RFC 5280) and optional, and briefly document validFrom and validTo as optional Date values representing the certificate's notBefore and notAfter times; update the JSDoc above the ValidityRangeOptions interface (and inline above serial, validFrom, validTo) to state types, optionality, units/semantics, and the serial must be > 0.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@ts/src/sdk/provider/auth/mtls/CertificateManager.ts`:
- Line 82: The generatePEM method in CertificateManager.ts must validate the
options.serial value to ensure X.509 compliance: check the provided serial (in
generatePEM) is a finite integer greater than zero (reject 0, negative,
non-integer, NaN, or non-number); if absent use the existing default
Math.floor(Date.now() * 1000); on invalid input throw a clear error (e.g.,
RangeError or TypeError) with a concise message mentioning "serial" so callers
can correct it. Ensure the check runs before constructing the serial field so
serial: { int: ... } always receives a valid positive integer.
- Around line 28-32: Add JSDoc comments to the ValidityRangeOptions interface
documenting the new serial field and expected constraints: annotate serial as a
positive integer (per X.509 / RFC 5280) and optional, and briefly document
validFrom and validTo as optional Date values representing the certificate's
notBefore and notAfter times; update the JSDoc above the ValidityRangeOptions
interface (and inline above serial, validFrom, validTo) to state types,
optionality, units/semantics, and the serial must be > 0.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 3679191f-e006-4e9b-b92e-ccc68ad18658
📒 Files selected for processing (1)
ts/src/sdk/provider/auth/mtls/CertificateManager.ts
📝 Description
To make it possible to generate certificate with custom serial
🔧 Purpose of the Change
📌 Related Issues
✅ Checklist
📎 Notes for Reviewers
[Include any additional context, architectural decisions, or specific areas to focus on]