yats.git

commit 2e4c3ab0d26191c16503254ec3048190e7e3bf2c

Author: Paolo Lulli <paolo@lulli.net>

Composes the path to cert,key,csr

 client/apiclient.go | 10 ++++++++--
 client/config/cli-config.go | 4 ++--
 client/pki.go | 13 ++++++++-----


diff --git a/client/apiclient.go b/client/apiclient.go
index f43b1a16b9dbf31ad87139aa2370e08c932ce434..32a7d23f1eae795c491d27fa747f8ef2399b6b49 100644
--- a/client/apiclient.go
+++ b/client/apiclient.go
@@ -16,6 +16,7 @@ 	"fmt"
 	"io"
 	"net/http"
 	"os"
+	"path"
 )
 
 func (c *YatsClient) httpClient(key string, cert string) (client *http.Client) {
@@ -44,7 +45,11 @@ 	return
 }
 
 func (c *YatsClient) ApiGet(endpoint string) string {
-	cert, certKey := c.config.TlsCertificate, c.config.TlsKeyFile
+	certKey := path.Join(c.config.ClientCertDir, c.config.ClientCn+".key")
+	cert := path.Join(c.config.ClientCertDir, c.config.ClientCn+".crt")
+
+	//fmt.Printf("cert: %s\nkey: %sendpoint:%s\n", cert, certKey, endpoint)
+
 	client := c.httpClient(certKey, cert)
 
 	req, err := http.NewRequest("GET", endpoint, nil)
@@ -64,7 +69,8 @@ 	return string(data)
 }
 
 func (c *YatsClient) ApiPost(endpoint string, body string) string {
-	cert, certKey := c.config.TlsCertificate, c.config.TlsKeyFile
+	certKey := path.Join(c.config.ClientCertDir, c.config.ClientCn+".key")
+	cert := path.Join(c.config.ClientCertDir, c.config.ClientCn+".crt")
 	client := c.httpClient(certKey, cert)
 
 	req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer([]byte(body)))




diff --git a/client/config/cli-config.go b/client/config/cli-config.go
index ae8bce2a047d0a14e2747ac78495abd9b2ee0277..c3cb1ddcbfff7780d6e8d07f4adc1f1f4d366991 100644
--- a/client/config/cli-config.go
+++ b/client/config/cli-config.go
@@ -17,8 +17,8 @@
 type ClientConfiguration struct {
 	Endpoint string `json:"endpoint"`
 
-	TlsKeyFile      string `json:"tlsKeyFile"`
-	TlsCertificate  string `json:"tlsCertificate"`
+	//TlsKeyFile      string `json:"tlsKeyFile"`
+	//TlsCertificate  string `json:"tlsCertificate"`
 	TlsVerifyServer string `json:"tlsVerifyServer"`
 
 	// For certificate request over PKI endpoint




diff --git a/client/pki.go b/client/pki.go
index 184f43d0f696f28a793259af70d13c2ab8307485..bb21d0d4c57260121b8b7c4383b1009456687f31 100644
--- a/client/pki.go
+++ b/client/pki.go
@@ -8,18 +8,21 @@ 	"crypto/x509/pkix"
 	"encoding/pem"
 	"fmt"
 	"os"
+	"path"
 )
 
 func (c *YatsClient) CreateCsr(csrFile string) ([]byte, error) {
 	//var oidEmailAddress = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 1}
+	TlsKeyFile := path.Join(c.config.ClientCertDir, c.config.ClientCn+".key")
+	TlsCertificate := path.Join(c.config.ClientCertDir, c.config.ClientCn+".crt")
 
-	if fileExists(c.config.TlsKeyFile) {
-		fmt.Printf("Private key file already exists: %v\n", c.config.TlsKeyFile)
+	if fileExists(TlsKeyFile) {
+		fmt.Printf("Private key file already exists: %v\n", TlsKeyFile)
 		os.Exit(-1)
 	}
 
-	if fileExists(c.config.TlsCertificate) {
-		fmt.Printf("Certificate file already exists: %v\n", c.config.TlsKeyFile)
+	if fileExists(TlsCertificate) {
+		fmt.Printf("Certificate file already exists: %v\n", TlsKeyFile)
 		os.Exit(-1)
 	}
 
@@ -37,7 +40,7 @@ 			Bytes: x509.MarshalPKCS1PrivateKey(keyBytes),
 		},
 	)
 
-	os.WriteFile(c.config.TlsKeyFile, pemdata, 0644)
+	os.WriteFile(TlsKeyFile, pemdata, 0644)
 
 	subj := pkix.Name{
 		CommonName: c.config.ClientCn,