Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Command = &cli.Command{ Name: "ssc", Aliases: nil, Usage: "fns scc --sa=ECDSA --cn={CN} --expire={days} {output dir}", Description: "create self sign cert", ArgsUsage: "", Category: "", Flags: []cli.Flag{ &cli.StringFlag{ Name: "cn", Required: true, Usage: "CN", }, &cli.StringFlag{ Name: "sa", Required: true, Usage: "signature algorithm", }, &cli.IntFlag{ Name: "expire", Required: true, Usage: "expire days", }, }, Action: func(ctx *cli.Context) (err error) { dstDir := strings.TrimSpace(ctx.Args().First()) if dstDir == "" { dstDir = "." } if !filepath.IsAbs(dstDir) { dstDir, err = filepath.Abs(dstDir) if err != nil { err = errors.Warning("fns: create self sign cert").WithCause(err).WithMeta("dir", dstDir) return } } dstDir = filepath.ToSlash(dstDir) cn := ctx.String("cn") // sa var keyType afssl.KeyType sa := strings.ToUpper(ctx.String("sa")) switch sa { case "ECDSA", "": keyType = afssl.ECDSA() break case "RSA": keyType = afssl.RSA() break case "ED25519": keyType = afssl.ED25519() break case "SM2": keyType = afssl.SM2() break default: err = errors.Warning("fns: create self sign cert").WithCause(fmt.Errorf("sa is not supported")).WithMeta("sa", sa) return } expire := ctx.Int("expire") if expire < 1 { expire = 365 } config := afssl.CertificateConfig{ Subject: &afssl.CertificatePkixName{ CommonName: cn, }, IPs: nil, Emails: nil, DNSNames: nil, } cert, key, genErr := afssl.GenerateCertificate(config, afssl.CA(), afssl.WithKeyType(keyType), afssl.WithExpirationDays(expire)) if genErr != nil { err = errors.Warning("fns: create self sign cert").WithCause(genErr) return } err = os.WriteFile(filepath.Join(dstDir, "ca.crt"), cert, 0644) if err != nil { err = errors.Warning("fns: create self sign cert").WithCause(err) return } err = os.WriteFile(filepath.Join(dstDir, "ca.key"), key, 0644) if err != nil { err = errors.Warning("fns: create self sign cert").WithCause(err) return } fmt.Println("fns: create self sign cert created!") return }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.