-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ssl): Generating a self-signed CA certificate and installing it …
…in Firefox and/or Chrome/Chromium browsers Refs: DL-T-97
- Loading branch information
Showing
19 changed files
with
834 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
mkdir -p "/etc/dl/config-files" | ||
mkdir -p "/usr/share/zsh/vendor-completions" | ||
install -m 0755 -d /etc/apt/keyrings | ||
install -m 0755 -d /etc/dl/config-files | ||
install -m 0755 -d /usr/share/zsh/vendor-completions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package command | ||
|
||
import ( | ||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var certCmd = &cobra.Command{ | ||
Use: "cert", | ||
Short: "CA certificate management", | ||
Long: `Generating and (un)installing a root certificate in Firefox and/or Chrome/Chromium browsers.`, | ||
ValidArgs: []string{"install", "i", "uninstall", "delete"}, | ||
} | ||
|
||
func certCommand() *cobra.Command { | ||
certCmd.AddCommand( | ||
installCertCommand(), | ||
uninstallCertCommand(), | ||
) | ||
return certCmd | ||
} | ||
|
||
func storeCertConfig(status bool) { | ||
viper.Set("ca", status) | ||
err := viper.WriteConfig() | ||
if err != nil { | ||
pterm.FgRed.Println(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package command | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/local-deploy/dl/helper" | ||
"github.com/local-deploy/dl/utils/cert" | ||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var reinstallCert bool | ||
|
||
func installCertCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "install", | ||
Aliases: []string{"i"}, | ||
Short: "Installing CA certificate", | ||
Long: `Generating a self-signed CA certificate and installing it in Firefox and/or Chrome/Chromium browsers.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
installCertRun() | ||
}, | ||
ValidArgs: []string{"--reinstall", "-r"}, | ||
} | ||
cmd.Flags().BoolVarP(&reinstallCert, "reinstall", "r", false, "Reinstall certificate") | ||
return cmd | ||
} | ||
|
||
func installCertRun() { | ||
certutilPath, err := helper.CertutilPath() | ||
if err != nil { | ||
pterm.FgRed.Printfln("Error: %s", err) | ||
return | ||
} | ||
|
||
err = helper.CreateDirectory(filepath.Join(helper.CertDir(), "conf")) | ||
if err != nil { | ||
pterm.FgRed.Printfln("Error: %s \n", err) | ||
os.Exit(1) | ||
} | ||
|
||
c := &cert.Cert{ | ||
CertutilPath: certutilPath, | ||
CaFileName: cert.CaRootName, | ||
CaFileKeyName: cert.CaRootKeyName, | ||
CaPath: helper.CertDir(), | ||
} | ||
|
||
if reinstallCert { | ||
err = c.LoadCA() | ||
if err != nil { | ||
pterm.FgRed.Printfln("Error: %s", err) | ||
return | ||
} | ||
c.Uninstall() | ||
helper.RemoveFilesInPath(filepath.Join(helper.CertDir(), "conf")) | ||
helper.RemoveFilesInPath(helper.CertDir()) | ||
} | ||
|
||
_, err = os.Stat(filepath.Join(helper.CertDir(), cert.CaRootName)) | ||
if err != nil { | ||
err := c.CreateCA() | ||
if err != nil { | ||
pterm.FgRed.Printfln("Error: %s", err) | ||
return | ||
} | ||
} | ||
|
||
err = c.LoadCA() | ||
if err != nil { | ||
pterm.FgRed.Printfln("Error: %s", err) | ||
return | ||
} | ||
|
||
if c.Check() { | ||
pterm.FgGreen.Println("The local CA is already installed in the browsers trust store!") | ||
} else if c.Install() { | ||
storeCertConfig(true) | ||
pterm.FgGreen.Println("The local CA is now installed in the browsers trust store (requires browser restart)!") | ||
|
||
// Restart traefik | ||
source = "traefik" | ||
ctx := context.Background() | ||
_ = downServiceRun(ctx) | ||
err = upServiceRun(ctx) | ||
if err != nil { | ||
pterm.FgYellow.Println("Restart services for changes to take effect: dl service recreate") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package command | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/local-deploy/dl/helper" | ||
"github.com/local-deploy/dl/utils/cert" | ||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func uninstallCertCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "uninstall", | ||
Short: "Removing CA certificate", | ||
Long: `Removing a self-signed CA certificate from the Firefox and/or Chrome/Chromium browsers.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
uninstallCertRun() | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
func uninstallCertRun() { | ||
certutilPath, err := helper.CertutilPath() | ||
if err != nil { | ||
pterm.FgRed.Printfln("Error: %s", err) | ||
return | ||
} | ||
|
||
c := &cert.Cert{ | ||
CertutilPath: certutilPath, | ||
CaFileName: cert.CaRootName, | ||
CaFileKeyName: cert.CaRootKeyName, | ||
CaPath: helper.CertDir(), | ||
} | ||
|
||
err = c.LoadCA() | ||
if err != nil { | ||
pterm.FgRed.Printfln("Error: %s", err) | ||
return | ||
} | ||
|
||
ca := viper.GetBool("ca") | ||
if !ca { | ||
pterm.FgYellow.Println("The local CA is not installed") | ||
return | ||
} | ||
|
||
c.Uninstall() | ||
|
||
helper.RemoveFilesInPath(filepath.Join(helper.CertDir(), "conf")) | ||
helper.RemoveFilesInPath(helper.CertDir()) | ||
|
||
storeCertConfig(false) | ||
pterm.FgYellow.Println("The local CA is now uninstalled from the browsers trust store!") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.