mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-15 02:04:46 +08:00
fix: 解决创建机构选择 RSA 加密失败的问题 (#3234)
This commit is contained in:
parent
3f8abf8ad8
commit
0fe9a87ea0
@ -92,36 +92,17 @@ func (w WebsiteCAService) Create(create request.WebsiteCACreate) (*request.Websi
|
|||||||
MaxPathLenZero: false,
|
MaxPathLenZero: false,
|
||||||
KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageCRLSign,
|
KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageCRLSign,
|
||||||
}
|
}
|
||||||
|
var (
|
||||||
|
caPEM = new(bytes.Buffer)
|
||||||
|
)
|
||||||
|
|
||||||
privateKey, err := certcrypto.GeneratePrivateKey(ssl.KeyType(create.KeyType))
|
interPrivateKey, interPublicKey, privateBytes, err := createPrivateKey(create.KeyType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var (
|
ca.PrivateKey = string(privateBytes)
|
||||||
publicKey any
|
|
||||||
caPEM = new(bytes.Buffer)
|
|
||||||
caPrivateKeyPEM = new(bytes.Buffer)
|
|
||||||
privateBlock = &pem.Block{}
|
|
||||||
)
|
|
||||||
if ssl.KeyType(create.KeyType) == certcrypto.EC256 || ssl.KeyType(create.KeyType) == certcrypto.EC384 {
|
|
||||||
publicKey = &privateKey.(*ecdsa.PrivateKey).PublicKey
|
|
||||||
publicKey = publicKey.(*ecdsa.PublicKey)
|
|
||||||
privateBlock.Type = "EC PRIVATE KEY"
|
|
||||||
privateBytes, err := x509.MarshalECPrivateKey(privateKey.(*ecdsa.PrivateKey))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
privateBlock.Bytes = privateBytes
|
|
||||||
_ = pem.Encode(caPrivateKeyPEM, privateBlock)
|
|
||||||
} else {
|
|
||||||
publicKey = privateKey.(*rsa.PrivateKey).PublicKey
|
|
||||||
publicKey = publicKey.(*rsa.PublicKey)
|
|
||||||
privateBlock.Type = "RSA PRIVATE KEY"
|
|
||||||
privateBlock.Bytes = x509.MarshalPKCS1PrivateKey(privateKey.(*rsa.PrivateKey))
|
|
||||||
}
|
|
||||||
ca.PrivateKey = string(pem.EncodeToMemory(privateBlock))
|
|
||||||
|
|
||||||
caBytes, err := x509.CreateCertificate(rand.Reader, rootCA, rootCA, publicKey, privateKey)
|
caBytes, err := x509.CreateCertificate(rand.Reader, rootCA, rootCA, interPublicKey, interPrivateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user