-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SecureTime wrapper for RoughtimeClient.
- Loading branch information
Showing
63 changed files
with
4,295 additions
and
39 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
app/src/main/AndroidManifest.xml → sample/src/main/AndroidManifest.xml
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
84 changes: 84 additions & 0 deletions
84
sample/src/main/java/pl/tajchert/securetime/sample/MainActivity.kt
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,84 @@ | ||
package pl.tajchert.securetime.sample | ||
|
||
import android.annotation.SuppressLint | ||
import android.os.Bundle | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AppCompatActivity | ||
import io.reactivex.Observable | ||
import io.reactivex.android.schedulers.AndroidSchedulers | ||
import io.reactivex.disposables.CompositeDisposable | ||
import io.reactivex.schedulers.Schedulers | ||
import kotlinx.android.synthetic.main.activity_main.* | ||
import pl.tajchert.securetime.SecureTime | ||
import timber.log.Timber | ||
import java.util.concurrent.TimeUnit | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
val disposable = CompositeDisposable() | ||
|
||
private var roughtimeHelper: SecureTime? = SecureTime( | ||
host = "roughtime.cloudflare.com", | ||
port = 2002, | ||
serverPubKeyBase64 = "gD63hSj3ScS+wuOeGrubXlq35N1c5Lby/S+T7MNTjxo=" | ||
) | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
buttonRefresh.setOnClickListener { | ||
getCurrentTime() | ||
} | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
getCurrentTime() | ||
} | ||
|
||
@SuppressLint("CheckResult") | ||
private fun getCurrentTime() { | ||
disposable.clear() | ||
|
||
disposable.add(Observable.fromCallable { | ||
if (roughtimeHelper == null) { | ||
Timber.e("Error while initializing SecureTime - most likely serverPubKey") | ||
throw RuntimeException("SecureTime is not initialized") | ||
} else { | ||
roughtimeHelper!!.getTime() | ||
} | ||
} | ||
.subscribeOn(Schedulers.io()) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.doOnSubscribe { | ||
//TODO show processing indicator | ||
Timber.d("Starting fetching time") | ||
|
||
timeServer.text = "Server midpoint time\nX" | ||
timeServerRadius.text = "Uncertainty radius X ms" | ||
timeDiffMilliseconds.text = "Time diff X ms" | ||
timeDiffSeconds.text = "Time diff X s" | ||
}.doOnComplete { | ||
//TODO hide pricessing indicator | ||
Timber.d("Fetched completed") | ||
} | ||
.subscribe( | ||
{ result -> | ||
val midpoint = result.first | ||
val radiousOfUncertanity = result.second | ||
val localTimeDiffMilliseconds = result.third | ||
val localTimeDiffSeconds = TimeUnit.MILLISECONDS.toSeconds(result.third) | ||
//Use result for something | ||
Timber.d("Result from server, midpoint: $midpoint, radius(ms): $radiousOfUncertanity, localDiff (ms): $localTimeDiffMilliseconds") | ||
timeServer.text = "Server midpoint time:\n$midpoint" | ||
timeServerRadius.text = "Uncertainty radius $radiousOfUncertanity ms" | ||
timeDiffMilliseconds.text = "Time diff $localTimeDiffMilliseconds ms" | ||
timeDiffSeconds.text = "Time diff $localTimeDiffSeconds s" | ||
}, | ||
{ | ||
Timber.e(it) | ||
Toast.makeText(MainActivity@ this, "Error: ${it.localizedMessage}", Toast.LENGTH_SHORT).show() | ||
}) | ||
) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
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,55 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".MainActivity"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:id="@+id/timeServer" | ||
android:text="Server midpoint time:\nX" | ||
android:gravity="center" | ||
android:textSize="18sp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toTopOf="parent"/> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:id="@+id/timeServerRadius" | ||
android:text="Uncertainty radius X" | ||
app:layout_constraintTop_toBottomOf="@+id/timeServer" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent"/> | ||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:id="@+id/timeDiffMilliseconds" | ||
android:text="Time diff X ms" | ||
app:layout_constraintTop_toBottomOf="@+id/timeServerRadius" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent"/> | ||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:id="@+id/timeDiffSeconds" | ||
android:text="Time diff X s" | ||
app:layout_constraintTop_toBottomOf="@+id/timeDiffMilliseconds" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent"/> | ||
|
||
<Button android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:id="@+id/buttonRefresh" | ||
android:text="Refresh" | ||
app:layout_constraintTop_toBottomOf="@+id/timeDiffSeconds" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent"/> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 @@ | ||
/build |
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,49 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-android-extensions' | ||
android { | ||
compileSdkVersion 29 | ||
buildToolsVersion "29.0.0" | ||
|
||
|
||
defaultConfig { | ||
minSdkVersion 26 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles 'consumer-rules.pro' | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility = 1.8 | ||
targetCompatibility = 1.8 | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
|
||
implementation 'io.netty:netty-all:4.1.36.Final' | ||
implementation 'net.i2p.crypto:eddsa:0.3.0' | ||
|
||
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' | ||
implementation 'io.reactivex.rxjava2:rxjava:2.2.10' | ||
|
||
implementation 'com.jakewharton.timber:timber:4.7.1' | ||
|
||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
implementation 'androidx.core:core-ktx:1.0.2' | ||
|
||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.1' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' | ||
} |
Empty file.
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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
24 changes: 24 additions & 0 deletions
24
securetime/src/androidTest/java/pl/tajchert/securetime/ExampleInstrumentedTest.kt
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,24 @@ | ||
package pl.tajchert.securetime | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("pl.tajchert.securetime.test", appContext.packageName) | ||
} | ||
} |
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,8 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="pl.tajchert.securetime"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET"/> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | ||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> | ||
|
||
</manifest> |
Oops, something went wrong.