Skip to content
This repository was archived by the owner on Sep 10, 2022. It is now read-only.
Closed
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
5 changes: 5 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Optional: GOPATH and ANDROID_HOME need to be passed to the bazel build command.
# To avoid typing them in the command line, please edit and uncomment the following lines.
# build --action_env=ANDROID_HOME=/Your/Android/Home/Path # example:/Users/YourUserName/Library/Android/sdk
# build --action_env=GOPATH=/Your/Go/Path/ # example: /Users/YourUserName/go

14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,17 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# AndroidStudio files
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild

# Bazel output files
bazel-*
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
# Names should be added to this file as:
# Name <email address>

Antonio Marcedone <a.marcedone@gmail.com>
6 changes: 6 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
android_sdk_repository(
name = "androidsdk",
path = "/Users/antonio.marcedone/Library/Android/sdk",
api_level = 25,
build_tools_version = "25.0.0"
)
13 changes: 13 additions & 0 deletions exampleapp/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
android_binary(
name = "exampleapp",
srcs = ["src/main/java/com/google/keytransparency/exampleapp/KeyTransparencyExample.java"],
custom_package = "com.google.keytransparency.exampleapp",
manifest = "src/main/AndroidManifest.xml",
resource_files = glob(["src/main/res/**"]),
deps = [
"//keytransparency:keytransparency",
"@androidsdk//com.android.support:appcompat-v7-25.0.0",
"@androidsdk//com.android.support.constraint:constraint-layout-1.0.2",
"@androidsdk//com.android.support:design-25.0.0",
],
)
25 changes: 25 additions & 0 deletions exampleapp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.keytransparency.exampleapp">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".KeyTransparencyExample">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

<uses-sdk android:minSdkVersion="16"/>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.google.keytransparency.exampleapp;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.method.ScrollingMovementMethod;
import android.widget.TextView;

import com.google.keytransparency.KTClient;
import com.google.keytransparency.KeyTransparencyException;

import java.io.IOException;

public class KeyTransparencyExample extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_key_transparency_example);
TextView tv = (TextView) findViewById(R.id.textView);

tv.setText("");
tv.setMovementMethod(new ScrollingMovementMethod());

