diff --git a/build.gradle b/build.gradle index 2226ca11..c11c54e1 100644 --- a/build.gradle +++ b/build.gradle @@ -34,23 +34,23 @@ buildscript { ext.versions = [ // Virgil - virgilSdk : '5.1.1', - virgilCrypto: '0.7.1', - pythia : '0.3.0', - keyknox : '0.2.0', + virgilSdk : '5.1.2', + virgilCrypto: '0.8.0', + pythia : '0.3.1', + keyknox : '0.2.1', // Kotlin - kotlin : '1.3.31', + kotlin : '1.3.40', coroutines : '1.3.0-M1', // Gradle - gardle : '3.4.1', + gardle : '3.4.2', // Android android : '4.1.1.4', // Docs - dokka : '0.9.17', + dokka : '0.9.18', // Tests junit : '4.12', @@ -85,9 +85,8 @@ task clean(type: Delete) { // Default value is ALL enum ArtifactType { ALL, - ALL_WITHOUT_COMMON, - STANDARD, - COROUTINES + COMMON, + STANDARD } static String getArtifactType(Project project) { @@ -116,13 +115,11 @@ task installEthree() { } if (artifactType == ArtifactType.STANDARD) { - dependsOn ':ethree-common:publishToMavenLocal', ':ethree-kotlin:publishToMavenLocal' - } else if (artifactType == ArtifactType.COROUTINES) { - dependsOn ':ethree-common:publishToMavenLocal', ':ethree-kotlin-coroutines:publishToMavenLocal' + dependsOn ':ethree-kotlin:publishToMavenLocal' } else if (artifactType == ArtifactType.ALL) { - dependsOn ':ethree-common:publishToMavenLocal', ':ethree-kotlin:publishToMavenLocal', ':ethree-kotlin-coroutines:publishToMavenLocal' - } else if (artifactType == ArtifactType.ALL_WITHOUT_COMMON) { - dependsOn ':ethree-kotlin:publishToMavenLocal', ':ethree-kotlin-coroutines:publishToMavenLocal' + dependsOn ':ethree-common:publishToMavenLocal', ':ethree-kotlin:publishToMavenLocal' + } else if (artifactType == ArtifactType.COMMON) { + dependsOn ':ethree-common:publishToMavenLocal' } else { throw new IllegalArgumentException("Please, choose one of artifacts type: " + ArtifactType.values()) } @@ -138,13 +135,11 @@ task publishEthree() { } if (artifactType == ArtifactType.STANDARD) { - dependsOn ':ethree-common:publish', ':ethree-kotlin:publish' - } else if (artifactType == ArtifactType.COROUTINES) { - dependsOn ':ethree-common:publish', ':ethree-kotlin-coroutines:publish' + dependsOn ':ethree-kotlin:publish' } else if (artifactType == ArtifactType.ALL) { - dependsOn ':ethree-common:publish', ':ethree-kotlin:publish', ':ethree-kotlin-coroutines:publish' - } else if (artifactType == ArtifactType.ALL_WITHOUT_COMMON) { - dependsOn ':ethree-kotlin:publish', ':ethree-kotlin-coroutines:publish' + dependsOn ':ethree-common:publish', ':ethree-kotlin:publish' + } else if (artifactType == ArtifactType.COMMON) { + dependsOn ':ethree-common:publish' } else { throw new IllegalArgumentException("Please, choose one of artifacts type: " + ArtifactType.values()) } diff --git a/ethree-kotlin-coroutines/.gitignore b/ethree-kotlin-coroutines/.gitignore deleted file mode 100644 index 5550d12d..00000000 --- a/ethree-kotlin-coroutines/.gitignore +++ /dev/null @@ -1,175 +0,0 @@ -### Java ### -*.class - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.ear - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - - -### Maven ### -target/ -pom.xml.tag -pom.xml.releaseBackup -pom.xml.versionsBackup -pom.xml.next -release.properties -dependency-reduced-pom.xml -buildNumber.properties -.mvn/timing.properties - -eclipse-aar/ - - -### Gradle ### -.gradle -build/ -gradle-wrapper.jar -gradle-wrapper.properties -gradle.properties - -# Ignore Gradle GUI config -gradle-app.setting - -# Cache of project -.gradletasknamecache - - -### Eclipse ### -*.pydevproject -.metadata -.gradle -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath - -# Eclipse Core -.project - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# CDT-specific -.cproject - -# JDT-specific (Eclipse Java Development Tools) -.classpath - -# Java annotation processor (APT) -.factorypath - -# PDT-specific -.buildpath - -# sbteclipse plugin -.target - -# TeXlipse plugin -.texlipse - -# STS (Spring Tool Suite) -.springBeans - - -### NetBeans ### -nbproject/private/ -build/ -nbbuild/ -dist/ -nbdist/ -nbactions.xml -.nb-gradle/ -.nb-gradle-properties - -### IntelliJ ### -### D ### -# Compiled Object files -*.o -*.obj - -# Compiled Dynamic libraries -#*.so -*.dylib -*.dll - -# Compiled Static libraries -*.a -*.lib - -# Executables -*.exe - -# DUB -.dub -docs.json -__dummy.html - - -### Intellij ### -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm - -*.iml - -## Directory-based project format: -.idea/ -# if you remove the above rule, at least ignore the following: - -# User-specific stuff: -# .idea/workspace.xml -# .idea/tasks.xml -# .idea/dictionaries -# .idea/shelf - -# Sensitive or high-churn files: -# .idea/dataSources.ids -# .idea/dataSources.xml -# .idea/sqlDataSources.xml -# .idea/dynamic.xml -# .idea/uiDesigner.xml - -# Gradle: -# .idea/gradle.xml -# .idea/libraries - -# Mongo Explorer plugin: -# .idea/mongoSettings.xml - -## File-based project format: -*.ipr -*.iws - -## Plugin-specific files: - -# IntelliJ -/out/ -/gen - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -# Project-specific -!crypto/libs/virgil_crypto_java.jar \ No newline at end of file diff --git a/ethree-kotlin-coroutines/README.md b/ethree-kotlin-coroutines/README.md deleted file mode 100644 index 228a7bbe..00000000 --- a/ethree-kotlin-coroutines/README.md +++ /dev/null @@ -1,59 +0,0 @@ -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.virgilsecurity/ethree-kotlin-coroutines/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.virgilsecurity/ethree-kotlin-coroutines) -[![GitHub license](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg)](https://github.com/VirgilSecurity/virgil/blob/master/LICENSE) - -# Deprecated. Please use the regular [`e3kit`](../ethree-kotlin) package. - -## Deprecated. Installation of E3Kit Coroutines - -> Android API 21+ is required. - -For Kotlin (and coroutines) fans we released a special package that returns [`Deferred`](https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/) instead of using callbacks. -It's not intended to use with java. -To use it add next in your `build.gradle`: - -``` - implementation 'com.virgilsecurity:ethree-kotlin-coroutines:' -``` - -The **\** of the SDK can be found in the [Maven Central Repository](https://mvnrepository.com/artifact/com.virgilsecurity/ethree-kotlin-coroutines) or in the header of current readme. - -## Deprecated. Usage - -#### Deprecated. Register User -Use the following lines of code to authenticate a user. - -```kotlin -// initialize E3Kit -val eThree = EThree.initialize(context, tokenCallback).await() -``` - -#### Deprecated. Encrypt & decrypt - -Virgil E3Kit lets you use a user's Private key and his or her Public Keys to sign, then encrypt text. - -```kotlin - -val eThree = EThree.initialize(context) { yourService.getVirgilToken() }.await() - -val keys = eThree.lookupPublicKeys(listOf("AliceUUID", "BobUUID")).await() - -val text = "I was a text, but become a byte array" -val data = text.toByteArray() - -// Encrypt data using user public keys -val encryptedData = eThree.encrypt(data, keys.values.toList()) - -// Encrypt message using user public keys -val encryptedText = eThree.encrypt(text, keys.values.toList()) - -// E3Kit using identity that specified in Jwt provided with *virgilTokenCallback* -val sendersKeys = eThree.lookupPublicKeys(listOf(identityInToken)).await() - -// Decrypt data using senders public key (In this example it's E3Kit current user) -val decryptedData = eThree.decrypt(encryptedData, sendersKeys[identityInToken]) - -// Decrypt data using senders public key (In this example it's E3Kit current user) -val decryptedText = eThree.decrypt(encryptedText, sendersKeys[identityInToken]) -``` - -You can checkout [Tests](https://github.com/VirgilSecurity/virgil-e3kit-kotlin/tree/master/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/interaction) to find out more of usage examples. diff --git a/ethree-kotlin-coroutines/build.gradle b/ethree-kotlin-coroutines/build.gradle deleted file mode 100644 index 1c5df439..00000000 --- a/ethree-kotlin-coroutines/build.gradle +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2015-2019, Virgil Security, Inc. - * - * Lead Maintainer: Virgil Security Inc. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * (1) Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * (2) Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * (3) Neither the name of virgil nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -plugins { - id 'signing' -} - -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' - -apply plugin: 'maven-publish' -apply plugin: 'digital.wup.android-maven-publish' -apply plugin: 'org.jetbrains.dokka' - -android { - compileSdkVersion 28 - buildToolsVersion "28.0.3" - - defaultConfig { - minSdkVersion 21 - targetSdkVersion 28 - consumerProguardFiles 'proguard-rules.txt' - } -} - -group 'com.virgilsecurity' -version '0.4.0' - -dependencies { - // Inner dependencies - api project(':ethree-common') - - // Virgil - api "com.virgilsecurity.sdk:crypto-android:$versions.virgilSdk" - implementation("com.virgilsecurity:pythia:$versions.pythia") { - exclude group: 'com.virgilsecurity.sdk', module: 'crypto' - exclude group: 'com.virgilsecurity.crypto', module: 'common' - exclude group: 'com.virgilsecurity.crypto', module: 'foundation' - exclude group: 'com.virgilsecurity.crypto', module: 'pythia' - } - implementation "com.virgilsecurity.crypto:pythia-android:$versions.virgilCrypto" - implementation("com.virgilsecurity:keyknox:$versions.keyknox") { - exclude group: 'com.virgilsecurity.sdk', module: 'crypto' - exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8' - } - - // Kotlin - implementation "org.jetbrains.kotlin:kotlin-stdlib:$versions.kotlin" - api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$versions.coroutines" - - // Android - compileOnly "com.google.android:android:$versions.android" -} - -task generateVersionVirgilAgent { - outputs.dir "$buildDir/generated" - doFirst { - def versionFile = file("$buildDir/generated/release/com/virgilsecurity/android/ethreecoroutines/build/VersionVirgilAgent.kt") - versionFile.parentFile.mkdirs() - versionFile.text = - """ -package com.virgilsecurity.android.ethreecoroutines.build; - -object VersionVirgilAgent { - const val VERSION = "$project.version" -} -""" - } -} - -project.android.sourceSets.main.java.srcDirs = ["${buildDir}/generated/release/", "src/main/java"] - -tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { - dependsOn(generateVersionVirgilAgent) -} - -sourceCompatibility = "8" -targetCompatibility = "8" - -task sourcesJar(type: Jar) { - from(project.android.sourceSets.main.java) - classifier = 'sources' -} - -task javadocJar(type: Jar, dependsOn: 'dokka') { - from("$buildDir/javadoc") - classifier = 'javadoc' -} - -def authentication_username = hasProperty('authentication_username') ? authentication_username : System.getenv('authentication_username') -def authentication_password = hasProperty('authentication_password') ? authentication_password : System.getenv('authentication_password') - -publishing { - publications { - mavenJava(MavenPublication) { - artifactId = 'ethree-kotlin-coroutines' - artifact javadocJar - artifact sourcesJar - from components.android - - pom { - name = 'Virgil E3Kit Kotlin Coroutines SDK' - description = 'Virgil Security provides an SDK which symplifies work with Virgil services and presents easy to use API for adding security to any application. In a few simple steps you can setup user encryption with multidevice support.' - url = 'https://www.virgilsecurity.com/' - licenses { - license { - name = 'Virgil Security, Inc. license' - url = 'https://github.com/VirgilSecurity/virgil-e3kit-kotlin/blob/master/LICENSE.txt' - } - } - developers { - developer { - id = 'BuddahLD' - name = 'Danylo Oliinyk' - email = 'doliinyk@virgilsecurity.com' - organizationUrl = 'https://github.com/BuddahLD' - } - } - scm { - connection = 'scm:git:https://github.com/VirgilSecurity/virgil-e3kit-kotlin.git' - developerConnection = 'scm:git:git@github.com:VirgilSecurity/virgil-e3kit-kotlin.git' - url = 'https://github.com/VirgilSecurity/virgil-e3kit-kotlin' - } - } - } - } - - repositories { - maven { - def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" - def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots" - url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl - credentials { - username "${authentication_username}" - password "${authentication_password}" - } - } - } -} - -signing { - sign publishing.publications.mavenJava -} - -dokka { - outputFormat = 'html' - outputDirectory = "$buildDir/javadoc" - reportUndocumented = false -} diff --git a/ethree-kotlin-coroutines/proguard-rules.txt b/ethree-kotlin-coroutines/proguard-rules.txt deleted file mode 100644 index 222d6685..00000000 --- a/ethree-kotlin-coroutines/proguard-rules.txt +++ /dev/null @@ -1,29 +0,0 @@ -# ------------ -# --- Gson --- -# ------------ --keepattributes Signature - -# For using GSON @Expose annotation --keepattributes Annotation - -# Gson specific classes --dontwarn sun.misc.** --keep class com.google.gson.stream.** { *; } --keep class com.google.** --dontwarn com.google.** - -# Prevent proguard from stripping interface information from TypeAdapterFactory, -# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter) --keep class * implements com.google.gson.TypeAdapterFactory --keep class * implements com.google.gson.JsonSerializer --keep class * implements com.google.gson.JsonDeserializer - -# ------------------------- -# --- DatatypeConverter --- -# ------------------------- --dontwarn javax.xml.bind.** - -# ----------------------- -# --- Virgil Security --- -# ----------------------- --keep class com.virgilsecurity.crypto.** { *; } \ No newline at end of file diff --git a/ethree-kotlin-coroutines/src/main/AndroidManifest.xml b/ethree-kotlin-coroutines/src/main/AndroidManifest.xml deleted file mode 100644 index e1f75bbe..00000000 --- a/ethree-kotlin-coroutines/src/main/AndroidManifest.xml +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/ethree-kotlin-coroutines/src/main/java/com/virgilsecurity/android/ethreecoroutines/extensions/CoroutineScopeExt.kt b/ethree-kotlin-coroutines/src/main/java/com/virgilsecurity/android/ethreecoroutines/extensions/CoroutineScopeExt.kt deleted file mode 100644 index 534705d9..00000000 --- a/ethree-kotlin-coroutines/src/main/java/com/virgilsecurity/android/ethreecoroutines/extensions/CoroutineScopeExt.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2015-2019, Virgil Security, Inc. - * - * Lead Maintainer: Virgil Security Inc. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * (1) Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * (2) Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * (3) Neither the name of virgil nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package com.virgilsecurity.android.ethreecoroutines.extensions - -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Deferred -import kotlinx.coroutines.async - -/** - * . _ _ - * .| || | _ - * -| || || | Created by: - * .| || || |- Danylo Oliinyk - * ..\_ || | on - * ....| _/ 11/2/18 - * ...-| | \ at Virgil Security - * ....|_|- - */ - -/** - * CoroutineScopeExt - */ - -fun CoroutineScope.asyncWithCatch( - block: suspend CoroutineScope.() -> T, - catch: (suspend (Throwable) -> Nothing)? = null -): Deferred = async { - try { - block() - } catch (throwable: Throwable) { - if (catch != null) - catch(throwable) - else - throw throwable - } -} diff --git a/ethree-kotlin-coroutines/src/main/java/com/virgilsecurity/android/ethreecoroutines/interaction/EThree.kt b/ethree-kotlin-coroutines/src/main/java/com/virgilsecurity/android/ethreecoroutines/interaction/EThree.kt deleted file mode 100644 index bfc4a42b..00000000 --- a/ethree-kotlin-coroutines/src/main/java/com/virgilsecurity/android/ethreecoroutines/interaction/EThree.kt +++ /dev/null @@ -1,560 +0,0 @@ -/* - * Copyright (c) 2015-2019, Virgil Security, Inc. - * - * Lead Maintainer: Virgil Security Inc. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * (1) Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * (2) Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * (3) Neither the name of virgil nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package com.virgilsecurity.android.ethreecoroutines.interaction - -import android.content.Context -import com.virgilsecurity.android.common.data.Const.NO_CONTEXT -import com.virgilsecurity.android.common.data.Const.VIRGIL_BASE_URL -import com.virgilsecurity.android.common.data.Const.VIRGIL_CARDS_SERVICE_PATH -import com.virgilsecurity.android.common.data.local.KeyManagerLocal -import com.virgilsecurity.android.common.data.remote.KeyManagerCloud -import com.virgilsecurity.android.common.exceptions.* -import com.virgilsecurity.android.ethreecoroutines.build.VersionVirgilAgent -import com.virgilsecurity.android.ethreecoroutines.extensions.asyncWithCatch -import com.virgilsecurity.keyknox.exception.DecryptionFailedException -import com.virgilsecurity.keyknox.exception.EntryAlreadyExistsException -import com.virgilsecurity.pythia.brainkey.BrainKey -import com.virgilsecurity.pythia.brainkey.BrainKeyContext -import com.virgilsecurity.pythia.client.VirgilPythiaClient -import com.virgilsecurity.pythia.crypto.VirgilPythiaCrypto -import com.virgilsecurity.sdk.cards.CardManager -import com.virgilsecurity.sdk.cards.validation.VirgilCardVerifier -import com.virgilsecurity.sdk.client.VirgilCardClient -import com.virgilsecurity.sdk.crypto.VirgilCardCrypto -import com.virgilsecurity.sdk.crypto.VirgilCrypto -import com.virgilsecurity.sdk.crypto.VirgilPrivateKey -import com.virgilsecurity.sdk.crypto.VirgilPublicKey -import com.virgilsecurity.sdk.exception.EmptyArgumentException -import com.virgilsecurity.sdk.jwt.Jwt -import com.virgilsecurity.sdk.jwt.accessProviders.CachingJwtProvider -import com.virgilsecurity.sdk.jwt.contract.AccessTokenProvider -import com.virgilsecurity.sdk.storage.DefaultKeyStorage -import com.virgilsecurity.sdk.utils.ConvertionUtils -import kotlinx.coroutines.Deferred -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.async - -/** - * . _ _ - * .| || | _ - * -| || || | Created by: - * .| || || |- Danylo Oliinyk - * ..\_ || | on - * ....| _/ 10/8/18 - * ...-| | \ at Virgil Security - * ....|_|- - */ - -/** - * [EThree] class simplifies work with Virgil Services to easily implement End to End Encrypted - * communication. - */ -class EThree -/** - * @constructor Initializing [CardManager] with provided in [EThree.initialize] callback - * [onGetTokenCallback] using [CachingJwtProvider] also initializing [DefaultKeyStorage] with - * default settings. - */ private constructor(context: Context, private val tokenProvider: AccessTokenProvider) { - - private val virgilCrypto = VirgilCrypto() - private val cardManager: CardManager - private val keyManagerLocal: KeyManagerLocal - private val keyManagerCloud: KeyManagerCloud - - init { - cardManager = VirgilCardCrypto().let { cardCrypto -> - CardManager(cardCrypto, - tokenProvider, - VirgilCardVerifier(cardCrypto, false, false), - VirgilCardClient(VIRGIL_BASE_URL + VIRGIL_CARDS_SERVICE_PATH)) - } - keyManagerLocal = KeyManagerLocal(tokenProvider.getToken(NO_CONTEXT).identity, context) - keyManagerCloud = KeyManagerCloud(currentIdentity(), - tokenProvider, - VersionVirgilAgent.VERSION) - } - - /** - * Publishes the public key in Virgil's Cards Service in case no public key for current - * identity is published yet. Otherwise [RegistrationException] will be thrown. - * - * @throws RegistrationException - * @throws CryptoException - */ - @Synchronized fun register(): Deferred = - GlobalScope.async { - if (cardManager.searchCards(currentIdentity()).isNotEmpty()) - throw RegistrationException("Card with identity " + - "${currentIdentity()} already exists") - - if (keyManagerLocal.exists()) - throw PrivateKeyExistsException("You already have a Private Key on this " + - "device for identity: ${currentIdentity()}. " + - "Please, use \'cleanup()\' function first.") - - virgilCrypto.generateKeyPair().run { - cardManager.publishCard(this.privateKey, - this.publicKey, - currentIdentity()) - - keyManagerLocal.store(virgilCrypto.exportPrivateKey(this.privateKey)) - } - } - - /** - * ! *WARNING* ! If you call this function after [register] without using [backupPrivateKey] - * then you loose private key permanently, as well you won't be able to use identity that - * was used with that private key no more. - * - * Cleans up user's private key from a device - call this function when you want to log your - * user out of the device. - * - * Can be called only if private key is on the device otherwise [PrivateKeyNotFoundException] - * exception will be thrown. - * - * @throws PrivateKeyNotFoundException - */ - fun cleanup() { - checkPrivateKeyOrThrow() - - keyManagerLocal.delete() - } - - /** - * Checks whether the private key is present in the local storage of current device. - * Returns *true* if the key is present in the local key storage otherwise *false*. - */ - fun hasLocalPrivateKey() = keyManagerLocal.exists() - - /** - * Encrypts the user's private key using the user's [password] and backs up the encrypted - * private key to Virgil's cloud. This enables users to log in from other devices and have - * access to their private key to decrypt data. - * - * Encrypts loaded from private keys local storage user's *Private key* using *Public key* - * that is generated based on provided [password] after that backs up encrypted user's - * *Private key* to the Virgil's cloud storage. - * - * Can be called only if private key is on the device otherwise [PrivateKeyNotFoundException] - * exception will be thrown. - * - * @throws PrivateKeyNotFoundException - * @throws BackupKeyException - */ - fun backupPrivateKey(password: String): Deferred = GlobalScope.asyncWithCatch( - { - checkPrivateKeyOrThrow() - - if (password.isBlank()) - throw IllegalArgumentException("\'password\' should not be empty") - - with(keyManagerLocal.load()) { - keyManagerCloud.store(password, - this.value, - this.meta) - .let { Unit } - } - }, - { - if (it is EntryAlreadyExistsException) - throw BackupKeyException("Key with identity ${currentIdentity()} " + - "already backuped.") - else - throw it - }) - - /** - * Deletes the user's private key from Virgil's cloud. - * - * Deletes private key backup using specified [password] and provides [onCompleteListener] - * callback that will notify you with successful completion or with a [Throwable] if - * something went wrong. - * - * Can be called only if private key is on the device otherwise [PrivateKeyNotFoundException] - * exception will be thrown. - * - * @throws PrivateKeyNotFoundException - * @throws WrongPasswordException - */ - fun resetPrivateKeyBackup(password: String? = null): Deferred = GlobalScope.asyncWithCatch( - { - checkPrivateKeyOrThrow() - - if (password == null) { - keyManagerCloud.deleteAll() - } else { - if (password.isBlank()) - throw IllegalArgumentException("\'password\' should not be empty") - - keyManagerCloud.delete(password) - } - Unit - }, - { - if (it is DecryptionFailedException) - throw WrongPasswordException("Specified password is not valid.") - else - throw it - }) - - /** - * Pulls user's private key from the Virgil's cloud, decrypts it with *Private key* that - * is generated based on provided [password] and saves it to the current private keys - * local storage. - * - * @throws WrongPasswordException - * @throws RestoreKeyException - */ - fun restorePrivateKey(password: String): Deferred = GlobalScope.asyncWithCatch( - { - if (keyManagerLocal.exists()) - throw RestoreKeyException("You already have a Private Key on this device" + - "for identity: ${currentIdentity()}. Please, use" + - "\'cleanup()\' function first.") - - if (keyManagerCloud.exists(password)) { - - Thread.sleep(THROTTLE_TIMEOUT) // To avoid next request been throttled - - val keyEntry = keyManagerCloud.retrieve(password) - - keyManagerLocal.store(keyEntry.data) - } else { - throw RestoreKeyException("There is no key backup with " + - "identity: ${currentIdentity()}") - } - }, - { - if (it is DecryptionFailedException) - throw WrongPasswordException("Specified password is not valid.") - else - throw it - }) - - /** - * Generates new key pair, publishes new public key for current identity and deprecating old - * public key, saves private key to the local storage. All data that was encrypted earlier - * will become undecryptable. - * - * @throws PrivateKeyExistsException - * @throws CardNotFoundException - * @throws CryptoException - */ - fun rotatePrivateKey(): Deferred = GlobalScope.async { - if (keyManagerLocal.exists()) - throw PrivateKeyExistsException("You already have a Private Key on this device" + - "for identity: ${currentIdentity()}. Please, use" + - "\'cleanup()\' function first.") - - val cards = cardManager.searchCards(currentIdentity()) - if (cards.isEmpty()) - throw CardNotFoundException("No cards was found " + - "with identity: ${currentIdentity()}") - if (cards.size > 1) - throw IllegalStateException("${cards.size} cards was found " + - "with identity: ${currentIdentity()}. How? (: " + - "Should be <= 1. Please, contact developers if " + - "it was not an intended behaviour.") - - (cards.first() to virgilCrypto.generateKeyPair()).run { - val rawCard = cardManager.generateRawCard(this.second.privateKey, - this.second.publicKey, - currentIdentity(), - this.first.identifier) - cardManager.publishCard(rawCard) - - keyManagerLocal.store(this.second.privateKey.privateKey.exportPrivateKey()) - } - } - - /** - * Changes the password of the private key backup. - * - * Pulls user's private key from the Virgil's cloud storage, decrypts it with *Private key* - * that is generated based on provided [oldPassword] after that encrypts user's *Private key* - * using *Public key* that is generated based on provided [newPassword] and pushes encrypted - * user's *Private key* to the Virgil's cloud storage. - * - * Can be called only if private key is on the device otherwise [PrivateKeyNotFoundException] - * exception will be thrown. - * - * @throws PrivateKeyNotFoundException - */ - fun changePassword(oldPassword: String, - newPassword: String): Deferred = GlobalScope.async { - checkPrivateKeyOrThrow() - - if (oldPassword.isBlank()) - throw IllegalArgumentException("\'oldPassword\' should not be empty") - if (newPassword.isBlank()) - throw IllegalArgumentException("\'newPassword\' should not be empty") - if (newPassword == oldPassword) - throw IllegalArgumentException("\'newPassword\' can't be the same as the old one") - - val brainKeyContext = BrainKeyContext.Builder() - .setAccessTokenProvider(tokenProvider) - .setPythiaClient(VirgilPythiaClient(VIRGIL_BASE_URL)) - .setPythiaCrypto(VirgilPythiaCrypto()) - .build() - - val keyPair = BrainKey(brainKeyContext).generateKeyPair(newPassword) - - Thread.sleep(THROTTLE_TIMEOUT) // To avoid next request been throttled - - keyManagerCloud.updateRecipients(oldPassword, listOf(keyPair.publicKey), keyPair.privateKey) - } - - /** - * Encrypts text messages for a group of users. - * - * Encrypts provided [text] using [publicKeys] list of recipients and returns encrypted - * message converted to *base64* [String]. - * - * Can be called only if private key is on the device otherwise [PrivateKeyNotFoundException] - * exception will be thrown. - * - * @throws PrivateKeyNotFoundException - * @throws CryptoException - */ - fun encrypt(text: String, publicKeys: List? = null): String { - checkPrivateKeyOrThrow() - - if (text.isBlank()) throw EmptyArgumentException("data") - if (publicKeys?.isEmpty() == true) throw EmptyArgumentException("publicKeys") - if (publicKeys?.contains(loadCurrentPublicKey()) == true) - throw IllegalArgumentException("You should not include your own public key.") - - return encrypt(text.toByteArray(), publicKeys).let { ConvertionUtils.toBase64String(it) } - } - - /** - * Encrypts messages/other data for a group of users. - * - * Encrypts provided [data] using [publicKeys] list of recipients and returns encrypted - * data as [ByteArray]. - * - * Can be called only if private key is on the device otherwise [PrivateKeyNotFoundException] - * exception will be thrown. - * - * @throws PrivateKeyNotFoundException - * @throws CryptoException - */ - fun encrypt(data: ByteArray, publicKeys: List? = null): ByteArray { - checkPrivateKeyOrThrow() - - if (data.isEmpty()) throw EmptyArgumentException("data") - if (publicKeys?.isEmpty() == true) throw EmptyArgumentException("publicKeys") - if (publicKeys?.contains(loadCurrentPublicKey()) == true) - throw IllegalArgumentException("You should not include your own public key.") - - return (publicKeys == null).let { isNull -> - (if (isNull) { - listOf(loadCurrentPublicKey()) - } else { - publicKeys?.asSequence()?.filterIsInstance()?.toMutableList() - ?.apply { - add(loadCurrentPublicKey()) - } - }) - }.let { keys -> - virgilCrypto.signThenEncrypt(data, loadCurrentPrivateKey(), keys) - } - } - - /** - * Decrypts encrypted text that is in base64 [String] format. - * - * Decrypts provided [base64String] (that was previously encrypted with [encrypt] function) - * using current user's private key. - * - * Can be called only if private key is on the device otherwise [PrivateKeyNotFoundException] - * exception will be thrown. - * - * @throws PrivateKeyNotFoundException - * @throws CryptoException - */ - fun decrypt(base64String: String, sendersKey: VirgilPublicKey? = null): String { - checkPrivateKeyOrThrow() - - if (base64String.isBlank()) throw EmptyArgumentException("data") - if (sendersKey == loadCurrentPublicKey()) - throw IllegalArgumentException("You should not provide your own public key.") - - return String(decrypt(ConvertionUtils.base64ToBytes(base64String), sendersKey)) - } - - /** - * Decrypts encrypted data. - * - * Decrypts provided [data] using current user's private key and returns decrypted data - * in [ByteArray]. - * - * Can be called only if private key is on the device otherwise [PrivateKeyNotFoundException] - * exception will be thrown. - * - * @throws PrivateKeyNotFoundException - * @throws CryptoException - */ - fun decrypt(data: ByteArray, sendersKey: VirgilPublicKey? = null): ByteArray { - checkPrivateKeyOrThrow() - - if (data.isEmpty()) throw EmptyArgumentException("data") - if (sendersKey == loadCurrentPublicKey()) - throw IllegalArgumentException("You should not provide your own public key.") - - return (sendersKey == null).let { isNull -> - (if (isNull) { - listOf(loadCurrentPublicKey()) - } else { - mutableListOf(sendersKey as VirgilPublicKey).apply { - add(loadCurrentPublicKey()) - } - }) - }.let { keys -> - virgilCrypto.decryptThenVerify( - data, - loadCurrentPrivateKey(), - keys - ) - } - } - - /** - * Retrieves user public keys from the cloud for encryption/verification operations. - * - * Searches for public keys with specified [identities] and returns list of [PublicKey] in - * [onResultListener] callback or [Throwable] if something went wrong. - * - * [PublicKeyNotFoundException] will be thrown for the first not found public key. - * - * Can be called only if private key is on the device otherwise [PrivateKeyNotFoundException] - * exception will be thrown. - * - * @throws PrivateKeyNotFoundException - * @throws PublicKeyDuplicateException - */ - fun lookupPublicKeys(identities: List): Deferred> = // TODO check arrayOf and [] with collections to not write listof() - GlobalScope.async { - if (identities.isEmpty()) throw EmptyArgumentException("identities") - - identities.groupingBy { it } - .eachCount() - .filter { it.value > 1 } - .run { - if (this.isNotEmpty()) - throw PublicKeyDuplicateException("Duplicates are not allowed. " + - "Duplicated identities:\n${this}") - } - - identities.map { - cardManager.searchCards(it) to it - }.map { - if (it.first.size > 1) - throw IllegalStateException("${it.first.size} cards was found with " + - "identity: ${currentIdentity()}. How? (: " + - "Should be <= 1. Please, contact developers " + - "if it was not an intended behaviour.") - else - it - }.map { - it.second to it.first - }.map { - if (it.second.isNotEmpty()) - it.first to it.second.first().publicKey as VirgilPublicKey - else - throw PublicKeyNotFoundException(it.first) - }.toMap() - } - - /** - * Loads and returns current user's [PrivateKey]. Current user's identity is taken - * from [tokenProvider]. - */ - private fun loadCurrentPrivateKey(): VirgilPrivateKey = - keyManagerLocal.load().let { - virgilCrypto.importPrivateKey(it.value).privateKey - } - - /** - * Loads and returns current user's [PublicKey] that is extracted from current - * user's [PrivateKey]. Current user's identity is taken from [tokenProvider]. - */ - private fun loadCurrentPublicKey(): VirgilPublicKey = - virgilCrypto.extractPublicKey(loadCurrentPrivateKey()) - - /** - * Extracts current user's *Identity* from Json Web Token received from [tokenProvider]. - */ - private fun currentIdentity() = tokenProvider.getToken(NO_CONTEXT).identity - - /** - * Checks if private key for current identity is present in local key storage or throws an - * [PrivateKeyNotFoundException] exception. - */ - private fun checkPrivateKeyOrThrow() { - if (!keyManagerLocal.exists()) - throw PrivateKeyNotFoundException("You have to get private key first. Use " + - "\'register\' or \'restorePrivateKey\' functions.") - } - - companion object { - /** - * Current method allows you to initialize EThree helper class. To do this you should - * provide [onGetToken] function that must return Json Web Token string representation - * with identity of the user which will use this class. You will receive instance of - * [EThree] class or an [Throwable] if something went wrong. - */ - @JvmStatic fun initialize(context: Context, - onGetToken: () -> String): Deferred { - val tokenProvider = CachingJwtProvider(CachingJwtProvider.RenewJwtCallback { - Jwt(onGetToken()) - }) - - return GlobalScope.async { - if (tokenProvider.getToken(NO_CONTEXT) != null) - EThree(context, - tokenProvider) - else - throw IllegalStateException("Token is null after successful parsing") - } - } - - - private const val VIRGIL_BASE_URL = "https://api.virgilsecurity.com" - private const val VIRGIL_CARDS_SERVICE_PATH = "/card/v5/" - - private const val THROTTLE_TIMEOUT = 2 * 1000L // 2 seconds - private val NO_CONTEXT = null - } -} diff --git a/ethree-kotlin/build.gradle b/ethree-kotlin/build.gradle index 1d2436d2..bbefa46f 100644 --- a/ethree-kotlin/build.gradle +++ b/ethree-kotlin/build.gradle @@ -55,7 +55,7 @@ android { } group 'com.virgilsecurity' -version '0.5.0' +version '0.5.1' dependencies { // Inner dependencies @@ -126,7 +126,7 @@ def authentication_password = hasProperty('authentication_password') ? authentic publishing { publications { mavenJava(MavenPublication) { - artifactId = 'ethree-kotlin' + artifactId = 'ethree' artifact javadocJar artifact sourcesJar from components.android diff --git a/ethree-kotlin/src/main/java/com/virgilsecurity/android/ethree/kotlin/interaction/EThree.kt b/ethree-kotlin/src/main/java/com/virgilsecurity/android/ethree/kotlin/interaction/EThree.kt index 48970995..4b7c78fc 100644 --- a/ethree-kotlin/src/main/java/com/virgilsecurity/android/ethree/kotlin/interaction/EThree.kt +++ b/ethree-kotlin/src/main/java/com/virgilsecurity/android/ethree/kotlin/interaction/EThree.kt @@ -100,10 +100,40 @@ class EThree VersionVirgilAgent.VERSION) } + companion object { + /** + * Current method allows you to initialize EThree helper class. To do this you + * should provide [onGetTokenCallback] that must return Json Web Token string + * representation with identity of the user which will use this class. + * In [onResultListener] you will receive instance of [EThree] class or an [Throwable] + * if something went wrong. + * + * To start execution of the current function, please see [Result] description. + */ + @JvmStatic fun initialize(context: Context, + onGetTokenCallback: OnGetTokenCallback) = object : Result { + override fun get(): EThree { + val tokenProvider = CachingJwtProvider(CachingJwtProvider.RenewJwtCallback { + Jwt(onGetTokenCallback.onGetToken()) + }) + + // Just check whether we can get token, otherwise there's no reasons to + // initialize EThree. We have caching JWT provider, so sequential calls + // won't take much time, as token will be cached after first call. + tokenProvider.getToken(NO_CONTEXT) + return EThree(context, tokenProvider) + } + } + + private const val THROTTLE_TIMEOUT = 2 * 1000L // 2 seconds + } + /** * Publishes the public key in Virgil's Cards Service in case no public key for current * identity is published yet. Otherwise [RegistrationException] will be thrown. * + * To start execution of the current function, please see [Completable] description. + * * @throws RegistrationException * @throws CryptoException */ @@ -129,6 +159,8 @@ class EThree * Revokes the public key for current *identity* in Virgil's Cards Service. After this operation * you can call [EThree.register] again. * + * To start execution of the current function, please see [Completable] description. + * * @throws UnRegistrationException if there's no public key published yet, or if there's more * than one public key is published. */ @@ -186,6 +218,8 @@ class EThree * Can be called only if private key is on the device otherwise [PrivateKeyNotFoundException] * exception will be thrown. * + * To start execution of the current function, please see [Completable] description. + * * @throws PrivateKeyNotFoundException * @throws BackupKeyException */ @@ -220,6 +254,8 @@ class EThree * Can be called only if private key is on the device otherwise [PrivateKeyNotFoundException] * exception will be thrown. * + * To start execution of the current function, please see [Completable] description. + * * @throws PrivateKeyNotFoundException * @throws WrongPasswordException */ @@ -251,6 +287,8 @@ class EThree * is generated based on provided [password] and saves it to the current private keys * local storage. * + * To start execution of the current function, please see [Completable] description. + * * @throws WrongPasswordException * @throws RestoreKeyException */ @@ -285,6 +323,8 @@ class EThree * public key, saves private key to the local storage. All data that was encrypted earlier * will become undecryptable. * + * To start execution of the current function, please see [Completable] description. + * * @throws PrivateKeyExistsException * @throws CardNotFoundException * @throws CryptoException @@ -329,6 +369,8 @@ class EThree * Can be called only if private key is on the device otherwise [PrivateKeyNotFoundException] * exception will be thrown. * + * To start execution of the current function, please see [Completable] description. + * * @throws PrivateKeyNotFoundException */ fun changePassword(oldPassword: String, @@ -564,10 +606,13 @@ class EThree * [PublicKey] in [onResultListener] callback or [Throwable] if something went wrong. * * [PublicKeyNotFoundException] will be thrown for the first not found public key. + * [EThree.register] * * Can be called only if private key is on the device, otherwise [PrivateKeyNotFoundException] * exception will be thrown. * + * To start execution of the current function, please see [Result] description. + * * @throws PrivateKeyNotFoundException * @throws PublicKeyDuplicateException */ @@ -634,31 +679,4 @@ class EThree "You have to get private key first. Use \'register\' " + "or \'restorePrivateKey\' functions.") } - - companion object { - /** - * Current method allows you to initialize EThree helper class. To do this you - * should provide [onGetTokenCallback] that must return Json Web Token string - * representation with identity of the user which will use this class. - * In [onResultListener] you will receive instance of [EThree] class or an [Throwable] - * if something went wrong. - */ - @JvmStatic fun initialize(context: Context, - onGetTokenCallback: OnGetTokenCallback) = object : Result { - override fun get(): EThree { - val tokenProvider = CachingJwtProvider(CachingJwtProvider.RenewJwtCallback { - Jwt(onGetTokenCallback.onGetToken()) - }) - - // Just check whether we can get token, otherwise there's no reasons to - // initialize EThree. We have caching JWT provider, so sequential calls - // won't take much time, as token will be cached after first call. - tokenProvider.getToken(NO_CONTEXT) - return EThree(context, tokenProvider) - } - } - - // private const val KEYKNOX_KEY_POSTFIX = "_keyknox" - private const val THROTTLE_TIMEOUT = 2 * 1000L // 2 seconds - } } diff --git a/ethree-kotlin/src/main/java/com/virgilsecurity/android/ethree/kotlin/model/Completable.kt b/ethree-kotlin/src/main/java/com/virgilsecurity/android/ethree/kotlin/model/Completable.kt index 6f1677a3..44e853d4 100644 --- a/ethree-kotlin/src/main/java/com/virgilsecurity/android/ethree/kotlin/model/Completable.kt +++ b/ethree-kotlin/src/main/java/com/virgilsecurity/android/ethree/kotlin/model/Completable.kt @@ -39,12 +39,20 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch /** - * Completable + * Completable's class intent is to give possibility to call a completable operation that got only Success or Error + * without actual result *synchronously* or *asynchronously*. */ interface Completable { + /** + * Call this method to complete operation *synchronously*. + */ fun execute() + /** + * Call this method to complete operation *asynchronously*. You'll get the completion status in the + * [onCompleteListener]. Provided [scope] will be used to execute operation. + */ fun addCallback(onCompleteListener: OnCompleteListener, scope: CoroutineScope = GlobalScope) { scope.launch { try { @@ -56,6 +64,10 @@ interface Completable { } } + /** + * Call this method to complete operation *asynchronously*. You'll get the completion status in the + * [onCompleteListener]. + */ fun addCallback(onCompleteListener: OnCompleteListener) = addCallback(onCompleteListener, GlobalScope) diff --git a/ethree-kotlin/src/main/java/com/virgilsecurity/android/ethree/kotlin/model/Result.kt b/ethree-kotlin/src/main/java/com/virgilsecurity/android/ethree/kotlin/model/Result.kt index a5d490e7..5ef724fb 100644 --- a/ethree-kotlin/src/main/java/com/virgilsecurity/android/ethree/kotlin/model/Result.kt +++ b/ethree-kotlin/src/main/java/com/virgilsecurity/android/ethree/kotlin/model/Result.kt @@ -39,12 +39,20 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch /** - * Result + * Result's class intent is to give possibility to call an operation that returns result in Success or Error in case of + * error *synchronously* or *asynchronously*. */ interface Result { + /** + * Call this method to get result *synchronously*. + */ fun get(): T + /** + * Call this method to get result *asynchronously*. You'll get the result of an operation in the + * [onResultListener]. Provided [scope] will be used to execute operation. + */ fun addCallback(onResultListener: OnResultListener, scope: CoroutineScope = GlobalScope) { scope.launch { try { @@ -56,8 +64,10 @@ interface Result { } } + /** + * Call this method to get result *asynchronously*. You'll get the result of an operation in the + * [onResultListener]. + */ fun addCallback(onResultListener: OnResultListener) = addCallback(onResultListener, GlobalScope) - - // TODO check whether we need cancel() } diff --git a/settings.gradle b/settings.gradle index 41504af6..7a3882a4 100644 --- a/settings.gradle +++ b/settings.gradle @@ -31,4 +31,4 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -include ':tests', ':ethree-kotlin', ':ethree-kotlin-coroutines', ':ethree-common', ':testscoroutines' +include ':ethree-common', ':ethree-kotlin', ':tests' diff --git a/tests/src/androidTest/java/com/virgilsecurity/android/ethree/kotlin/interaction/async/EThreeAuthTest.kt b/tests/src/androidTest/java/com/virgilsecurity/android/ethree/kotlin/interaction/async/EThreeAuthTest.kt index ff468c28..ee1d418e 100644 --- a/tests/src/androidTest/java/com/virgilsecurity/android/ethree/kotlin/interaction/async/EThreeAuthTest.kt +++ b/tests/src/androidTest/java/com/virgilsecurity/android/ethree/kotlin/interaction/async/EThreeAuthTest.kt @@ -161,7 +161,8 @@ class EThreeAuthTest { // STE-Auth-8 @Test fun delete_local_key() { val keys = VirgilCrypto().generateKeyPair() - keyStorage.store(JsonKeyEntry(identity, keys.privateKey.privateKey.exportPrivateKey())) + val privateKey = VirgilCrypto().exportPrivateKey(keys.privateKey) + keyStorage.store(JsonKeyEntry(identity, privateKey)) assertTrue(keyStorage.exists(identity)) initEThree(identity).cleanup() assertFalse(keyStorage.exists(identity)) @@ -198,11 +199,9 @@ class EThreeAuthTest { // STE-Auth-11 @Test fun register_with_existing_private_key() { - keyStorage.store(JsonKeyEntry(identity, - virgilCrypto.generateKeyPair() - .privateKey - .privateKey - .exportPrivateKey())) + val privateKeyData = + virgilCrypto.exportPrivateKey(virgilCrypto.generateKeyPair().privateKey) + keyStorage.store(JsonKeyEntry(identity, privateKeyData)) val eThree = initEThree(identity) val waiter = CountDownLatch(1) @@ -281,7 +280,7 @@ class EThreeAuthTest { assertTrue(cardManager.searchCards(identity).last().previousCardId != null) val newKeyData = keyStorage.load(identity).value - val oldKeyData = publishPair.left.privateKey.privateKey.exportPrivateKey() + val oldKeyData = VirgilCrypto().exportPrivateKey(publishPair.left.privateKey) assertThat(oldKeyData, not(equalTo(newKeyData))) } diff --git a/tests/src/androidTest/java/com/virgilsecurity/android/ethree/kotlin/interaction/profile/EThreeProfile.kt b/tests/src/androidTest/java/com/virgilsecurity/android/ethree/kotlin/interaction/profile/EThreeProfile.kt index 6dd28932..c69f05d8 100644 --- a/tests/src/androidTest/java/com/virgilsecurity/android/ethree/kotlin/interaction/profile/EThreeProfile.kt +++ b/tests/src/androidTest/java/com/virgilsecurity/android/ethree/kotlin/interaction/profile/EThreeProfile.kt @@ -37,6 +37,7 @@ import android.os.Debug import com.virgilsecurity.sdk.crypto.VirgilCrypto import com.virgilsecurity.sdk.crypto.VirgilKeyPair import org.junit.Before +import org.junit.Ignore import org.junit.Test import kotlin.random.Random @@ -59,25 +60,25 @@ class EThreeProfile { signature = crypto.generateSignature(oneMbData, keyPair.privateKey) } - @Test fun encrypt_debug_profile() { + @Ignore("Needed only to profile from time to time") @Test fun encrypt_debug_profile() { Debug.startMethodTracing("EThreeProfile_encrypt") crypto.encrypt(oneMbData, keyPair.publicKey) Debug.stopMethodTracing() } - @Test fun decrypt_debug_profile() { + @Ignore("Needed only to profile from time to time") @Test fun decrypt_debug_profile() { Debug.startMethodTracing("EThreeProfile_decrypt") crypto.decrypt(encryptedData, keyPair.privateKey) Debug.stopMethodTracing() } - @Test fun generate_signature_debug_profile() { + @Ignore("Needed only to profile from time to time") @Test fun generate_signature_debug_profile() { Debug.startMethodTracing("EThreeProfile_generate_signature") crypto.generateSignature(oneMbData, keyPair.privateKey) Debug.stopMethodTracing() } - @Test fun verify_signature_debug_profile() { + @Ignore("Needed only to profile from time to time") @Test fun verify_signature_debug_profile() { Debug.startMethodTracing("EThreeProfile_verify_signature") crypto.verifySignature(signature, oneMbData, keyPair.publicKey) Debug.stopMethodTracing() diff --git a/testscoroutines/.gitignore b/testscoroutines/.gitignore deleted file mode 100644 index 5550d12d..00000000 --- a/testscoroutines/.gitignore +++ /dev/null @@ -1,175 +0,0 @@ -### Java ### -*.class - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.ear - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - - -### Maven ### -target/ -pom.xml.tag -pom.xml.releaseBackup -pom.xml.versionsBackup -pom.xml.next -release.properties -dependency-reduced-pom.xml -buildNumber.properties -.mvn/timing.properties - -eclipse-aar/ - - -### Gradle ### -.gradle -build/ -gradle-wrapper.jar -gradle-wrapper.properties -gradle.properties - -# Ignore Gradle GUI config -gradle-app.setting - -# Cache of project -.gradletasknamecache - - -### Eclipse ### -*.pydevproject -.metadata -.gradle -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath - -# Eclipse Core -.project - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# CDT-specific -.cproject - -# JDT-specific (Eclipse Java Development Tools) -.classpath - -# Java annotation processor (APT) -.factorypath - -# PDT-specific -.buildpath - -# sbteclipse plugin -.target - -# TeXlipse plugin -.texlipse - -# STS (Spring Tool Suite) -.springBeans - - -### NetBeans ### -nbproject/private/ -build/ -nbbuild/ -dist/ -nbdist/ -nbactions.xml -.nb-gradle/ -.nb-gradle-properties - -### IntelliJ ### -### D ### -# Compiled Object files -*.o -*.obj - -# Compiled Dynamic libraries -#*.so -*.dylib -*.dll - -# Compiled Static libraries -*.a -*.lib - -# Executables -*.exe - -# DUB -.dub -docs.json -__dummy.html - - -### Intellij ### -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm - -*.iml - -## Directory-based project format: -.idea/ -# if you remove the above rule, at least ignore the following: - -# User-specific stuff: -# .idea/workspace.xml -# .idea/tasks.xml -# .idea/dictionaries -# .idea/shelf - -# Sensitive or high-churn files: -# .idea/dataSources.ids -# .idea/dataSources.xml -# .idea/sqlDataSources.xml -# .idea/dynamic.xml -# .idea/uiDesigner.xml - -# Gradle: -# .idea/gradle.xml -# .idea/libraries - -# Mongo Explorer plugin: -# .idea/mongoSettings.xml - -## File-based project format: -*.ipr -*.iws - -## Plugin-specific files: - -# IntelliJ -/out/ -/gen - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -# Project-specific -!crypto/libs/virgil_crypto_java.jar \ No newline at end of file diff --git a/testscoroutines/build.gradle b/testscoroutines/build.gradle deleted file mode 100644 index dfa85732..00000000 --- a/testscoroutines/build.gradle +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2015-2019, Virgil Security, Inc. - * - * Lead Maintainer: Virgil Security Inc. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * (1) Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * (2) Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * (3) Neither the name of virgil nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' - -def APP_ID = hasProperty('APP_ID') ? APP_ID : System.getenv('APP_ID') -def API_PRIVATE_KEY = hasProperty('API_PRIVATE_KEY') ? API_PRIVATE_KEY : System.getenv('API_PRIVATE_KEY') -def API_PUBLIC_KEY = hasProperty('API_PUBLIC_KEY') ? API_PUBLIC_KEY : System.getenv('API_PUBLIC_KEY') -def API_PUBLIC_KEY_ID = hasProperty('API_PUBLIC_KEY_ID') ? API_PUBLIC_KEY_ID : System.getenv('API_PUBLIC_KEY_ID') -def VIRGIL_BASE_URL = hasProperty('VIRGIL_BASE_URL') ? VIRGIL_BASE_URL : System.getenv('VIRGIL_BASE_URL') - -android { - compileSdkVersion 28 - defaultConfig { - applicationId "com.virgilsecurity.ethree" - minSdkVersion 21 - targetSdkVersion 28 - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } - buildTypes { - buildTypes.each { - it.buildConfigField "String", "APP_ID", "$APP_ID" - it.buildConfigField "String", "API_PRIVATE_KEY", "$API_PRIVATE_KEY" - it.buildConfigField "String", "API_PUBLIC_KEY", "$API_PUBLIC_KEY" - it.buildConfigField "String", "API_PUBLIC_KEY_ID", "$API_PUBLIC_KEY_ID" - it.buildConfigField "String", "VIRGIL_BASE_URL", "$VIRGIL_BASE_URL" - } - } -} - -dependencies { - // Internal - implementation project(':ethree-kotlin-coroutines') - - // Kotlin - androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlin" - implementation 'com.android.support:appcompat-v7:28.0.0' - - // Coroutines - androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$versions.coroutines" - - // Virgil - androidTestImplementation("com.virgilsecurity:pythia:$versions.pythia") { - exclude group: 'com.virgilsecurity.sdk', module: 'crypto' - exclude group: 'com.virgilsecurity.crypto', module: 'common' - exclude group: 'com.virgilsecurity.crypto', module: 'foundation' - exclude group: 'com.virgilsecurity.crypto', module: 'pythia' - } - androidTestImplementation "com.virgilsecurity.crypto:pythia-android:$versions.virgilCrypto" - androidTestImplementation("com.virgilsecurity:keyknox:$versions.keyknox") { - exclude group: 'com.virgilsecurity.sdk', module: 'crypto' - exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8' - } - - // Tests core - testImplementation "junit:junit:$versions.junit" - androidTestImplementation "com.android.support.test:runner:$versions.testsRunner" - androidTestImplementation "com.android.support.test.espresso:espresso-core:$versions.espresso" -} diff --git a/testscoroutines/proguard-rules.pro b/testscoroutines/proguard-rules.pro deleted file mode 100644 index f1b42451..00000000 --- a/testscoroutines/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile diff --git a/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/extension/DeferredExt.kt b/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/extension/DeferredExt.kt deleted file mode 100644 index a578ae6a..00000000 --- a/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/extension/DeferredExt.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2015-2019, Virgil Security, Inc. - * - * Lead Maintainer: Virgil Security Inc. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * (1) Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * (2) Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * (3) Neither the name of virgil nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package com.virgilsecurity.android.ethreeCoroutines.extension - -import com.virgilsecurity.android.ethreeCoroutines.model.Failure -import com.virgilsecurity.android.ethreeCoroutines.model.Result -import com.virgilsecurity.android.ethreeCoroutines.model.Success -import kotlinx.coroutines.Deferred - -/** - * Created by: - * Danylo Oliinyk - * on - * 11/5/18 - * at Virgil Security - */ - -suspend fun Deferred.awaitResult(): Result = try { - Success(await()) -} catch (throwable: Throwable) { - Failure(throwable) -} diff --git a/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/interaction/EThreeAuthTest.kt b/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/interaction/EThreeAuthTest.kt deleted file mode 100644 index f8428c00..00000000 --- a/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/interaction/EThreeAuthTest.kt +++ /dev/null @@ -1,269 +0,0 @@ -/* - * Copyright (c) 2015-2019, Virgil Security, Inc. - * - * Lead Maintainer: Virgil Security Inc. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * (1) Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * (2) Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * (3) Neither the name of virgil nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package com.virgilsecurity.android.ethreeCoroutines.interaction - -import com.virgilsecurity.android.common.exceptions.CardNotFoundException -import com.virgilsecurity.android.common.exceptions.PrivateKeyExistsException -import com.virgilsecurity.android.common.exceptions.RegistrationException -import com.virgilsecurity.android.ethreeCoroutines.extension.awaitResult -import com.virgilsecurity.android.ethreeCoroutines.model.onError -import com.virgilsecurity.android.ethreeCoroutines.model.onSuccess -import com.virgilsecurity.android.ethreeCoroutines.utils.TestConfig -import com.virgilsecurity.android.ethreeCoroutines.utils.TestConfig.Companion.virgilBaseUrl -import com.virgilsecurity.android.ethreeCoroutines.utils.TestConfig.Companion.virgilCrypto -import com.virgilsecurity.android.ethreeCoroutines.utils.TestUtils -import com.virgilsecurity.android.ethreecoroutines.interaction.EThree -import com.virgilsecurity.sdk.cards.CardManager -import com.virgilsecurity.sdk.cards.model.RawSignedModel -import com.virgilsecurity.sdk.cards.validation.VirgilCardVerifier -import com.virgilsecurity.sdk.client.VirgilCardClient -import com.virgilsecurity.sdk.common.TimeSpan -import com.virgilsecurity.sdk.crypto.VirgilAccessTokenSigner -import com.virgilsecurity.sdk.crypto.VirgilCardCrypto -import com.virgilsecurity.sdk.crypto.VirgilCrypto -import com.virgilsecurity.sdk.crypto.VirgilKeyPair -import com.virgilsecurity.sdk.jwt.JwtGenerator -import com.virgilsecurity.sdk.jwt.accessProviders.GeneratorJwtProvider -import com.virgilsecurity.sdk.storage.DefaultKeyStorage -import com.virgilsecurity.sdk.storage.JsonKeyEntry -import com.virgilsecurity.sdk.storage.KeyStorage -import com.virgilsecurity.sdk.utils.Tuple -import kotlinx.coroutines.runBlocking -import org.hamcrest.core.IsEqual -import org.hamcrest.core.IsNot -import org.junit.Assert -import org.junit.Assert.* -import org.junit.Before -import org.junit.Test -import java.util.* -import java.util.concurrent.TimeUnit - -/** - * Created by: - * Danylo Oliinyk - * on - * 10/9/18 - * at Virgil Security - */ -class EThreeAuthTest { - - private val identity = UUID.randomUUID().toString() - - private lateinit var jwtGenerator: JwtGenerator - private lateinit var keyStorage: KeyStorage - - @Before fun setup() { - TestUtils.pause() - - jwtGenerator = JwtGenerator( - TestConfig.appId, - TestConfig.apiKey, - TestConfig.apiPublicKeyId, - TimeSpan.fromTime(600, TimeUnit.SECONDS), - VirgilAccessTokenSigner(TestConfig.virgilCrypto) - ) - - keyStorage = DefaultKeyStorage(TestConfig.DIRECTORY_PATH, TestConfig.KEYSTORE_NAME) - } - - private fun initAndRegisterEThree(identity: String): EThree { - val eThree = initEThree(identity) - bootstrapEThree(eThree) - return eThree - } - - private fun initEThree(identity: String): EThree { - var eThree: EThree? = null - - runBlocking { - eThree = EThree.initialize( - TestConfig.context) { - jwtGenerator.generateToken(identity).stringRepresentation() - }.await() - } - - return eThree!! - } - - private fun bootstrapEThree(eThree: EThree): EThree { - runBlocking { - eThree.register().await() - } - - return eThree - } - - private fun initCardManager(identity: String): CardManager { - val cardCrypto = VirgilCardCrypto() - return CardManager( - cardCrypto, - GeneratorJwtProvider(jwtGenerator, identity), - VirgilCardVerifier(cardCrypto, false, false), - VirgilCardClient(virgilBaseUrl + TestConfig.VIRGIL_CARDS_SERVICE_PATH) - ) - } - - private fun generateRawCard(identity: String, - cardManager: CardManager): Tuple { - return VirgilCrypto().generateKeyPair().let { - Tuple(it, cardManager.generateRawCard(it.privateKey, it.publicKey, identity)) - } - } - - // STE-Auth-8 - @Test fun delete_local_key() { - val keys = VirgilCrypto().generateKeyPair() - keyStorage.store(JsonKeyEntry(identity, keys.privateKey.privateKey.exportPrivateKey())) - assertTrue(keyStorage.exists(identity)) - initEThree(identity).cleanup() - Assert.assertFalse(keyStorage.exists(identity)) - } - - // STE-Auth-9 - @Test fun init_and_register() { - initAndRegisterEThree(identity) - assertTrue(keyStorage.exists(identity)) - - val card = initCardManager(identity).searchCards(identity) - assertNotNull(card) - } - - // STE-Auth-10 - @Test fun register_existing_identity() { - val cardManager = initCardManager(identity) - cardManager.publishCard(generateRawCard(identity, cardManager).right) - val eThree = initEThree(identity) - - runBlocking { - eThree.register().awaitResult().onError { assertTrue(it is RegistrationException) } - } - } - - // STE-Auth-11 - @Test fun register_with_existing_private_key() { - keyStorage.store(JsonKeyEntry(identity, - virgilCrypto.generateKeyPair() - .privateKey - .privateKey - .exportPrivateKey())) - val eThree = initEThree(identity) - - runBlocking { - eThree.register() - .awaitResult() - .onSuccess { fail("Illegal state") } - .onError { assertTrue(it is PrivateKeyExistsException) } - } - } - - // STE-Auth-12 - @Test fun rotate_without_published_card() { - val eThree = initEThree(identity) - - runBlocking { - eThree.rotatePrivateKey() - .awaitResult() - .onSuccess { fail("Illegal state") } - .onError { assertTrue(it is CardNotFoundException) } - } - } - - // STE-Auth-13 - @Test fun rotate_with_local_key_present() { - val eThree = initAndRegisterEThree(identity) - - assertTrue(initCardManager(identity).searchCards(identity).isNotEmpty()) - - runBlocking { - eThree.rotatePrivateKey() - .awaitResult() - .onSuccess { fail("Illegal state") } - .onError { assertTrue(it is PrivateKeyExistsException) } - } - } - - // STE-Auth-14 - @Test fun rotate_keys() { - val cardManager = initCardManager(identity) - val publishPair = generateRawCard(identity, cardManager) - cardManager.publishCard(publishPair.right) - val eThree = initEThree(identity) - - runBlocking { - eThree.rotatePrivateKey().awaitResult().onError { fail(it.message) } - } - - assertTrue(cardManager.searchCards(identity).last().previousCardId != null) - - val newKeyData = keyStorage.load(identity).value - val oldKeyData = publishPair.left.privateKey.privateKey.exportPrivateKey() - assertThat(oldKeyData, IsNot.not(IsEqual.equalTo(newKeyData))) - } - - @Test fun rotate_when_multiply_cards_available() { - val cardManager = initCardManager(identity) - val publishPair = generateRawCard(identity, cardManager) - val publishPairTwo = generateRawCard(identity, cardManager) - cardManager.publishCard(publishPair.right) - cardManager.publishCard(publishPairTwo.right) - val eThree = initEThree(identity) - - runBlocking { - eThree.rotatePrivateKey() - .awaitResult() - .onSuccess { fail("Illegal state") } - .onError { - assertTrue(it is IllegalStateException) - } - } - } - - @Test fun lookup_when_multiply_cards_available() { - val cardManager = initCardManager(identity) - val publishPair = generateRawCard(identity, cardManager) - val publishPairTwo = generateRawCard(identity, cardManager) - cardManager.publishCard(publishPair.right) - cardManager.publishCard(publishPairTwo.right) - val eThree = initEThree(identity) - - runBlocking { - eThree.lookupPublicKeys(listOf(identity)) - .awaitResult() - .onSuccess { fail("Illegal state") } - .onError { - assertTrue(it is IllegalStateException) - } - } - } -} diff --git a/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/interaction/EThreeBackupTest.kt b/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/interaction/EThreeBackupTest.kt deleted file mode 100644 index 67c6bcc0..00000000 --- a/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/interaction/EThreeBackupTest.kt +++ /dev/null @@ -1,409 +0,0 @@ -/* - * Copyright (c) 2015-2019, Virgil Security, Inc. - * - * Lead Maintainer: Virgil Security Inc. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * (1) Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * (2) Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * (3) Neither the name of virgil nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package com.virgilsecurity.android.ethreeCoroutines.interaction - -import com.virgilsecurity.android.common.exceptions.BackupKeyException -import com.virgilsecurity.android.common.exceptions.PrivateKeyNotFoundException -import com.virgilsecurity.android.common.exceptions.RestoreKeyException -import com.virgilsecurity.android.common.exceptions.WrongPasswordException -import com.virgilsecurity.android.ethreeCoroutines.extension.awaitResult -import com.virgilsecurity.android.ethreeCoroutines.model.onError -import com.virgilsecurity.android.ethreeCoroutines.model.onSuccess -import com.virgilsecurity.android.ethreeCoroutines.utils.TestConfig -import com.virgilsecurity.android.ethreeCoroutines.utils.TestConfig.Companion.virgilBaseUrl -import com.virgilsecurity.android.ethreeCoroutines.utils.TestUtils -import com.virgilsecurity.android.ethreecoroutines.interaction.EThree -import com.virgilsecurity.keyknox.KeyknoxManager -import com.virgilsecurity.keyknox.client.KeyknoxClient -import com.virgilsecurity.keyknox.cloud.CloudKeyStorage -import com.virgilsecurity.keyknox.crypto.KeyknoxCrypto -import com.virgilsecurity.keyknox.storage.SyncKeyStorage -import com.virgilsecurity.pythia.brainkey.BrainKey -import com.virgilsecurity.pythia.brainkey.BrainKeyContext -import com.virgilsecurity.pythia.client.VirgilPythiaClient -import com.virgilsecurity.pythia.crypto.VirgilPythiaCrypto -import com.virgilsecurity.sdk.cards.CardManager -import com.virgilsecurity.sdk.cards.model.RawSignedModel -import com.virgilsecurity.sdk.cards.validation.VirgilCardVerifier -import com.virgilsecurity.sdk.client.VirgilCardClient -import com.virgilsecurity.sdk.common.TimeSpan -import com.virgilsecurity.sdk.crypto.VirgilAccessTokenSigner -import com.virgilsecurity.sdk.crypto.VirgilCardCrypto -import com.virgilsecurity.sdk.crypto.VirgilCrypto -import com.virgilsecurity.sdk.crypto.VirgilKeyPair -import com.virgilsecurity.sdk.jwt.JwtGenerator -import com.virgilsecurity.sdk.jwt.accessProviders.CachingJwtProvider -import com.virgilsecurity.sdk.jwt.accessProviders.GeneratorJwtProvider -import com.virgilsecurity.sdk.storage.DefaultKeyStorage -import com.virgilsecurity.sdk.storage.KeyStorage -import com.virgilsecurity.sdk.utils.Tuple -import kotlinx.coroutines.runBlocking -import org.junit.Assert -import org.junit.Assert.* -import org.junit.Before -import org.junit.Test -import java.net.URL -import java.util.* -import java.util.concurrent.TimeUnit - -/** - * Created by: - * Danylo Oliinyk - * on - * 10/9/18 - * at Virgil Security - */ -class EThreeBackupTest { - - private lateinit var jwtGenerator: JwtGenerator - private lateinit var keyStorage: KeyStorage - - @Before fun setup() { - TestUtils.pause() - - jwtGenerator = JwtGenerator( - TestConfig.appId, - TestConfig.apiKey, - TestConfig.apiPublicKeyId, - TimeSpan.fromTime(600, TimeUnit.SECONDS), - VirgilAccessTokenSigner(TestConfig.virgilCrypto) - ) - - keyStorage = DefaultKeyStorage(TestConfig.DIRECTORY_PATH, TestConfig.KEYSTORE_NAME) - } - - private fun initAndRegisterEThree(identity: String): EThree { - val eThree = initEThree(identity) - bootstrapEThree(eThree) - return eThree - } - - private fun initEThree(identity: String): EThree { - var eThree: EThree? = null - - runBlocking { - eThree = EThree.initialize( - TestConfig.context) { - jwtGenerator.generateToken(identity).stringRepresentation() - }.await() - } - - return eThree!! - } - - private fun bootstrapEThree(eThree: EThree): EThree { - runBlocking { - eThree.register().await() - } - - return eThree - } - - private fun initSyncKeyStorage(identity: String, passwordBrainKey: String): SyncKeyStorage { - val tokenProvider = CachingJwtProvider(CachingJwtProvider.RenewJwtCallback { - jwtGenerator.generateToken(identity) - }) - val brainKeyContext = BrainKeyContext.Builder() - .setAccessTokenProvider(tokenProvider) - .setPythiaClient(VirgilPythiaClient(virgilBaseUrl)) - .setPythiaCrypto(VirgilPythiaCrypto()) - .build() - val keyPair = BrainKey(brainKeyContext).generateKeyPair(passwordBrainKey) - - val syncKeyStorage = - SyncKeyStorage( - identity, keyStorage, CloudKeyStorage( - KeyknoxManager( - tokenProvider, - KeyknoxClient(URL(virgilBaseUrl)), - listOf(keyPair.publicKey), - keyPair.privateKey, - KeyknoxCrypto() - ) - ) - ) - - syncKeyStorage.sync() - - return syncKeyStorage - } - - private fun initCardManager(identity: String): CardManager { - val cardCrypto = VirgilCardCrypto() - return CardManager( - cardCrypto, - GeneratorJwtProvider(jwtGenerator, identity), - VirgilCardVerifier(cardCrypto, false, false), - VirgilCardClient(virgilBaseUrl + TestConfig.VIRGIL_CARDS_SERVICE_PATH) - ) - } - - private fun generateRawCard(identity: String, cardManager: CardManager): Tuple { - return VirgilCrypto().generateKeyPair().let { - Tuple(it, cardManager.generateRawCard(it.privateKey, it.publicKey, identity)) - } - } - - // STE-15_1 - @Test fun backup_key_before_register() { - val identity = UUID.randomUUID().toString() - val password = UUID.randomUUID().toString() - - val eThree = initEThree(identity) - - runBlocking { - eThree.backupPrivateKey(password).awaitResult() - .onSuccess { fail("Illegal state") } - .onError { assertTrue(it is PrivateKeyNotFoundException) } - } - } - - // STE-15_2-4 - @Test fun backup_key_after_register() { - val identity = UUID.randomUUID().toString() - val password = UUID.randomUUID().toString() - val eThree = initAndRegisterEThree(identity) - - TestUtils.pause() - - runBlocking { - eThree.backupPrivateKey(password).awaitResult() - .onError { fail(it.message) } - } - - TestUtils.pause() - - val syncKeyStorage = initSyncKeyStorage(identity, password) - assertTrue(syncKeyStorage.exists(identity)) - val retrievedKey = syncKeyStorage.retrieve(identity) - assertEquals(TestConfig.virgilCrypto.importPrivateKey(keyStorage.load(identity).value), - TestConfig.virgilCrypto.importPrivateKey(retrievedKey.value)) - - TestUtils.pause() - - runBlocking { - eThree.backupPrivateKey(password).awaitResult() - .onSuccess { fail("Illegal state") } - .onError { - assertTrue(it is BackupKeyException) - } - } - } - - // STE-16 - @Test fun restore_private_key() { - val identity = UUID.randomUUID().toString() - val password = UUID.randomUUID().toString() - - val eThreeWithPass = initAndRegisterEThree(identity) - - TestUtils.pause() - - runBlocking { - eThreeWithPass.backupPrivateKey(password).awaitResult().onError { fail(it.message) } - } - - TestUtils.pause() - - eThreeWithPass.cleanup() - runBlocking { - eThreeWithPass.restorePrivateKey(password).awaitResult().onError { fail(it.message) } - } - - TestUtils.pause() - - val syncKeyStorage = initSyncKeyStorage(identity, password) - assertTrue(syncKeyStorage.exists(identity)) - val retrievedKey = syncKeyStorage.retrieve(identity) - assertEquals(TestConfig.virgilCrypto.importPrivateKey(keyStorage.load(identity).value), - TestConfig.virgilCrypto.importPrivateKey(retrievedKey.value)) - - TestUtils.pause() - - runBlocking { - eThreeWithPass.restorePrivateKey(password) - .awaitResult() - .onSuccess { fail("Illegal state") } - .onError { assertTrue(it is RestoreKeyException) } - } - } - - // STE-17 - @Test fun change_password() { - val identity = UUID.randomUUID().toString() - val password = UUID.randomUUID().toString() - val passwordNew = UUID.randomUUID().toString() - - val eThreeWithPass = initAndRegisterEThree(identity) - - TestUtils.pause() - - runBlocking { - eThreeWithPass.backupPrivateKey(password).awaitResult().onError { fail(it.message) } - } - - TestUtils.pause() - - runBlocking { - eThreeWithPass.changePassword(password, passwordNew) - .awaitResult() - .onError { fail(it.message) } - } - - TestUtils.pause() - - eThreeWithPass.cleanup() - runBlocking { - eThreeWithPass.restorePrivateKey(password) - .awaitResult() - .onSuccess { fail("Illegal state") } - .onError { - assertTrue(it is WrongPasswordException) - } - } - - TestUtils.pause() - - var successWithNewPassword = false - runBlocking { - eThreeWithPass.restorePrivateKey(passwordNew) - .awaitResult() - .onSuccess { successWithNewPassword = true } - .onError { fail(it.message) } - } - assertTrue(successWithNewPassword) - } - - // STE-18_1 - @Test fun reset_key_backup_before_backup() { - val identity = UUID.randomUUID().toString() - val password = UUID.randomUUID().toString() - val eThreeWithPass = initEThree(identity) - - TestUtils.pause() - - runBlocking { - eThreeWithPass.resetPrivateKeyBackup(password) - .awaitResult() - .onSuccess { fail("Illegal state") } - .onError { assertTrue(it is PrivateKeyNotFoundException) } - } - - TestUtils.pause() - - val syncKeyStorage = initSyncKeyStorage(identity, password) - Assert.assertFalse(syncKeyStorage.exists(identity)) - } - - // STE-18_2 - @Test fun reset_key_backup_after_backup() { - val identity = UUID.randomUUID().toString() - val password = UUID.randomUUID().toString() - val eThreeWithPass = initAndRegisterEThree(identity) - - TestUtils.pause() - - runBlocking { - eThreeWithPass.backupPrivateKey(password).awaitResult().onError { fail(it.message) } - } - - TestUtils.pause() - - runBlocking { - eThreeWithPass.resetPrivateKeyBackup(password) - .awaitResult() - .onError { fail(it.message) } - } - - TestUtils.pause() - - val syncKeyStorage = initSyncKeyStorage(identity, password) - Assert.assertFalse(syncKeyStorage.exists(identity)) - } - - // Reset without password - @Test fun reset_key_backup_after_backup_no_password() { - val identity = UUID.randomUUID().toString() - val password = UUID.randomUUID().toString() - val eThreeWithPass = initAndRegisterEThree(identity) - - TestUtils.pause() - - runBlocking { - eThreeWithPass.backupPrivateKey(password).awaitResult().onError { fail(it.message) } - } - - TestUtils.pause() - - runBlocking { - eThreeWithPass.resetPrivateKeyBackup() - .awaitResult() - .onError { fail(it.message) } - } - - TestUtils.pause() - - val syncKeyStorage = initSyncKeyStorage(identity, password) - Assert.assertFalse(syncKeyStorage.exists(identity)) - } - - @Test - fun reset_backed_key_wrong_pass() { - val identity = UUID.randomUUID().toString() - val password = UUID.randomUUID().toString() - val eThreeWithPass = initAndRegisterEThree(identity) - - TestUtils.pause() - - runBlocking { - eThreeWithPass.backupPrivateKey(password).awaitResult().onError { fail(it.message) } - } - - TestUtils.pause() - - runBlocking { - eThreeWithPass.resetPrivateKeyBackup(WRONG_PASSWORD) - .awaitResult() - .onSuccess { fail("Illegal state") } - .onError { - assertTrue("Key reset failed with wrong error", - it is WrongPasswordException) - } - } - } - - companion object { - const val WRONG_PASSWORD = "WRONG_PASSWORD" - } -} diff --git a/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/interaction/EThreeEncryptionTest.kt b/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/interaction/EThreeEncryptionTest.kt deleted file mode 100644 index cb61cebf..00000000 --- a/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/interaction/EThreeEncryptionTest.kt +++ /dev/null @@ -1,335 +0,0 @@ -/* - * Copyright (c) 2015-2019, Virgil Security, Inc. - * - * Lead Maintainer: Virgil Security Inc. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * (1) Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * (2) Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * (3) Neither the name of virgil nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package com.virgilsecurity.android.ethreeCoroutines.interaction - -import com.virgilsecurity.android.common.exceptions.PrivateKeyNotFoundException -import com.virgilsecurity.android.ethreeCoroutines.extension.awaitResult -import com.virgilsecurity.android.ethreeCoroutines.model.onError -import com.virgilsecurity.android.ethreeCoroutines.model.onSuccess -import com.virgilsecurity.android.ethreeCoroutines.utils.TestConfig -import com.virgilsecurity.android.ethreecoroutines.interaction.EThree -import com.virgilsecurity.sdk.cards.CardManager -import com.virgilsecurity.sdk.cards.model.RawSignedModel -import com.virgilsecurity.sdk.cards.validation.VirgilCardVerifier -import com.virgilsecurity.sdk.client.VirgilCardClient -import com.virgilsecurity.sdk.common.TimeSpan -import com.virgilsecurity.sdk.crypto.* -import com.virgilsecurity.sdk.exception.EmptyArgumentException -import com.virgilsecurity.sdk.jwt.JwtGenerator -import com.virgilsecurity.sdk.jwt.accessProviders.GeneratorJwtProvider -import com.virgilsecurity.sdk.storage.DefaultKeyStorage -import com.virgilsecurity.sdk.storage.JsonKeyEntry -import com.virgilsecurity.sdk.storage.KeyStorage -import com.virgilsecurity.sdk.utils.Tuple -import kotlinx.coroutines.runBlocking -import org.junit.Assert.* -import org.junit.Before -import org.junit.Test -import java.util.* -import java.util.concurrent.TimeUnit - -/** - * Created by: - * Danylo Oliinyk - * on - * 10/9/18 - * at Virgil Security - */ -class EThreeEncryptionTest { - - private val identity = UUID.randomUUID().toString() - - private lateinit var eThree: EThree - private lateinit var jwtGenerator: JwtGenerator - private lateinit var keyStorage: KeyStorage - - @Before fun setup() { - jwtGenerator = JwtGenerator( - TestConfig.appId, - TestConfig.apiKey, - TestConfig.apiPublicKeyId, - TimeSpan.fromTime(600, TimeUnit.SECONDS), - VirgilAccessTokenSigner(TestConfig.virgilCrypto) - ) - - eThree = initAndRegisterEThree(identity) - keyStorage = DefaultKeyStorage(TestConfig.DIRECTORY_PATH, TestConfig.KEYSTORE_NAME) - } - - private fun initAndRegisterEThree(identity: String): EThree { - val eThree = initEThree(identity) - bootstrapEThree(eThree) - return eThree - } - - private fun initEThree(identity: String): EThree { - var eThree: EThree? = null - - runBlocking { - eThree = EThree.initialize( - TestConfig.context) { - jwtGenerator.generateToken(identity).stringRepresentation() - }.await() - } - - return eThree!! - } - - private fun bootstrapEThree(eThree: EThree): EThree { - runBlocking { - eThree.register().await() - } - - return eThree - } - - private fun initCardManager(identity: String): CardManager { - val cardCrypto = VirgilCardCrypto() - return CardManager( - cardCrypto, - GeneratorJwtProvider(jwtGenerator, identity), - VirgilCardVerifier(cardCrypto, false, false), - VirgilCardClient(TestConfig.virgilBaseUrl + TestConfig.VIRGIL_CARDS_SERVICE_PATH) - ) - } - - private fun generateRawCard(identity: String, - cardManager: CardManager): Tuple { - return VirgilCrypto().generateKeyPair().let { - Tuple(it, cardManager.generateRawCard(it.privateKey, it.publicKey, identity)) - } - } - - @Test fun lookup_one_user() { - val identityOne = UUID.randomUUID().toString() - val cardManagerOne = initCardManager(identityOne) - val publishedCardOne = cardManagerOne.publishCard(generateRawCard(identityOne, - cardManagerOne).right) - - runBlocking { - val keys = eThree.lookupPublicKeys(listOf(identityOne)).await() - assertTrue(keys.isNotEmpty() && keys.size == 1) - assertEquals(publishedCardOne.publicKey, keys[identityOne]) - } - } - - // STE-1 - @Test fun lookup_multiply_users() { - var foundCards = false - - // Card one - val identityOne = UUID.randomUUID().toString() - val cardManagerOne = initCardManager(identityOne) - val publishedCardOne = cardManagerOne.publishCard(generateRawCard(identityOne, - cardManagerOne).right) - // Card two - val identityTwo = UUID.randomUUID().toString() - val cardManagerTwo = initCardManager(identityTwo) - val publishedCardTwo = cardManagerTwo.publishCard(generateRawCard(identityTwo, - cardManagerTwo).right) - // Card three - val identityThree = UUID.randomUUID().toString() - val cardManagerThree = initCardManager(identityThree) - val publishedCardThree = cardManagerThree.publishCard(generateRawCard(identityThree, - cardManagerThree).right) - - runBlocking { - val keys = eThree.lookupPublicKeys(listOf(identityOne, identityTwo, identityThree)) - .await() - assertTrue(keys.isNotEmpty() && keys.size == 3) - if (keys[identityOne] == publishedCardOne.publicKey - && keys[identityTwo] == publishedCardTwo.publicKey - && keys[identityThree] == publishedCardThree.publicKey) { - foundCards = true - } - - assertTrue(foundCards) - } - } - - //STE-2 - @Test fun lookup_zero_users() { - runBlocking { - eThree.lookupPublicKeys(listOf()).awaitResult().onError { - assertTrue(it is EmptyArgumentException) - } - } - } - - @Test fun encrypt_adding_owner_public_key() { - val identityTwo = UUID.randomUUID().toString() - initAndRegisterEThree(identityTwo) - - var eThreeKeys = mapOf() - - runBlocking { - eThreeKeys = eThree.lookupPublicKeys(listOf(identity, identityTwo)).await() - assertTrue(eThreeKeys.size == 2) - } - - var failedEncrypt = false - try { - eThree.encrypt(RAW_TEXT, eThreeKeys.values.toList()) - } catch (e: IllegalArgumentException) { - failedEncrypt = true - } - assertTrue(failedEncrypt) - } - - - // STE-3 - @Test fun encrypt_decrypt() { - val identityTwo = UUID.randomUUID().toString() - val eThreeTwo = initAndRegisterEThree(identityTwo) - - var eThreeKeys = mapOf() - - runBlocking { - eThreeKeys = eThree.lookupPublicKeys(listOf(identity, identityTwo)).await() - assertTrue(eThreeKeys.size == 2) - } - val encryptedForOne = - eThree.encrypt(RAW_TEXT, - listOf(eThreeKeys[identityTwo] ?: error("No key for $identityTwo"))) - - val wrongPublicKey = TestConfig.virgilCrypto.generateKeyPair().publicKey - var failedWithWrongKey = false - try { - eThreeTwo.decrypt(encryptedForOne, wrongPublicKey) - } catch (throwable: Throwable) { - failedWithWrongKey = true - } - assertTrue(failedWithWrongKey) - - val decryptedByTwo = eThreeTwo.decrypt(encryptedForOne, eThreeKeys[identity]) - - assertEquals(RAW_TEXT, decryptedByTwo) - } - - // STE-4 - @Test(expected = EmptyArgumentException::class) - fun encrypt_for_zero_users() { - eThree.encrypt(RAW_TEXT, listOf()) - } - - // STE-5 - @Test fun encrypt_without_sign() { - val keyPair = TestConfig.virgilCrypto.generateKeyPair() - val encryptedWithoutSign = TestConfig.virgilCrypto.encrypt(RAW_TEXT.toByteArray(), - keyPair.publicKey) - - var failedDecrypt = false - try { - eThree.decrypt(encryptedWithoutSign, keyPair.publicKey) - } catch (e: Exception) { - failedDecrypt = true - } - assertTrue(failedDecrypt) - } - - // STE-6 - @Test fun encrypt_decrypt_without_register() { - var eThreeTwo: EThree? = null - val identity = UUID.randomUUID().toString() - - runBlocking { - EThree.initialize(TestConfig.context) { - jwtGenerator.generateToken(identity).stringRepresentation() - }.awaitResult() - .onSuccess { eThreeTwo = it } - .onError { fail(it.message) } - } - - val keys = TestConfig.virgilCrypto.generateKeyPair() - - var failedToEncrypt = false - try { - eThreeTwo!!.encrypt(RAW_TEXT, listOf(keys.publicKey)) - } catch (exception: PrivateKeyNotFoundException) { - failedToEncrypt = true - } - assertTrue(failedToEncrypt) - - var failedToDecrypt = false - try { - eThreeTwo!!.decrypt("fakeEncryptedText", keys.publicKey) - } catch (exception: PrivateKeyNotFoundException) { - failedToDecrypt = true - } - assertTrue(failedToDecrypt) - } - - @Test fun encrypt_decrypt_without_register_for_owner() { - var eThreeTwo: EThree? = null - - runBlocking { - EThree.initialize(TestConfig.context) { - jwtGenerator.generateToken(identity).stringRepresentation() - }.awaitResult() - .onSuccess { eThreeTwo = it } - .onError { fail(it.message) } - } - - val encryptedText = eThreeTwo!!.encrypt(RAW_TEXT) - val decryptedText = eThreeTwo!!.decrypt(encryptedText) - - assertEquals(RAW_TEXT, decryptedText) - } - - // STE-7 - @Test fun encrypt_decrypt_for_owner() { - val encryptedText = eThree.encrypt(RAW_TEXT) - val decryptedText = eThree.decrypt(encryptedText) - - assertEquals(RAW_TEXT, decryptedText) - } - - @Test fun init_without_local_key_and_create_after() { - val identityTwo = UUID.randomUUID().toString() - val eThreeTwo = initEThree(identityTwo) - - val anyKeypair = TestConfig.virgilCrypto.generateKeyPair() - keyStorage.store(JsonKeyEntry(identityTwo, - VirgilCrypto().exportPrivateKey(anyKeypair.privateKey))) - - val encrypted = eThreeTwo.encrypt(RAW_TEXT) - val decrypted = eThreeTwo.decrypt(encrypted) - - assertEquals(RAW_TEXT, decrypted) - } - - companion object { - const val RAW_TEXT = "This is the best text ever made by the whole humanity." - } -} diff --git a/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/interaction/EThreeNegativeTest.kt b/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/interaction/EThreeNegativeTest.kt deleted file mode 100644 index 7908f99d..00000000 --- a/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/interaction/EThreeNegativeTest.kt +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (c) 2015-2019, Virgil Security, Inc. - * - * Lead Maintainer: Virgil Security Inc. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * (1) Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * (2) Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * (3) Neither the name of virgil nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package com.virgilsecurity.android.ethreeCoroutines.interaction - -import com.virgilsecurity.android.common.exceptions.PrivateKeyNotFoundException -import com.virgilsecurity.android.common.exceptions.PublicKeyDuplicateException -import com.virgilsecurity.android.common.exceptions.PublicKeyNotFoundException -import com.virgilsecurity.android.ethreeCoroutines.extension.awaitResult -import com.virgilsecurity.android.ethreeCoroutines.model.onError -import com.virgilsecurity.android.ethreeCoroutines.utils.TestConfig -import com.virgilsecurity.android.ethreecoroutines.interaction.EThree -import com.virgilsecurity.sdk.common.TimeSpan -import com.virgilsecurity.sdk.crypto.VirgilAccessTokenSigner -import com.virgilsecurity.sdk.jwt.JwtGenerator -import com.virgilsecurity.sdk.storage.DefaultKeyStorage -import com.virgilsecurity.sdk.storage.KeyStorage -import kotlinx.coroutines.runBlocking -import org.junit.Assert.assertTrue -import org.junit.Before -import org.junit.Test -import java.util.* -import java.util.concurrent.TimeUnit - -/** - * Created by: - * Danylo Oliinyk - * on - * 10/24/18 - * at Virgil Security - */ -class EThreeNegativeTest { - - private lateinit var jwtGenerator: JwtGenerator - private lateinit var keyStorage: KeyStorage - private lateinit var eThree: EThree - private val identity = UUID.randomUUID().toString() - private val password = UUID.randomUUID().toString() - - - @Before fun setup() { - jwtGenerator = JwtGenerator( - TestConfig.appId, - TestConfig.apiKey, - TestConfig.apiPublicKeyId, - TimeSpan.fromTime(600, TimeUnit.SECONDS), - VirgilAccessTokenSigner(TestConfig.virgilCrypto) - ) - - keyStorage = DefaultKeyStorage(TestConfig.DIRECTORY_PATH, TestConfig.KEYSTORE_NAME) - eThree = initEThree(identity) - } - - private fun initEThree(identity: String): EThree { - var eThree: EThree? = null - - runBlocking { - eThree = EThree.initialize( - TestConfig.context) { - jwtGenerator.generateToken(identity).stringRepresentation() - }.await() - } - - return eThree!! - } - - private fun bootstrapEThree(eThree: EThree): EThree { - runBlocking { - eThree.register().await() - } - - return eThree - } - - @Test(expected = PrivateKeyNotFoundException::class) - fun cleanup_fail_without_bootstrap() { - eThree.cleanup() - } - - @Test fun backup_fail_without_bootstrap() { - var failed = false - runBlocking { - eThree.backupPrivateKey(password).awaitResult().onError { - if (it is PrivateKeyNotFoundException) - failed = true - } - } - assertTrue(failed) - } - - @Test fun reset_key_fail_without_bootstrap() { - var failed = false - runBlocking { - eThree.resetPrivateKeyBackup(password).awaitResult().onError { - if (it is PrivateKeyNotFoundException) - failed = true - } - } - assertTrue(failed) - } - - @Test fun change_pass_fail_without_bootstrap() { - var failed = false - runBlocking { - eThree.changePassword(password, password + password).awaitResult().onError { - if (it is PrivateKeyNotFoundException) - failed = true - } - } - assertTrue(failed) - } - - @Test(expected = PrivateKeyNotFoundException::class) - fun encrypt_text_fail_without_bootstrap() { - eThree.encrypt("") - } - - @Test(expected = PrivateKeyNotFoundException::class) - fun encrypt_data_fail_without_bootstrap() { - eThree.encrypt(ByteArray(0)) - } - - @Test(expected = PrivateKeyNotFoundException::class) - fun decrypt_text_fail_without_bootstrap() { - eThree.decrypt("") - } - - @Test(expected = PrivateKeyNotFoundException::class) - fun decrypt_data_fail_without_bootstrap() { - eThree.decrypt(ByteArray(0)) - } - - @Test fun lookup_fail_without_bootstrap() { - var failed = false - runBlocking { - eThree.lookupPublicKeys(listOf("")).awaitResult().onError { - failed = true - } - } - assertTrue(failed) - } - - @Test fun lookup_fail_wrong_identity() { - bootstrapEThree(eThree) - - var failed = false - runBlocking { - eThree.lookupPublicKeys(listOf(identity, - WRONG_IDENTITY)).awaitResult().onError { - if (it is PublicKeyNotFoundException && it.identity == WRONG_IDENTITY) - failed = true - } - } - assertTrue(failed) - } - - @Test fun init_ethree_with_empty_token() { - var failed = false - runBlocking { - EThree.initialize(TestConfig.context) { "" }.awaitResult().onError { - failed = true - } - } - assertTrue(failed) - } - - @Test fun lookup_with_duplicate_identities() { - var failed = false - bootstrapEThree(eThree) - - runBlocking { - eThree.lookupPublicKeys(listOf(identity, identity, identity, - WRONG_IDENTITY, - WRONG_IDENTITY, - WRONG_IDENTITY + identity)).awaitResult().onError { - if (it is PublicKeyDuplicateException) - failed = true - } - } - assertTrue(failed) - } - - @Test fun change_pass_with_same_new() { - var failed = false - bootstrapEThree(eThree) - runBlocking { - eThree.changePassword(password, password).awaitResult().onError { - if (it is IllegalArgumentException) - failed = true - } - } - assertTrue(failed) - } - - companion object { - const val WRONG_IDENTITY = "WRONG_IDENTITY" - } -} diff --git a/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/model/Result.kt b/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/model/Result.kt deleted file mode 100644 index a6783418..00000000 --- a/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/model/Result.kt +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2015-2019, Virgil Security, Inc. - * - * Lead Maintainer: Virgil Security Inc. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * (1) Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * (2) Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * (3) Neither the name of virgil nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package com.virgilsecurity.android.ethreeCoroutines.model - -/** - * . _ _ - * .| || | _ - * -| || || | Created by: - * .| || || |- Danylo Oliinyk - * ..\_ || | on - * ....| _/ 11/1/18 - * ...-| | \ at Virgil Security - * ....|_|- - */ - -/** - * Result that can be [Success] or [Error] - */ - -sealed class Result - -data class Success(val data: T) : Result() - -data class Failure(val error: Throwable?) : Result() - -inline fun Result.onSuccess(action: (T) -> Unit): Result { - if (this is Success) action(data) - - return this -} - -inline fun Result.onError(action: (Throwable) -> Unit) { - if (this is Failure && error != null) action(error) -} - -inline fun Result.mapOnSuccess(map: (T) -> R) = when (this) { - is Success -> Success( - map(data)) - is Failure -> this -} diff --git a/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/utils/TestConfig.kt b/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/utils/TestConfig.kt deleted file mode 100644 index 440e9676..00000000 --- a/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/utils/TestConfig.kt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2015-2019, Virgil Security, Inc. - * - * Lead Maintainer: Virgil Security Inc. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * (1) Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * (2) Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * (3) Neither the name of virgil nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package com.virgilsecurity.android.ethreeCoroutines.utils - -import android.support.test.InstrumentationRegistry -import com.virgilsecurity.ethree.test.BuildConfig -import com.virgilsecurity.sdk.crypto.VirgilCrypto -import com.virgilsecurity.sdk.crypto.VirgilPrivateKey -import com.virgilsecurity.sdk.crypto.VirgilPublicKey -import com.virgilsecurity.sdk.utils.ConvertionUtils - -class TestConfig { - companion object { - val virgilCrypto = VirgilCrypto(false) - val appId = BuildConfig.APP_ID - val apiKey: VirgilPrivateKey by lazy { - virgilCrypto.importPrivateKey(ConvertionUtils.base64ToBytes( - BuildConfig.API_PRIVATE_KEY)).privateKey - } - val apiPublicKey: VirgilPublicKey by lazy { - virgilCrypto.importPublicKey(ConvertionUtils.base64ToBytes( - BuildConfig.API_PUBLIC_KEY)) - } - val apiPublicKeyId = BuildConfig.API_PUBLIC_KEY_ID - - val virgilBaseUrl = BuildConfig.VIRGIL_BASE_URL - const val VIRGIL_CARDS_SERVICE_PATH = "/card/v5/" - - val context = InstrumentationRegistry.getTargetContext() - val DIRECTORY_PATH = InstrumentationRegistry.getTargetContext().filesDir.absolutePath - val KEYSTORE_NAME = "virgil.keystore" - } -} diff --git a/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/utils/TestUtils.kt b/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/utils/TestUtils.kt deleted file mode 100644 index 67a76c72..00000000 --- a/testscoroutines/src/androidTest/java/com/virgilsecurity/android/ethreeCoroutines/utils/TestUtils.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2015-2019, Virgil Security, Inc. - * - * Lead Maintainer: Virgil Security Inc. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * (1) Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * (2) Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * (3) Neither the name of virgil nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package com.virgilsecurity.android.ethreeCoroutines.utils - -class TestUtils { - - companion object { - const val THROTTLE_TIMEOUT = 2 * 1000L // 2 seconds - - fun pause() { - Thread.sleep(THROTTLE_TIMEOUT) - } - } -} diff --git a/testscoroutines/src/main/AndroidManifest.xml b/testscoroutines/src/main/AndroidManifest.xml deleted file mode 100644 index 113566d2..00000000 --- a/testscoroutines/src/main/AndroidManifest.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - diff --git a/testscoroutines/src/main/res/drawable-v24/ic_launcher_foreground.xml b/testscoroutines/src/main/res/drawable-v24/ic_launcher_foreground.xml deleted file mode 100644 index 9666db06..00000000 --- a/testscoroutines/src/main/res/drawable-v24/ic_launcher_foreground.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - diff --git a/testscoroutines/src/main/res/drawable/ic_launcher_background.xml b/testscoroutines/src/main/res/drawable/ic_launcher_background.xml deleted file mode 100644 index d3027ea2..00000000 --- a/testscoroutines/src/main/res/drawable/ic_launcher_background.xml +++ /dev/null @@ -1,203 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/testscoroutines/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/testscoroutines/src/main/res/mipmap-anydpi-v26/ic_launcher.xml deleted file mode 100644 index 235c4fa8..00000000 --- a/testscoroutines/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/testscoroutines/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/testscoroutines/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml deleted file mode 100644 index 235c4fa8..00000000 --- a/testscoroutines/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/testscoroutines/src/main/res/mipmap-hdpi/ic_launcher.png b/testscoroutines/src/main/res/mipmap-hdpi/ic_launcher.png deleted file mode 100644 index 898f3ed5..00000000 Binary files a/testscoroutines/src/main/res/mipmap-hdpi/ic_launcher.png and /dev/null differ diff --git a/testscoroutines/src/main/res/mipmap-hdpi/ic_launcher_round.png b/testscoroutines/src/main/res/mipmap-hdpi/ic_launcher_round.png deleted file mode 100644 index dffca360..00000000 Binary files a/testscoroutines/src/main/res/mipmap-hdpi/ic_launcher_round.png and /dev/null differ diff --git a/testscoroutines/src/main/res/mipmap-mdpi/ic_launcher.png b/testscoroutines/src/main/res/mipmap-mdpi/ic_launcher.png deleted file mode 100644 index 64ba76f7..00000000 Binary files a/testscoroutines/src/main/res/mipmap-mdpi/ic_launcher.png and /dev/null differ diff --git a/testscoroutines/src/main/res/mipmap-mdpi/ic_launcher_round.png b/testscoroutines/src/main/res/mipmap-mdpi/ic_launcher_round.png deleted file mode 100644 index dae5e082..00000000 Binary files a/testscoroutines/src/main/res/mipmap-mdpi/ic_launcher_round.png and /dev/null differ diff --git a/testscoroutines/src/main/res/mipmap-xhdpi/ic_launcher.png b/testscoroutines/src/main/res/mipmap-xhdpi/ic_launcher.png deleted file mode 100644 index e5ed4659..00000000 Binary files a/testscoroutines/src/main/res/mipmap-xhdpi/ic_launcher.png and /dev/null differ diff --git a/testscoroutines/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/testscoroutines/src/main/res/mipmap-xhdpi/ic_launcher_round.png deleted file mode 100644 index 14ed0af3..00000000 Binary files a/testscoroutines/src/main/res/mipmap-xhdpi/ic_launcher_round.png and /dev/null differ diff --git a/testscoroutines/src/main/res/mipmap-xxhdpi/ic_launcher.png b/testscoroutines/src/main/res/mipmap-xxhdpi/ic_launcher.png deleted file mode 100644 index b0907cac..00000000 Binary files a/testscoroutines/src/main/res/mipmap-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/testscoroutines/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/testscoroutines/src/main/res/mipmap-xxhdpi/ic_launcher_round.png deleted file mode 100644 index d8ae0315..00000000 Binary files a/testscoroutines/src/main/res/mipmap-xxhdpi/ic_launcher_round.png and /dev/null differ diff --git a/testscoroutines/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/testscoroutines/src/main/res/mipmap-xxxhdpi/ic_launcher.png deleted file mode 100644 index 2c18de9e..00000000 Binary files a/testscoroutines/src/main/res/mipmap-xxxhdpi/ic_launcher.png and /dev/null differ diff --git a/testscoroutines/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/testscoroutines/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png deleted file mode 100644 index beed3cdd..00000000 Binary files a/testscoroutines/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png and /dev/null differ diff --git a/testscoroutines/src/main/res/values/colors.xml b/testscoroutines/src/main/res/values/colors.xml deleted file mode 100644 index 605d9555..00000000 --- a/testscoroutines/src/main/res/values/colors.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - #008577 - #00574B - #D81B60 - diff --git a/testscoroutines/src/main/res/values/strings.xml b/testscoroutines/src/main/res/values/strings.xml deleted file mode 100644 index 03f59b41..00000000 --- a/testscoroutines/src/main/res/values/strings.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - testsCoroutines - diff --git a/testscoroutines/src/main/res/values/styles.xml b/testscoroutines/src/main/res/values/styles.xml deleted file mode 100644 index 28f4828c..00000000 --- a/testscoroutines/src/main/res/values/styles.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - -