decryption: GopenPGPInterface tries to identify decryption key from message metadata
So the system can have multiple private keys, and the caller doesn't need to specify a specific one regardless. Ideally: If there are several matches we could also take into account which keys have already been unlocked (or passthrases saved in keychain). Right now it only grabs the first match.
This commit is contained in:
parent
510eb8e15e
commit
39dab8c6c0
5 changed files with 75 additions and 14 deletions
|
|
@ -87,6 +87,25 @@ final class PGPAgentTest: XCTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
func testMultiKeysSelectMatchingPrivateKeyToDecrypt() throws {
|
||||
keychain.removeAllContent()
|
||||
try importKeys(RSA2048_RSA4096.publicKeys, RSA2048_RSA4096.privateKeys)
|
||||
try pgpAgent.initKeys()
|
||||
try [
|
||||
(true, true),
|
||||
(true, false),
|
||||
(false, true),
|
||||
(false, false),
|
||||
].forEach { encryptInArmored, decryptFromArmored in
|
||||
passKit.Defaults.encryptInArmored = encryptInArmored
|
||||
let encryptedData = try pgpAgent.encrypt(plainData: testData, keyID: RSA2048.fingerprint)
|
||||
passKit.Defaults.encryptInArmored = decryptFromArmored
|
||||
// Note: not specifying the keyID to decrypt, so that the agent needs to find the matching private key by itself.
|
||||
let decryptedData = try pgpAgent.decrypt(encryptedData: encryptedData, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
|
||||
XCTAssertEqual(decryptedData, testData)
|
||||
}
|
||||
}
|
||||
|
||||
func testNoPrivateKey() throws {
|
||||
try KeyFileManager(keyType: PGPKey.PUBLIC, keyPath: "", keyHandler: keychain.add).importKey(from: RSA2048.publicKey)
|
||||
XCTAssertFalse(pgpAgent.isPrepared)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue