Skip to content
Snippets Groups Projects
Commit 9c3f1276 authored by Florent Gluck's avatar Florent Gluck
Browse files

Started removing code dealing with embedded CA certificate as it is not needed anymore

parent 5a70a771
Branches
No related tags found
No related merge requests found
......@@ -262,13 +262,14 @@ help_client:
@echo " xbuild_client Cross-build $(BIN) for Linux, Windows, Darwin (OSX)"
@echo " Require the BIN variable which specifies which client to"
@echo " cross-build: nexush or nexus-cli"
@echo " Require SERVER and CERT (see below)"
@echo " build_nexush Build nexush for Linux/amd64; require the SERVER variable"
@echo " and CERT (see below)"
@echo " Require SERVER environment variable (see below)"
@echo " build_nexush Build nexush for Linux/amd64; require SERVER environment"
@echo " variable (see below)"
@echo " build_nexus-cli Build nexus-cli for Linux/amd64; same as above"
@echo " build_nexus-exam Build nexus-exam for Linux/amd64; require CERT, SERVER"
@echo " EXAM_USER and EXAM_PWD. The last two define credentials"
@echo " for the user used by nexus-exam to connect to nexus server"
@echo " build_nexus-exam Build nexus-exam for Linux/amd64; require SERVER, EXAM_USER"
@echo " and EXAM_PWD environment variables. The last two define"
@echo " credentials for the user used by nexus-exam to connect to"
@echo " nexus server"
@echo " clean_clients Delete all generated client binaries"
@echo ""
@echo "┌──────────────────────────────────────────────────────────────────────────────┐"
......@@ -282,21 +283,15 @@ help_client:
@echo "│ VALIDATION tests │"
@echo "└──────────────────────────────────────────────────────────────────────────────┘"
@echo " tests Run validation tests using nexus-cli"
@echo " Require LOGIN variable. Example:"
@echo " Require LOGIN variable."
@echo ""
@echo "────────────────────────────────────────────────────────────────────────────────"
@echo " CERT: path to public CA certificate file ($(CA_CERT_FILE))."
@echo " SERVER: server ip address and port, separated by a colon,"
@echo " for instance: SERVER=127.0.0.1:1077"
copy_resources_client:
@mkdir -p $(RESOURCES_DIR_CLIENT)
@echo -n "$(SERVER)" > $(RESOURCES_DIR_CLIENT)/server
ifdef CERT
@cp $(CERT) $(RESOURCES_DIR_CLIENT)/$(CA_CERT_FILE)
else
@echo -n "" > $(RESOURCES_DIR_CLIENT)/$(CA_CERT_FILE)
endif
xbuild_client: check_bin_var check_server_var check_cert_var copy_resources_client $(SRC_CLIENT)/nexush $(SRC_CLIENT)/nexus-cli
@echo "[Cross-building $(BIN) into $(BUILD_DIR) directory]"
......@@ -318,15 +313,15 @@ xbuild_client: check_bin_var check_server_var check_cert_var copy_resources_clie
done \
done
build_nexush: check_server_var check_cert_var copy_resources_client $(BUILD_DIR) $(SRC_CLIENT)/nexush
build_nexush: check_server_var copy_resources_client $(BUILD_DIR) $(SRC_CLIENT)/nexush
@echo "[Building nexush into $(BUILD_DIR) directory]"
@cd $(SRC_CLIENT)/nexush && go build $(BUILD_FLAGS) $(BUILD_CLIENT_FLAGS) && mv $(NEXUSH_BINARY) $(BUILD_DIR_ABS)
build_nexus-cli: check_server_var check_cert_var copy_resources_client $(BUILD_DIR) $(SRC_CLIENT)/nexus-cli
build_nexus-cli: check_server_var copy_resources_client $(BUILD_DIR) $(SRC_CLIENT)/nexus-cli
@echo "[Building nexus-cli into $(BUILD_DIR) directory]"
@cd $(SRC_CLIENT)/nexus-cli && go build $(BUILD_FLAGS) $(BUILD_CLIENT_FLAGS) && mv $(NEXUSCLI_BINARY) $(BUILD_DIR_ABS)
build_nexus-exam: check_server_var check_cert_var check_nexus_exam_vars copy_resources_client $(BUILD_DIR) $(SRC_CLIENT)/nexus-exam
build_nexus-exam: check_server_var check_nexus_exam_vars copy_resources_client $(BUILD_DIR) $(SRC_CLIENT)/nexus-exam
@echo "[Building nexus-exam into $(BUILD_DIR) directory]"
@echo -n '$(value EXAM_USER)' > $(NEXUS_EXAM_USER_CREDS_FILE)
@echo -n '$(value EXAM_PWD)' > $(NEXUS_EXAM_PWD_CREDS_FILE)
......
package defaults
import (
"os"
_ "embed"
)
var (
//go:embed resources/ca-cert.pem
nexusPubCert string
//go:embed resources/server
NexusServer string
)
func CreateCert() (string, error) {
// No embedded certificate
if nexusPubCert == "" {
return "", nil
} else {
f, err := os.CreateTemp("", "nexus-client-")
if err != nil {
return "", err
}
if _, err := f.Write([]byte(nexusPubCert)); err != nil {
return "", err
}
defer f.Close()
return f.Name(), nil
}
}
......@@ -27,7 +27,6 @@ import (
"gitedu.hesge.ch/flg_projects/nexus_vdi/nexus/client/version"
"gitedu.hesge.ch/flg_projects/nexus_vdi/nexus/common/buildversion"
"gitedu.hesge.ch/flg_projects/nexus_vdi/nexus/common/utils"
"github.com/peterh/liner"
"golang.org/x/term"
......@@ -111,44 +110,12 @@ func run() int {
var err error // necessary for certPath below to be ref as the same variable
certPath, found := os.LookupEnv(g.ENV_NEXUS_CERT)
if !found {
certPath, err = defaults.CreateCert()
if err != nil {
u.PrintlnErr("Failed creating certificate from embedded certificate!")
return 1
}
// No embedded certificate, exit with a information message.
if certPath == "" {
u.PrintlnErr("Environment variable \"" + g.ENV_NEXUS_CERT + "\" must be set!")
u.PrintlnErr("It specifies the path to the public certificate required for encrypted communications (TLS) with the nexus server.")
u.PrintlnErr("Example: export " + g.ENV_NEXUS_CERT + "=ca-cert.pem")
return 1
}
defer os.Remove(certPath)
// This thread acts as a signal handler for SIGINT or SIGTERM.
// When one of these signals is received, the temporary certificate file is deleted.
// Without this "handler", the temporary certificate file wouldn't be deleted.
go func(certFile string) {
u.WaitForSignals()
os.Remove(certFile)
restoreTerm()
os.Exit(1)
}(certPath)
} else {
// As above, this thread acts as a signal handler for SIGINT or SIGTERM.
go func() {
u.WaitForSignals()
restoreTerm()
os.Exit(1)
}()
}
if !utils.FileExists(certPath) {
u.PrintlnErr("Failed reading certificate \"" + certPath + "\"!")
return 1
}
// This thread acts as a signal handler for SIGINT or SIGTERM.
go func() {
u.WaitForSignals()
restoreTerm()
os.Exit(1)
}()
nc := nc.New(serverEnvVar)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment