Skip to content

Commit

Permalink
Merge pull request #42 from VirgilSecurity/dev
Browse files Browse the repository at this point in the history
Fixed group.add bug and gh-pages
  • Loading branch information
BuddahLD authored Feb 17, 2020
2 parents 7567446 + 0a6a031 commit 38e67be
Show file tree
Hide file tree
Showing 14 changed files with 269 additions and 72 deletions.
51 changes: 26 additions & 25 deletions .ci/push-javadoc-to-gh-pages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ get_version () {

while read line; do

firstWord="$(cut -d' ' -f1 <<< "$line")"
firstWord="$(cut -d'=' -f1 <<< "$line")"

if [[ "$firstWord" = "version" ]];
if [[ "$firstWord" = "final String SDK_VERSION " ]];
then
version="$(cut -d"'" -f2 <<< "$line")"
fi
Expand Down Expand Up @@ -77,17 +77,17 @@ generate_index_page() {
<h2 style="color:#110B91B0;">User modules</h2>
<hr/>
<h3>E3Kit</h3>
<ul><li><a href="content/ethree-kotlin/${2}/ethree-kotlin/index.html">${2}</a></li></ul>
<ul><li><a href="content/ethree-kotlin/${2}/ethree-kotlin/index.html">${4}</a></li></ul>
<h3>E3Kit Coroutines</h3>
<ul><li><a href="content/ethree-kotlin-coroutines/${3}/ethree-kotlin-coroutines/index.html">${3}</a></li></ul>
<h3>E3Kit Enclave</h3>
<ul><li><a href="content/ethree-enclave/${3}/ethree-enclave/index.html">${4}</a></li></ul>
<p>&nbsp;</p>
<h2 style="color:#110B91B1;">Internal modules</h2>
<hr/>
<h3>E3Kit Common</h3>
<ul><li><a href="content/ethree-common/${1}/ethree-common/index.html">${1}</a></li></ul>
<ul><li><a href="content/ethree-common/${1}/ethree-common/index.html">${4}</a></li></ul>
</div>
<p>&nbsp;</p>
Expand All @@ -106,25 +106,26 @@ if [[ "$TRAVIS_REPO_SLUG" == "VirgilSecurity/virgil-e3kit-kotlin" ]] && [[ "$TRA
# Generate docs
./gradlew :ethree-common:javadocJar
./gradlew :ethree-kotlin:javadocJar
./gradlew :ethree-kotlin-coroutines:javadocJar
./gradlew :ethree-enclave:javadocJar

versionCommon="-1"
versionEthree="-1"
versionEthreeCoroutines="-1"
version="-1"

# Get each module version
get_version "ethree-common/build.gradle" versionCommon
get_version "ethree-kotlin/build.gradle" versionEthree
get_version "ethree-kotlin-coroutines/build.gradle" versionEthreeCoroutines
get_version "build.gradle" version

# Folder names with module name and version
commonFolder="common_v${version}"
kotlinFolder="kotlin_v${version}"
enclaveFolder="enclave_v${version}"

# Create each module docs temporary folder
mkdir $HOME/javadoc-latest/
mkdir $HOME/javadoc-latest/${versionCommon}/
mkdir $HOME/javadoc-latest/${versionEthree}/
mkdir $HOME/javadoc-latest/${versionEthreeCoroutines}/
cp -R ethree-common/build/javadoc/. $HOME/javadoc-latest/${versionCommon}/
cp -R ethree-kotlin/build/javadoc/. $HOME/javadoc-latest/${versionEthree}/
cp -R ethree-kotlin-coroutines/build/javadoc/. $HOME/javadoc-latest/${versionEthreeCoroutines}/
mkdir $HOME/javadoc-latest/${commonFolder}/
mkdir $HOME/javadoc-latest/${kotlinFolder}/
mkdir $HOME/javadoc-latest/${enclaveFolder}/
cp -R ethree-common/build/javadoc/. $HOME/javadoc-latest/${commonFolder}/
cp -R ethree-kotlin/build/javadoc/. $HOME/javadoc-latest/${kotlinFolder}/
cp -R ethree-enclave/build/javadoc/. $HOME/javadoc-latest/${enclaveFolder}/

# Get last gh-pages docs
cd $HOME
Expand All @@ -138,17 +139,17 @@ if [[ "$TRAVIS_REPO_SLUG" == "VirgilSecurity/virgil-e3kit-kotlin" ]] && [[ "$TRA
git rm -rf content

# Create main index page for all modules
versions=(${versionCommon} ${versionEthree} ${versionEthreeCoroutines})
generate_index_page ${versions[*]}
args=(${commonFolder} ${kotlinFolder} ${enclaveFolder} ${version})
generate_index_page ${args[*]}

# Move each module docs to actual folder
mkdir content
mkdir content/ethree-common/
mkdir content/ethree-kotlin/
mkdir content/ethree-kotlin-coroutines/
mv $HOME/javadoc-latest/${versionCommon} content/ethree-common/
mv $HOME/javadoc-latest/${versionEthree} content/ethree-kotlin/
mv $HOME/javadoc-latest/${versionEthreeCoroutines} content/ethree-kotlin-coroutines/
mkdir content/ethree-enclave/
mv $HOME/javadoc-latest/${commonFolder} content/ethree-common/
mv $HOME/javadoc-latest/${kotlinFolder} content/ethree-kotlin/
mv $HOME/javadoc-latest/${enclaveFolder} content/ethree-enclave/

# Add new docs to index and commit
git add -f .
Expand Down
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ language: android
sudo: required
jdk: oraclejdk8

# Build all branches including gh-pages. Without this gh-pages will not be built.
branches:
only:
- gh-pages
- /.*/

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def getGradleOrSystemProperty(String name, Project project) {
final String BASE_VIRGIL_PACKAGE = 'com.virgilsecurity'

// Packages versions
final String SDK_VERSION = '0.8.0'
final String SDK_VERSION = '2.0.0'

subprojects {
group BASE_VIRGIL_PACKAGE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,19 @@ class GroupTests {
ethree.deleteGroup(fakeId).execute()
}

// test021 STE_86
@Test fun add_participants() {
val ethree2 = createEThree()

val identifier = UUID.randomUUID().toString()
val group = this.ethree.createGroup(identifier).get()
val card2 = ethree.findUser(ethree2.identity).get()
group.add(card2).execute()
val cachedGroup = this.ethree.getGroup(identifier)!!

assertEquals(cachedGroup.participants.toSet(), setOf(ethree.identity, ethree2.identity))
}

private fun createEThree(): EThree {
val identity = UUID.randomUUID().toString()
val tokenCallback = object : OnGetTokenCallback {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ import com.virgilsecurity.android.common.exception.*
import com.virgilsecurity.android.common.manager.GroupManager
import com.virgilsecurity.android.common.manager.LookupManager
import com.virgilsecurity.android.common.manager.TempChannelManager
import com.virgilsecurity.android.common.model.*
import com.virgilsecurity.android.common.model.DerivedPasswords
import com.virgilsecurity.android.common.model.FindUsersResult
import com.virgilsecurity.android.common.model.Group
import com.virgilsecurity.android.common.model.LookupResult
import com.virgilsecurity.android.common.model.ratchet.RatchetChannel
import com.virgilsecurity.android.common.model.temporary.TemporaryChannel
import com.virgilsecurity.android.common.storage.cloud.CloudKeyManager
Expand Down Expand Up @@ -124,14 +127,6 @@ abstract class EThreeCore {
val cardManager: CardManager
val identity: String

protected constructor(params: EThreeParams) : this(params.identity,
params.tokenCallback,
params.keyChangedCallback,
params.keyPairType,
params.enableRatchet,
params.keyRotationInterval,
params.context)

protected constructor(identity: String,
getTokenCallback: OnGetTokenCallback,
keyChangedCallback: OnKeyChangedCallback?,
Expand Down Expand Up @@ -325,9 +320,9 @@ abstract class EThreeCore {
* @throws FindUsersException(FindUsersException.Description.CARD_WAS_NOT_FOUND) If card
* duplicates was found or at least one card was not found.
*/
fun findUsers(identities: List<String>,
forceReload: Boolean = false,
checkResult: Boolean = true): Result<FindUsersResult> =
@JvmOverloads fun findUsers(identities: List<String>,
forceReload: Boolean = false,
checkResult: Boolean = true): Result<FindUsersResult> =
searchWorker.findUsers(identities, forceReload, checkResult)

/**
Expand All @@ -343,7 +338,7 @@ abstract class EThreeCore {
* @throws FindUsersException(FindUsersException.Description.CARD_WAS_NOT_FOUND) If card
* duplicates was found or at least one card was not found.
*/
fun findUser(identity: String, forceReload: Boolean = false): Result<Card> =
@JvmOverloads fun findUser(identity: String, forceReload: Boolean = false): Result<Card> =
searchWorker.findUser(identity, forceReload)

/**
Expand Down Expand Up @@ -486,7 +481,7 @@ abstract class EThreeCore {
* @throws GroupException.Description.INVALID_PARTICIPANTS_COUNT If participants count is out
* of [Group.VALID_PARTICIPANTS_COUNT_RANGE] range.
*/
fun createGroup(identifier: Data, users: FindUsersResult? = null): Result<Group> =
@JvmOverloads fun createGroup(identifier: Data, users: FindUsersResult? = null): Result<Group> =
groupWorker.createGroup(identifier, users)

/**
Expand Down Expand Up @@ -532,6 +527,7 @@ abstract class EThreeCore {
*
* @return New [Group].
*/
@JvmOverloads
fun createGroup(identifier: String, users: FindUsersResult? = null): Result<Group> =
groupWorker.createGroup(identifier, users)

Expand Down Expand Up @@ -976,6 +972,7 @@ abstract class EThreeCore {
* @throws EThreeException(EThreeException.Description.VERIFICATION_FAILED)
* @throws rethrows [VirgilCrypto.authDecrypt]
*/
@JvmOverloads
fun authDecrypt(inputStream: InputStream, outputStream: OutputStream, user: Card? = null) =
streamsEncryptWorker.authDecrypt(inputStream, outputStream, user)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ internal class GroupManager internal constructor(
?: throw GroupException(GroupException.Description.INCONSISTENT_STATE)
}

internal fun addAccess(cards: List<Card>, sessionId: Data) =
cloudTicketStorage.addRecipients(cards, sessionId)
internal fun addAccess(cards: List<Card>, newSet: Set<String>, sessionId: Data) {
cloudTicketStorage.addRecipients(cards, sessionId)
localGroupStorage.setParticipants(newSet, sessionId)
}

internal fun reAddAccess(card: Card, sessionId: Data) =
cloudTicketStorage.reAddRecipient(card, sessionId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class EThreeParams(
val identity: String,

// Callback to get Virgil access token.
val tokenCallback: OnGetTokenCallback,
// This method should return valid Json Web Token [String] representation with identity
// (in it) of the user which will use this class.
val tokenCallback: () -> String,

// Context
val context: Context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ class Group internal constructor(
return session
}

private fun shareTickets(cards: List<Card>) {
private fun shareTickets(cards: List<Card>, newSet: Set<String>) {
val sessionId = this.session.sessionId.toData()
groupManager.addAccess(cards, sessionId)
val newParticipants = cards.map { it.identity }
this.participants.addAll(newParticipants.toSet())
groupManager.addAccess(cards, newSet, sessionId)
this.participants = newSet.toMutableSet()
}

private fun addNewTicket(participants: FindUsersResult) {
Expand Down Expand Up @@ -162,7 +161,7 @@ class Group internal constructor(
*
* @return decrypted byte array.
*/
fun decrypt(data: ByteArray, senderCard: Card, date: Date? = null): ByteArray {
@JvmOverloads fun decrypt(data: ByteArray, senderCard: Card, date: Date? = null): ByteArray {
require(data.isNotEmpty()) { "\'data\' should not be empty" }

val encrypted = GroupSessionMessage.deserialize(data)
Expand Down Expand Up @@ -217,7 +216,7 @@ class Group internal constructor(
*
* @return decrypted String.
*/
fun decrypt(text: String, senderCard: Card, date: Date? = null): String {
@JvmOverloads fun decrypt(text: String, senderCard: Card, date: Date? = null): String {
require(text.isNotEmpty()) { "\'text\' should not be empty" }

val data: Data
Expand Down Expand Up @@ -276,7 +275,7 @@ class Group internal constructor(
addedCards.add(card)
}

this@Group.shareTickets(addedCards)
this@Group.shareTickets(addedCards, newSet)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2015-2020, Virgil Security, Inc.
*
* Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
*
* 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.common.model.java

import android.content.Context
import com.virgilsecurity.android.common.callback.OnGetTokenCallback
import com.virgilsecurity.android.common.callback.OnKeyChangedCallback
import com.virgilsecurity.android.common.util.Defaults
import com.virgilsecurity.sdk.client.CardClient
import com.virgilsecurity.sdk.common.TimeSpan
import com.virgilsecurity.sdk.crypto.KeyPairType

/**
* EThreeParams
*/
class EThreeParams(
// Identity of user.
val identity: String,

// Callback to get Virgil access token.
val tokenCallback: OnGetTokenCallback,

// Context
val context: Context) {

// Callback to notify the change of User's keys.
var keyChangedCallback: OnKeyChangedCallback? = null

// Enables ratchet operations.
var enableRatchet: Boolean = Defaults.enableRatchet

// TimeSpan of automatic rotate keys for double ratchet.
var keyRotationInterval: TimeSpan = Defaults.keyRotationInterval

// Default key pair type
var keyPairType: KeyPairType = Defaults.keyPairType
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
package com.virgilsecurity.android.common.storage.local

import com.virgilsecurity.android.common.exception.FileGroupStorageException
import com.virgilsecurity.android.common.exception.GroupException
import com.virgilsecurity.android.common.exception.RawGroupException
import com.virgilsecurity.android.common.model.GroupInfo
import com.virgilsecurity.android.common.model.RawGroup
Expand Down Expand Up @@ -111,6 +112,16 @@ internal class FileGroupStorage internal constructor(
fileSystemEncrypted.write(data, GROUP_INFO_NAME, subdir)
}

internal fun setParticipants(newParticipants: Set<String>, sessionId: Data) {
val tickets = retrieveLastTickets(1, sessionId)
val lastTicket = tickets.firstOrNull()
?: throw GroupException(GroupException.Description.INVALID_GROUP)
val newTicket = Ticket(lastTicket.groupMessage, newParticipants)
val subdir = sessionId.toHexString()

store(newTicket, subdir)
}

internal fun retrieve(sessionId: Data, count: Int): RawGroup {
val tickets = retrieveLastTickets(count, sessionId)
val groupInfo = retrieveGroupInfo(sessionId)
Expand Down
Loading

0 comments on commit 38e67be

Please sign in to comment.