Skip to content

Commit 9d091b4

Browse files
authored
Merge pull request #31 from VirgilSecurity/enclave
Added Secure Enclave module
2 parents f53faf5 + a813413 commit 9d091b4

File tree

148 files changed

+4420
-292
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+4420
-292
lines changed

build.gradle

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ buildscript {
4444
coroutines : '1.3.0-M1',
4545

4646
// Gradle
47-
gardle : '3.4.2',
47+
gradle : '3.4.2',
48+
49+
// Maven
50+
mavenPublish: '3.6.2',
4851

4952
// Android
5053
android : '4.1.1.4',
@@ -63,15 +66,16 @@ buildscript {
6366
mavenCentral()
6467
}
6568
dependencies {
66-
classpath "com.android.tools.build:gradle:$versions.gardle"
69+
classpath "com.android.tools.build:gradle:$versions.gradle"
6770
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin"
6871
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$versions.dokka"
69-
classpath 'digital.wup:android-maven-publish:3.6.2'
72+
classpath "digital.wup:android-maven-publish:$versions.mavenPublish"
7073
}
7174
}
7275

7376
allprojects {
7477
repositories {
78+
mavenLocal()
7579
google()
7680
jcenter()
7781
mavenCentral()

ethree-common/src/main/java/com/virgilsecurity/android/common/data/Const.kt renamed to ethree-common/src/main/java/com/virgilsecurity/android/common/Const.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232
*/
3333

34-
package com.virgilsecurity.android.common.data
34+
package com.virgilsecurity.android.common
3535

3636
/**
3737
* Const
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232
*/
3333

34-
package com.virgilsecurity.android.ethree.kotlin.callback
34+
package com.virgilsecurity.android.common.callback
3535

3636
/**
3737
* Interface that is intended to signal if some asynchronous process is completed successfully
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232
*/
3333

34-
package com.virgilsecurity.android.ethree.kotlin.callback
34+
package com.virgilsecurity.android.common.callback
3535

3636
/**
3737
* Interface that should provide Json Web Token when [onGetToken] callback is called.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232
*/
3333

34-
package com.virgilsecurity.android.ethree.kotlin.callback
34+
package com.virgilsecurity.android.common.callback
3535

3636
/**
3737
* Interface that is intended to return *<T>* type result if some asynchronous process is

ethree-common/src/main/java/com/virgilsecurity/android/common/data/model/LookupResult.kt

Lines changed: 0 additions & 9 deletions
This file was deleted.

ethree-kotlin/src/main/java/com/virgilsecurity/android/ethree/kotlin/interaction/EThree.kt renamed to ethree-common/src/main/java/com/virgilsecurity/android/common/interaction/EThreeCore.kt

Lines changed: 26 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,17 @@
3131
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232
*/
3333

34-
package com.virgilsecurity.android.ethree.kotlin.interaction
35-
36-
import android.content.Context
37-
import com.virgilsecurity.android.common.data.Const
38-
import com.virgilsecurity.android.common.data.Const.NO_CONTEXT
39-
import com.virgilsecurity.android.common.data.Const.VIRGIL_BASE_URL
40-
import com.virgilsecurity.android.common.data.Const.VIRGIL_CARDS_SERVICE_PATH
41-
import com.virgilsecurity.android.common.data.local.KeyManagerLocal
42-
import com.virgilsecurity.android.common.data.model.LookupResult
43-
import com.virgilsecurity.android.common.data.remote.KeyManagerCloud
34+
package com.virgilsecurity.android.common.interaction
35+
36+
import com.virgilsecurity.android.common.Const
37+
import com.virgilsecurity.android.common.Const.NO_CONTEXT
38+
import com.virgilsecurity.android.common.Const.VIRGIL_BASE_URL
39+
import com.virgilsecurity.android.common.Const.VIRGIL_CARDS_SERVICE_PATH
4440
import com.virgilsecurity.android.common.exceptions.*
45-
import com.virgilsecurity.android.ethree.build.VersionVirgilAgent
46-
import com.virgilsecurity.android.ethree.kotlin.callback.OnGetTokenCallback
47-
import com.virgilsecurity.android.ethree.kotlin.model.Completable
48-
import com.virgilsecurity.android.ethree.kotlin.model.Result
41+
import com.virgilsecurity.android.common.model.Completable
42+
import com.virgilsecurity.android.common.model.LookupResult
43+
import com.virgilsecurity.android.common.model.Result
44+
import com.virgilsecurity.keyknox.build.VersionVirgilAgent
4945
import com.virgilsecurity.keyknox.exception.DecryptionFailedException
5046
import com.virgilsecurity.keyknox.exception.EntryAlreadyExistsException
5147
import com.virgilsecurity.pythia.brainkey.BrainKey
@@ -61,7 +57,6 @@ import com.virgilsecurity.sdk.crypto.VirgilCrypto
6157
import com.virgilsecurity.sdk.crypto.VirgilPrivateKey
6258
import com.virgilsecurity.sdk.crypto.VirgilPublicKey
6359
import com.virgilsecurity.sdk.exception.EmptyArgumentException
64-
import com.virgilsecurity.sdk.jwt.Jwt
6560
import com.virgilsecurity.sdk.jwt.accessProviders.CachingJwtProvider
6661
import com.virgilsecurity.sdk.jwt.contract.AccessTokenProvider
6762
import com.virgilsecurity.sdk.storage.DefaultKeyStorage
@@ -70,19 +65,20 @@ import java.io.InputStream
7065
import java.io.OutputStream
7166

7267
/**
73-
* [EThree] class simplifies work with Virgil Services to easily implement End to End Encrypted
68+
* [EThreeCore] class simplifies work with Virgil Services to easily implement End to End Encrypted
7469
* communication.
7570
*/
76-
class EThree
71+
abstract class EThreeCore
7772
/**
78-
* @constructor Initializing [CardManager] with provided in [EThree.initialize] callback
73+
* @constructor Initializing [CardManager] with provided in [EThreeCore.initialize] callback
7974
* [onGetTokenCallback] using [CachingJwtProvider] also initializing [DefaultKeyStorage] with
8075
* default settings.
81-
*/ private constructor(context: Context, private val tokenProvider: AccessTokenProvider) {
76+
*/
77+
constructor(private val tokenProvider: AccessTokenProvider) {
8278

8379
private val virgilCrypto = VirgilCrypto()
8480
private val cardManager: CardManager
85-
private val keyManagerLocal: KeyManagerLocal
81+
protected abstract val keyManagerLocal: KeyManagerLocal
8682
private val keyManagerCloud: KeyManagerCloud
8783

8884
init {
@@ -94,38 +90,11 @@ class EThree
9490
VirgilCardClient(VIRGIL_BASE_URL + VIRGIL_CARDS_SERVICE_PATH,
9591
httpClient))
9692
}
97-
keyManagerLocal = KeyManagerLocal(tokenProvider.getToken(NO_CONTEXT).identity, context)
98-
keyManagerCloud = KeyManagerCloud(currentIdentity(),
99-
tokenProvider,
100-
VersionVirgilAgent.VERSION)
101-
}
102-
103-
companion object {
104-
/**
105-
* Current method allows you to initialize EThree helper class. To do this you
106-
* should provide [onGetTokenCallback] that must return Json Web Token string
107-
* representation with identity of the user which will use this class.
108-
* In [onResultListener] you will receive instance of [EThree] class or an [Throwable]
109-
* if something went wrong.
110-
*
111-
* To start execution of the current function, please see [Result] description.
112-
*/
113-
@JvmStatic fun initialize(context: Context,
114-
onGetTokenCallback: OnGetTokenCallback) = object : Result<EThree> {
115-
override fun get(): EThree {
116-
val tokenProvider = CachingJwtProvider(CachingJwtProvider.RenewJwtCallback {
117-
Jwt(onGetTokenCallback.onGetToken())
118-
})
119-
120-
// Just check whether we can get token, otherwise there's no reasons to
121-
// initialize EThree. We have caching JWT provider, so sequential calls
122-
// won't take much time, as token will be cached after first call.
123-
tokenProvider.getToken(NO_CONTEXT)
124-
return EThree(context, tokenProvider)
125-
}
126-
}
12793

128-
private const val THROTTLE_TIMEOUT = 2 * 1000L // 2 seconds
94+
keyManagerCloud = KeyManagerCloud(
95+
currentIdentity(),
96+
tokenProvider,
97+
VersionVirgilAgent.VERSION)
12998
}
13099

131100
/**
@@ -157,7 +126,7 @@ class EThree
157126

158127
/**
159128
* Revokes the public key for current *identity* in Virgil's Cards Service. After this operation
160-
* you can call [EThree.register] again.
129+
* you can call [EThreeCore.register] again.
161130
*
162131
* To start execution of the current function, please see [Completable] description.
163132
*
@@ -606,7 +575,7 @@ class EThree
606575
* [PublicKey] in [onResultListener] callback or [Throwable] if something went wrong.
607576
*
608577
* [PublicKeyNotFoundException] will be thrown for the first not found public key.
609-
* [EThree.register]
578+
* [EThreeCore.register]
610579
*
611580
* Can be called only if private key is on the device, otherwise [PrivateKeyNotFoundException]
612581
* exception will be thrown.
@@ -679,4 +648,8 @@ class EThree
679648
"You have to get private key first. Use \'register\' " +
680649
"or \'restorePrivateKey\' functions.")
681650
}
651+
652+
companion object {
653+
private const val THROTTLE_TIMEOUT = 2 * 1000L // 2 seconds
654+
}
682655
}

ethree-common/src/main/java/com/virgilsecurity/android/common/data/remote/KeyManagerCloud.kt renamed to ethree-common/src/main/java/com/virgilsecurity/android/common/interaction/KeyManagerCloud.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232
*/
3333

34-
package com.virgilsecurity.android.common.data.remote
34+
package com.virgilsecurity.android.common.interaction
3535

36-
import com.virgilsecurity.android.common.data.Const
37-
import com.virgilsecurity.android.common.data.Const.VIRGIL_BASE_URL
36+
import com.virgilsecurity.android.common.Const
37+
import com.virgilsecurity.android.common.Const.VIRGIL_BASE_URL
3838
import com.virgilsecurity.keyknox.KeyknoxManager
3939
import com.virgilsecurity.keyknox.client.HttpClient
4040
import com.virgilsecurity.keyknox.client.KeyknoxClient
@@ -71,7 +71,7 @@ class KeyManagerCloud(
7171

7272
fun exists(password: String) = initCloudKeyStorage(password).exists(identity)
7373

74-
fun store(password: String, data: ByteArray, meta: Map<String, String>? = null) =
74+
fun store(password: String, data: ByteArray, meta: Map<String, String>?) =
7575
initCloudKeyStorage(password).store(identity, data, meta)
7676

7777
fun retrieve(password: String) = initCloudKeyStorage(password).retrieve(identity)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2015-2019, Virgil Security, Inc.
3+
*
4+
* Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
5+
*
6+
* All rights reserved.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* (1) Redistributions of source code must retain the above copyright notice, this
12+
* list of conditions and the following disclaimer.
13+
*
14+
* (2) Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* (3) Neither the name of virgil nor the names of its
19+
* contributors may be used to endorse or promote products derived from
20+
* this software without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
34+
package com.virgilsecurity.android.common.interaction
35+
36+
import com.virgilsecurity.sdk.storage.KeyEntry
37+
38+
/**
39+
* KeyManagerLocal
40+
*/
41+
interface KeyManagerLocal {
42+
43+
fun exists() : Boolean
44+
45+
fun store(privateKey: ByteArray)
46+
47+
fun load(): KeyEntry
48+
49+
fun delete()
50+
}

ethree-kotlin/src/main/java/com/virgilsecurity/android/ethree/kotlin/model/Completable.kt renamed to ethree-common/src/main/java/com/virgilsecurity/android/common/model/Completable.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232
*/
3333

34-
package com.virgilsecurity.android.ethree.kotlin.model
34+
package com.virgilsecurity.android.common.model
3535

36-
import com.virgilsecurity.android.ethree.kotlin.callback.OnCompleteListener
36+
import com.virgilsecurity.android.common.callback.OnCompleteListener
3737
import kotlinx.coroutines.CoroutineScope
3838
import kotlinx.coroutines.GlobalScope
3939
import kotlinx.coroutines.launch
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2015-2019, Virgil Security, Inc.
3+
*
4+
* Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
5+
*
6+
* All rights reserved.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* (1) Redistributions of source code must retain the above copyright notice, this
12+
* list of conditions and the following disclaimer.
13+
*
14+
* (2) Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* (3) Neither the name of virgil nor the names of its
19+
* contributors may be used to endorse or promote products derived from
20+
* this software without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
34+
package com.virgilsecurity.android.common.model
35+
36+
import com.virgilsecurity.sdk.crypto.VirgilPublicKey
37+
38+
/**
39+
* Lookup Result typealias to ease e3kit usage
40+
*/
41+
42+
typealias LookupResult = Map<String, VirgilPublicKey>

ethree-kotlin/src/main/java/com/virgilsecurity/android/ethree/kotlin/model/Result.kt renamed to ethree-common/src/main/java/com/virgilsecurity/android/common/model/Result.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232
*/
3333

34-
package com.virgilsecurity.android.ethree.kotlin.model
34+
package com.virgilsecurity.android.common.model
3535

36-
import com.virgilsecurity.android.ethree.kotlin.callback.OnResultListener
36+
import com.virgilsecurity.android.common.callback.OnResultListener
3737
import kotlinx.coroutines.CoroutineScope
3838
import kotlinx.coroutines.GlobalScope
3939
import kotlinx.coroutines.launch

0 commit comments

Comments
 (0)