mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-09 15:06:37 +08:00
feat: 续签证书不重置私钥 (#5458)
Refs https://github.com/1Panel-dev/1Panel/issues/5314
This commit is contained in:
parent
2513c10d22
commit
25b0725570
2 changed files with 29 additions and 5 deletions
|
@ -2,6 +2,7 @@ package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -226,9 +227,32 @@ func (w WebsiteSSLService) ObtainSSL(apply request.WebsiteSSLApply) error {
|
||||||
domains = append(domains, strings.Split(websiteSSL.Domains, ",")...)
|
domains = append(domains, strings.Split(websiteSSL.Domains, ",")...)
|
||||||
}
|
}
|
||||||
|
|
||||||
privateKey, err := certcrypto.GeneratePrivateKey(ssl.KeyType(websiteSSL.KeyType))
|
var privateKey crypto.PrivateKey
|
||||||
if err != nil {
|
if websiteSSL.PrivateKey == "" {
|
||||||
return err
|
privateKey, err = certcrypto.GeneratePrivateKey(ssl.KeyType(websiteSSL.KeyType))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
block, _ := pem.Decode([]byte(websiteSSL.PrivateKey))
|
||||||
|
if block == nil {
|
||||||
|
return buserr.New("invalid PEM block")
|
||||||
|
}
|
||||||
|
var privKey crypto.PrivateKey
|
||||||
|
keyType := ssl.KeyType(websiteSSL.KeyType)
|
||||||
|
switch keyType {
|
||||||
|
case certcrypto.EC256, certcrypto.EC384:
|
||||||
|
privKey, err = x509.ParseECPrivateKey(block.Bytes)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
case certcrypto.RSA2048, certcrypto.RSA3072, certcrypto.RSA4096:
|
||||||
|
privKey, err = x509.ParsePKCS1PrivateKey(block.Bytes)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
privateKey = privKey
|
||||||
}
|
}
|
||||||
|
|
||||||
websiteSSL.Status = constant.SSLApply
|
websiteSSL.Status = constant.SSLApply
|
||||||
|
@ -382,7 +406,7 @@ func (w WebsiteSSLService) Update(update request.WebsiteSSLUpdate) error {
|
||||||
updateParams["primary_domain"] = update.PrimaryDomain
|
updateParams["primary_domain"] = update.PrimaryDomain
|
||||||
updateParams["description"] = update.Description
|
updateParams["description"] = update.Description
|
||||||
updateParams["provider"] = update.Provider
|
updateParams["provider"] = update.Provider
|
||||||
updateParams["key_type"] = update.KeyType
|
//updateParams["key_type"] = update.KeyType
|
||||||
updateParams["push_dir"] = update.PushDir
|
updateParams["push_dir"] = update.PushDir
|
||||||
updateParams["disable_cname"] = update.DisableCNAME
|
updateParams["disable_cname"] = update.DisableCNAME
|
||||||
updateParams["skip_dns"] = update.SkipDNS
|
updateParams["skip_dns"] = update.SkipDNS
|
||||||
|
|
|
@ -53,7 +53,7 @@
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="$t('website.keyType')" prop="keyType">
|
<el-form-item :label="$t('website.keyType')" prop="keyType">
|
||||||
<el-select v-model="ssl.keyType">
|
<el-select v-model="ssl.keyType" :disabled="operate == 'edit'">
|
||||||
<el-option
|
<el-option
|
||||||
v-for="(keyType, index) in KeyTypes"
|
v-for="(keyType, index) in KeyTypes"
|
||||||
:key="index"
|
:key="index"
|
||||||
|
|
Loading…
Add table
Reference in a new issue