forked from cloudflare/cfssl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfssl_bundle.go
74 lines (61 loc) · 2.24 KB
/
cfssl_bundle.go
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
package main
import (
"fmt"
"github.com/cloudflare/cfssl/bundler"
"github.com/cloudflare/cfssl/ubiquity"
)
// Usage text of 'cfssl bundle'
var bundlerUsageText = `cfssl bundle -- create a certificate bundle that contains the client cert
Usage of bundle:
- Bundle local certificate files
cfssl bundle [-ca-bundle file] [-int-bundle file] [-key keyfile] [-flavor int] [-metadata file] CERT
- Bundle certificate from remote server.
cfssl bundle -domain domain_name [-ip ip_address] [-ca-bundle file] [-int-bundle file] [-metadata file]
Arguments:
CERT: Client certificate that contains the public key, possible followed by intermediates to form a partial chain.
Note:
CERT can be specified as flag value. But flag value will take precedence, overwriting the argument.
Flags:
`
// flags used by 'cfssl bundle'
var bundlerFlags = []string{"cert", "key", "ca-bundle", "int-bundle", "flavor", "metadata", "domain", "ip", "f"}
// bundlerMain is the main CLI of bundler functionality.
// TODO(zi): Decide whether to drop the argument list and only use flags to specify all the inputs.
// There are debates on whether flag or arg is more appropriate for required parameters.
func bundlerMain(args []string) (err error) {
// Grab cert file through args only if flag values for cert and domain are absent
if Config.certFile == "" && Config.domain == "" {
Config.certFile, args, err = popFirstArgument(args)
if err != nil {
return
}
}
ubiquity.LoadPlatforms(Config.metadata)
flavor := bundler.BundleFlavor(Config.flavor)
// Initialize a bundler with CA bundle and intermediate bundle.
b, err := bundler.NewBundler(Config.caBundleFile, Config.intBundleFile)
if err != nil {
return
}
var bundle *bundler.Bundle
if Config.certFile != "" {
// Bundle the client cert
bundle, err = b.BundleFromFile(Config.certFile, Config.keyFile, flavor)
if err != nil {
return
}
} else if Config.domain != "" {
bundle, err = b.BundleFromRemote(Config.domain, Config.ip)
if err != nil {
return
}
}
marshaled, err := bundle.MarshalJSON()
if err != nil {
return
}
fmt.Printf("%s", marshaled)
return
}
// CLIBundler assembles the definition of Command 'bundle'
var CLIBundler = &Command{bundlerUsageText, bundlerFlags, bundlerMain}