Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #5

Merged
merged 8 commits into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,5 @@ gradle-app.setting
testsDev.sh
testsStg.sh
testsProd.sh
env.json
!env.json.enc
7 changes: 1 addition & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ language: android
sudo: required
jdk: oraclejdk8

# Include branches
branches:
only:
- dev
- master

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
Expand Down Expand Up @@ -57,6 +51,7 @@ before_install:
- echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license"
- chmod +x gradlew
- ./gradlew dependencies || true
- openssl aes-256-cbc -K $encrypted_5e363c91209e_key -iv $encrypted_5e363c91209e_iv -in env.json.enc -out env.json -d

before_script:
- android list targets
Expand Down
21 changes: 9 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2019, Virgil Security, Inc.
* Copyright (c) 2015-2020, Virgil Security, Inc.
*
* Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
*
Expand Down Expand Up @@ -34,15 +34,15 @@
buildscript {
ext.versions = [
// Kotlin
kotlinVersion : '1.3.40',
coroutines : '1.3.0-M1',
kotlinVersion : '1.3.61',
coroutines : '1.3.2',

// Gradle
gradle : '3.4.1',
gradle : '3.5.2',

// Virgil
virgilSdk : '5.1.2',
virgilCrypto : '0.8.0',
virgilSdk : '7.1.0',
virgilCrypto : '0.12.0',

// Serializer
gson : '2.8.5',
Expand All @@ -52,6 +52,7 @@ buildscript {

// Android
android : '4.1.1.4',
compatLibs : '28.0.0',

// Publish
mavenPublishPlugin: '3.6.2',
Expand All @@ -63,13 +64,13 @@ buildscript {
junit : '5.5.0',
junitPlugin : '1.0.0',
junitOld : '4.12',
virgilTestCommon : '0.1',
]

repositories {
google()
jcenter()
mavenCentral()
mavenLocal()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlinVersion"
Expand All @@ -81,16 +82,12 @@ buildscript {

allprojects {
repositories {
mavenLocal()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
google()
jcenter()
mavenCentral()
}
}

subprojects {
version = '0.1.0'
version = '0.1.1'
}
Binary file added env.json.enc
Binary file not shown.
38 changes: 36 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
#
# 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.
#

#Thu Dec 05 16:14:58 EET 2019
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
33 changes: 21 additions & 12 deletions ratchet-android-tests/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2019, Virgil Security, Inc.
* Copyright (c) 2015-2020, Virgil Security, Inc.
*
* Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
*
Expand Down Expand Up @@ -47,10 +47,10 @@ static def getEnvironmentValue(String name) {
}
}

def APP_ID = hasProperty('APP_ID') ? "\"$APP_ID\"" : getEnvironmentValue('APP_ID')
def API_PRIVATE_KEY = hasProperty('API_PRIVATE_KEY') ? "\"$API_PRIVATE_KEY\"" : getEnvironmentValue('API_PRIVATE_KEY')
def API_PUBLIC_KEY_ID = hasProperty('API_PUBLIC_KEY_ID') ? "\"$API_PUBLIC_KEY_ID\"" : getEnvironmentValue('API_PUBLIC_KEY_ID')
def SERVICE_URL = hasProperty('SERVICE_URL') ? "\"$SERVICE_URL\"" : getEnvironmentValue('SERVICE_URL')
def APP_ID = hasProperty('APP_ID') ? "\"${project.property("APP_ID")}\"" : getEnvironmentValue('APP_ID')
def API_PRIVATE_KEY = hasProperty('API_PRIVATE_KEY') ? "\"${project.property("API_PRIVATE_KEY")}\"" : getEnvironmentValue('API_PRIVATE_KEY')
def API_PUBLIC_KEY_ID = hasProperty('API_PUBLIC_KEY_ID') ? "\"${project.property("API_PUBLIC_KEY_ID")}\"" : getEnvironmentValue('API_PUBLIC_KEY_ID')
def SERVICE_URL = hasProperty('SERVICE_URL') ? "\"${project.property("SERVICE_URL")}\"" : getEnvironmentValue('SERVICE_URL')

android {
compileSdkVersion 28
Expand All @@ -72,19 +72,28 @@ android {

dependencies {
// Internal
implementation project(':ratchet-android')
androidTestImplementation project(':ratchet-android')

// Kotlin
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$versions.kotlinVersion"
implementation 'com.android.support:appcompat-v7:28.0.0'

// Virgil
androidTestImplementation "com.virgilsecurity.crypto:common-android:$versions.virgilCrypto"
androidTestImplementation "com.virgilsecurity.crypto:foundation-android:$versions.virgilCrypto"
androidTestImplementation "com.virgilsecurity.crypto:ratchet-android:$versions.virgilCrypto"
implementation "com.android.support:appcompat-v7:$versions.compatLibs"

// Test
testImplementation "junit:junit:$versions.junitOld"
androidTestImplementation "com.android.support.test:runner:$versions.testsRunner"
androidTestImplementation "com.android.support.test.espresso:espresso-core:$versions.espresso"

androidTestImplementation "com.virgilsecurity:test-common:$versions.virgilTestCommon"
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
dependsOn(copyEnvFile)
}

task copyEnvFile(type: Copy) {
def assetsFolder = new File(project.projectDir.absolutePath + '/src/androidTest/resources/testProperties')
if (!assetsFolder.exists()) assetsFolder.mkdirs()

from rootProject.projectDir.absolutePath + '/env.json'
into assetsFolder.absolutePath
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2019, Virgil Security, Inc.
* Copyright (c) 2015-2020, Virgil Security, Inc.
*
* Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
*
Expand Down Expand Up @@ -35,7 +35,6 @@ package com.virgilsecurity.android.ratchet

import com.virgilsecurity.crypto.ratchet.RatchetException
import com.virgilsecurity.ratchet.client.RatchetClient
import com.virgilsecurity.ratchet.exception.SecureGroupSessionException
import com.virgilsecurity.ratchet.keystorage.FileLongTermKeysStorage
import com.virgilsecurity.ratchet.keystorage.FileOneTimeKeysStorage
import com.virgilsecurity.ratchet.securechat.SecureChat
Expand All @@ -49,7 +48,7 @@ import com.virgilsecurity.sdk.cards.CardManager
import com.virgilsecurity.sdk.cards.validation.VirgilCardVerifier
import com.virgilsecurity.sdk.client.VirgilCardClient
import com.virgilsecurity.sdk.common.TimeSpan
import com.virgilsecurity.sdk.crypto.KeyType
import com.virgilsecurity.sdk.crypto.KeyPairType
import com.virgilsecurity.sdk.crypto.VirgilAccessTokenSigner
import com.virgilsecurity.sdk.crypto.VirgilCardCrypto
import com.virgilsecurity.sdk.crypto.VirgilCrypto
Expand Down Expand Up @@ -82,13 +81,13 @@ class GroupIntegrationTest {

for (i in 0 until numberOfParticipants) {
val identity = generateIdentity()
val keyPair = this.crypto.generateKeyPair(KeyType.ED25519)
val keyPair = this.crypto.generateKeyPair(KeyPairType.ED25519)
val tokenProvider = CachingJwtProvider(CachingJwtProvider.RenewJwtCallback {
val generator = JwtGenerator(
TestConfig.appId,
TestConfig.apiPrivateKey,
TestConfig.apiPublicKeyId,
TimeSpan.fromTime(10050, TimeUnit.MILLISECONDS), VirgilAccessTokenSigner(this.crypto)
TestConfig.appPrivateKey,
TestConfig.appPublicKeyId,
TimeSpan.fromTime(30, TimeUnit.MINUTES), VirgilAccessTokenSigner(this.crypto)
)

return@RenewJwtCallback generator.generateToken(identity)
Expand Down Expand Up @@ -294,13 +293,13 @@ class GroupIntegrationTest {

@Test
fun decrypt__wrong_sender__should_return_error() {
val num = 2
val num = 3
init(num)

val sessionId = this.crypto.generateRandomData(32)
val initMsg = this.chats.first().startNewGroupSession(sessionId)

var sessions = mutableListOf<SecureGroupSession>()
val sessions = mutableListOf<SecureGroupSession>()

for (i in 0 until num) {
val localCards = cards.toMutableList()
Expand All @@ -319,18 +318,18 @@ class GroupIntegrationTest {
val crypto = VirgilCrypto()

try {
sessions[1].decryptString(message, sessions[1].myIdentifier())
sessions[1].decryptString(message, sessions[2].myIdentifier())
fail()
} catch (e: SecureGroupSessionException) {
assertEquals(SecureGroupSessionException.WRONG_SENDER, e.errorCode)
} catch (e: RatchetException) {
assertEquals(RatchetException.ERROR_INVALID_SIGNATURE, e.statusCode)
}

try {
val randomCardId = crypto.generateRandomData(32).hexEncodedString()
sessions[1].decryptString(message, randomCardId)
fail()
} catch (e: SecureGroupSessionException) {
assertEquals(SecureGroupSessionException.WRONG_SENDER, e.errorCode)
} catch (e: RatchetException) {
assertEquals(RatchetException.ERROR_SENDER_NOT_FOUND, e.statusCode)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2019, Virgil Security, Inc.
* Copyright (c) 2015-2020, Virgil Security, Inc.
*
* Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
*
Expand Down Expand Up @@ -45,7 +45,7 @@ import com.virgilsecurity.sdk.cards.CardManager
import com.virgilsecurity.sdk.cards.validation.VirgilCardVerifier
import com.virgilsecurity.sdk.client.VirgilCardClient
import com.virgilsecurity.sdk.common.TimeSpan
import com.virgilsecurity.sdk.crypto.KeyType
import com.virgilsecurity.sdk.crypto.KeyPairType
import com.virgilsecurity.sdk.crypto.VirgilAccessTokenSigner
import com.virgilsecurity.sdk.crypto.VirgilCardCrypto
import com.virgilsecurity.sdk.crypto.VirgilCrypto
Expand Down Expand Up @@ -314,14 +314,14 @@ class IntegrationTest {
val client = RatchetClient(URL(TestConfig.serviceURL))

val senderIdentity = generateIdentity()
val senderIdentityKeyPair = this.crypto.generateKeyPair(KeyType.ED25519)
val senderIdentityKeyPair = this.crypto.generateKeyPair(KeyPairType.ED25519)

val senderTokenProvider = CachingJwtProvider(CachingJwtProvider.RenewJwtCallback {
val generator = JwtGenerator(
TestConfig.appId,
TestConfig.apiPrivateKey,
TestConfig.apiPublicKeyId,
TimeSpan.fromTime(10050, TimeUnit.MILLISECONDS),
TestConfig.appPrivateKey,
TestConfig.appPublicKeyId,
TimeSpan.fromTime(30, TimeUnit.MINUTES),
VirgilAccessTokenSigner(this.crypto)
)

Expand Down Expand Up @@ -360,14 +360,14 @@ class IntegrationTest {
)

val receiverIdentity = generateIdentity()
val receiverIdentityKeyPair = this.crypto.generateKeyPair(KeyType.ED25519)
val receiverIdentityKeyPair = this.crypto.generateKeyPair(KeyPairType.ED25519)

val receiverTokenProvider = CachingJwtProvider(CachingJwtProvider.RenewJwtCallback {
val generator = JwtGenerator(
TestConfig.appId,
TestConfig.apiPrivateKey,
TestConfig.apiPublicKeyId,
TimeSpan.fromTime(10050, TimeUnit.MILLISECONDS),
TestConfig.appPrivateKey,
TestConfig.appPublicKeyId,
TimeSpan.fromTime(30, TimeUnit.MINUTES),
VirgilAccessTokenSigner(this.crypto)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2019, Virgil Security, Inc.
* Copyright (c) 2015-2020, Virgil Security, Inc.
*
* Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
*
Expand Down Expand Up @@ -33,6 +33,7 @@

package com.virgilsecurity.android.ratchet

import com.virgilsecurity.common.model.Completable
import com.virgilsecurity.crypto.ratchet.RatchetKeyId
import com.virgilsecurity.ratchet.client.RatchetClientInterface
import com.virgilsecurity.ratchet.client.data.IdentityPublicKeySet
Expand All @@ -44,8 +45,7 @@ import com.virgilsecurity.ratchet.keystorage.LongTermKey
import com.virgilsecurity.ratchet.keystorage.LongTermKeysStorage
import com.virgilsecurity.ratchet.keystorage.OneTimeKey
import com.virgilsecurity.ratchet.keystorage.OneTimeKeysStorage
import com.virgilsecurity.ratchet.model.Completable
import com.virgilsecurity.ratchet.model.Result
import com.virgilsecurity.common.model.Result
import com.virgilsecurity.ratchet.securechat.SecureGroupSession
import com.virgilsecurity.ratchet.securechat.SecureSession
import com.virgilsecurity.ratchet.securechat.keysrotation.KeysRotatorInterface
Expand All @@ -59,7 +59,7 @@ import com.virgilsecurity.sdk.cards.model.RawSignedModel
import com.virgilsecurity.sdk.cards.validation.CardVerifier
import com.virgilsecurity.sdk.client.VirgilCardClient
import com.virgilsecurity.sdk.crypto.HashAlgorithm
import com.virgilsecurity.sdk.crypto.KeyType
import com.virgilsecurity.sdk.crypto.KeyPairType
import com.virgilsecurity.sdk.crypto.VirgilCrypto
import com.virgilsecurity.sdk.crypto.VirgilPublicKey
import com.virgilsecurity.sdk.jwt.Jwt
Expand Down Expand Up @@ -397,21 +397,21 @@ fun generateText(): String {

fun generateKeyId(): ByteArray {
val crypto = VirgilCrypto()
val keyPair = crypto.generateKeyPair(KeyType.CURVE25519)
val keyPair = crypto.generateKeyPair(KeyPairType.CURVE25519)
return keyPair.publicKey.identifier
}

fun generatePrivateKeyData(): ByteArray {
val crypto = VirgilCrypto()
val keyPair = crypto.generateKeyPair(KeyType.CURVE25519)
val keyPair = crypto.generateKeyPair(KeyPairType.CURVE25519)
return crypto.exportPrivateKey(keyPair.privateKey)
}

fun generatePublicKeyData(): ByteArray {
val crypto = VirgilCrypto()
val keyPair = crypto.generateKeyPair(KeyType.CURVE25519)
val keyPair = crypto.generateKeyPair(KeyPairType.CURVE25519)
return crypto.exportPublicKey(keyPair.publicKey)
}

private inline fun returnNothing(): Nothing =
private fun returnNothing(): Nothing =
throw NotImplementedError("This method is supposed to not be called.")
Loading