diff options
author | Tad Fisher <tadfisher@gmail.com> | 2022-10-09 15:10:10 -0700 |
---|---|---|
committer | Tad Fisher <tadfisher@gmail.com> | 2022-10-09 16:13:36 -0700 |
commit | 4b7457c7f712b92f21604d8612ec8ff19df75c81 (patch) | |
tree | bf1256e72d1ead8079daa514c5f9c0a96469ab73 /crypto-common/src/main | |
parent | a244a0f3b84d64cceaf0eefd662c78aadab2514e (diff) |
Add crypto-hwsecurity library
Diffstat (limited to 'crypto-common/src/main')
-rw-r--r-- | crypto-common/src/main/kotlin/app/passwordstore/crypto/DeviceHandler.kt | 12 | ||||
-rw-r--r-- | crypto-common/src/main/kotlin/app/passwordstore/crypto/errors/CryptoException.kt | 39 |
2 files changed, 48 insertions, 3 deletions
diff --git a/crypto-common/src/main/kotlin/app/passwordstore/crypto/DeviceHandler.kt b/crypto-common/src/main/kotlin/app/passwordstore/crypto/DeviceHandler.kt new file mode 100644 index 00000000..74eb0cfa --- /dev/null +++ b/crypto-common/src/main/kotlin/app/passwordstore/crypto/DeviceHandler.kt @@ -0,0 +1,12 @@ +package app.passwordstore.crypto + +import app.passwordstore.crypto.errors.DeviceHandlerException +import com.github.michaelbull.result.Result + +public interface DeviceHandler<Key, EncryptedSessionKey, DecryptedSessionKey> { + public suspend fun pairWithPublicKey(publicKey: Key): Result<Key, DeviceHandlerException> + + public suspend fun decryptSessionKey( + encryptedSessionKey: EncryptedSessionKey + ): Result<DecryptedSessionKey, DeviceHandlerException> +} diff --git a/crypto-common/src/main/kotlin/app/passwordstore/crypto/errors/CryptoException.kt b/crypto-common/src/main/kotlin/app/passwordstore/crypto/errors/CryptoException.kt index 81bdf95f..328a7a32 100644 --- a/crypto-common/src/main/kotlin/app/passwordstore/crypto/errors/CryptoException.kt +++ b/crypto-common/src/main/kotlin/app/passwordstore/crypto/errors/CryptoException.kt @@ -6,7 +6,7 @@ public sealed class CryptoException(message: String? = null, cause: Throwable? = Exception(message, cause) /** Sealed exception types for [KeyManager]. */ -public sealed class KeyManagerException(message: String? = null) : CryptoException(message) +public sealed class KeyManagerException(message: String? = null, cause: Throwable? = null) : CryptoException(message, cause) /** Store contains no keys. */ public object NoKeysAvailableException : KeyManagerException("No keys were found") @@ -19,8 +19,8 @@ public object KeyDirectoryUnavailableException : public object KeyDeletionFailedException : KeyManagerException("Couldn't delete the key file") /** Failed to parse the key as a known type. */ -public object InvalidKeyException : - KeyManagerException("Given key cannot be parsed as a known key type") +public class InvalidKeyException(cause: Throwable? = null) : + KeyManagerException("Given key cannot be parsed as a known key type", cause) /** No key matching `keyId` could be found. */ public class KeyNotFoundException(keyId: String) : @@ -30,6 +30,9 @@ public class KeyNotFoundException(keyId: String) : public class KeyAlreadyExistsException(keyId: String) : KeyManagerException("Pre-existing key was found for $keyId") +public class NoSecretKeyException(keyId: String) : + KeyManagerException("No secret keys found for $keyId") + /** Sealed exception types for [app.passwordstore.crypto.CryptoHandler]. */ public sealed class CryptoHandlerException(message: String? = null, cause: Throwable? = null) : CryptoException(message, cause) @@ -42,3 +45,33 @@ public class NoKeysProvided(message: String?) : CryptoHandlerException(message, /** An unexpected error that cannot be mapped to a known type. */ public class UnknownError(cause: Throwable) : CryptoHandlerException(null, cause) + +public class KeySpecific(public val key: Any, cause: Throwable?) : CryptoHandlerException(key.toString(), cause) + +/** Wrapper containing possibly multiple child exceptions via [suppressedExceptions]. */ +public class MultipleKeySpecific( + message: String?, + public val errors: List<KeySpecific> +) : CryptoHandlerException(message) { + init { + for (error in errors) { + addSuppressed(error) + } + } +} + +/** Sealed exception types for [app.passwordstore.crypto.DeviceHandler]. */ +public sealed class DeviceHandlerException(message: String? = null, cause: Throwable? = null) : + CryptoHandlerException(message, cause) + +/** The device crypto operation was canceled by the user. */ +public class DeviceOperationCanceled(message: String) : DeviceHandlerException(message, null) + +/** The device crypto operation failed. */ +public class DeviceOperationFailed(message: String?, cause: Throwable? = null) : DeviceHandlerException(message, cause) + +/** The device's key fingerprint doesn't match the fingerprint we are trying to pair it to. */ +public class DeviceFingerprintMismatch( + public val publicFingerprint: String, + public val deviceFingerprint: String, +) : DeviceHandlerException() |