This repository was archived by the owner on Oct 15, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +15
-0
lines changed
crypto-common/src/main/kotlin/app/passwordstore/crypto/errors
main/kotlin/app/passwordstore/crypto
test/kotlin/app/passwordstore/crypto Expand file tree Collapse file tree 3 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ public object KeyDeletionFailedException : KeyManagerException("Couldn't delete
22
22
public object InvalidKeyException :
23
23
KeyManagerException (" Given key cannot be parsed as a known key type" )
24
24
25
+ /* * Key failed the [app.passwordstore.crypto.KeyUtils.isKeyUsable] test. */
26
+ public object UnusableKeyException :
27
+ KeyManagerException (" Given key is not usable for encryption - is it using AEAD?" )
28
+
25
29
/* * No key matching `keyId` could be found. */
26
30
public class KeyNotFoundException (keyId : String ) :
27
31
KeyManagerException (" No key found with id: $keyId " )
Original file line number Diff line number Diff line change 7
7
package app.passwordstore.crypto
8
8
9
9
import androidx.annotation.VisibleForTesting
10
+ import app.passwordstore.crypto.KeyUtils.isKeyUsable
10
11
import app.passwordstore.crypto.KeyUtils.tryGetId
11
12
import app.passwordstore.crypto.KeyUtils.tryParseKeyring
12
13
import app.passwordstore.crypto.errors.InvalidKeyException
@@ -15,6 +16,7 @@ import app.passwordstore.crypto.errors.KeyDeletionFailedException
15
16
import app.passwordstore.crypto.errors.KeyDirectoryUnavailableException
16
17
import app.passwordstore.crypto.errors.KeyNotFoundException
17
18
import app.passwordstore.crypto.errors.NoKeysAvailableException
19
+ import app.passwordstore.crypto.errors.UnusableKeyException
18
20
import app.passwordstore.util.coroutines.runSuspendCatching
19
21
import com.github.michaelbull.result.Result
20
22
import com.github.michaelbull.result.unwrap
@@ -42,6 +44,7 @@ constructor(
42
44
runSuspendCatching {
43
45
if (! keyDirExists()) throw KeyDirectoryUnavailableException
44
46
val incomingKeyRing = tryParseKeyring(key) ? : throw InvalidKeyException
47
+ if (! isKeyUsable(key)) throw UnusableKeyException
45
48
val keyFile = File (keyDir, " ${tryGetId(key)} .$KEY_EXTENSION " )
46
49
if (keyFile.exists()) {
47
50
val existingKeyBytes = keyFile.readBytes()
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import app.passwordstore.crypto.PGPIdentifier.UserId
6
6
import app.passwordstore.crypto.errors.KeyAlreadyExistsException
7
7
import app.passwordstore.crypto.errors.KeyNotFoundException
8
8
import app.passwordstore.crypto.errors.NoKeysAvailableException
9
+ import app.passwordstore.crypto.errors.UnusableKeyException
9
10
import com.github.michaelbull.result.Err
10
11
import com.github.michaelbull.result.Ok
11
12
import com.github.michaelbull.result.unwrap
@@ -70,6 +71,13 @@ class PGPKeyManagerTest {
70
71
assertEquals(KeyId (CryptoConstants .KEY_ID ), keyId)
71
72
}
72
73
74
+ @Test
75
+ fun addKeyWithUnusableKey () =
76
+ runTest(dispatcher) {
77
+ val error = keyManager.addKey(PGPKey (TestUtils .getAEADSecretKey())).unwrapError()
78
+ assertEquals(UnusableKeyException , error)
79
+ }
80
+
73
81
@Test
74
82
fun removeKey () =
75
83
runTest(dispatcher) {
You can’t perform that action at this time.
0 commit comments