This commit is contained in:
1 parent
39c27b0de3
commit
e6526fb780
8 files changed
+169
-114
No files matched your search
@@ -8,12 +8,13 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"os"
|
||||
"scm/model"
|
||||
"time"
|
||||
|
||||
"github.com/youmark/pkcs8"
|
||||
)
|
||||
|
||||
func CreateRootKeyCertificate() error {
|
||||
func CreateRootKeyCertificate(data model.CreateRootCertRequest) error {
|
||||
privkey, err := rsa.GenerateKey(rand.Reader, 4096)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -27,18 +28,18 @@ func CreateRootKeyCertificate() error {
|
||||
template := x509.Certificate{
|
||||
SerialNumber: serialNumber,
|
||||
Subject: pkix.Name{
|
||||
CommonName: "Root Certificate",
|
||||
OrganizationalUnit: []string{"Organizational Unit"},
|
||||
Organization: []string{"Organization"},
|
||||
Country: []string{"Country"},
|
||||
Locality: []string{"Locality"},
|
||||
Province: []string{"Province"},
|
||||
StreetAddress: []string{"Street Address"},
|
||||
PostalCode: []string{"Postal Code"},
|
||||
CommonName: data.CommonName,
|
||||
OrganizationalUnit: data.OrganizationalUnit,
|
||||
Organization: data.Organization,
|
||||
Country: data.Country,
|
||||
Locality: data.Locality,
|
||||
Province: data.Province,
|
||||
StreetAddress: data.StreetAddress,
|
||||
PostalCode: data.PostalCode,
|
||||
SerialNumber: serialNumber.String(),
|
||||
},
|
||||
NotBefore: time.Now(),
|
||||
NotAfter: time.Now().AddDate(10, 0, 0),
|
||||
NotAfter: time.Now().AddDate(data.ValidityYears, 0, 0),
|
||||
KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageCRLSign | x509.KeyUsageDigitalSignature,
|
||||
ExtKeyUsage: []x509.ExtKeyUsage{
|
||||
x509.ExtKeyUsageServerAuth,
|
||||
@@ -55,7 +56,7 @@ func CreateRootKeyCertificate() error {
|
||||
|
||||
encryptedKey, err := pkcs8.ConvertPrivateKeyToPKCS8(
|
||||
privkey,
|
||||
[]byte("Simba28082020"),
|
||||
[]byte(data.KeyPassword),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in new issue
Block a user