+2
-2
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"scm/utils"
|
||||
"scm/crt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -47,7 +47,7 @@ func Certs(w http.ResponseWriter, r *http.Request) {
|
||||
new_cert["href"] = fmt.Sprintf("https://%s", entry.Name())
|
||||
new_cert["cert"] = string(certdata)
|
||||
new_cert["key"] = string(keydata)
|
||||
new_cert["certinfo"] = utils.ParseCert(fmt.Sprintf("%s/%s/%s.crt", os.Getenv("CERTS_PATH"), entry.Name(), entry.Name()))
|
||||
new_cert["certinfo"] = crt.ParseCert(fmt.Sprintf("%s/%s/%s.crt", os.Getenv("CERTS_PATH"), entry.Name(), entry.Name()))
|
||||
certs_info = append(certs_info, new_cert)
|
||||
}
|
||||
}
|
||||
|
||||
+5
-35
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"scm/crt"
|
||||
"scm/model"
|
||||
"scm/utils"
|
||||
)
|
||||
@@ -22,7 +23,7 @@ func CreateCert(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "invalid JSON format", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
caCert, caKey, err := utils.LoadRootCertAndKey(
|
||||
caCert, caKey, err := crt.LoadRootCertAndKey(
|
||||
fmt.Sprintf(
|
||||
"%s/%s/%s.crt",
|
||||
os.Getenv("CERTS_PATH"),
|
||||
@@ -49,7 +50,7 @@ func CreateCert(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("error generating server key:", err)
|
||||
return
|
||||
}
|
||||
serverCert, err := utils.CreateServerCert(caCert, caKey, serverKey, requestData)
|
||||
serverCert, err := crt.CreateServerCert(caCert, caKey, serverKey, requestData)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
fmt.Println("error creating server certificate:", err)
|
||||
@@ -60,7 +61,7 @@ func CreateCert(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
err = utils.SavePEMFile(
|
||||
err = crt.SavePEMFile(
|
||||
fmt.Sprintf(
|
||||
"%s/%s/%s.crt",
|
||||
os.Getenv("CERTS_PATH"),
|
||||
@@ -75,7 +76,7 @@ func CreateCert(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("error saving certificate:", err)
|
||||
return
|
||||
}
|
||||
err = utils.SavePEMFile(
|
||||
err = crt.SavePEMFile(
|
||||
fmt.Sprintf(
|
||||
"%s/%s/%s.key",
|
||||
os.Getenv("CERTS_PATH"),
|
||||
@@ -92,34 +93,3 @@ func CreateCert(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
fmt.Fprintf(w, "%s", `{"status": "success", "message": "Certificate created successfully"}`)
|
||||
}
|
||||
|
||||
// func createServerCert(
|
||||
// caCert *x509.Certificate,
|
||||
// caKey *rsa.PrivateKey,
|
||||
// serverKey *rsa.PrivateKey,
|
||||
// certdata model.CreateCertificateRequest,
|
||||
// ) ([]byte, error) {
|
||||
// // Шаблон серверного сертификата
|
||||
// template := x509.Certificate{
|
||||
// SerialNumber: big.NewInt(time.Now().Unix()),
|
||||
// Subject: pkix.Name{
|
||||
// Organization: certdata.OrganizationName,
|
||||
// CommonName: certdata.CommonName,
|
||||
// OrganizationalUnit: certdata.OrganizationUnit,
|
||||
// },
|
||||
// NotBefore: time.Now(),
|
||||
// NotAfter: time.Now().AddDate(1, 0, 0), // 1 год
|
||||
// KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment,
|
||||
// ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
|
||||
// DNSNames: certdata.DNSNames,
|
||||
// }
|
||||
|
||||
// // Создаем сертификат, подписанный CA
|
||||
// return x509.CreateCertificate(
|
||||
// rand.Reader,
|
||||
// &template,
|
||||
// caCert,
|
||||
// &serverKey.PublicKey,
|
||||
// caKey,
|
||||
// )
|
||||
// }
|
||||
|
||||
+2
-2
@@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"scm/crt"
|
||||
"scm/model"
|
||||
"scm/utils"
|
||||
)
|
||||
|
||||
func RootCert(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -25,7 +25,7 @@ func RootCert(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
err = utils.CreateRootKeyCertificate(rootCertRequest)
|
||||
err = crt.CreateRootKeyCertificate(rootCertRequest)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package utils
|
||||
package crt
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"math/big"
|
||||
"os"
|
||||
"scm/model"
|
||||
"scm/utils"
|
||||
"time"
|
||||
|
||||
"github.com/youmark/pkcs8"
|
||||
@@ -62,7 +63,7 @@ func CreateRootKeyCertificate(data model.CreateRootCertRequest) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = CheckExistsOrCreateDir("root")
|
||||
err = utils.CheckExistsOrCreateDir("root")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -87,6 +88,5 @@ func CreateRootKeyCertificate(data model.CreateRootCertRequest) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Implementation of CreateRootCertificate function
|
||||
return nil
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package utils
|
||||
package crt
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
@@ -1,4 +1,4 @@
|
||||
package utils
|
||||
package crt
|
||||
|
||||
import (
|
||||
"crypto/rsa"
|
||||
@@ -1,4 +1,4 @@
|
||||
package utils
|
||||
package crt
|
||||
|
||||
import (
|
||||
"crypto/x509"
|
||||
@@ -1,4 +1,4 @@
|
||||
package utils
|
||||
package crt
|
||||
|
||||
import (
|
||||
"encoding/pem"
|
||||
Reference in New Issue
Block a user