try{
tv.append("\n\n --- GetEntry test --- \n");

KTClient client = KTClient.getClient(1000);
client.setTextViewForLogs(tv);
String ktUrl = "35.184.134.53:8080";
client.addKtServer(ktUrl, true, null, null);

try {
String username = "gary.belvin@gmail.com";

tv.append("\nTrying to get public key for " + username + " from server " + ktUrl +"\n");
byte[] entry = client.getEntry(ktUrl, username,"app1");
if (entry==null){
tv.append("Received key is null: entry does not exists");
} else {
tv.append("Received key: " + new String(entry, "UTF-8"));
}

username = "NOT_A_USER@gmail.com";
tv.append("\n\nTrying to get public key for " + username + " from server " + ktUrl +"\n");
entry = client.getEntry(ktUrl, username,"app1");
if (entry==null){
tv.append("Received key is null: entry does not exists");
} else {
tv.append("Received key: " + new String(entry, "UTF-8"));
}


} catch (KeyTransparencyException e) {
tv.append("Exception was raised: " + e);
}

} catch (IOException e) {
e.printStackTrace();
tv.append("\nError reading one of the public keys: "+e.getMessage());
throw new RuntimeException("Error reading one of the public keys: "+e.getMessage(),e );
} catch (KeyTransparencyException e) {
e.printStackTrace();
tv.append("\nError creating the client: "+e.getMessage());
throw new RuntimeException("Error creating the client: "+e.getMessage(),e );
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="horizontal"
android:gravity="center">


<TextView
android:id="@+id/textView"
android:scrollbars = "vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=""
/>


</LinearLayout>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions exampleapp/src/main/res/raw/p256_pubkey.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEKv9XdfRJkfSF16zbMfr1hCKQsFcF
rZtX5urHF9ZDuOaR5xrCwd4Ji6dGxV2xNT87mi8kVAGQ/4q68QGt8rZ9Fw==
-----END PUBLIC KEY-----
18 changes: 18 additions & 0 deletions exampleapp/src/main/res/raw/server.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-----BEGIN CERTIFICATE-----
MIIC2jCCAcKgAwIBAgIJAIV5/kPqON/PMA0GCSqGSIb3DQEBCwUAMA0xCzAJBgNV
BAYTAlVTMB4XDTE3MDgxMzE3MDAxMloXDTE4MDgxMzE3MDAxMlowDTELMAkGA1UE
BhMCVVMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDS3NkbsiKlAKuA
ARyUJxtnnskTKJlFoCFzyhP5Ls7qU4MB5xiytzVPVNafDFDTOfs0S46fZhJBzbl1
PP1zFuR4NoM+y+RkTo5Ixo+kVEwlUZR+pxPTQw9vpL+Rj/c2/loILmUZqTsSnaPP
HrcS9Z6qGfwOA0RK8nWelannSG1ssPjytaWgWg5yFwm2G4I++S+Up90Pks1bddfp
9Ea9Hn5Y/eP+6+/mn5zzKtbQJMcV7DzxsCNd2Xo3UG3hiJD1bt1TWJC+vyHM2zM7
n7+/3YhxM7owKCUFWTPUlXAhqEfJo6irXnoZ2QWSSEbDQYn1fyB2RePZ6tffIupF
blZ6b90xAgMBAAGjPTA7MAwGA1UdEwQFMAMBAf8wKwYDVR0RBCQwIoIJa3Qtc2Vy
dmVygglsb2NhbGhvc3SHBAAAAACHBCO4hjUwDQYJKoZIhvcNAQELBQADggEBAKxq
B5nn4STghFI+d2Y8g5CFmB95EuzMp1sd5wt9cS8WdCxLoX0YJD5zSvZv5Lpqpbll
s9Yd8CVKQhRxQJlBvLM4rrIa7A2mlRCnhou3MH2ePe+hoU7ptKRjFZVjv9QxUlQc
mp9PTEu72c3lTk8FTSdorVLkJtpazfh0YMeLW8dmLOm9P4yx4ql4u66POArOllg7
3aGyc6U17s6AcdrwyI0iH9t/flDOivD+g50nDam496ZIASt6FwJ6BAl7InG/FJlC
hA70cqVLNsotA3EZNpQNr4++/mwruB2Do2VhIB9ifvenqWXuI/W2eChzAoZ9ULoI
/dW2DLTJtRjWWjC/XBY=
-----END CERTIFICATE-----
3 changes: 3 additions & 0 deletions exampleapp/src/main/res/raw/trillian_log.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-----BEGIN PUBLIC KEY-----
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can now be pulled directly from v1/domain/info for a simpler configuration

MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEfzsONlxOpdPmNMtxsAahUGLgrwX+OSJDjTkLTgl3JaztUQnTpVh10DjYoaDhiJNiZqmKOPkxveVoPJ5Jr/Ex0Q==
-----END PUBLIC KEY-----
4 changes: 4 additions & 0 deletions exampleapp/src/main/res/raw/vrf_pubkey.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAENZuDzGYmrJuoG7EkD0O2OEasXxoO
JA4HLQexWcF8MDgmlh27xS/Zwv20DNha8iBT26h2xNDo7exwVzL6+IBB2Q==
-----END PUBLIC KEY-----
6 changes: 6 additions & 0 deletions exampleapp/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
1 change: 1 addition & 0 deletions exampleapp/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<resources></resources>
3 changes: 3 additions & 0 deletions exampleapp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">KeyTransparencyAndroid</string>
</resources>
20 changes: 20 additions & 0 deletions exampleapp/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>
28 changes: 28 additions & 0 deletions keytransparency/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
android_library(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this file could use a format pass with the buildifier formatter
go get github.com/bazelbuild/buildtools/buildifier

name = "keytransparency",
visibility = ["//visibility:public"],
srcs = ["src/main/java/com/google/keytransparency/KeyTransparencyException.java",
"src/main/java/com/google/keytransparency/KTClient.java"],
custom_package = "com.google.keytransparency",
manifest = "src/main/AndroidManifest.xml",
resource_files = glob(["src/main/res/**"]),
deps = [":gobind_keytransparency_android"],
)

aar_import(
name = "gobind_keytransparency_android",
aar = "keytransparency_gobind.aar",
)

genrule(
name = "gobind_keytransparency_android_gen_aar",
srcs = [
# "//some:files", # a filegroup with multiple files in it ==> $(locations)
# "//other:gen", # a genrule with a single output ==> $(location)
],
outs = ["keytransparency_gobind.aar"],
tags=["local"],
cmd = "gomobile bind -target android -o $@ -javapkg com.google.keytransparency.gobind github.com/google/keytransparency/core/client/gobindClient", # github.com/google/keytransparency/core/client/kt github.com/google/keytransparency/core/crypto/commitments",
)


12 changes: 12 additions & 0 deletions keytransparency/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.google.keytransparency">

<uses-permission android:name="android.permission.INTERNET" />

<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.google.keytransparency;

import android.content.Context;
import android.util.Log;
import android.widget.TextView;

import com.google.keytransparency.gobind.gobindClient.GobindClient;
import com.google.keytransparency.gobind.gobindClient.BWriter;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;


public class KTClient {
private static final String TAG_LOGS_FROM_GOBIND = "KTGo:";

private static KTClient client;

// TODO remove me
TextView tv;
public void setTextViewForLogs(TextView tv) {
this.tv = tv;
}


private KTClient(int timeoutInMs){
try {
GobindClient.bInit(timeoutInMs);
GobindClient.bSetCustomLogger(new WriterForGoLogs());
}catch (Exception e) {
// This should never happen actually. We are enforcing init can be called only once,
// and so far the only error comes from calling init twice.
throw new RuntimeException(e);
}
}

public static KTClient getClient(int timeoutInMs){
if (client == null) {
client = new KTClient(timeoutInMs);
}
return client;
}

public void addKtServer(String ktUrl, boolean insecureTLS, byte[] ktTlsCertPem, byte[] domainInfoHash) throws KeyTransparencyException {
try {
GobindClient.bAddKtServer(ktUrl, insecureTLS, ktTlsCertPem, domainInfoHash);
} catch (Exception e) {
throw new KeyTransparencyException(e);
}
}

public byte[] getEntry(String ktUrl, String userName, String appName) throws KeyTransparencyException {
try {
// TODO(amarcedone): do we want to store the latest smr so that it can be used for consistency of new requests?
return GobindClient.bGetEntry(ktUrl, userName, appName);
} catch (Exception e) {
throw new KeyTransparencyException(e);
}
}

private class WriterForGoLogs implements BWriter {
@Override
public long write(byte[] bytes) throws Exception {
// TODO(amarcedone): confirm utf-8 is the correct encoding here, as well as loglevel (i).
Log.i(TAG_LOGS_FROM_GOBIND, new String(bytes, "UTF-8"));

// TODO REMOVE ME.
if(tv != null){
tv.append(TAG_LOGS_FROM_GOBIND + new String(bytes, "UTF-8"));
}

return bytes.length;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.google.keytransparency;

/**
* A KeyTransparencyException is thrown whenever the go native code throws an Exception.
*/
public class KeyTransparencyException extends Throwable {
public KeyTransparencyException(Exception e) {
super(e);
}
}
3 changes: 3 additions & 0 deletions keytransparency/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">keytransparency</string>
</resources>