diff --git a/app/build.gradle b/app/build.gradle index 61b532886960..6fe63b338c68 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -235,10 +235,6 @@ dependencies { implementation project(':site-permissions-api') implementation project(':site-permissions-impl') - implementation project(':secure-storage-api') - implementation project(':secure-storage-impl') - implementation project(':secure-storage-store') - implementation project(':ad-click-api') implementation project(':ad-click-impl') implementation project(':ad-click-store') diff --git a/autofill/autofill-impl/build.gradle b/autofill/autofill-impl/build.gradle index be94e5f5d071..cbb82ae5fa70 100644 --- a/autofill/autofill-impl/build.gradle +++ b/autofill/autofill-impl/build.gradle @@ -30,7 +30,6 @@ dependencies { implementation project(path: ':common-utils') implementation project(path: ':common-ui') implementation project(path: ':autofill-api') - implementation project(path: ':secure-storage-api') implementation project(path: ':browser-api') implementation project(path: ':autofill-store') implementation project(path: ':statistics') @@ -60,6 +59,8 @@ dependencies { implementation AndroidX.room.ktx implementation AndroidX.biometric + implementation "net.zetetic:android-database-sqlcipher:_" + implementation "com.jakewharton.threetenabp:threetenabp:_" testImplementation "org.threeten:threetenbp:_" diff --git a/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/SecureStoreBackedAutofillStore.kt b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/SecureStoreBackedAutofillStore.kt index c195696bb577..d3a67ae41733 100644 --- a/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/SecureStoreBackedAutofillStore.kt +++ b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/SecureStoreBackedAutofillStore.kt @@ -23,6 +23,9 @@ import com.duckduckgo.autofill.api.domain.app.LoginCredentials import com.duckduckgo.autofill.api.store.AutofillStore import com.duckduckgo.autofill.api.store.AutofillStore.ContainsCredentialsResult import com.duckduckgo.autofill.api.store.AutofillStore.ContainsCredentialsResult.NoMatch +import com.duckduckgo.autofill.impl.securestorage.SecureStorage +import com.duckduckgo.autofill.impl.securestorage.WebsiteLoginDetails +import com.duckduckgo.autofill.impl.securestorage.WebsiteLoginDetailsWithCredentials import com.duckduckgo.autofill.impl.urlmatcher.AutofillUrlMatcher import com.duckduckgo.autofill.store.AutofillPrefsStore import com.duckduckgo.autofill.store.LastUpdatedTimeProvider @@ -30,9 +33,6 @@ import com.duckduckgo.autofill.sync.SyncCredentialsListener import com.duckduckgo.common.utils.DefaultDispatcherProvider import com.duckduckgo.common.utils.DispatcherProvider import com.duckduckgo.di.scopes.AppScope -import com.duckduckgo.securestorage.api.SecureStorage -import com.duckduckgo.securestorage.api.WebsiteLoginDetails -import com.duckduckgo.securestorage.api.WebsiteLoginDetailsWithCredentials import com.squareup.anvil.annotations.ContributesBinding import dagger.SingleInstanceIn import javax.inject.Inject diff --git a/secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/DerivedKeySecretFactory.kt b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/DerivedKeySecretFactory.kt similarity index 93% rename from secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/DerivedKeySecretFactory.kt rename to autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/DerivedKeySecretFactory.kt index f579f909560d..05d8001134f8 100644 --- a/secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/DerivedKeySecretFactory.kt +++ b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/DerivedKeySecretFactory.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 DuckDuckGo + * Copyright (c) 2023 DuckDuckGo * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.duckduckgo.securestorage.impl +package com.duckduckgo.autofill.impl.securestorage import java.security.Key import javax.crypto.SecretKeyFactory diff --git a/secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/L2DataTransformer.kt b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/L2DataTransformer.kt similarity index 83% rename from secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/L2DataTransformer.kt rename to autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/L2DataTransformer.kt index 77adb0259073..0b2205d2230e 100644 --- a/secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/L2DataTransformer.kt +++ b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/L2DataTransformer.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 DuckDuckGo + * Copyright (c) 2023 DuckDuckGo * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package com.duckduckgo.securestorage.impl +package com.duckduckgo.autofill.impl.securestorage +import com.duckduckgo.autofill.impl.securestorage.SecureStorageException.InternalSecureStorageException +import com.duckduckgo.autofill.impl.securestorage.encryption.EncryptionHelper +import com.duckduckgo.autofill.impl.securestorage.encryption.EncryptionHelper.EncryptedBytes +import com.duckduckgo.autofill.impl.securestorage.encryption.EncryptionHelper.EncryptedString import com.duckduckgo.di.scopes.AppScope -import com.duckduckgo.securestorage.api.SecureStorageException -import com.duckduckgo.securestorage.api.SecureStorageException.InternalSecureStorageException -import com.duckduckgo.securestorage.impl.encryption.EncryptionHelper -import com.duckduckgo.securestorage.impl.encryption.EncryptionHelper.EncryptedBytes -import com.duckduckgo.securestorage.impl.encryption.EncryptionHelper.EncryptedString import com.squareup.anvil.annotations.ContributesBinding import dagger.SingleInstanceIn import javax.inject.Inject diff --git a/secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/RealSecureStorageRepositoryFactory.kt b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/RealSecureStorageRepositoryFactory.kt similarity index 93% rename from secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/RealSecureStorageRepositoryFactory.kt rename to autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/RealSecureStorageRepositoryFactory.kt index e6f6dc318efa..eff648d96684 100644 --- a/secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/RealSecureStorageRepositoryFactory.kt +++ b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/RealSecureStorageRepositoryFactory.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 DuckDuckGo + * Copyright (c) 2023 DuckDuckGo * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.duckduckgo.securestorage.impl +package com.duckduckgo.autofill.impl.securestorage import com.duckduckgo.di.scopes.AppScope import com.duckduckgo.securestorage.store.RealSecureStorageRepository diff --git a/secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/RealSecureStorage.kt b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/SecureStorage.kt similarity index 53% rename from secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/RealSecureStorage.kt rename to autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/SecureStorage.kt index e9ea3c773d77..e054d94a2999 100644 --- a/secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/RealSecureStorage.kt +++ b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/SecureStorage.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 DuckDuckGo + * Copyright (c) 2023 DuckDuckGo * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,11 @@ * limitations under the License. */ -package com.duckduckgo.securestorage.impl +package com.duckduckgo.autofill.impl.securestorage +import com.duckduckgo.autofill.impl.securestorage.encryption.EncryptionHelper.EncryptedString import com.duckduckgo.common.utils.DispatcherProvider import com.duckduckgo.di.scopes.AppScope -import com.duckduckgo.securestorage.api.SecureStorage -import com.duckduckgo.securestorage.api.WebsiteLoginDetails -import com.duckduckgo.securestorage.api.WebsiteLoginDetailsWithCredentials -import com.duckduckgo.securestorage.impl.encryption.EncryptionHelper.EncryptedString import com.duckduckgo.securestorage.store.SecureStorageRepository import com.duckduckgo.securestorage.store.db.WebsiteLoginCredentialsEntity import com.squareup.anvil.annotations.ContributesBinding @@ -33,6 +30,100 @@ import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.withContext +/** Public API for the secure storage feature */ +interface SecureStorage { + + /** + * This method can be used to check if the secure storage has been instantiated properly. + * + * @return `true` if all dependencies of SecureStorage have been instantiated properly otherwise `false` + */ + fun canAccessSecureStorage(): Boolean + + /** + * This method adds a raw plaintext [WebsiteLoginDetailsWithCredentials] into the [SecureStorage]. If [canAccessSecureStorage] is false when + * this is invoked, nothing will be done. + * + * @throws [SecureStorageException] if something went wrong while trying to perform the action. See type to get more info on the cause. + * @return The saved credential if it saved successfully, otherwise null + */ + @Throws(SecureStorageException::class) + suspend fun addWebsiteLoginDetailsWithCredentials( + websiteLoginDetailsWithCredentials: WebsiteLoginDetailsWithCredentials, + ): WebsiteLoginDetailsWithCredentials? + + /** + * This method returns all [WebsiteLoginDetails] with the [domain] stored in the [SecureStorage]. + * Only L1 encrypted data is returned by these function. This is best use when the need is only to access non-sensitive data. + * If [canAccessSecureStorage] is false when this is invoked, an empty flow will be emitted. + * + * @return Flow> a flow emitting a List of plain text WebsiteLoginDetails stored in SecureStorage. + */ + suspend fun websiteLoginDetailsForDomain(domain: String): Flow> + + /** + * This method returns all [WebsiteLoginDetails] stored in the [SecureStorage]. + * Only L1 encrypted data is returned by these function. This is best use when the need is only to access non-sensitive data. + * If [canAccessSecureStorage] is false when this is invoked, an empty flow will be emitted. + * + * @return Flow> a flow containing a List of plain text WebsiteLoginDetails stored in SecureStorage. + */ + suspend fun websiteLoginDetails(): Flow> + + /** + * This method returns the [WebsiteLoginDetailsWithCredentials] with the [id] stored in the [SecureStorage]. + * This returns decrypted sensitive data (encrypted in L2). Use this only when sensitive data is needed to be accessed. + * If [canAccessSecureStorage] is false when this is invoked, null will be returned. + * + * @return [WebsiteLoginDetailsWithCredentials] containing the plaintext password + * @throws [SecureStorageException] if something went wrong while trying to perform the action. See type to get more info on the cause. + */ + @Throws(SecureStorageException::class) + suspend fun getWebsiteLoginDetailsWithCredentials(id: Long): WebsiteLoginDetailsWithCredentials? + + /** + * This method returns the [WebsiteLoginDetailsWithCredentials] with the [domain] stored in the [SecureStorage]. + * This returns decrypted sensitive data (encrypted in L2). Use this only when sensitive data is needed to be accessed. + * If [canAccessSecureStorage] is false when this is invoked, an empty flow will be emitted. + * + * @return Flow> a flow emitting a List of plain text WebsiteLoginDetailsWithCredentials stored + * in SecureStorage containing the plaintext password + * @throws [SecureStorageException] if something went wrong while trying to perform the action. See type to get more info on the cause. + */ + @Throws(SecureStorageException::class) + suspend fun websiteLoginDetailsWithCredentialsForDomain(domain: String): Flow> + + /** + * This method returns all the [WebsiteLoginDetailsWithCredentials] stored in the [SecureStorage]. + * This returns decrypted sensitive data (encrypted in L2). Use this only when sensitive data is needed to be accessed. + * If [canAccessSecureStorage] is false when this is invoked, an empty flow will be emitted. + * + * @return Flow> a flow emitting a List of plain text WebsiteLoginDetailsWithCredentials stored + * in SecureStorage containing the plaintext password + * @throws [SecureStorageException] if something went wrong while trying to perform the action. See type to get more info on the cause. + */ + @Throws(SecureStorageException::class) + suspend fun websiteLoginDetailsWithCredentials(): Flow> + + /** + * This method updates an existing [WebsiteLoginDetailsWithCredentials] in the [SecureStorage]. + * If [canAccessSecureStorage] is false when this is invoked, nothing will be done. + * + * @throws [SecureStorageException] if something went wrong while trying to perform the action. See type to get more info on the cause. + * @return The updated credential if it saved successfully, otherwise null + */ + @Throws(SecureStorageException::class) + suspend fun updateWebsiteLoginDetailsWithCredentials( + websiteLoginDetailsWithCredentials: WebsiteLoginDetailsWithCredentials, + ): WebsiteLoginDetailsWithCredentials? + + /** + * This method removes an existing [WebsiteLoginDetailsWithCredentials] associated with an [id] from the [SecureStorage]. + * If [canAccessSecureStorage] is false when this is invoked, nothing will be done. + */ + suspend fun deleteWebsiteLoginDetailsWithCredentials(id: Long) +} + @ContributesBinding(AppScope::class) @SingleInstanceIn(AppScope::class) class RealSecureStorage @Inject constructor( diff --git a/secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/SecureStorageDatabaseFactory.kt b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/SecureStorageDatabaseFactory.kt similarity index 96% rename from secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/SecureStorageDatabaseFactory.kt rename to autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/SecureStorageDatabaseFactory.kt index 5a54bc43b450..19c2dcc3a87b 100644 --- a/secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/SecureStorageDatabaseFactory.kt +++ b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/SecureStorageDatabaseFactory.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 DuckDuckGo + * Copyright (c) 2023 DuckDuckGo * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.duckduckgo.securestorage.impl +package com.duckduckgo.autofill.impl.securestorage import android.content.Context import androidx.room.Room diff --git a/secure-storage/secure-storage-api/src/main/java/com/duckduckgo/securestorage/api/SecureStorageException.kt b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/SecureStorageException.kt similarity index 92% rename from secure-storage/secure-storage-api/src/main/java/com/duckduckgo/securestorage/api/SecureStorageException.kt rename to autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/SecureStorageException.kt index f16bd271dbcb..a73c131291e8 100644 --- a/secure-storage/secure-storage-api/src/main/java/com/duckduckgo/securestorage/api/SecureStorageException.kt +++ b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/SecureStorageException.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 DuckDuckGo + * Copyright (c) 2023 DuckDuckGo * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.duckduckgo.securestorage.api +package com.duckduckgo.autofill.impl.securestorage import java.lang.Exception diff --git a/secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/SecureStorageKeyGenerator.kt b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/SecureStorageKeyGenerator.kt similarity index 97% rename from secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/SecureStorageKeyGenerator.kt rename to autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/SecureStorageKeyGenerator.kt index a513477ecc05..a6f5f439dc94 100644 --- a/secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/SecureStorageKeyGenerator.kt +++ b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/SecureStorageKeyGenerator.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 DuckDuckGo + * Copyright (c) 2023 DuckDuckGo * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.duckduckgo.securestorage.impl +package com.duckduckgo.autofill.impl.securestorage import android.os.Build import android.security.keystore.KeyProperties diff --git a/secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/SecureStorageKeyProvider.kt b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/SecureStorageKeyProvider.kt similarity index 94% rename from secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/SecureStorageKeyProvider.kt rename to autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/SecureStorageKeyProvider.kt index 7eb4a49cddb5..0401778933e9 100644 --- a/secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/SecureStorageKeyProvider.kt +++ b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/SecureStorageKeyProvider.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 DuckDuckGo + * Copyright (c) 2023 DuckDuckGo * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -package com.duckduckgo.securestorage.impl +package com.duckduckgo.autofill.impl.securestorage +import com.duckduckgo.autofill.impl.securestorage.encryption.EncryptionHelper +import com.duckduckgo.autofill.impl.securestorage.encryption.EncryptionHelper.EncryptedBytes import com.duckduckgo.di.scopes.AppScope -import com.duckduckgo.securestorage.impl.encryption.EncryptionHelper -import com.duckduckgo.securestorage.impl.encryption.EncryptionHelper.EncryptedBytes import com.duckduckgo.securestorage.impl.encryption.RandomBytesGenerator import com.duckduckgo.securestorage.store.SecureStorageKeyRepository import com.squareup.anvil.annotations.ContributesBinding diff --git a/secure-storage/secure-storage-api/src/main/java/com/duckduckgo/securestorage/api/SecureStorageModels.kt b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/SecureStorageModels.kt similarity index 96% rename from secure-storage/secure-storage-api/src/main/java/com/duckduckgo/securestorage/api/SecureStorageModels.kt rename to autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/SecureStorageModels.kt index e61796a358a9..9650d40ef567 100644 --- a/secure-storage/secure-storage-api/src/main/java/com/duckduckgo/securestorage/api/SecureStorageModels.kt +++ b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/SecureStorageModels.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 DuckDuckGo + * Copyright (c) 2023 DuckDuckGo * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.duckduckgo.securestorage.api +package com.duckduckgo.autofill.impl.securestorage /** * Public data class that wraps all data related to a website login. All succeeding l2 and above attributes should be added here directly. diff --git a/secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/di/SecureStorageModule.kt b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/di/SecureStorageModule.kt similarity index 84% rename from secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/di/SecureStorageModule.kt rename to autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/di/SecureStorageModule.kt index 6ada6500766e..d8367b000a92 100644 --- a/secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/di/SecureStorageModule.kt +++ b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/di/SecureStorageModule.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 DuckDuckGo + * Copyright (c) 2023 DuckDuckGo * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package com.duckduckgo.securestorage.impl.di +package com.duckduckgo.autofill.impl.securestorage.di import android.content.Context +import com.duckduckgo.autofill.impl.securestorage.DerivedKeySecretFactory +import com.duckduckgo.autofill.impl.securestorage.LegacyDerivedKeySecretFactory +import com.duckduckgo.autofill.impl.securestorage.RealDerivedKeySecretFactory import com.duckduckgo.di.scopes.AppScope -import com.duckduckgo.securestorage.impl.DerivedKeySecretFactory -import com.duckduckgo.securestorage.impl.LegacyDerivedKeySecretFactory -import com.duckduckgo.securestorage.impl.RealDerivedKeySecretFactory import com.duckduckgo.securestorage.store.RealSecureStorageKeyRepository import com.duckduckgo.securestorage.store.SecureStorageKeyRepository import com.duckduckgo.securestorage.store.keys.RealSecureStorageKeyStore diff --git a/secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/encryption/EncryptionHelper.kt b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/encryption/EncryptionHelper.kt similarity index 88% rename from secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/encryption/EncryptionHelper.kt rename to autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/encryption/EncryptionHelper.kt index 409595485864..33210841757d 100644 --- a/secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/encryption/EncryptionHelper.kt +++ b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/encryption/EncryptionHelper.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 DuckDuckGo + * Copyright (c) 2023 DuckDuckGo * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,13 @@ * limitations under the License. */ -package com.duckduckgo.securestorage.impl.encryption +package com.duckduckgo.autofill.impl.securestorage.encryption import android.security.keystore.KeyProperties +import com.duckduckgo.autofill.impl.securestorage.SecureStorageException +import com.duckduckgo.autofill.impl.securestorage.SecureStorageException.InternalSecureStorageException +import com.duckduckgo.autofill.impl.securestorage.encryption.EncryptionHelper.EncryptedBytes import com.duckduckgo.di.scopes.AppScope -import com.duckduckgo.securestorage.api.SecureStorageException -import com.duckduckgo.securestorage.api.SecureStorageException.InternalSecureStorageException -import com.duckduckgo.securestorage.impl.encryption.EncryptionHelper.EncryptedBytes import com.squareup.anvil.annotations.ContributesBinding import java.lang.Exception import java.security.Key diff --git a/secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/encryption/RandomBytesGenerator.kt b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/encryption/RandomBytesGenerator.kt similarity index 100% rename from secure-storage/secure-storage-impl/src/main/java/com/duckduckgo/securestorage/impl/encryption/RandomBytesGenerator.kt rename to autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/securestorage/encryption/RandomBytesGenerator.kt diff --git a/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/sync/CredentialsSync.kt b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/sync/CredentialsSync.kt index 42207fefce3f..d844545ea053 100644 --- a/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/sync/CredentialsSync.kt +++ b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/sync/CredentialsSync.kt @@ -17,13 +17,13 @@ package com.duckduckgo.autofill.sync import com.duckduckgo.autofill.api.domain.app.LoginCredentials +import com.duckduckgo.autofill.impl.securestorage.SecureStorage +import com.duckduckgo.autofill.impl.securestorage.WebsiteLoginDetails +import com.duckduckgo.autofill.impl.securestorage.WebsiteLoginDetailsWithCredentials import com.duckduckgo.autofill.store.CredentialsSyncMetadataEntity import com.duckduckgo.autofill.sync.provider.LoginCredentialEntry import com.duckduckgo.common.utils.formatters.time.DatabaseDateFormatter import com.duckduckgo.di.scopes.AppScope -import com.duckduckgo.securestorage.api.SecureStorage -import com.duckduckgo.securestorage.api.WebsiteLoginDetails -import com.duckduckgo.securestorage.api.WebsiteLoginDetailsWithCredentials import com.duckduckgo.sync.api.SyncCrypto import dagger.SingleInstanceIn import javax.inject.* diff --git a/autofill/autofill-impl/src/test/java/com/duckduckgo/app/browser/autofill/RealDuckAddressLoginCreatorTest.kt b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/RealDuckAddressLoginCreatorTest.kt similarity index 86% rename from autofill/autofill-impl/src/test/java/com/duckduckgo/app/browser/autofill/RealDuckAddressLoginCreatorTest.kt rename to autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/RealDuckAddressLoginCreatorTest.kt index 6ef1325aa2aa..10cc0250f8dc 100644 --- a/autofill/autofill-impl/src/test/java/com/duckduckgo/app/browser/autofill/RealDuckAddressLoginCreatorTest.kt +++ b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/RealDuckAddressLoginCreatorTest.kt @@ -1,10 +1,25 @@ -package com.duckduckgo.app.browser.autofill +/* + * Copyright (c) 2023 DuckDuckGo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.duckduckgo.autofill.impl import com.duckduckgo.autofill.api.AutofillCapabilityChecker import com.duckduckgo.autofill.api.domain.app.LoginCredentials import com.duckduckgo.autofill.api.passwordgeneration.AutomaticSavedLoginsMonitor import com.duckduckgo.autofill.api.store.AutofillStore -import com.duckduckgo.autofill.impl.RealDuckAddressLoginCreator import com.duckduckgo.common.test.CoroutineTestRule import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest diff --git a/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/SecureStoreBackedAutofillStoreTest.kt b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/SecureStoreBackedAutofillStoreTest.kt index eaf4f01ee175..4b1c3baff2cf 100644 --- a/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/SecureStoreBackedAutofillStoreTest.kt +++ b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/SecureStoreBackedAutofillStoreTest.kt @@ -26,6 +26,9 @@ import com.duckduckgo.autofill.api.store.AutofillStore.ContainsCredentialsResult import com.duckduckgo.autofill.api.store.AutofillStore.ContainsCredentialsResult.UsernameMatch import com.duckduckgo.autofill.api.store.AutofillStore.ContainsCredentialsResult.UsernameMissing import com.duckduckgo.autofill.impl.encoding.TestUrlUnicodeNormalizer +import com.duckduckgo.autofill.impl.securestorage.SecureStorage +import com.duckduckgo.autofill.impl.securestorage.WebsiteLoginDetails +import com.duckduckgo.autofill.impl.securestorage.WebsiteLoginDetailsWithCredentials import com.duckduckgo.autofill.impl.urlmatcher.AutofillDomainNameUrlMatcher import com.duckduckgo.autofill.impl.urlmatcher.AutofillUrlMatcher import com.duckduckgo.autofill.store.AutofillPrefsStore @@ -34,9 +37,6 @@ import com.duckduckgo.autofill.sync.CredentialsSyncMetadata import com.duckduckgo.autofill.sync.SyncCredentialsListener import com.duckduckgo.autofill.sync.inMemoryAutofillDatabase import com.duckduckgo.common.test.CoroutineTestRule -import com.duckduckgo.securestorage.api.SecureStorage -import com.duckduckgo.securestorage.api.WebsiteLoginDetails -import com.duckduckgo.securestorage.api.WebsiteLoginDetailsWithCredentials import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.first diff --git a/secure-storage/secure-storage-impl/src/test/java/com/duckduckgo/securestorage/impl/Fakes.kt b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/securestorage/Fakes.kt similarity index 86% rename from secure-storage/secure-storage-impl/src/test/java/com/duckduckgo/securestorage/impl/Fakes.kt rename to autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/securestorage/Fakes.kt index dfaf41d6808c..860c2133c752 100644 --- a/secure-storage/secure-storage-impl/src/test/java/com/duckduckgo/securestorage/impl/Fakes.kt +++ b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/securestorage/Fakes.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 DuckDuckGo + * Copyright (c) 2023 DuckDuckGo * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,11 @@ * limitations under the License. */ -package com.duckduckgo.securestorage.impl +package com.duckduckgo.securestorage -import com.duckduckgo.securestorage.impl.encryption.EncryptionHelper -import com.duckduckgo.securestorage.impl.encryption.EncryptionHelper.EncryptedBytes +import com.duckduckgo.autofill.impl.securestorage.SecureStorageKeyGenerator +import com.duckduckgo.autofill.impl.securestorage.encryption.EncryptionHelper +import com.duckduckgo.autofill.impl.securestorage.encryption.EncryptionHelper.EncryptedBytes import com.duckduckgo.securestorage.store.SecureStorageKeyRepository import java.security.Key import okio.ByteString.Companion.decodeBase64 diff --git a/secure-storage/secure-storage-impl/src/test/java/com/duckduckgo/securestorage/impl/RealL2DataTransformerTest.kt b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/securestorage/RealL2DataTransformerTest.kt similarity index 92% rename from secure-storage/secure-storage-impl/src/test/java/com/duckduckgo/securestorage/impl/RealL2DataTransformerTest.kt rename to autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/securestorage/RealL2DataTransformerTest.kt index ce976c00529c..f0791d21164c 100644 --- a/secure-storage/secure-storage-impl/src/test/java/com/duckduckgo/securestorage/impl/RealL2DataTransformerTest.kt +++ b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/securestorage/RealL2DataTransformerTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 DuckDuckGo + * Copyright (c) 2023 DuckDuckGo * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,10 @@ * limitations under the License. */ -package com.duckduckgo.securestorage.impl +package com.duckduckgo.securestorage +import com.duckduckgo.autofill.impl.securestorage.RealL2DataTransformer +import com.duckduckgo.autofill.impl.securestorage.SecureStorageKeyProvider import java.security.Key import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse diff --git a/secure-storage/secure-storage-impl/src/test/java/com/duckduckgo/securestorage/impl/RealSecureStorageKeyGeneratorTest.kt b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/securestorage/RealSecureStorageKeyGeneratorTest.kt similarity index 92% rename from secure-storage/secure-storage-impl/src/test/java/com/duckduckgo/securestorage/impl/RealSecureStorageKeyGeneratorTest.kt rename to autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/securestorage/RealSecureStorageKeyGeneratorTest.kt index faedb8338d26..6c7bad8dfce0 100644 --- a/secure-storage/secure-storage-impl/src/test/java/com/duckduckgo/securestorage/impl/RealSecureStorageKeyGeneratorTest.kt +++ b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/securestorage/RealSecureStorageKeyGeneratorTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 DuckDuckGo + * Copyright (c) 2023 DuckDuckGo * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,11 @@ * limitations under the License. */ -package com.duckduckgo.securestorage.impl +package com.duckduckgo.securestorage import com.duckduckgo.appbuildconfig.api.AppBuildConfig +import com.duckduckgo.autofill.impl.securestorage.DerivedKeySecretFactory +import com.duckduckgo.autofill.impl.securestorage.RealSecureStorageKeyGenerator import java.security.Key import org.junit.Assert.* import org.junit.Before diff --git a/secure-storage/secure-storage-impl/src/test/java/com/duckduckgo/securestorage/impl/RealSecureStorageKeyProviderTest.kt b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/securestorage/RealSecureStorageKeyProviderTest.kt similarity index 96% rename from secure-storage/secure-storage-impl/src/test/java/com/duckduckgo/securestorage/impl/RealSecureStorageKeyProviderTest.kt rename to autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/securestorage/RealSecureStorageKeyProviderTest.kt index 8c159fec5080..cc1aa84bf32e 100644 --- a/secure-storage/secure-storage-impl/src/test/java/com/duckduckgo/securestorage/impl/RealSecureStorageKeyProviderTest.kt +++ b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/securestorage/RealSecureStorageKeyProviderTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 DuckDuckGo + * Copyright (c) 2023 DuckDuckGo * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,9 @@ * limitations under the License. */ -package com.duckduckgo.securestorage.impl +package com.duckduckgo.securestorage +import com.duckduckgo.autofill.impl.securestorage.RealSecureStorageKeyProvider import com.duckduckgo.securestorage.impl.encryption.RandomBytesGenerator import java.security.Key import okio.ByteString.Companion.toByteString diff --git a/secure-storage/secure-storage-impl/src/test/java/com/duckduckgo/securestorage/impl/RealSecureStorageTest.kt b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/securestorage/RealSecureStorageTest.kt similarity index 95% rename from secure-storage/secure-storage-impl/src/test/java/com/duckduckgo/securestorage/impl/RealSecureStorageTest.kt rename to autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/securestorage/RealSecureStorageTest.kt index 908ed24aeb43..75f1f83111d0 100644 --- a/secure-storage/secure-storage-impl/src/test/java/com/duckduckgo/securestorage/impl/RealSecureStorageTest.kt +++ b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/securestorage/RealSecureStorageTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 DuckDuckGo + * Copyright (c) 2023 DuckDuckGo * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,14 +14,13 @@ * limitations under the License. */ -package com.duckduckgo.securestorage.impl +package com.duckduckgo.autofill.impl.securestorage import app.cash.turbine.test +import com.duckduckgo.autofill.impl.securestorage.encryption.EncryptionHelper.EncryptedString import com.duckduckgo.common.test.CoroutineTestRule -import com.duckduckgo.securestorage.api.WebsiteLoginDetails -import com.duckduckgo.securestorage.api.WebsiteLoginDetailsWithCredentials -import com.duckduckgo.securestorage.impl.encryption.EncryptionHelper.EncryptedString import com.duckduckgo.securestorage.store.SecureStorageRepository +import com.duckduckgo.securestorage.store.SecureStorageRepository.Factory import com.duckduckgo.securestorage.store.db.WebsiteLoginCredentialsEntity import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.MutableStateFlow @@ -86,7 +85,7 @@ class RealSecureStorageTest { EncryptedString(expectedEncryptedData, expectedEncryptedIv), ) testee = RealSecureStorage( - object : SecureStorageRepository.Factory { + object : Factory { override fun get(): SecureStorageRepository = secureStorageRepository }, coroutineRule.testDispatcherProvider, @@ -256,7 +255,7 @@ class RealSecureStorageTest { private fun setUpNoSecureStorageRepository() { testee = RealSecureStorage( - object : SecureStorageRepository.Factory { + object : Factory { override fun get(): SecureStorageRepository? = null }, coroutineRule.testDispatcherProvider, diff --git a/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/sharedcreds/AppleSharedCredentialsParserTest.kt b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/sharedcreds/AppleSharedCredentialsParserTest.kt similarity index 71% rename from autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/sharedcreds/AppleSharedCredentialsParserTest.kt rename to autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/sharedcreds/AppleSharedCredentialsParserTest.kt index 38b274b6c524..e965d2167b62 100644 --- a/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/sharedcreds/AppleSharedCredentialsParserTest.kt +++ b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/sharedcreds/AppleSharedCredentialsParserTest.kt @@ -1,7 +1,21 @@ -package com.duckduckgo.autofill.sharedcreds +/* + * Copyright (c) 2023 DuckDuckGo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.duckduckgo.autofill.impl.sharedcreds -import com.duckduckgo.autofill.impl.sharedcreds.AppleSharedCredentialsParser -import com.duckduckgo.autofill.impl.sharedcreds.SharedCredentialJsonReader import com.duckduckgo.autofill.impl.sharedcreds.SharedCredentialsParser.SharedCredentialConfig import com.duckduckgo.autofill.impl.urlmatcher.AutofillUrlMatcher import com.duckduckgo.common.test.CoroutineTestRule diff --git a/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/sharedcreds/RealShareableCredentialsUrlGeneratorTest.kt b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/sharedcreds/RealShareableCredentialsUrlGeneratorTest.kt similarity index 92% rename from autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/sharedcreds/RealShareableCredentialsUrlGeneratorTest.kt rename to autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/sharedcreds/RealShareableCredentialsUrlGeneratorTest.kt index 67d5e7fc8fba..f4dcfe432a35 100644 --- a/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/sharedcreds/RealShareableCredentialsUrlGeneratorTest.kt +++ b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/sharedcreds/RealShareableCredentialsUrlGeneratorTest.kt @@ -1,9 +1,23 @@ -package com.duckduckgo.autofill.sharedcreds +/* + * Copyright (c) 2023 DuckDuckGo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.duckduckgo.autofill.impl.sharedcreds import androidx.test.ext.junit.runners.AndroidJUnit4 import com.duckduckgo.autofill.impl.encoding.TestUrlUnicodeNormalizer -import com.duckduckgo.autofill.impl.sharedcreds.RealShareableCredentialsUrlGenerator -import com.duckduckgo.autofill.impl.sharedcreds.SharedCredentialsParser import com.duckduckgo.autofill.impl.sharedcreds.SharedCredentialsParser.OmnidirectionalRule import com.duckduckgo.autofill.impl.sharedcreds.SharedCredentialsParser.SharedCredentialConfig import com.duckduckgo.autofill.impl.sharedcreds.SharedCredentialsParser.UnidirectionalRule diff --git a/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/sync/CredentialsFixtures.kt b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/sync/CredentialsFixtures.kt index ec430758e6ae..2051e4ff5777 100644 --- a/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/sync/CredentialsFixtures.kt +++ b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/sync/CredentialsFixtures.kt @@ -17,8 +17,8 @@ package com.duckduckgo.autofill.sync import com.duckduckgo.autofill.api.domain.app.LoginCredentials -import com.duckduckgo.securestorage.api.WebsiteLoginDetails -import com.duckduckgo.securestorage.api.WebsiteLoginDetailsWithCredentials +import com.duckduckgo.autofill.impl.securestorage.WebsiteLoginDetails +import com.duckduckgo.autofill.impl.securestorage.WebsiteLoginDetailsWithCredentials object CredentialsFixtures { val twitterCredentials = LoginCredentials( diff --git a/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/sync/CredentialsSyncTest.kt b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/sync/CredentialsSyncTest.kt index c532d67bdaac..e486a7b1cf3e 100644 --- a/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/sync/CredentialsSyncTest.kt +++ b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/sync/CredentialsSyncTest.kt @@ -18,14 +18,14 @@ package com.duckduckgo.autofill.sync import androidx.test.ext.junit.runners.AndroidJUnit4 import com.duckduckgo.autofill.api.domain.app.LoginCredentials +import com.duckduckgo.autofill.impl.securestorage.WebsiteLoginDetails +import com.duckduckgo.autofill.impl.securestorage.WebsiteLoginDetailsWithCredentials import com.duckduckgo.autofill.store.CredentialsSyncMetadataEntity import com.duckduckgo.autofill.sync.CredentialsFixtures.spotifyCredentials import com.duckduckgo.autofill.sync.CredentialsFixtures.toLoginCredentials import com.duckduckgo.autofill.sync.CredentialsFixtures.twitterCredentials import com.duckduckgo.autofill.sync.provider.LoginCredentialEntry import com.duckduckgo.common.utils.formatters.time.DatabaseDateFormatter -import com.duckduckgo.securestorage.api.WebsiteLoginDetails -import com.duckduckgo.securestorage.api.WebsiteLoginDetailsWithCredentials import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.runTest diff --git a/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/sync/FakeSecureStorage.kt b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/sync/FakeSecureStorage.kt index be20ddbdbcfa..310fa78d9bf7 100644 --- a/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/sync/FakeSecureStorage.kt +++ b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/sync/FakeSecureStorage.kt @@ -16,9 +16,9 @@ package com.duckduckgo.autofill.sync -import com.duckduckgo.securestorage.api.SecureStorage -import com.duckduckgo.securestorage.api.WebsiteLoginDetails -import com.duckduckgo.securestorage.api.WebsiteLoginDetailsWithCredentials +import com.duckduckgo.autofill.impl.securestorage.SecureStorage +import com.duckduckgo.autofill.impl.securestorage.WebsiteLoginDetails +import com.duckduckgo.autofill.impl.securestorage.WebsiteLoginDetailsWithCredentials import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flowOf diff --git a/autofill/autofill-store/build.gradle b/autofill/autofill-store/build.gradle index 5ee79484a8bb..bdcc7c7cb779 100644 --- a/autofill/autofill-store/build.gradle +++ b/autofill/autofill-store/build.gradle @@ -9,12 +9,14 @@ apply from: "$rootProject.projectDir/gradle/android-library.gradle" dependencies { implementation project(path: ':common-utils') implementation project(path: ':autofill-api') - implementation project(path: ':secure-storage-api') implementation project(path: ':privacy-config-api') implementation project(path: ':feature-toggles-api') implementation project(path: ':app-build-config-api') implementation project(path: ':browser-api') + implementation AndroidX.security.crypto + implementation Square.okio + implementation AndroidX.core.ktx implementation AndroidX.appCompat implementation KotlinX.coroutines.core diff --git a/secure-storage/secure-storage-store/schemas/com.duckduckgo.securestorage.store.db.SecureStorageDatabase/1.json b/autofill/autofill-store/schemas/com.duckduckgo.securestorage.store.db.SecureStorageDatabase/1.json similarity index 100% rename from secure-storage/secure-storage-store/schemas/com.duckduckgo.securestorage.store.db.SecureStorageDatabase/1.json rename to autofill/autofill-store/schemas/com.duckduckgo.securestorage.store.db.SecureStorageDatabase/1.json diff --git a/secure-storage/secure-storage-store/schemas/com.duckduckgo.securestorage.store.db.SecureStorageDatabase/2.json b/autofill/autofill-store/schemas/com.duckduckgo.securestorage.store.db.SecureStorageDatabase/2.json similarity index 100% rename from secure-storage/secure-storage-store/schemas/com.duckduckgo.securestorage.store.db.SecureStorageDatabase/2.json rename to autofill/autofill-store/schemas/com.duckduckgo.securestorage.store.db.SecureStorageDatabase/2.json diff --git a/secure-storage/secure-storage-store/schemas/com.duckduckgo.securestorage.store.db.SecureStorageDatabase/3.json b/autofill/autofill-store/schemas/com.duckduckgo.securestorage.store.db.SecureStorageDatabase/3.json similarity index 100% rename from secure-storage/secure-storage-store/schemas/com.duckduckgo.securestorage.store.db.SecureStorageDatabase/3.json rename to autofill/autofill-store/schemas/com.duckduckgo.securestorage.store.db.SecureStorageDatabase/3.json diff --git a/secure-storage/secure-storage-store/src/main/java/com/duckduckgo/securestorage/store/SecureStorageKeyRepository.kt b/autofill/autofill-store/src/main/java/com/duckduckgo/securestorage/store/SecureStorageKeyRepository.kt similarity index 100% rename from secure-storage/secure-storage-store/src/main/java/com/duckduckgo/securestorage/store/SecureStorageKeyRepository.kt rename to autofill/autofill-store/src/main/java/com/duckduckgo/securestorage/store/SecureStorageKeyRepository.kt diff --git a/secure-storage/secure-storage-store/src/main/java/com/duckduckgo/securestorage/store/SecureStorageRepository.kt b/autofill/autofill-store/src/main/java/com/duckduckgo/securestorage/store/SecureStorageRepository.kt similarity index 100% rename from secure-storage/secure-storage-store/src/main/java/com/duckduckgo/securestorage/store/SecureStorageRepository.kt rename to autofill/autofill-store/src/main/java/com/duckduckgo/securestorage/store/SecureStorageRepository.kt diff --git a/secure-storage/secure-storage-store/src/main/java/com/duckduckgo/securestorage/store/db/SecureStorageDatabase.kt b/autofill/autofill-store/src/main/java/com/duckduckgo/securestorage/store/db/SecureStorageDatabase.kt similarity index 100% rename from secure-storage/secure-storage-store/src/main/java/com/duckduckgo/securestorage/store/db/SecureStorageDatabase.kt rename to autofill/autofill-store/src/main/java/com/duckduckgo/securestorage/store/db/SecureStorageDatabase.kt diff --git a/secure-storage/secure-storage-store/src/main/java/com/duckduckgo/securestorage/store/db/WebsiteLoginCredentialsDao.kt b/autofill/autofill-store/src/main/java/com/duckduckgo/securestorage/store/db/WebsiteLoginCredentialsDao.kt similarity index 100% rename from secure-storage/secure-storage-store/src/main/java/com/duckduckgo/securestorage/store/db/WebsiteLoginCredentialsDao.kt rename to autofill/autofill-store/src/main/java/com/duckduckgo/securestorage/store/db/WebsiteLoginCredentialsDao.kt diff --git a/secure-storage/secure-storage-store/src/main/java/com/duckduckgo/securestorage/store/db/WebsiteLoginCredentialsEntity.kt b/autofill/autofill-store/src/main/java/com/duckduckgo/securestorage/store/db/WebsiteLoginCredentialsEntity.kt similarity index 100% rename from secure-storage/secure-storage-store/src/main/java/com/duckduckgo/securestorage/store/db/WebsiteLoginCredentialsEntity.kt rename to autofill/autofill-store/src/main/java/com/duckduckgo/securestorage/store/db/WebsiteLoginCredentialsEntity.kt diff --git a/secure-storage/secure-storage-store/src/main/java/com/duckduckgo/securestorage/store/keys/SecureStorageKeyStore.kt b/autofill/autofill-store/src/main/java/com/duckduckgo/securestorage/store/keys/SecureStorageKeyStore.kt similarity index 100% rename from secure-storage/secure-storage-store/src/main/java/com/duckduckgo/securestorage/store/keys/SecureStorageKeyStore.kt rename to autofill/autofill-store/src/main/java/com/duckduckgo/securestorage/store/keys/SecureStorageKeyStore.kt diff --git a/secure-storage/secure-storage-store/src/test/java/com/duckduckgo/securestorage/store/RealSecureStorageKeyRepositoryTest.kt b/autofill/autofill-store/src/test/java/com.duckduckgo.autofill.store/RealSecureStorageKeyRepositoryTest.kt similarity index 96% rename from secure-storage/secure-storage-store/src/test/java/com/duckduckgo/securestorage/store/RealSecureStorageKeyRepositoryTest.kt rename to autofill/autofill-store/src/test/java/com.duckduckgo.autofill.store/RealSecureStorageKeyRepositoryTest.kt index 201e73de128e..db232bc111b2 100644 --- a/secure-storage/secure-storage-store/src/test/java/com/duckduckgo/securestorage/store/RealSecureStorageKeyRepositoryTest.kt +++ b/autofill/autofill-store/src/test/java/com.duckduckgo.autofill.store/RealSecureStorageKeyRepositoryTest.kt @@ -14,8 +14,9 @@ * limitations under the License. */ -package com.duckduckgo.securestorage.store +package com.duckduckgo.autofill.store +import com.duckduckgo.securestorage.store.RealSecureStorageKeyRepository import com.duckduckgo.securestorage.store.keys.SecureStorageKeyStore import org.junit.Assert.assertEquals import org.junit.Before diff --git a/secure-storage/secure-storage-store/src/test/java/com/duckduckgo/securestorage/store/RealSecureStorageRepositoryTest.kt b/autofill/autofill-store/src/test/java/com.duckduckgo.autofill.store/RealSecureStorageRepositoryTest.kt similarity index 96% rename from secure-storage/secure-storage-store/src/test/java/com/duckduckgo/securestorage/store/RealSecureStorageRepositoryTest.kt rename to autofill/autofill-store/src/test/java/com.duckduckgo.autofill.store/RealSecureStorageRepositoryTest.kt index abdf7e16207f..978a25348a2c 100644 --- a/secure-storage/secure-storage-store/src/test/java/com/duckduckgo/securestorage/store/RealSecureStorageRepositoryTest.kt +++ b/autofill/autofill-store/src/test/java/com.duckduckgo.autofill.store/RealSecureStorageRepositoryTest.kt @@ -14,12 +14,12 @@ * limitations under the License. */ -package com.duckduckgo.securestorage.store +package com.duckduckgo.autofill.store -import androidx.arch.core.executor.testing.InstantTaskExecutorRule import androidx.room.Room import androidx.test.ext.junit.runners.AndroidJUnit4 import com.duckduckgo.common.test.CoroutineTestRule +import com.duckduckgo.securestorage.store.RealSecureStorageRepository import com.duckduckgo.securestorage.store.db.SecureStorageDatabase import com.duckduckgo.securestorage.store.db.WebsiteLoginCredentialsDao import com.duckduckgo.securestorage.store.db.WebsiteLoginCredentialsEntity @@ -46,10 +46,6 @@ class RealSecureStorageRepositoryTest { @Suppress("unused") val coroutineRule = CoroutineTestRule() - @get:Rule - @Suppress("unused") - var instantTaskExecutorRule = InstantTaskExecutorRule() - private lateinit var db: SecureStorageDatabase private lateinit var dao: WebsiteLoginCredentialsDao diff --git a/secure-storage/readme.md b/secure-storage/readme.md deleted file mode 100644 index 41a1375e3f4b..000000000000 --- a/secure-storage/readme.md +++ /dev/null @@ -1,14 +0,0 @@ -# Secure Storage - -Secure storage is responsible for storing and retrieving sensitive data, such as logins, on the device using encryption. - -While the vast majority of devices support secure storage, there are some which don't. -The secure storage APIs provide the capability to check if secure storage can be used on this device. -If a feature relies on secure storage, but it's not available, it is the feature's responsibility to handle this gracefully. - -## Who can help you better understand this feature? -- Craig Russell -- Karl Dimla - -## More information -- [Asana: documentation](https://app.asana.com/0/0/1202486288441738/f) \ No newline at end of file diff --git a/secure-storage/secure-storage-api/.gitignore b/secure-storage/secure-storage-api/.gitignore deleted file mode 100644 index 42afabfd2abe..000000000000 --- a/secure-storage/secure-storage-api/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/secure-storage/secure-storage-api/build.gradle b/secure-storage/secure-storage-api/build.gradle deleted file mode 100644 index 6bd2f617fd56..000000000000 --- a/secure-storage/secure-storage-api/build.gradle +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2022 DuckDuckGo - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -plugins { - id 'com.android.library' - id 'kotlin-android' -} - -apply from: "$rootProject.projectDir/gradle/android-library.gradle" - -dependencies { - implementation KotlinX.coroutines.core -} -android { - namespace 'com.duckduckgo.securestorage.api' -} diff --git a/secure-storage/secure-storage-api/src/main/java/com/duckduckgo/securestorage/api/SecureStorage.kt b/secure-storage/secure-storage-api/src/main/java/com/duckduckgo/securestorage/api/SecureStorage.kt deleted file mode 100644 index b825f8eae150..000000000000 --- a/secure-storage/secure-storage-api/src/main/java/com/duckduckgo/securestorage/api/SecureStorage.kt +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2022 DuckDuckGo - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.duckduckgo.securestorage.api - -import kotlinx.coroutines.flow.Flow - -/** Public API for the secure storage feature */ -interface SecureStorage { - - /** - * This method can be used to check if the secure storage has been instantiated properly. - * - * @return `true` if all dependencies of SecureStorage have been instantiated properly otherwise `false` - */ - fun canAccessSecureStorage(): Boolean - - /** - * This method adds a raw plaintext [WebsiteLoginDetailsWithCredentials] into the [SecureStorage]. If [canAccessSecureStorage] is false when - * this is invoked, nothing will be done. - * - * @throws [SecureStorageException] if something went wrong while trying to perform the action. See type to get more info on the cause. - * @return The saved credential if it saved successfully, otherwise null - */ - @Throws(SecureStorageException::class) - suspend fun addWebsiteLoginDetailsWithCredentials( - websiteLoginDetailsWithCredentials: WebsiteLoginDetailsWithCredentials, - ): WebsiteLoginDetailsWithCredentials? - - /** - * This method returns all [WebsiteLoginDetails] with the [domain] stored in the [SecureStorage]. - * Only L1 encrypted data is returned by these function. This is best use when the need is only to access non-sensitive data. - * If [canAccessSecureStorage] is false when this is invoked, an empty flow will be emitted. - * - * @return Flow> a flow emitting a List of plain text WebsiteLoginDetails stored in SecureStorage. - */ - suspend fun websiteLoginDetailsForDomain(domain: String): Flow> - - /** - * This method returns all [WebsiteLoginDetails] stored in the [SecureStorage]. - * Only L1 encrypted data is returned by these function. This is best use when the need is only to access non-sensitive data. - * If [canAccessSecureStorage] is false when this is invoked, an empty flow will be emitted. - * - * @return Flow> a flow containing a List of plain text WebsiteLoginDetails stored in SecureStorage. - */ - suspend fun websiteLoginDetails(): Flow> - - /** - * This method returns the [WebsiteLoginDetailsWithCredentials] with the [id] stored in the [SecureStorage]. - * This returns decrypted sensitive data (encrypted in L2). Use this only when sensitive data is needed to be accessed. - * If [canAccessSecureStorage] is false when this is invoked, null will be returned. - * - * @return [WebsiteLoginDetailsWithCredentials] containing the plaintext password - * @throws [SecureStorageException] if something went wrong while trying to perform the action. See type to get more info on the cause. - */ - @Throws(SecureStorageException::class) - suspend fun getWebsiteLoginDetailsWithCredentials(id: Long): WebsiteLoginDetailsWithCredentials? - - /** - * This method returns the [WebsiteLoginDetailsWithCredentials] with the [domain] stored in the [SecureStorage]. - * This returns decrypted sensitive data (encrypted in L2). Use this only when sensitive data is needed to be accessed. - * If [canAccessSecureStorage] is false when this is invoked, an empty flow will be emitted. - * - * @return Flow> a flow emitting a List of plain text WebsiteLoginDetailsWithCredentials stored - * in SecureStorage containing the plaintext password - * @throws [SecureStorageException] if something went wrong while trying to perform the action. See type to get more info on the cause. - */ - @Throws(SecureStorageException::class) - suspend fun websiteLoginDetailsWithCredentialsForDomain(domain: String): Flow> - - /** - * This method returns all the [WebsiteLoginDetailsWithCredentials] stored in the [SecureStorage]. - * This returns decrypted sensitive data (encrypted in L2). Use this only when sensitive data is needed to be accessed. - * If [canAccessSecureStorage] is false when this is invoked, an empty flow will be emitted. - * - * @return Flow> a flow emitting a List of plain text WebsiteLoginDetailsWithCredentials stored - * in SecureStorage containing the plaintext password - * @throws [SecureStorageException] if something went wrong while trying to perform the action. See type to get more info on the cause. - */ - @Throws(SecureStorageException::class) - suspend fun websiteLoginDetailsWithCredentials(): Flow> - - /** - * This method updates an existing [WebsiteLoginDetailsWithCredentials] in the [SecureStorage]. - * If [canAccessSecureStorage] is false when this is invoked, nothing will be done. - * - * @throws [SecureStorageException] if something went wrong while trying to perform the action. See type to get more info on the cause. - * @return The updated credential if it saved successfully, otherwise null - */ - @Throws(SecureStorageException::class) - suspend fun updateWebsiteLoginDetailsWithCredentials( - websiteLoginDetailsWithCredentials: WebsiteLoginDetailsWithCredentials, - ): WebsiteLoginDetailsWithCredentials? - - /** - * This method removes an existing [WebsiteLoginDetailsWithCredentials] associated with an [id] from the [SecureStorage]. - * If [canAccessSecureStorage] is false when this is invoked, nothing will be done. - */ - suspend fun deleteWebsiteLoginDetailsWithCredentials(id: Long) -} diff --git a/secure-storage/secure-storage-impl/.gitignore b/secure-storage/secure-storage-impl/.gitignore deleted file mode 100644 index 42afabfd2abe..000000000000 --- a/secure-storage/secure-storage-impl/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/secure-storage/secure-storage-impl/build.gradle b/secure-storage/secure-storage-impl/build.gradle deleted file mode 100644 index 874368a1d578..000000000000 --- a/secure-storage/secure-storage-impl/build.gradle +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2022 DuckDuckGo - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -plugins { - id 'com.android.library' - id 'kotlin-android' - id 'com.squareup.anvil' -} - -apply from: "$rootProject.projectDir/gradle/android-library.gradle" - -dependencies { - implementation project(path: ':app-build-config-api') - implementation project(path: ':common-utils') - implementation project(path: ':di') - implementation project(path: ':secure-storage-api') - implementation project(path: ':secure-storage-store') - - implementation AndroidX.room.ktx - implementation Google.dagger - implementation KotlinX.coroutines.core - implementation Square.okio - - implementation "net.zetetic:android-database-sqlcipher:_" - - testImplementation CashApp.turbine - testImplementation project(path: ':common-test') - testImplementation Testing.junit4 - testImplementation "org.mockito.kotlin:mockito-kotlin:_" - testImplementation (KotlinX.coroutines.test) { - // https://github.com/Kotlin/kotlinx.coroutines/issues/2023 - // conflicts with mockito due to direct inclusion of byte buddy - exclude group: "org.jetbrains.kotlinx", module: "kotlinx-coroutines-debug" - } -} - -android { - anvil { - generateDaggerFactories = true // default is false - } - namespace 'com.duckduckgo.securestorage.impl' -} \ No newline at end of file diff --git a/secure-storage/secure-storage-store/.gitignore b/secure-storage/secure-storage-store/.gitignore deleted file mode 100644 index 42afabfd2abe..000000000000 --- a/secure-storage/secure-storage-store/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/secure-storage/secure-storage-store/build.gradle b/secure-storage/secure-storage-store/build.gradle deleted file mode 100644 index 8be38408f394..000000000000 --- a/secure-storage/secure-storage-store/build.gradle +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2022 DuckDuckGo - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -plugins { - id 'com.android.library' - id 'kotlin-android' - id 'com.google.devtools.ksp' version "$ksp_version" -} - -apply from: "$rootProject.projectDir/gradle/android-library.gradle" - -android { - defaultConfig { - javaCompileOptions { - annotationProcessorOptions { - arguments = ["room.schemaLocation": "$projectDir/schemas".toString()] - } - } - } - namespace 'com.duckduckgo.securestorage.store' -} - -dependencies { - implementation AndroidX.core.ktx - implementation AndroidX.room.ktx - implementation AndroidX.security.crypto - implementation Square.okio - - ksp AndroidX.room.compiler - - testImplementation Testing.junit4 - testImplementation project(path: ':common-test') - testImplementation Testing.robolectric - testImplementation AndroidX.archCore.testing - testImplementation AndroidX.test.ext.junit - testImplementation "org.mockito.kotlin:mockito-kotlin:_" - testImplementation (KotlinX.coroutines.test) { - // https://github.com/Kotlin/kotlinx.coroutines/issues/2023 - // conflicts with mockito due to direct inclusion of byte buddy - exclude group: "org.jetbrains.kotlinx", module: "kotlinx-coroutines-debug" - } -} \ No newline at end of file