1 parent
e6526fb780
commit
d5da23849f
8 files changed
+16
-46
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package crt
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"crypto/x509/pkix"
|
||||
"math/big"
|
||||
"scm/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
func CreateServerCert(
|
||||
caCert *x509.Certificate,
|
||||
caKey *rsa.PrivateKey,
|
||||
serverKey *rsa.PrivateKey,
|
||||
certdata model.CreateCertRequest,
|
||||
) ([]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,
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user