mirror of
https://github.com/jkl1337/duplicacy.git
synced 2026-01-02 11:44:45 -06:00
Fixed a bug that caused all copied chunks to be RSA encrypted
The field encryptionVersion in the Chunk struct is supposed to pass the status of RSA encrytpion from a source chunk to a destination chunk in a copy command. This field needs to be a 3-state boolean in order to pass the status correctly.
This commit is contained in:
@@ -1732,7 +1732,11 @@ func (manager *BackupManager) CopySnapshots(otherManager *BackupManager, snapsho
|
|||||||
newChunk := otherManager.config.GetChunk()
|
newChunk := otherManager.config.GetChunk()
|
||||||
newChunk.Reset(true)
|
newChunk.Reset(true)
|
||||||
newChunk.Write(chunk.GetBytes())
|
newChunk.Write(chunk.GetBytes())
|
||||||
newChunk.encryptionVersion = chunk.encryptionVersion
|
if chunk.encryptionVersion == ENCRYPTION_VERSION_RSA {
|
||||||
|
newChunk.encryptionVersion = CHUNK_RSA_ENCRYPTION_ENABLED
|
||||||
|
} else {
|
||||||
|
newChunk.encryptionVersion = CHUNK_RSA_ENCRYPTION_DISABLED
|
||||||
|
}
|
||||||
chunkUploader.StartChunk(newChunk, chunkIndex)
|
chunkUploader.StartChunk(newChunk, chunkIndex)
|
||||||
totalCopied++
|
totalCopied++
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -63,14 +63,21 @@ type Chunk struct {
|
|||||||
config *Config // Every chunk is associated with a Config object. Which hashing algorithm to use is determined
|
config *Config // Every chunk is associated with a Config object. Which hashing algorithm to use is determined
|
||||||
// by the config
|
// by the config
|
||||||
|
|
||||||
encryptionVersion byte // The version type in the encrytion header
|
encryptionVersion byte // The version type in the encrytion header; for a chunk to be copied, this field contains
|
||||||
|
// one of the CHUNK_RSA_ENCRYPTION_* constants to indicate how the new chunk should be encrypted
|
||||||
}
|
}
|
||||||
|
|
||||||
// Magic word to identify a duplicacy format encrypted file, plus a version number.
|
// Magic word to identify a duplicacy format encrypted file, plus a version number.
|
||||||
var ENCRYPTION_HEADER = "duplicacy\000"
|
var ENCRYPTION_HEADER = "duplicacy\000"
|
||||||
|
|
||||||
|
// RSA encrypted chunks start with "duplicacy\002"
|
||||||
var ENCRYPTION_VERSION_RSA byte = 2
|
var ENCRYPTION_VERSION_RSA byte = 2
|
||||||
|
|
||||||
|
// These constants are used to control how a new chunk should be encrypted by the copy command
|
||||||
|
var CHUNK_RSA_ENCRYPTION_DEFAULT byte = 0 // No RSA encryption explicitly requested
|
||||||
|
var CHUNK_RSA_ENCRYPTION_DISABLED byte = 1 // The RSA encryption should be turned off
|
||||||
|
var CHUNK_RSA_ENCRYPTION_ENABLED byte = 2 // The RSA encryption should be forced on
|
||||||
|
|
||||||
// CreateChunk creates a new chunk.
|
// CreateChunk creates a new chunk.
|
||||||
func CreateChunk(config *Config, bufferNeeded bool) *Chunk {
|
func CreateChunk(config *Config, bufferNeeded bool) *Chunk {
|
||||||
|
|
||||||
@@ -193,7 +200,10 @@ func (chunk *Chunk) Encrypt(encryptionKey []byte, derivationKey string, isSnapsh
|
|||||||
|
|
||||||
key := encryptionKey
|
key := encryptionKey
|
||||||
usingRSA := false
|
usingRSA := false
|
||||||
if chunk.config.rsaPublicKey != nil && (!isSnapshot || chunk.encryptionVersion == ENCRYPTION_VERSION_RSA) {
|
// If encryptionVersion is not set, use the default setting (RSA for file chunks only);
|
||||||
|
// otherwise, enable RSA encryption only when explicitly requested
|
||||||
|
if chunk.config.rsaPublicKey != nil &&
|
||||||
|
((!isSnapshot && chunk.encryptionVersion == CHUNK_RSA_ENCRYPTION_DEFAULT) || chunk.encryptionVersion == CHUNK_RSA_ENCRYPTION_ENABLED) {
|
||||||
// If the chunk is not a snpashot chunk, we attempt to encrypt it with the RSA publick key if there is one
|
// If the chunk is not a snpashot chunk, we attempt to encrypt it with the RSA publick key if there is one
|
||||||
randomKey := make([]byte, 32)
|
randomKey := make([]byte, 32)
|
||||||
_, err := rand.Read(randomKey)
|
_, err := rand.Read(randomKey)
|
||||||
|
|||||||
Reference in New Issue
Block a user