Skip to content

Commit e7383bf

Browse files
committed
ReadMasterKey: strict tpm option match
ReadMasterKey should return an error if the TPM option is selected, but the master key was created without the TPM.
1 parent 3e83705 commit e7383bf

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

crypto/aes.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,12 @@ func ReadAESMasterKey(passphrase []byte, file string, opts ...Option) (MasterKey
156156
opt.logger.Debugf("ReadMasterKey: unexpected version: %d", version)
157157
return nil, ErrDecryptFailed
158158
}
159+
if version == 1 && opt.tpm != nil {
160+
opt.logger.Error("ReadMasterKey: TPM option selected but master key was created without TPM")
161+
return nil, ErrDecryptFailed
162+
}
159163
if version == 3 && opt.tpm == nil {
160-
opt.logger.Debug("ReadMasterKey: missing WithTPM option")
164+
opt.logger.Error("ReadMasterKey: master key was created with TPM but TPM option not selected")
161165
return nil, ErrDecryptFailed
162166
}
163167
salt := make([]byte, 16)

crypto/chacha20poly1305.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ func ReadChacha20Poly1305MasterKey(passphrase []byte, file string, opts ...Optio
137137
opt.logger.Debugf("ReadMasterKey: unexpected version: %d", version)
138138
return nil, ErrDecryptFailed
139139
}
140+
if opt.tpm != nil {
141+
opt.logger.Error("ReadMasterKey: TPM option selected but master key was created without TPM")
142+
return nil, ErrDecryptFailed
143+
}
140144
salt, b := b[:16], b[16:]
141145
time, b := uint32(b[0]), b[1:]
142146
memory, b := binary.LittleEndian.Uint32(b[:4]), b[4:]

0 commit comments

Comments
 (0)