mirror of
https://github.com/tobychui/zoraxy.git
synced 2025-11-14 21:04:10 +01:00
Fix TLS cert key and pem file handling order
This commit is contained in:
@@ -84,12 +84,14 @@ func (m *Manager) SetCertAsDefault(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Check if the previous default cert exists. If yes, get its hostname from cert contents
|
//Check if the previous default cert exists. If yes, get its hostname from cert contents
|
||||||
defaultPubKey := filepath.Join(m.CertStore, "default.key")
|
defaultPubKey := filepath.Join(m.CertStore, "default.pem")
|
||||||
defaultPriKey := filepath.Join(m.CertStore, "default.pem")
|
defaultPriKey := filepath.Join(m.CertStore, "default.key")
|
||||||
defaultJSON := filepath.Join(m.CertStore, "default.json")
|
defaultJSON := filepath.Join(m.CertStore, "default.json")
|
||||||
|
|
||||||
|
fmt.Println(defaultPubKey, defaultPriKey, defaultJSON)
|
||||||
if utils.FileExists(defaultPubKey) && utils.FileExists(defaultPriKey) {
|
if utils.FileExists(defaultPubKey) && utils.FileExists(defaultPriKey) {
|
||||||
//Move the existing default cert to its original name
|
//Move the existing default cert to its original name
|
||||||
certBytes, err := os.ReadFile(defaultPriKey)
|
certBytes, err := os.ReadFile(defaultPubKey)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
block, _ := pem.Decode(certBytes)
|
block, _ := pem.Decode(certBytes)
|
||||||
if block != nil {
|
if block != nil {
|
||||||
@@ -99,8 +101,10 @@ func (m *Manager) SetCertAsDefault(w http.ResponseWriter, r *http.Request) {
|
|||||||
originalPemName := filepath.Join(m.CertStore, domainToFilename(cert.Subject.CommonName, "pem"))
|
originalPemName := filepath.Join(m.CertStore, domainToFilename(cert.Subject.CommonName, "pem"))
|
||||||
originalJSONName := filepath.Join(m.CertStore, domainToFilename(cert.Subject.CommonName, "json"))
|
originalJSONName := filepath.Join(m.CertStore, domainToFilename(cert.Subject.CommonName, "json"))
|
||||||
|
|
||||||
os.Rename(defaultPubKey, originalKeyName)
|
fmt.Println(defaultPubKey, originalPemName)
|
||||||
os.Rename(defaultPriKey, originalPemName)
|
os.Rename(defaultPubKey, originalPemName)
|
||||||
|
fmt.Println(defaultPriKey, originalKeyName)
|
||||||
|
os.Rename(defaultPriKey, originalKeyName)
|
||||||
if utils.FileExists(defaultJSON) {
|
if utils.FileExists(defaultJSON) {
|
||||||
os.Rename(defaultJSON, originalJSONName)
|
os.Rename(defaultJSON, originalJSONName)
|
||||||
}
|
}
|
||||||
@@ -111,12 +115,12 @@ func (m *Manager) SetCertAsDefault(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
//Check if the cert exists
|
//Check if the cert exists
|
||||||
certname = filepath.Base(certname) //prevent path escape
|
certname = filepath.Base(certname) //prevent path escape
|
||||||
pubKey := filepath.Join(filepath.Join(m.CertStore), certname+".key")
|
pubKey := filepath.Join(filepath.Join(m.CertStore), certname+".pem")
|
||||||
priKey := filepath.Join(filepath.Join(m.CertStore), certname+".pem")
|
priKey := filepath.Join(filepath.Join(m.CertStore), certname+".key")
|
||||||
certJSON := filepath.Join(filepath.Join(m.CertStore), certname+".json")
|
certJSON := filepath.Join(filepath.Join(m.CertStore), certname+".json")
|
||||||
if utils.FileExists(pubKey) && utils.FileExists(priKey) {
|
if utils.FileExists(pubKey) && utils.FileExists(priKey) {
|
||||||
os.Rename(pubKey, filepath.Join(m.CertStore, "default.key"))
|
os.Rename(pubKey, filepath.Join(m.CertStore, "default.pem"))
|
||||||
os.Rename(priKey, filepath.Join(m.CertStore, "default.pem"))
|
os.Rename(priKey, filepath.Join(m.CertStore, "default.key"))
|
||||||
if utils.FileExists(certJSON) {
|
if utils.FileExists(certJSON) {
|
||||||
os.Rename(certJSON, filepath.Join(m.CertStore, "default.json"))
|
os.Rename(certJSON, filepath.Join(m.CertStore, "default.json"))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user