mirror of
https://github.com/gilbertchen/duplicacy
synced 2025-12-06 00:03:38 +00:00
Allow RSA keys to be passed directly via CML instead of a file
This change is intended to be used by the web GUI to create an RSA encrypted storage.
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"hash"
|
"hash"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@@ -554,10 +555,16 @@ func ConfigStorage(storage Storage, iterations int, compressionLevel int, averag
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (config *Config) loadRSAPublicKey(keyFile string) {
|
func (config *Config) loadRSAPublicKey(keyFile string) {
|
||||||
encodedKey, err := ioutil.ReadFile(keyFile)
|
encodedKey := []byte(keyFile)
|
||||||
if err != nil {
|
var err error
|
||||||
LOG_ERROR("BACKUP_KEY", "Failed to read the public key file: %v", err)
|
|
||||||
return
|
// keyFile may be the actually key, in which case we don't need to read from a file
|
||||||
|
if !strings.Contains(keyFile, "-----BEGIN") {
|
||||||
|
encodedKey, err = ioutil.ReadFile(keyFile)
|
||||||
|
if err != nil {
|
||||||
|
LOG_ERROR("BACKUP_KEY", "Failed to read the public key file: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
decodedKey, _ := pem.Decode(encodedKey)
|
decodedKey, _ := pem.Decode(encodedKey)
|
||||||
@@ -593,10 +600,16 @@ func (config *Config) loadRSAPrivateKey(keyFile string, passphrase string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
encodedKey, err := ioutil.ReadFile(keyFile)
|
encodedKey := []byte(keyFile)
|
||||||
if err != nil {
|
var err error
|
||||||
LOG_ERROR("RSA_PRIVATE", "Failed to read the private key file: %v", err)
|
|
||||||
return
|
// keyFile may be the actually key, in which case we don't need to read from a file
|
||||||
|
if !strings.Contains(keyFile, "-----BEGIN") {
|
||||||
|
encodedKey, err = ioutil.ReadFile(keyFile)
|
||||||
|
if err != nil {
|
||||||
|
LOG_ERROR("RSA_PRIVATE", "Failed to read the private key file: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
decodedKey, _ := pem.Decode(encodedKey)
|
decodedKey, _ := pem.Decode(encodedKey)
|
||||||
|
|||||||
Reference in New Issue
Block a user