diff options
author | Gibheer <gibheer@gmail.com> | 2015-03-05 21:37:52 +0100 |
---|---|---|
committer | Gibheer <gibheer@gmail.com> | 2015-03-05 21:37:52 +0100 |
commit | 52102b0f24b03be251efa863c3b7cd657f09d5d9 (patch) | |
tree | 4c1ba442c8f824c9cbfb5444a02940fd865cdd72 /main.go | |
parent | 2954be520de58f9760d378fb87be92b448666401 (diff) |
finally add certificate sign request generation
This adds finally a way to create certificate sign requests. There are
still some options missing, but it is coming together.
With the next step, the ccertificate data container will probably be put
into the pki library.
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -2,7 +2,10 @@ package main import ( "crypto" + "crypto/rand" + "crypto/x509" "encoding/base64" + "encoding/pem" "fmt" "io" "io/ioutil" @@ -25,7 +28,7 @@ func main() { case "create-public": create_public_key() case "sign-input": sign_input() case "verify-signature": verify_input() -// case "create-cert-sign": create_sign_request() + case "create-cert-sign": create_sign_request() // case "sign-request": sign_request() case "help": print_modules() // case "info": info_on_file() @@ -115,6 +118,22 @@ func verify_input() { os.Exit(1) } +// create a certificate sign request +func create_sign_request() { + fs := NewFlags("create-cert-sign") + fs.AddPrivateKey() + fs.AddOutput() + fs.AddCertificateFields() + fs.Parse(program_args()) + + csrt := fs.Flags.CertificateData.GenerateCSR() + csr, err := x509.CreateCertificateRequest(rand.Reader, csrt, fs.Flags.PrivateKey.PrivateKey()) + if err != nil { crash_with_help(2, "Could not create certificate sign request: %s", err) } + pem_block := &pem.Block{Type: "CERTIFICATE REQUEST", Bytes: csr} + err = pem.Encode(fs.Flags.Output, pem_block) + if err != nil { crash_with_help(2, "Encoding didn't work: %s", err) } +} + // print the module help func print_modules() { fmt.Printf(`Usage: %s command args |