(args []string, c cli.Config)
| 38 | var selfSignFlags = []string{"config"} |
| 39 | |
| 40 | func selfSignMain(args []string, c cli.Config) (err error) { |
| 41 | if c.Hostname == "" && !c.IsCA { |
| 42 | c.Hostname, args, err = cli.PopFirstArgument(args) |
| 43 | if err != nil { |
| 44 | return |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | csrFile, args, err := cli.PopFirstArgument(args) |
| 49 | if err != nil { |
| 50 | return |
| 51 | } |
| 52 | |
| 53 | if len(args) > 0 { |
| 54 | return errors.New("too many arguments are provided, please check with usage") |
| 55 | } |
| 56 | |
| 57 | csrFileBytes, err := cli.ReadStdin(csrFile) |
| 58 | if err != nil { |
| 59 | return |
| 60 | } |
| 61 | |
| 62 | var req = csr.New() |
| 63 | err = json.Unmarshal(csrFileBytes, req) |
| 64 | if err != nil { |
| 65 | return |
| 66 | } |
| 67 | |
| 68 | var key, csrPEM []byte |
| 69 | g := &csr.Generator{Validator: genkey.Validator} |
| 70 | csrPEM, key, err = g.ProcessRequest(req) |
| 71 | if err != nil { |
| 72 | key = nil |
| 73 | return |
| 74 | } |
| 75 | |
| 76 | priv, err := helpers.ParsePrivateKeyPEM(key) |
| 77 | if err != nil { |
| 78 | key = nil |
| 79 | return |
| 80 | } |
| 81 | |
| 82 | var profile *config.SigningProfile |
| 83 | |
| 84 | // If there is a config, use its signing policy. Otherwise, leave policy == nil |
| 85 | // and NewSigner will use DefaultConfig(). |
| 86 | if c.CFG != nil { |
| 87 | if c.Profile != "" && c.CFG.Signing.Profiles != nil { |
| 88 | profile = c.CFG.Signing.Profiles[c.Profile] |
| 89 | } |
| 90 | if profile == nil { |
| 91 | profile = c.CFG.Signing.Default |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | if profile == nil { |
| 96 | profile = config.DefaultConfig() |
| 97 | profile.Expiry = 2190 * time.Hour |
searching dependent graphs…