diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2021-10-23 17:02:50 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-23 17:02:50 +0530 |
commit | aac74ae4515aa1d746f46287029441f5a945c98e (patch) | |
tree | 9d23e06592ecd884d6b58dd089692d9e4224a3f9 /crypto-common | |
parent | 21c8653e6815ca34574e783a5ce7ac783b188228 (diff) |
Switch new PGP backend to use PGPainless (#1522)
* crypto-pgpainless: init
* crypto-pgpainless: add an opinionated CryptoHandler impl
* app: migrate to crypto-pgpainless
* crypto-pgp: remove
* github: remove now unused instrumentation tests job
* crypto-common: fixup package names
* wip(crypto-pgpainless): add `PGPKeyPair` and `PGPKeyManager`
Signed-off-by: Aditya Wasan <adityawasan55@gmail.com>
(cherry picked from commit 02d07e9e797a8600cc8c534a731dfffcc44cfdde)
* crypto-pgpainless: use hex-encoded key IDs
* crypto-pgpainless: replace legacy Gopenpgp-generated key file
* crypto-pgpainless: fix CryptoConstants source set
* crypto-pgpainless: fix tests
* crypto-pgpainless: reinstate PGPKeyManager tests
Co-authored-by: Aditya Wasan <adityawasan55@gmail.com>
Diffstat (limited to 'crypto-common')
-rw-r--r-- | crypto-common/api/crypto-common.api | 44 | ||||
-rw-r--r-- | crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoException.kt (renamed from crypto-common/src/main/kotlin/dev/msfjarvis/aps/data/crypto/CryptoException.kt) | 2 | ||||
-rw-r--r-- | crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoHandler.kt | 37 | ||||
-rw-r--r-- | crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/KeyManager.kt (renamed from crypto-common/src/main/kotlin/dev/msfjarvis/aps/data/crypto/KeyManager.kt) | 2 | ||||
-rw-r--r-- | crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/KeyPair.kt (renamed from crypto-common/src/main/kotlin/dev/msfjarvis/aps/data/crypto/KeyPair.kt) | 2 | ||||
-rw-r--r-- | crypto-common/src/main/kotlin/dev/msfjarvis/aps/data/crypto/CryptoHandler.kt | 25 |
6 files changed, 62 insertions, 50 deletions
diff --git a/crypto-common/api/crypto-common.api b/crypto-common/api/crypto-common.api index 6468ea9b..6d137885 100644 --- a/crypto-common/api/crypto-common.api +++ b/crypto-common/api/crypto-common.api @@ -1,63 +1,63 @@ -public abstract class dev/msfjarvis/aps/data/crypto/CryptoException : java/lang/Exception { +public abstract class dev/msfjarvis/aps/crypto/CryptoException : java/lang/Exception { public synthetic fun <init> (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public synthetic fun <init> (Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V } -public abstract interface class dev/msfjarvis/aps/data/crypto/CryptoHandler { +public abstract interface class dev/msfjarvis/aps/crypto/CryptoHandler { public abstract fun canHandle (Ljava/lang/String;)Z - public abstract fun decrypt (Ljava/lang/String;[B[B)[B - public abstract fun encrypt (Ljava/lang/String;[B)[B + public abstract fun decrypt (Ljava/lang/String;Ljava/lang/String;Ljava/io/InputStream;Ljava/io/OutputStream;)V + public abstract fun encrypt (Ljava/util/List;Ljava/io/InputStream;Ljava/io/OutputStream;)V } -public abstract interface class dev/msfjarvis/aps/data/crypto/KeyManager { - public abstract fun addKey (Ldev/msfjarvis/aps/data/crypto/KeyPair;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; +public abstract interface class dev/msfjarvis/aps/crypto/KeyManager { + public abstract fun addKey (Ldev/msfjarvis/aps/crypto/KeyPair;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun canHandle (Ljava/lang/String;)Z public abstract fun getAllKeys (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun getKeyById (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun removeKey (Ldev/msfjarvis/aps/data/crypto/KeyPair;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public abstract fun removeKey (Ldev/msfjarvis/aps/crypto/KeyPair;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } -public final class dev/msfjarvis/aps/data/crypto/KeyManager$DefaultImpls { - public static synthetic fun addKey$default (Ldev/msfjarvis/aps/data/crypto/KeyManager;Ldev/msfjarvis/aps/data/crypto/KeyPair;ZLkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; +public final class dev/msfjarvis/aps/crypto/KeyManager$DefaultImpls { + public static synthetic fun addKey$default (Ldev/msfjarvis/aps/crypto/KeyManager;Ldev/msfjarvis/aps/crypto/KeyPair;ZLkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; } -public abstract class dev/msfjarvis/aps/data/crypto/KeyManagerException : dev/msfjarvis/aps/data/crypto/CryptoException { +public abstract class dev/msfjarvis/aps/crypto/KeyManagerException : dev/msfjarvis/aps/crypto/CryptoException { public synthetic fun <init> (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public synthetic fun <init> (Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V } -public final class dev/msfjarvis/aps/data/crypto/KeyManagerException$KeyAlreadyExistsException : dev/msfjarvis/aps/data/crypto/KeyManagerException { +public final class dev/msfjarvis/aps/crypto/KeyManagerException$KeyAlreadyExistsException : dev/msfjarvis/aps/crypto/KeyManagerException { public fun <init> (Ljava/lang/String;)V } -public final class dev/msfjarvis/aps/data/crypto/KeyManagerException$KeyDeletionFailedException : dev/msfjarvis/aps/data/crypto/KeyManagerException { - public static final field INSTANCE Ldev/msfjarvis/aps/data/crypto/KeyManagerException$KeyDeletionFailedException; +public final class dev/msfjarvis/aps/crypto/KeyManagerException$KeyDeletionFailedException : dev/msfjarvis/aps/crypto/KeyManagerException { + public static final field INSTANCE Ldev/msfjarvis/aps/crypto/KeyManagerException$KeyDeletionFailedException; } -public final class dev/msfjarvis/aps/data/crypto/KeyManagerException$KeyDirectoryUnavailableException : dev/msfjarvis/aps/data/crypto/KeyManagerException { - public static final field INSTANCE Ldev/msfjarvis/aps/data/crypto/KeyManagerException$KeyDirectoryUnavailableException; +public final class dev/msfjarvis/aps/crypto/KeyManagerException$KeyDirectoryUnavailableException : dev/msfjarvis/aps/crypto/KeyManagerException { + public static final field INSTANCE Ldev/msfjarvis/aps/crypto/KeyManagerException$KeyDirectoryUnavailableException; } -public final class dev/msfjarvis/aps/data/crypto/KeyManagerException$KeyNotFoundException : dev/msfjarvis/aps/data/crypto/KeyManagerException { +public final class dev/msfjarvis/aps/crypto/KeyManagerException$KeyNotFoundException : dev/msfjarvis/aps/crypto/KeyManagerException { public fun <init> (Ljava/lang/String;)V } -public final class dev/msfjarvis/aps/data/crypto/KeyManagerException$NoKeysAvailableException : dev/msfjarvis/aps/data/crypto/KeyManagerException { - public static final field INSTANCE Ldev/msfjarvis/aps/data/crypto/KeyManagerException$NoKeysAvailableException; +public final class dev/msfjarvis/aps/crypto/KeyManagerException$NoKeysAvailableException : dev/msfjarvis/aps/crypto/KeyManagerException { + public static final field INSTANCE Ldev/msfjarvis/aps/crypto/KeyManagerException$NoKeysAvailableException; } -public abstract interface class dev/msfjarvis/aps/data/crypto/KeyPair { +public abstract interface class dev/msfjarvis/aps/crypto/KeyPair { public abstract fun getKeyId ()Ljava/lang/String; public abstract fun getPrivateKey ()[B public abstract fun getPublicKey ()[B } -public abstract class dev/msfjarvis/aps/data/crypto/KeyPairException : dev/msfjarvis/aps/data/crypto/CryptoException { +public abstract class dev/msfjarvis/aps/crypto/KeyPairException : dev/msfjarvis/aps/crypto/CryptoException { public synthetic fun <init> (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public synthetic fun <init> (Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V } -public final class dev/msfjarvis/aps/data/crypto/KeyPairException$PrivateKeyUnavailableException : dev/msfjarvis/aps/data/crypto/KeyPairException { - public static final field INSTANCE Ldev/msfjarvis/aps/data/crypto/KeyPairException$PrivateKeyUnavailableException; +public final class dev/msfjarvis/aps/crypto/KeyPairException$PrivateKeyUnavailableException : dev/msfjarvis/aps/crypto/KeyPairException { + public static final field INSTANCE Ldev/msfjarvis/aps/crypto/KeyPairException$PrivateKeyUnavailableException; } diff --git a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/data/crypto/CryptoException.kt b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoException.kt index 6a73d381..34e64d5f 100644 --- a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/data/crypto/CryptoException.kt +++ b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoException.kt @@ -1,4 +1,4 @@ -package dev.msfjarvis.aps.data.crypto +package dev.msfjarvis.aps.crypto public sealed class CryptoException(message: String? = null) : Exception(message) diff --git a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoHandler.kt b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoHandler.kt new file mode 100644 index 00000000..c64e9c9b --- /dev/null +++ b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoHandler.kt @@ -0,0 +1,37 @@ +/* + * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +package dev.msfjarvis.aps.crypto + +import java.io.InputStream +import java.io.OutputStream + +/** Generic interface to implement cryptographic operations on top of. */ +public interface CryptoHandler { + + /** + * Decrypt the given [ciphertextStream] using a [privateKey] and [password], and writes the + * resultant plaintext to [outputStream]. + */ + public fun decrypt( + privateKey: String, + password: String, + ciphertextStream: InputStream, + outputStream: OutputStream, + ) + + /** + * Encrypt the given [plaintextStream] to the provided [pubKeys], and writes the encrypted + * ciphertext to [outputStream]. + */ + public fun encrypt( + pubKeys: List<String>, + plaintextStream: InputStream, + outputStream: OutputStream, + ) + + /** Given a [fileName], return whether this instance can handle it. */ + public fun canHandle(fileName: String): Boolean +} diff --git a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/data/crypto/KeyManager.kt b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/KeyManager.kt index b5ba881e..2f901354 100644 --- a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/data/crypto/KeyManager.kt +++ b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/KeyManager.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: GPL-3.0-only */ -package dev.msfjarvis.aps.data.crypto +package dev.msfjarvis.aps.crypto import com.github.michaelbull.result.Result diff --git a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/data/crypto/KeyPair.kt b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/KeyPair.kt index e2362612..b8dec216 100644 --- a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/data/crypto/KeyPair.kt +++ b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/KeyPair.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: GPL-3.0-only */ -package dev.msfjarvis.aps.data.crypto +package dev.msfjarvis.aps.crypto /** Defines expectations for a keypair used in public key cryptography. */ public interface KeyPair { diff --git a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/data/crypto/CryptoHandler.kt b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/data/crypto/CryptoHandler.kt deleted file mode 100644 index 453613a4..00000000 --- a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/data/crypto/CryptoHandler.kt +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. - * SPDX-License-Identifier: GPL-3.0-only - */ - -package dev.msfjarvis.aps.data.crypto - -/** Generic interface to implement cryptographic operations on top of. */ -public interface CryptoHandler { - - /** - * Decrypt the given [ciphertext] using a [privateKey] and [passphrase], returning a [ByteArray] - * corresponding to the decrypted plaintext. - */ - public fun decrypt(privateKey: String, passphrase: ByteArray, ciphertext: ByteArray): ByteArray - - /** - * Encrypt the given [plaintext] to the provided [publicKey], returning the encrypted ciphertext - * as a [ByteArray] - */ - public fun encrypt(publicKey: String, plaintext: ByteArray): ByteArray - - /** Given a [fileName], return whether this instance can handle it. */ - public fun canHandle(fileName: String): Boolean -} |