1 parent
e6526fb780
commit
d5da23849f
8 files changed
+16
-46
No files matched your search
+2
-2
@@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"scm/utils"
|
"scm/crt"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"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["href"] = fmt.Sprintf("https://%s", entry.Name())
|
||||||
new_cert["cert"] = string(certdata)
|
new_cert["cert"] = string(certdata)
|
||||||
new_cert["key"] = string(keydata)
|
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)
|
certs_info = append(certs_info, new_cert)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-35
@@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"scm/crt"
|
||||||
"scm/model"
|
"scm/model"
|
||||||
"scm/utils"
|
"scm/utils"
|
||||||
)
|
)
|
||||||
@@ -22,7 +23,7 @@ func CreateCert(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(w, "invalid JSON format", http.StatusBadRequest)
|
http.Error(w, "invalid JSON format", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
caCert, caKey, err := utils.LoadRootCertAndKey(
|
caCert, caKey, err := crt.LoadRootCertAndKey(
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"%s/%s/%s.crt",
|
"%s/%s/%s.crt",
|
||||||
os.Getenv("CERTS_PATH"),
|
os.Getenv("CERTS_PATH"),
|
||||||
@@ -49,7 +50,7 @@ func CreateCert(w http.ResponseWriter, r *http.Request) {
|
|||||||
fmt.Println("error generating server key:", err)
|
fmt.Println("error generating server key:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
serverCert, err := utils.CreateServerCert(caCert, caKey, serverKey, requestData)
|
serverCert, err := crt.CreateServerCert(caCert, caKey, serverKey, requestData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
fmt.Println("error creating server certificate:", err)
|
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)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = utils.SavePEMFile(
|
err = crt.SavePEMFile(
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"%s/%s/%s.crt",
|
"%s/%s/%s.crt",
|
||||||
os.Getenv("CERTS_PATH"),
|
os.Getenv("CERTS_PATH"),
|
||||||
@@ -75,7 +76,7 @@ func CreateCert(w http.ResponseWriter, r *http.Request) {
|
|||||||
fmt.Println("error saving certificate:", err)
|
fmt.Println("error saving certificate:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = utils.SavePEMFile(
|
err = crt.SavePEMFile(
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"%s/%s/%s.key",
|
"%s/%s/%s.key",
|
||||||
os.Getenv("CERTS_PATH"),
|
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"}`)
|
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"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"scm/crt"
|
||||||
"scm/model"
|
"scm/model"
|
||||||
"scm/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func RootCert(w http.ResponseWriter, r *http.Request) {
|
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)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = utils.CreateRootKeyCertificate(rootCertRequest)
|
err = crt.CreateRootKeyCertificate(rootCertRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package utils
|
package crt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"scm/model"
|
"scm/model"
|
||||||
|
"scm/utils"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/youmark/pkcs8"
|
"github.com/youmark/pkcs8"
|
||||||
@@ -62,7 +63,7 @@ func CreateRootKeyCertificate(data model.CreateRootCertRequest) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = CheckExistsOrCreateDir("root")
|
err = utils.CheckExistsOrCreateDir("root")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -87,6 +88,5 @@ func CreateRootKeyCertificate(data model.CreateRootCertRequest) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Implementation of CreateRootCertificate function
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package utils
|
package crt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package utils
|
package crt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package utils
|
package crt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package utils
|
package crt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
Reference in new issue
Block a user