Skip to content

Conversation

@mcpherrinm
Copy link
Contributor

@mcpherrinm mcpherrinm commented Sep 29, 2025

This is code to store keys and certificates on disk.
The general way I expect this to be used is outlined in the test:
A user generates a key, goes off to a CA for a cert, and stores it as the "next" certificate. Once it is verified to be "good" for whatever definition that means to the caller, they can copy it to the current key.

The goal here is to abstract the disk format away from the user, but it uses PEM for both PKCS8 keys and certificates to make it easy to use the files in an external program if required (eg, openssl x509 -text ...)

This is code to store keys and certificates on disk.
The general way I expect this to be used is outlined in the test:
A user generates a key, goes off to a CA for a cert, and stores it as the
"next" certificate. Once it is verified to be "good" for whatever definition
that means to the caller, they can copy it to the current key.

The goal here is to abstract the disk format away from the user, but it uses
PEM for both PKCS8 keys and certificates to make it easy to use the files in
an external program if required (eg, openssl x509 -text ...)
@mcpherrinm mcpherrinm requested a review from a team as a code owner September 29, 2025 21:38
@mcpherrinm mcpherrinm requested a review from jsha September 29, 2025 21:38
I thought about doing this but realized it wasn't really needed.
Loading checks that they match, so there's no need to eagerly remove certs.
@mcpherrinm mcpherrinm requested a review from Copilot September 29, 2025 21:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a certificate storage system that manages TLS certificates and private keys on disk using a structured directory layout with "current" and "next" versions for safe certificate rotation.

Key changes:

  • Implements a certificate lifecycle management system with "next" staging and "current" production versions
  • Provides key generation for P256 ECDSA and RSA 2048-bit keys stored in PKCS8 PEM format
  • Includes comprehensive test coverage demonstrating the full certificate rotation workflow

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
storage/storage.go Core implementation of certificate storage with key generation, certificate staging, and rotation functionality
storage/storage_test.go Test suite validating the complete certificate lifecycle including key generation, storage, and rotation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Using a crypto.Signer makes the tests a bit cleaner, and is what is actually
needed to use the key.
This uses constants for next/current, making API call sites more readable.

TakeNext now returns the now-current values, which also adds an extra level of
protection that the next key and certificate match
@mcpherrinm mcpherrinm requested a review from jsha September 30, 2025 02:44
@mcpherrinm mcpherrinm merged commit 0fa0b9e into main Oct 3, 2025
1 check passed
@mcpherrinm mcpherrinm deleted the mattm-cert-storage branch October 3, 2025 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants