File: gencrl.go

package info (click to toggle)
golang-github-cloudflare-cfssl 1.2.0%2Bgit20160825.89.7fb22c8-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,916 kB
  • ctags: 2,827
  • sloc: sh: 146; sql: 62; python: 11; makefile: 8
file content (87 lines) | stat: -rw-r--r-- 2,033 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//Package gencrl implements the gencrl command
package gencrl

import (
	"github.com/cloudflare/cfssl/cli"
	"github.com/cloudflare/cfssl/crl"
	"strings"
)

var gencrlUsageText = `cfssl gencrl -- generate a new Certificate Revocation List

Usage of gencrl:
        cfssl gencrl INPUTFILE CERT KEY TIME

Arguments:
        INPUTFILE:               Text file with one serial number per line, use '-' for reading text from stdin
        CERT:                    The certificate that is signing this CRL, use '-' for reading text from stdin
        KEY:                     The private key of the certificate that is signing the CRL, use '-' for reading text from stdin
        TIME (OPTIONAL):         The desired expiration from now, in seconds, use '-' for reading text from stdin

Flags:
`
var gencrlFlags = []string{}

func gencrlMain(args []string, c cli.Config) (err error) {
	serialList, args, err := cli.PopFirstArgument(args)
	if err != nil {
		return
	}

	serialListBytes, err := cli.ReadStdin(serialList)
	if err != nil {
		return
	}

	certFile, args, err := cli.PopFirstArgument(args)
	if err != nil {
		return
	}

	certFileBytes, err := cli.ReadStdin(certFile)
	if err != nil {
		return
	}

	keyFile, args, err := cli.PopFirstArgument(args)
	if err != nil {
		return
	}

	keyBytes, err := cli.ReadStdin(keyFile)
	if err != nil {
		return
	}

	// Default value if no expiry time is given
	timeString := string("0")

	if len(args) > 0 {
		timeArg, _, err := cli.PopFirstArgument(args)
		if err != nil {
			return err
		}

		timeBytes, err := cli.ReadStdin(timeArg)
		if err != nil {
			return err
		}

		timeString = string(timeBytes)

		// This is used to get rid of newlines
		timeString = strings.TrimSpace(timeString)

	}

	req, err := crl.NewCRLFromFile(serialListBytes, certFileBytes, keyBytes, timeString)
	if err != nil {
		return
	}

	cli.PrintCRL(req)
	return nil
}

// Command assembles the definition of Command 'gencrl'
var Command = &cli.Command{UsageText: gencrlUsageText, Flags: gencrlFlags, Main: gencrlMain}