Skip to content

Commit

Permalink
feat: Add StringSerials to workaround BigInt/uint64 Serial. (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-lobocki authored Dec 30, 2024
1 parent 51d7d3a commit a014ff3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
10 changes: 8 additions & 2 deletions cmd/command_sshcerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func exportSshMain(args []string) {

sshCertificateWithRevocation tSshCertificateWithRevocation
sshCertificatesWithRevocations []tSshCertificateWithRevocation
sshCertificateStringSerials tCertificateStringSerials
)

// Open the database.
Expand Down Expand Up @@ -116,10 +117,15 @@ func exportSshMain(args []string) {
logInfo.Printf("RevocationProvisionerID: %s", sshCertificateRevocation.ProvisionerID)
}

// Get serials and embed them as strings. This is to handle uint64 compatibility issues.
sshCertificateStringSerials.SerialDec = strconv.FormatUint(sshCertificate.Serial, 10)
sshCertificateStringSerials.SerialHex = strconv.FormatUint(sshCertificate.Serial, 16)

// Populate the child.
sshCertificateWithRevocation = tSshCertificateWithRevocation{
SshCertificate: sshCertificate,
SshCertificateRevocation: sshCertificateRevocation,
SshCertificate: sshCertificate,
SshCertificateRevocation: sshCertificateRevocation,
SshCertificateStringSerials: sshCertificateStringSerials,
}

// Populate child validity info of the certificate.
Expand Down
12 changes: 9 additions & 3 deletions cmd/command_x509certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func exportX509Main(args []string) {

x509CertificateProvisionerRevocation tX509CertificateProvisionerRevocation
x509CertificatesProvisionersRevocations []tX509CertificateProvisionerRevocation
x509CertificateStringSerials tCertificateStringSerials
)

// Open the database.
Expand Down Expand Up @@ -131,11 +132,16 @@ func exportX509Main(args []string) {
logInfo.Printf("Provisioner: %s", x509CertificateData.Provisioner.Type)
}

// Get serials and embed them as strings. This is to handle uint64 compatibility issues.
x509CertificateStringSerials.SerialDec = x509Certificate.SerialNumber.String()
x509CertificateStringSerials.SerialHex = x509Certificate.SerialNumber.Text(16)

// Populate the child.
x509CertificateProvisionerRevocation = tX509CertificateProvisionerRevocation{
X509Certificate: x509Certificate,
X509Revocation: x509CertificateRevocation,
X509Provisioner: x509CertificateData.Provisioner,
X509Certificate: x509Certificate,
X509Revocation: x509CertificateRevocation,
X509Provisioner: x509CertificateData.Provisioner,
X509CertificateStringSerials: x509CertificateStringSerials,
}

// Populate child validity info of the certificate.
Expand Down
5 changes: 5 additions & 0 deletions cmd/defs_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ type tCertificateRevocation struct {
ACME bool `json:"ACME"`
}

type tCertificateStringSerials struct {
SerialDec string `json:"SerialDec"`
SerialHex string `json:"SerialHex"`
}

const (
VALID_STR string = "Valid"
EXPIRED_STR string = "Expired"
Expand Down
7 changes: 4 additions & 3 deletions cmd/defs_sshcerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import "golang.org/x/crypto/ssh"
Combined information of certificate and revocation.
*/
type tSshCertificateWithRevocation struct {
SshCertificate ssh.Certificate `json:"Certificate"`
Validity string `json:"Validity"`
SshCertificateRevocation tCertificateRevocation `json:"Revocation,omitempty"`
SshCertificate ssh.Certificate `json:"Certificate"`
Validity string `json:"Validity"`
SshCertificateRevocation tCertificateRevocation `json:"Revocation,omitempty"`
SshCertificateStringSerials tCertificateStringSerials `json:"StringSerials"`
}
9 changes: 5 additions & 4 deletions cmd/defs_x509certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
Combined information of certificate, revocation and provisioner.
*/
type tX509CertificateProvisionerRevocation struct {
X509Certificate x509.Certificate `json:"Certificate"`
Validity string `json:"Validity"`
X509Revocation tCertificateRevocation `json:"Revocation,omitempty"`
X509Provisioner tX509CertificateProvisioner `json:"Provisioner,omitempty"`
X509Certificate x509.Certificate `json:"Certificate"`
Validity string `json:"Validity"`
X509Revocation tCertificateRevocation `json:"Revocation,omitempty"`
X509Provisioner tX509CertificateProvisioner `json:"Provisioner,omitempty"`
X509CertificateStringSerials tCertificateStringSerials `json:"StringSerials"`
}

/*
Expand Down

0 comments on commit a014ff3

Please sign in to comment.