mirror of https://github.com/docker/docs.git
Added listing and removal of signing certs
This commit is contained in:
parent
3e828b5796
commit
770cca453a
|
@ -27,23 +27,15 @@ var cmdKeys = &cobra.Command{
|
||||||
Use: "keys",
|
Use: "keys",
|
||||||
Short: "Operates on keys.",
|
Short: "Operates on keys.",
|
||||||
Long: "operations on signature keys and trusted certificate authorities.",
|
Long: "operations on signature keys and trusted certificate authorities.",
|
||||||
Run: nil,
|
Run: keysList,
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cmdKeys.AddCommand(cmdKeysTrust)
|
cmdKeys.AddCommand(cmdKeysTrust)
|
||||||
cmdKeys.AddCommand(cmdKeysList)
|
|
||||||
cmdKeys.AddCommand(cmdKeysRemove)
|
cmdKeys.AddCommand(cmdKeysRemove)
|
||||||
cmdKeys.AddCommand(cmdKeysGenerate)
|
cmdKeys.AddCommand(cmdKeysGenerate)
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmdKeysList = &cobra.Command{
|
|
||||||
Use: "list",
|
|
||||||
Short: "List the currently trusted certificate authorities.",
|
|
||||||
Long: "lists the currently trusted certificate authorities.",
|
|
||||||
Run: keysList,
|
|
||||||
}
|
|
||||||
|
|
||||||
var cmdKeysRemove = &cobra.Command{
|
var cmdKeysRemove = &cobra.Command{
|
||||||
Use: "remove [ Subject Key ID ]",
|
Use: "remove [ Subject Key ID ]",
|
||||||
Short: "removes trust from a specific certificate authority or certificate.",
|
Short: "removes trust from a specific certificate authority or certificate.",
|
||||||
|
@ -71,17 +63,33 @@ func keysRemove(cmd *cobra.Command, args []string) {
|
||||||
fatalf("must specify a SHA256 SubjectKeyID of the certificate")
|
fatalf("must specify a SHA256 SubjectKeyID of the certificate")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
failed := true
|
||||||
cert, err := caStore.GetCertificateBySKID(args[0])
|
cert, err := caStore.GetCertificateBySKID(args[0])
|
||||||
if err != nil {
|
if err == nil {
|
||||||
fatalf("certificate not found")
|
fmt.Printf("Removing: ")
|
||||||
|
printCert(cert)
|
||||||
|
|
||||||
|
err = caStore.RemoveCert(cert)
|
||||||
|
if err != nil {
|
||||||
|
fatalf("failed to remove certificate for Root KeyStore")
|
||||||
|
}
|
||||||
|
failed = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Removing: ")
|
cert, err = privStore.GetCertificateBySKID(args[0])
|
||||||
printCert(cert)
|
if err == nil {
|
||||||
|
fmt.Printf("Removing: ")
|
||||||
|
printCert(cert)
|
||||||
|
|
||||||
err = caStore.RemoveCert(cert)
|
//TODO (diogo): remove associated private key
|
||||||
if err != nil {
|
err = privStore.RemoveCert(cert)
|
||||||
fatalf("failed to remove certificate for Key Store")
|
if err != nil {
|
||||||
|
fatalf("failed to remove certificate for Private KeyStore")
|
||||||
|
}
|
||||||
|
failed = false
|
||||||
|
}
|
||||||
|
if failed {
|
||||||
|
fatalf("certificate not found in any store")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,13 +129,24 @@ func keysTrust(cmd *cobra.Command, args []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func keysList(cmd *cobra.Command, args []string) {
|
func keysList(cmd *cobra.Command, args []string) {
|
||||||
// Load all the certificates
|
if len(args) > 0 {
|
||||||
trustedCAs := caStore.GetCertificates()
|
cmd.Usage()
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("# Trusted Root keys: ")
|
||||||
|
trustedCAs := caStore.GetCertificates()
|
||||||
for _, c := range trustedCAs {
|
for _, c := range trustedCAs {
|
||||||
printCert(c)
|
printCert(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("")
|
||||||
|
fmt.Println("# Signing keys: ")
|
||||||
|
privateCerts := privStore.GetCertificates()
|
||||||
|
for _, c := range privateCerts {
|
||||||
|
printCert(c)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func keysGenerate(cmd *cobra.Command, args []string) {
|
func keysGenerate(cmd *cobra.Command, args []string) {
|
||||||
|
|
|
@ -20,6 +20,7 @@ const caDir string = ".docker/trust/certificate_authorities/"
|
||||||
const privDir string = ".docker/trust/private/"
|
const privDir string = ".docker/trust/private/"
|
||||||
|
|
||||||
var caStore trustmanager.X509Store
|
var caStore trustmanager.X509Store
|
||||||
|
var privStore trustmanager.X509Store
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// Retrieve current user to get home directory
|
// Retrieve current user to get home directory
|
||||||
|
@ -69,6 +70,13 @@ func init() {
|
||||||
cert.SignatureAlgorithm != x509.DSAWithSHA1 &&
|
cert.SignatureAlgorithm != x509.DSAWithSHA1 &&
|
||||||
cert.SignatureAlgorithm != x509.ECDSAWithSHA1
|
cert.SignatureAlgorithm != x509.ECDSAWithSHA1
|
||||||
})
|
})
|
||||||
|
|
||||||
|
privStore = trustmanager.NewX509FilteredFileStore(finalPrivDir, func(cert *x509.Certificate) bool {
|
||||||
|
return time.Now().Before(cert.NotAfter) &&
|
||||||
|
cert.SignatureAlgorithm != x509.SHA1WithRSA &&
|
||||||
|
cert.SignatureAlgorithm != x509.DSAWithSHA1 &&
|
||||||
|
cert.SignatureAlgorithm != x509.ECDSAWithSHA1
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
Loading…
Reference in New Issue