Skip to content

Commit

Permalink
added suggestions by Ben to capture more details for cert requester, …
Browse files Browse the repository at this point in the history
…added entire cert in case needed in future
  • Loading branch information
ps-spb committed Apr 27, 2023
1 parent d46ab0a commit 0be0235
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# A golang PKI in less than 1000 lines of code.
# A golang PKI in just over a 1000 lines of code.

# Introduction

Expand Down
11 changes: 11 additions & 0 deletions db.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package main

import (
"bufio"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rsa"
"crypto/x509"
"encoding/asn1"
"fmt"
"log"
"net"
"net/url"
"os"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -21,6 +24,7 @@ import (
var dyndb *dynamodb.DynamoDB

type x509Record struct {
Requester string
SerialNumber string
Issuer string
Subject string
Expand All @@ -33,6 +37,7 @@ type x509Record struct {
IPAddresses []net.IP
URIs []*url.URL
PubKey []byte
DerCert []byte
}

func addDbRecord(crtBytes []byte) error {
Expand All @@ -54,7 +59,12 @@ func addDbRecord(crtBytes []byte) error {
default:
return errors.New("only ECDSA and RSA public keys are supported")
}
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter Requester in the format of \"Joe Blogs <[email protected]>\" -> ")
requester, _ := reader.ReadString('\n') // E: requester declared and not used // E: requester declared and not used
// marshal the crt to a pem byte array
record := x509Record{
Requester: requester,
SerialNumber: crt.SerialNumber.String(), // serial number should be unique (as in cryptographically) so we can use this as the key
Issuer: crt.Issuer.String(),
Subject: crt.Subject.String(),
Expand All @@ -67,6 +77,7 @@ func addDbRecord(crtBytes []byte) error {
IPAddresses: crt.IPAddresses,
URIs: crt.URIs,
PubKey: pubBytes,
DerCert: crtBytes,
}

// we should be running under the role given to us by the sts tokens.
Expand Down
1 change: 1 addition & 0 deletions x509.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ func signCSR(signer crypto11.Signer, csr *x509.CertificateRequest) (crtBytes []b
Critical: false,
Value: yy,
}

tmpl := &x509.Certificate{
SerialNumber: serialNumber,
Subject: newSubject,
Expand Down

0 comments on commit 0be0235

Please sign in to comment.