-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from DP-3T/develop
Version 1.0.5
- Loading branch information
Showing
18 changed files
with
280 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Upload AAR to bintray | ||
|
||
on: | ||
push: | ||
branches: [ develop ] | ||
|
||
jobs: | ||
build: | ||
name: "Upload AAR to bintray" | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: set up JDK 1.8 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 1.8 | ||
- name: Upload | ||
run: cd dp3t-sdk; ./gradlew bintrayUpload -PbintrayUser=${{secrets.BINTRAY_USER}} -PbintrayApikey=${{secrets.BINTRAY_APIKEY}} -PbintrayVersionSuffix=-dev-$GITHUB_RUN_NUMBER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Thu Mar 26 09:44:37 CET 2020 | ||
#Wed Sep 09 14:40:57 CEST 2020 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
...est/java/org/dpppt/android/sdk/internal/backend/SignatureVerificationInterceptorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* | ||
* Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
package org.dpppt.android.sdk.internal.backend; | ||
|
||
import android.content.Context; | ||
import androidx.test.platform.app.InstrumentationRegistry; | ||
|
||
import java.io.IOException; | ||
import java.security.KeyPair; | ||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.util.HashMap; | ||
|
||
import org.dpppt.android.sdk.backend.SignatureException; | ||
import org.dpppt.android.sdk.internal.logger.LogLevel; | ||
import org.dpppt.android.sdk.internal.logger.Logger; | ||
import org.dpppt.android.sdk.internal.util.Base64Util; | ||
import org.dpppt.android.sdk.models.DayDate; | ||
import org.dpppt.android.sdk.util.SignatureUtil; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import io.jsonwebtoken.Jwts; | ||
import io.jsonwebtoken.SignatureAlgorithm; | ||
import io.jsonwebtoken.security.Keys; | ||
import okhttp3.mockwebserver.Dispatcher; | ||
import okhttp3.mockwebserver.MockResponse; | ||
import okhttp3.mockwebserver.MockWebServer; | ||
import okhttp3.mockwebserver.RecordedRequest; | ||
|
||
import static org.dpppt.android.sdk.util.SignatureUtil.JWS_CLAIM_CONTENT_HASH; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.fail; | ||
|
||
public class SignatureVerificationInterceptorTest { | ||
|
||
Context context; | ||
MockWebServer server; | ||
BackendBucketRepository bucketRepository; | ||
KeyPair keyPair; | ||
|
||
@Before | ||
public void setup() { | ||
context = InstrumentationRegistry.getInstrumentation().getContext(); | ||
|
||
Logger.init(context, LogLevel.DEBUG); | ||
|
||
ProxyConfig.DISABLE_SYSTEM_PROXY = true; | ||
|
||
server = new MockWebServer(); | ||
keyPair = Keys.keyPairFor(SignatureAlgorithm.ES256); | ||
|
||
bucketRepository = new BackendBucketRepository(context, server.url("/bucket/").toString(), keyPair.getPublic()); | ||
} | ||
|
||
private String getJwtForContent(String content) { | ||
HashMap<String, Object> claims = new HashMap<>(); | ||
try { | ||
MessageDigest digest = MessageDigest.getInstance(SignatureUtil.HASH_ALGO); | ||
claims.put(JWS_CLAIM_CONTENT_HASH, Base64Util.toBase64(digest.digest(content.getBytes()))); | ||
} catch (NoSuchAlgorithmException e) { | ||
e.printStackTrace(); | ||
} | ||
return Jwts.builder().addClaims(claims).signWith(keyPair.getPrivate()).compact(); | ||
} | ||
|
||
@Test | ||
public void testValidSignature() throws IOException, StatusCodeException { | ||
String responseString = "someRandomContent"; | ||
server.setDispatcher(new Dispatcher() { | ||
@Override | ||
public MockResponse dispatch(RecordedRequest request) { | ||
|
||
return new MockResponse() | ||
.setResponseCode(200) | ||
.setBody(responseString) | ||
.addHeader(SignatureUtil.HTTP_HEADER_JWS, getJwtForContent(responseString)); | ||
} | ||
}); | ||
String response = bucketRepository.getGaenExposees(new DayDate(), null).body().string(); | ||
assertEquals(responseString, response); | ||
} | ||
|
||
@Test | ||
public void testInvalidSignature() throws IOException, StatusCodeException { | ||
String responseString = "someRandomContent"; | ||
server.setDispatcher(new Dispatcher() { | ||
@Override | ||
public MockResponse dispatch(RecordedRequest request) { | ||
return new MockResponse() | ||
.setResponseCode(200) | ||
.setBody(responseString) | ||
.addHeader(SignatureUtil.HTTP_HEADER_JWS, getJwtForContent("differentContent")); | ||
} | ||
}); | ||
try { | ||
bucketRepository.getGaenExposees(new DayDate(), null).body().string(); | ||
fail(); | ||
} catch (SignatureException e) { | ||
assertEquals("Signature mismatch", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testInvalidJwt() throws IOException, StatusCodeException { | ||
String responseString = "someRandomContent"; | ||
server.setDispatcher(new Dispatcher() { | ||
@Override | ||
public MockResponse dispatch(RecordedRequest request) { | ||
return new MockResponse() | ||
.setResponseCode(200) | ||
.setBody(responseString) | ||
.addHeader(SignatureUtil.HTTP_HEADER_JWS, | ||
"eyJhbGciOiJFUzI1NiJ9.eyJjb250ZW50LWhhc2giOiJsTzd3TDBkOFl5MFBSaU" + | ||
"w5NGhUa2txMkRXNUxXVjlPNi9zRWNZVDJHZ2t3PSIsImhhc2gtYWxnIjoic2hhLTI1Ni" + | ||
"IsImlzcyI6ImRwM3QiLCJpYXQiOjE1ODgwODk2MDAsImV4cCI6MTU4OTkwNDAwMCwiYm" + | ||
"F0Y2gtcmVsZWFzZS10aW1lIjoiMTU4ODA4OTYwMDAwMCJ9.1uiVGBOWqD8jLKm0_EOmN" + | ||
"MMgHr4FQOsD1ci4iWR1QMitg_MPgtbuggedbuggedbuggedbuggedbuggedbugged"); | ||
} | ||
}); | ||
try { | ||
bucketRepository.getGaenExposees(new DayDate(), null).body().string(); | ||
fail(); | ||
} catch (SignatureException e) { | ||
assertEquals("JWT signature does not match locally computed signature. " + | ||
"JWT validity cannot be asserted and should not be trusted.", e.getMessage()); | ||
} | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
.../src/androidTest/java/org/dpppt/android/sdk/internal/nearby/LocationLessScanningTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
package org.dpppt.android.sdk.internal.nearby; | ||
|
||
import android.content.Context; | ||
import android.os.Build; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import androidx.test.platform.app.InstrumentationRegistry; | ||
|
||
import org.dpppt.android.sdk.internal.ErrorHelper; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class LocationLessScanningTest { | ||
|
||
private Context context; | ||
|
||
@Before | ||
public void setup() { | ||
context = InstrumentationRegistry.getInstrumentation().getContext(); | ||
} | ||
|
||
@Test | ||
public void checkLocationLessScanningOnAndroidR(){ | ||
assertEquals(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R, ErrorHelper.deviceSupportsLocationlessScanning(context)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.