Skip to content

Commit

Permalink
tools: gofmt make-hsm-ee and makecsr
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Guthe committed May 22, 2019
1 parent febdf7b commit 38dc422
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 75 deletions.
4 changes: 2 additions & 2 deletions tools/make-hsm-ee/make-hsm-ee.go
Expand Up @@ -124,7 +124,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
err = ioutil.WriteFile(outputBasename + ".crt", eePem.Bytes(), 0644)
err = ioutil.WriteFile(outputBasename+".crt", eePem.Bytes(), 0644)
if err != nil {
log.Fatal(err)
}
Expand All @@ -143,7 +143,7 @@ func main() {
log.Fatal(err)
}
msgBody := fmt.Sprintf("%s%s\n", secp384r1ECParams, eePrivPem.Bytes())
err = ioutil.WriteFile(outputBasename + ".key", []byte(msgBody), 0644)
err = ioutil.WriteFile(outputBasename+".key", []byte(msgBody), 0644)
if err != nil {
log.Fatal(err)
}
Expand Down
146 changes: 73 additions & 73 deletions tools/makecsr/makecsr.go
@@ -1,73 +1,73 @@
// This code requires a configuration file to initialize the crypto11
// library. Use the following config in a file named "crypto11.config"
// {
// "Path" : "/opt/cloudhsm/lib/libcloudhsm_pkcs11.so",
// "TokenLabel": "cavium",
// "Pin" : "$CRYPTO_USER:$PASSWORD"
// }
package main

import (
"crypto/rand"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"flag"
"fmt"
"log"
"os"

"github.com/ThalesIgnite/crypto11"
)

func main() {
var (
keyLabel string
ou string
cn string
email string
)
flag.StringVar(&keyLabel, "l", "mykey", "Label of the key in the HSM")
flag.StringVar(&ou, "ou", "Mozilla AMO Production Signing Service", "OrganizationalUnit of the Subject")
flag.StringVar(&cn, "cn", "Content Signing Intermediate", "CommonName of the Subject")
flag.StringVar(&email, "email", "foxsec@mozilla.com", "Email of the Subject")
flag.Parse()

p11Ctx, err := crypto11.ConfigureFromFile("crypto11.config")
if err != nil {
log.Fatal(err)
}
slots, err := p11Ctx.GetSlotList(true)
if err != nil {
log.Fatalf("Failed to list PKCS#11 Slots: %s", err.Error())
}
if len(slots) < 1 {
log.Fatal("No slot found")
}
privKey, err := crypto11.FindKeyPair(nil, []byte(keyLabel))
if err != nil {
log.Fatal(err)
}
sigalg := x509.ECDSAWithSHA384
switch privKey.(type) {
case *crypto11.PKCS11PrivateKeyRSA:
sigalg = x509.SHA384WithRSA

}
crtReq := &x509.CertificateRequest{
Subject: pkix.Name{
CommonName: fmt.Sprintf("%s/emailAddress=%s", cn, email),
Organization: []string{"Mozilla Corporation"},
OrganizationalUnit: []string{ou},
Country: []string{"US"},
},
DNSNames: []string{cn},
SignatureAlgorithm: sigalg,
}
fmt.Printf("+%v\n", crtReq)
csrBytes, err := x509.CreateCertificateRequest(rand.Reader, crtReq, privKey)
if err != nil {
log.Fatal(err)
}
pem.Encode(os.Stdout, &pem.Block{Type: "CERTIFICATE REQUEST", Bytes: csrBytes})
}
// This code requires a configuration file to initialize the crypto11
// library. Use the following config in a file named "crypto11.config"
// {
// "Path" : "/opt/cloudhsm/lib/libcloudhsm_pkcs11.so",
// "TokenLabel": "cavium",
// "Pin" : "$CRYPTO_USER:$PASSWORD"
// }
package main

import (
"crypto/rand"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"flag"
"fmt"
"log"
"os"

"github.com/ThalesIgnite/crypto11"
)

func main() {
var (
keyLabel string
ou string
cn string
email string
)
flag.StringVar(&keyLabel, "l", "mykey", "Label of the key in the HSM")
flag.StringVar(&ou, "ou", "Mozilla AMO Production Signing Service", "OrganizationalUnit of the Subject")
flag.StringVar(&cn, "cn", "Content Signing Intermediate", "CommonName of the Subject")
flag.StringVar(&email, "email", "foxsec@mozilla.com", "Email of the Subject")
flag.Parse()

p11Ctx, err := crypto11.ConfigureFromFile("crypto11.config")
if err != nil {
log.Fatal(err)
}
slots, err := p11Ctx.GetSlotList(true)
if err != nil {
log.Fatalf("Failed to list PKCS#11 Slots: %s", err.Error())
}
if len(slots) < 1 {
log.Fatal("No slot found")
}
privKey, err := crypto11.FindKeyPair(nil, []byte(keyLabel))
if err != nil {
log.Fatal(err)
}
sigalg := x509.ECDSAWithSHA384
switch privKey.(type) {
case *crypto11.PKCS11PrivateKeyRSA:
sigalg = x509.SHA384WithRSA

}
crtReq := &x509.CertificateRequest{
Subject: pkix.Name{
CommonName: fmt.Sprintf("%s/emailAddress=%s", cn, email),
Organization: []string{"Mozilla Corporation"},
OrganizationalUnit: []string{ou},
Country: []string{"US"},
},
DNSNames: []string{cn},
SignatureAlgorithm: sigalg,
}
fmt.Printf("+%v\n", crtReq)
csrBytes, err := x509.CreateCertificateRequest(rand.Reader, crtReq, privKey)
if err != nil {
log.Fatal(err)
}
pem.Encode(os.Stdout, &pem.Block{Type: "CERTIFICATE REQUEST", Bytes: csrBytes})
}

0 comments on commit 38dc422

Please sign in to comment.