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",
Copy link
Contributor

Choose a reason for hiding this comment

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

Set to an environment variable and mention it in the README?

api_level = 25,
build_tools_version = "25.0.0"
)
28 changes: 28 additions & 0 deletions keytransparency/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
android_library(
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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move the client package into com.google.keytransparency.client


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>