Skip to content

Commit cd8dbd6

Browse files
authored
Merge pull request #35 from VirgilSecurity/dev-before-group-chats
Dev before group chats
2 parents fd53377 + 9d091b4 commit cd8dbd6

File tree

286 files changed

+12647
-3872
lines changed

Some content is hidden

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

286 files changed

+12647
-3872
lines changed

README.md

Lines changed: 123 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Build Status](https://travis-ci.com/VirgilSecurity/virgil-e3kit-kotlin.svg?branch=master)](https://travis-ci.com/VirgilSecurity/virgil-e3kit-kotlin)
44
[![GitHub license](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg)](https://github.com/VirgilSecurity/virgil/blob/master/LICENSE)
55

6-
[Introduction](#introduction) | [SDK Features](#sdk-features) | [Install E3Kit SDK](#install-e3kit-sdk) | [Usage](#usage) | [Samples](#samples) | [License](#license) | [Support](#support)
6+
[Introduction](#introduction) | [SDK Features](#sdk-features) | [Installation](#installation) | [Usage Examples](#usage-examples) | [Samples](#samples) | [License](#license) | [Docs](#docs) | [Support](#support)
77

88
## Introduction
99

@@ -15,40 +15,27 @@ Virgil E3kit allows you to setup user encryption with multidevice support in jus
1515
- group chats
1616
- manage users' Public Keys
1717

18-
## Install E3Kit SDK
18+
## Installation
1919

2020
You can install E3Kit SDK using [Gradle](https://gradle.org/). Please, choose package that suits best for your needs:
2121

2222
| Package | Description |
2323
|----------|---------|
2424
| [`E3Kit`](./ethree-kotlin) | Standard package for Java/Kotlin with methods responses in `callbacks` |
25-
| [`E3Kit Coroutines`](./ethree-kotlin-coroutines) | [Coroutines](https://github.com/Kotlin/kotlinx.coroutines) package with methods responses in [`Deferred`](https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/) |
2625

27-
## Samples
28-
29-
You can find the code samples for Java and Kotlin (for Kotlin-Coroutines module as well) here:
30-
31-
| Sample type |
32-
|----------|
33-
| [`Android Java`](./samples/android-java) |
34-
| [`Android Kotlin`](./samples/android-kotlin) |
35-
| [`Android Kotlin Coroutines`](./samples/android-kotlin-coroutines) |
36-
| [`Android Java Firebase`](./samples/android-java-firebase-function) |
37-
| [`Android Kotlin Firebase`](./samples/android-kotlin-firebase-function) |
3826

39-
You can run any of them on an emulator to check out the example of how to initialize the SDK, register users and encrypt messages using the E3Kit.
27+
## Usage Examples
4028

41-
## Usage
29+
#### Initialize e3kit
4230

43-
#### Register User
44-
Use the following lines of code to authenticate a user.
31+
In order to interact with the Virgil Cloud, the Virgil e3kit SDK must be provided with a callback that it will call to fetch the Virgil JWT from your backend for the current user.
4532

4633
```kotlin
47-
var eThree: EThree? = null
34+
lateinit var eThree: EThree
4835

4936
// Listener for E3Kit initialization
5037
val initializeListener =
51-
object : EThree.OnResultListener<EThree> {
38+
object : OnResultListener<EThree> {
5239
override fun onSuccess(result: EThree) {
5340
// Init done!
5441
eThree = result
@@ -60,91 +47,156 @@ val initializeListener =
6047
}
6148

6249
// initialize E3Kit
63-
EThree.initialize(context, virgilTokenCallback, initializeListener)
50+
EThree.initialize(context, virgilTokenCallback).addCallback(initializeListener)
6451
```
6552

66-
#### Encrypt & decrypt
53+
#### Register user
6754

68-
Virgil E3Kit lets you use a user's Private key and his or her Public Keys to sign, then encrypt text.
55+
Use the following lines of code to register a user:
6956

7057
```kotlin
71-
var eThree: EThree? = null
72-
var encryptedData: ByteArray? = null
73-
var encryptedText: String? = null
74-
75-
// Listener for keys lookup Two
76-
val lookupKeysListenerTwo =
77-
object : EThree.OnResultListener<Map<String, PublicKey>> {
78-
override fun onSuccess(result: Map<String, PublicKey>) {
79-
// Decrypt data using senders public key (In this example it's E3Kit current user)
80-
val decryptedData = eThree.decrypt(encryptedData!!, result[identityInToken])
81-
82-
// Decrypt data using senders public key (In this example it's E3Kit current user)
83-
val decryptedText = eThree.decrypt(encryptedText!!, result[identityInToken])
58+
// TODO: Initialize e3kit
59+
60+
val registerListener =
61+
object : OnCompleteListener {
62+
override fun onSuccess() {
63+
// User private key loaded, ready for end-to-end encrypt!
8464
}
8565

8666
override fun onError(throwable: Throwable) {
8767
// Error handling
8868
}
8969
}
9070

91-
// Listener for keys lookup
71+
eThree.register().addCallback(registerListener)
72+
```
73+
This function generates PrivateKey/PublicKey keypair, saves PrivateKey locally on device and publishes PublicKey to Virgil Cards Service.
74+
75+
#### Sign and encrypt data/text
76+
77+
This method signs the data/text with the sender's private key and encrypts the message for recipients' public key(s).
78+
79+
```kotlin
80+
// TODO: Initialize e3kit, Register e3kit user
81+
9282
val lookupKeysListener =
93-
object : EThree.OnResultListener<Map<String, PublicKey>> {
94-
override fun onSuccess(result: Map<String, PublicKey>) {
95-
val text = "I was a text, but become a byte array"
83+
object : OnResultListener<LookupResult> {
84+
override fun onSuccess(result: LookupResult) {
85+
val text = "I was text but become byte array"
9686
val data = text.toByteArray()
9787

9888
// Encrypt data using user public keys
99-
encryptedData = eThree.encrypt(data, result.values.toList())
89+
val encryptedData = eThree.encrypt(data, result)
10090

10191
// Encrypt message using user public keys
102-
encryptedText = eThree.encrypt(text, result.values.toList())
103-
104-
// E3Kit using identity that specified in Jwt provided with *virgilTokenCallback*
105-
eThree!!.lookupPublicKeys(listOf(identityInToken), lookupKeysListenerTwo)
92+
val encryptedText = eThree.encrypt(text, result)
10693
}
10794

10895
override fun onError(throwable: Throwable) {
10996
// Error handling
11097
}
11198
}
11299

113-
// Listener for register
114-
val registerListener =
115-
object : EThree.OnCompleteListener {
116-
override fun onSuccess() {
117-
// User private key loaded!
118-
// Now we need public keys and we ready for end-to-end encrypt.
119-
eThree!!.lookupPublicKeys(listOf("AliceUUID", "BobUUID"), lookupKeysListener)
100+
// Lookup destination user public keys
101+
eThree.lookupPublicKeys(listOf("userUID1", "userUID2", "userUID3")).addCallback(lookupKeysListener)
102+
```
103+
104+
#### Decrypt data/text and verify signature
105+
106+
This method decrypts the data using the recipient's private key and verifies authenticity of the decrypted data with sender's public key.
107+
108+
```kotlin
109+
// TODO: Initialize e3kit, Register e3kit user
110+
111+
val lookupKeysListener =
112+
object : OnResultListener<LookupResult> {
113+
override fun onSuccess(result: LookupResult) {
114+
// Decrypt data and verify if it was really written by Bob
115+
val decryptedData = eThree.decrypt(encryptedData, result["bobUID"])
116+
117+
// Decrypt text and verify if it was really written by Bob
118+
val decryptedText = eThree.decrypt(encryptedText, result["bobUID"])
120119
}
121120

122121
override fun onError(throwable: Throwable) {
123122
// Error handling
124123
}
125124
}
126125

127-
// Listener for E3Kit initialization
128-
val initializeListener =
129-
object : EThree.OnResultListener<EThree> {
130-
override fun onSuccess(result: EThree) {
131-
// Init done!
132-
eThree = result
133-
eThree!!.register(registerListener)
134-
}
126+
// Lookup chat room member key
127+
eThree.lookupPublicKeys("bobUID").addCallback(lookupKeysListener)
128+
```
135129

136-
override fun onError(throwable: Throwable) {
137-
// Error handling
130+
#### Encrypt & decrypt large files
131+
132+
If the data that needs to be encrypted is too large for your RAM to encrypt all at once, use the following snippets to encrypt and decrypt streams.
133+
> Stream encryption doesn’t sign the data. This is why stream decryption doesn’t require VirgilPublicKey for verification unlike the general data decryption.
134+
135+
Encryption:
136+
```kotlin
137+
// TODO: initialize and register user (see EThree.initialize and EThree#register)
138+
139+
// Listener for keys lookup
140+
val lookupKeysListener =
141+
object : OnResultListener<LookupResult> {
142+
override fun onSuccess(result: LookupResult) {
143+
val assetManager = context.assets
144+
145+
assetManager.open("some_file.txt").use { inputStream ->
146+
ByteArrayOutputStream().use { outputStream ->
147+
// Encrypt input stream using user public keys and writes output to the output stream
148+
eThree.encrypt(inputStream, outputStream, result)
149+
}
150+
}
151+
}
152+
153+
override fun onError(throwable: Throwable) {
154+
// Error handling
155+
}
138156
}
139-
}
140157

141-
// initialize E3Kit
142-
EThree.initialize(context, virgilTokenCallback, initializeListener)
158+
// Lookup destination user public keys
159+
eThree.lookupPublicKeys(listOf("userUID1", "userUID2", "userUID3")).addCallback(lookupKeysListener)
160+
```
161+
162+
Decryption:
163+
```kotlin
164+
// TODO: init SDK and register users - see EThree.initialize and EThree#register
165+
ByteArrayOutputStream().use { outputStream ->
166+
// Decrypt encrypted input stream and writes output to the output stream
167+
eThree.decrypt(encryptedStream, outputStream)
168+
}
143169
```
144170

171+
## Samples
172+
173+
You can find the code samples for Java and Kotlin here:
174+
175+
| Sample type |
176+
|----------|
177+
| [`Android Java`](./samples/android-java) |
178+
| [`Android Kotlin`](./samples/android-kotlin) |
179+
| [`Android Java Firebase`](./samples/android-java-firebase-function) |
180+
| [`Android Kotlin Firebase`](./samples/android-kotlin-firebase-function) |
181+
| [`Android Kotlin Back4App`](./samples/android-kotlin-back4app) |
182+
| [`Android Kotlin Nexmo`](./samples/android-kotlin-nexmo) |
183+
184+
You can run any of them on an emulator to check out the example of how to initialize the SDK, register users and encrypt messages using the E3Kit.
185+
145186
## License
146187

147-
This library is released under the [3-clause BSD License](LICENSE).
188+
This library is released under the [3-clause BSD License](LICENSE.md).
189+
190+
## Docs
191+
Virgil Security has a powerful set of APIs, and the documentation below can get you started today.
192+
193+
* E3kit integrations with:
194+
* [Custom platform][_any_platform]
195+
* [Firebase][_firebase]
196+
* [Twilio][_twilio]
197+
* [Nexmo][_nexmo]
198+
* [Pubnub][_pubnub]
199+
* [Reference API][_reference_api]
148200

149201
## Support
150202
Our developer support team is here to help you. Find out more information on our [Help Center](https://help.virgilsecurity.com/).
@@ -153,16 +205,9 @@ You can find us on [Twitter](https://twitter.com/VirgilSecurity) or send us emai
153205

154206
Also, get extra help from our support team on [Slack](https://virgilsecurity.com/join-community).
155207

156-
[_cards_service]: https://developer.virgilsecurity.com/docs/api-reference/card-service/v5
157-
[_use_card]: https://developer.virgilsecurity.com/docs/swift/how-to/public-key-management/v5/use-card-for-crypto-operation
158-
[_get_card]: https://developer.virgilsecurity.com/docs/swift/how-to/public-key-management/v5/get-card
159-
[_search_card]: https://developer.virgilsecurity.com/docs/swift/how-to/public-key-management/v5/search-card
160-
[_create_card]: https://developer.virgilsecurity.com/docs/swift/how-to/public-key-management/v5/create-card
161-
[_own_crypto]: https://developer.virgilsecurity.com/docs/swift/how-to/setup/v5/setup-own-crypto-library
162-
[_key_storage]: https://developer.virgilsecurity.com/docs/swift/how-to/setup/v5/setup-key-storage
163-
[_card_verifier]: https://developer.virgilsecurity.com/docs/swift/how-to/setup/v5/setup-card-verifier
164-
[_card_manager]: https://developer.virgilsecurity.com/docs/swift/how-to/setup/v5/setup-card-manager
165-
[_setup_authentication]: https://developer.virgilsecurity.com/docs/swift/how-to/setup/v5/setup-authentication
208+
[_any_platform]: https://developer.virgilsecurity.com/docs/use-cases/v5/encrypted-communication
209+
[_twilio]: https://developer.virgilsecurity.com/docs/use-cases/v5/encrypted-communication-for-twilio
210+
[_nexmo]: https://developer.virgilsecurity.com/docs/use-cases/v5/encrypted-communication-for-nexmo
211+
[_firebase]: https://developer.virgilsecurity.com/docs/use-cases/v5/encrypted-communication-for-firebase
212+
[_pubnub]: https://developer.virgilsecurity.com/docs/use-cases/v5/smart-door-lock
166213
[_reference_api]: https://developer.virgilsecurity.com/docs/api-reference
167-
[_configure_sdk]: https://developer.virgilsecurity.com/docs/how-to#sdk-configuration
168-
[_more_examples]: https://developer.virgilsecurity.com/docs/how-to#public-key-management

0 commit comments

Comments
 (0)