forked from Luzifer/vault-openvpn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
revoke.go
43 lines (35 loc) · 967 Bytes
/
revoke.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
package cmd
import (
"errors"
"github.com/hashicorp/vault/helper/certutil"
"github.com/spf13/cobra"
)
// revokeCmd represents the revoke command
var revokeCmd = &cobra.Command{
Use: "revoke <fqdn>",
Short: "Revoke all certificates matching to FQDN",
PreRunE: func(cmd *cobra.Command, args []string) error { return initVaultClient() },
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 || !validateFQDN(args[0]) {
return errors.New("You need to provide a valid FQDN")
}
return revokeCertificateByFQDN(args[0])
},
}
func init() {
RootCmd.AddCommand(revokeCmd)
}
func revokeCertificateByFQDN(fqdn string) error {
certs, err := fetchCertificatesFromVault(false)
if err != nil {
return err
}
for _, cert := range certs {
if cert.Subject.CommonName == fqdn {
if err := revokeCertificateBySerial(certutil.GetHexFormatted(cert.SerialNumber.Bytes(), ":")); err != nil {
return err
}
}
}
return nil
}