initial code dump

This commit is contained in:
Bruno Bierbaumer 2015-11-23 22:20:14 +01:00
parent d97972bf6e
commit faec1dfd88
51 changed files with 2332 additions and 0 deletions

1
.idea/.name Normal file
View file

@ -0,0 +1 @@
otp-authenticator

22
.idea/compiler.xml Normal file
View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>

View file

@ -0,0 +1,3 @@
<component name="CopyrightManager">
<settings default="" />
</component>

18
.idea/gradle.xml Normal file
View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="1.8" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

35
.idea/misc.xml Normal file
View file

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
<component name="masterDetails">
<states>
<state key="ProjectJDKs.UI">
<settings>
<last-edited>1.8</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
</states>
</component>
</project>

9
.idea/modules.xml Normal file
View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://$PROJECT_DIR$/otp-authenticator.iml" filepath="$PROJECT_DIR$/otp-authenticator.iml" />
</modules>
</component>
</project>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>

6
.idea/vcs.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="" />
</component>
</project>

1
app/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/build

45
app/build.gradle Normal file
View file

@ -0,0 +1,45 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "net.bierbaumer.otp_authenticator"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled = true
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.journeyapps:zxing-android-embedded:3.0.3@aar'
compile 'com.google.zxing:core:3.2.0'
compile 'commons-codec:commons-codec:1.5'
androidTestCompile 'com.android.support:support-annotations:23.1.1'
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
}

17
app/proguard-rules.pro vendored Normal file
View file

@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/bb/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# 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 *;
#}

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:tools="http://schemas.android.com/tools"
package="com.example.android.testing.uiautomator.BasicSample" >
<uses-sdk tools:overrideLibrary="android.support.test.uiautomator.v18"/>
</manifest>

View file

@ -0,0 +1,158 @@
package net.bierbaumer.otp_authenticator;
import android.app.Application;
import android.content.Context;
import android.test.ApplicationTestCase;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base32;
import org.apache.commons.codec.binary.Hex;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.util.ArrayList;
import java.util.Arrays;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
public void testTOTPHelper(){
byte[] b = "12345678901234567890".getBytes();
assertEquals(94287082, TOTPHelper.generate(b, 59l, 8));
assertEquals(7081804, TOTPHelper.generate(b, 1111111109l, 8));
assertEquals(14050471, TOTPHelper.generate(b, 1111111111l, 8));
assertEquals(89005924, TOTPHelper.generate(b, 1234567890l, 8));
assertEquals(69279037, TOTPHelper.generate(b, 2000000000l, 8));
assertEquals(65353130, TOTPHelper.generate(b, 20000000000l, 8));
}
public void testEntry() throws JSONException {
byte secret[] = "Das System ist sicher".getBytes();
String label = "5 von 5 Sterne";
String s = "{\"secret\":\""+ new String(new Base32().encode(secret)) +"\",\"label\":\"" + label + "\"}";
Entry e = new Entry(new JSONObject(s));
assertTrue(Arrays.equals(secret, e.getSecret()));
assertEquals(label, e.getLabel());
assertEquals(s, e.toJSON()+"");
}
public void testEntryURL() throws Exception {
try {
new Entry("DON'T CARE");
assertTrue(false);
} catch (Exception e) {
}
try {
new Entry("https://github.com/0xbb/");
assertTrue(false);
} catch (Exception e) {
}
try {
new Entry("otpauth://hotp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ");
assertTrue(false);
}
catch (Exception e){
}
try {
new Entry("otpauth://totp/ACME");
assertTrue(false);
}
catch (Exception e){
}
Entry entry = new Entry("otpauth://totp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&ALGORITHM=SHA1&digits=6&period=30");
assertEquals("ACME Co - ACME Co:john.doe@email.com", entry.getLabel());
assertEquals("HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ", new String(new Base32().encode(entry.getSecret())));
}
public void testSettingsHelper() throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {
Context context = getContext();
final KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
keyStore.load(null);
keyStore.deleteEntry("settings");
new File(context.getFilesDir() + "/" + SettingsHelper.SETTINGS_FILE).delete();
new File(context.getFilesDir() + "/" + SettingsHelper.KEY_FILE).delete();
ArrayList<Entry> b = SettingsHelper.load(context);
assertEquals(0, b.size());
ArrayList<Entry> a = new ArrayList<>();
Entry e = new Entry();
e.setLabel("label");
e.setSecret("secret".getBytes());
a.add(e);
e = new Entry();
e.setLabel("label2");
e.setSecret("secret2".getBytes());
a.add(e);
SettingsHelper.store(context, a);
b = SettingsHelper.load(context);
assertEquals(a, b);
new File(context.getFilesDir() + "/" + SettingsHelper.SETTINGS_FILE).delete();
new File(context.getFilesDir() + "/" + SettingsHelper.KEY_FILE).delete();
}
public void testEncryptionHelper() throws NoSuchPaddingException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, UnsupportedEncodingException, InvalidAlgorithmParameterException, DecoderException {
// https://golang.org/src/crypto/cipher/gcm_test.go
String[][] testCases = new String[][]{
new String []{"11754cd72aec309bf52f7687212e8957","3c819d9a9bed087615030b65","", "250327c674aaf477aef2675748cf6971" },
new String []{"ca47248ac0b6f8372a97ac43508308ed","ffd2b598feabc9019262d2be","", "60d20404af527d248d893ae495707d1a" },
new String []{"7fddb57453c241d03efbed3ac44e371c","ee283a3fc75575e33efd4887","d5de42b461646c255c87bd2962d3b9a2", "2ccda4a5415cb91e135c2a0f78c9b2fdb36d1df9b9d5e596f83e8b7f52971cb3" },
new String []{"ab72c77b97cb5fe9a382d9fe81ffdbed","54cc7dc2c37ec006bcc6d1da","007c5e5b3e59df24a7c355584fc1518d", "0e1bde206a07a9c2c1b65300f8c649972b4401346697138c7a4891ee59867d0c" },
new String []{"feffe9928665731c6d6a8f9467308308","cafebabefacedbaddecaf888","d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b391aafd255", "42831ec2217774244b7221b784d0d49ce3aa212f2c02a4e035c17e2329aca12e21d514b25466931c7d8f6a5aac84aa051ba30b396a0aac973d58e091473f59854d5c2af327cd64a62cf35abd2ba6fab4" },
};
for(String[] testCase: testCases){
SecretKeySpec k = new SecretKeySpec(new Hex().decode(testCase[0].getBytes()), "AES");
IvParameterSpec iv = new IvParameterSpec(new Hex().decode(testCase[1].getBytes()));
byte[] cipherTExt = EncryptionHelper.encrypt(k,iv,new Hex().decode(testCase[2].getBytes()));
String cipher = new String(new Hex().encode(cipherTExt));
assertEquals(cipher, testCase[3]);
assertEquals(testCase[2], new String(new Hex().encode(EncryptionHelper.decrypt(k, iv, cipherTExt))));
}
}
}

View file

@ -0,0 +1,483 @@
package net.bierbaumer.otp_authenticator;
import android.app.Activity;
import android.app.Instrumentation;
import android.content.Intent;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.action.GeneralLocation;
import android.support.test.espresso.action.GeneralSwipeAction;
import android.support.test.espresso.action.Press;
import android.support.test.espresso.action.Swipe;
import android.support.test.espresso.action.ViewActions;
import android.support.test.espresso.intent.Intents;
import android.support.test.uiautomator.UiCollection;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiSelector;
import android.support.v7.widget.ActionBarContextView;
import android.test.ActivityInstrumentationTestCase2;
import android.test.ViewAsserts;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.binary.Base32;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import java.util.ArrayList;
import static android.support.test.espresso.Espresso.onData;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
import static android.support.test.espresso.action.ViewActions.actionWithAssertions;
import static android.support.test.espresso.action.ViewActions.clearText;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.longClick;
import static android.support.test.espresso.action.ViewActions.pressBack;
import static android.support.test.espresso.action.ViewActions.swipeDown;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.intent.Intents.intended;
import static android.support.test.espresso.intent.Intents.intending;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasAction;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasExtra;
import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anything;
import static org.hamcrest.Matchers.is;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {
private MainActivity mActivity;
public MainActivityTest() {
super(MainActivity.class);
}
@Before
public void setUp() throws Exception {
super.setUp();
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
mActivity = getActivity();
}
public void testStart(){
ViewAsserts.assertOnScreen(mActivity.getWindow().getDecorView(), mActivity.findViewById(R.id.listView));
}
//TODO. switch to toolbar
public void test000About() throws InterruptedException {
openActionBarOverflowOrOptionsMenu(InstrumentationRegistry.getContext());
onView(allOf(withText("About"), isDisplayed())).perform(click());
Thread.sleep(1000);
onView(withId(R.id.webViewAbout)).check(matches(isDisplayed()));
onView(withId(R.id.webViewAbout)).perform(pressBack());
onView(withId(R.id.webViewAbout)).check(doesNotExist());
}
public void test000EmptyStart() throws InterruptedException {
onView(withText("No Account has been added yet")).check(matches(isDisplayed()));
onView(withText("Add")).check(matches(isDisplayed()));
Intents.init();
String qr = "XXX" ;
// Build a result to return from the ZXING app
Intent resultData = new Intent();
resultData.putExtra(com.google.zxing.client.android.Intents.Scan.RESULT, qr);
Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData);
// Stub out the Camera. When an intent is sent to the Camera, this tells Espresso to respond
// with the ActivityResult we just created
intending(hasAction("com.google.zxing.client.android.SCAN")).respondWith(result);
onView(withText("Add")).check(matches(isDisplayed()));
onView(withText("Add")).perform(click());
// We can also validate that an intent resolving to the "camera" activity has been sent out by our app
intended(hasAction("com.google.zxing.client.android.SCAN"));
Intents.release();
}
public void test001InvalidQRCode() throws InterruptedException {
Intents.init();
String qr ="invalid qr code";
// Build a result to return from the ZXING app
Intent resultData = new Intent();
resultData.putExtra(com.google.zxing.client.android.Intents.Scan.RESULT, qr);
Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData);
// Stub out the Camera. When an intent is sent to the Camera, this tells Espresso to respond
// with the ActivityResult we just created
intending(hasAction("com.google.zxing.client.android.SCAN")).respondWith(result);
// Now that we have the stub in place, click on the button in our app that launches into the Camera
onView(withId(R.id.action_scan)).perform(click());
// We can also validate that an intent resolving to the "camera" activity has been sent out by our app
intended(hasAction("com.google.zxing.client.android.SCAN"));
onView(withText("Invalid QR Code")).check(matches(isDisplayed()));
Thread.sleep(5000);
onView(withText("No Account has been added yet")).check(matches(isDisplayed()));
Intents.release();
}
public void test002NocodeScanned() throws InterruptedException {
Intents.init();
// Build a result to return from the ZXING app
Intent resultData = new Intent();
Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_CANCELED, resultData);
// Stub out the Camera. When an intent is sent to the Camera, this tells Espresso to respond
// with the ActivityResult we just created
intending(hasAction("com.google.zxing.client.android.SCAN")).respondWith(result);
// Now that we have the stub in place, click on the button in our app that launches into the Camera
onView(withId(R.id.action_scan)).perform(click());
// We can also validate that an intent resolving to the "camera" activity has been sent out by our app
intended(hasAction("com.google.zxing.client.android.SCAN"));
onView(withText("No Account has been added yet")).check(matches(isDisplayed()));
Intents.release();
}
String[][] codes = new String [][]{
new String[]{"WOW", "Sicherheit00000"},
new String[]{"SUCH", "Sicherheit00001"},
new String[]{"APP", "Sicherheit00002"},
};
public void test003AddCodes() throws InterruptedException {
for(String[] code: codes){
Intents.init();
String qr = "otpauth://totp/"+code[0] +"?secret="+new String(new Base32().encode(code[1].getBytes())) ;
// Build a result to return from the ZXING app
Intent resultData = new Intent();
resultData.putExtra(com.google.zxing.client.android.Intents.Scan.RESULT, qr);
Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData);
// Stub out the Camera. When an intent is sent to the Camera, this tells Espresso to respond
// with the ActivityResult we just created
intending(hasAction("com.google.zxing.client.android.SCAN")).respondWith(result);
// Now that we have the stub in place, click on the button in our app that launches into the Camera
onView(withId(R.id.action_scan)).perform(click());
// We can also validate that an intent resolving to the "camera" activity has been sent out by our app
intended(hasAction("com.google.zxing.client.android.SCAN"));
onView(withText("Account added")).check(matches(isDisplayed()));
Intents.release();
}
Thread.sleep(500);
for(int i = 0; i < codes.length; i++){
onData(anything()).inAdapterView(withId(R.id.listView))
.atPosition(i)
.onChildView(withId(R.id.textViewLabel))
.check(matches(withText(codes[i][0])));
String otp = TOTPHelper.generate(codes[i][1].getBytes());
onData(anything()).inAdapterView(withId(R.id.listView))
.atPosition(i)
.onChildView(withId(R.id.textViewOTP))
.check(matches(withText(otp)));
}
}
public void test003CodesChange() throws InterruptedException {
ArrayList<String> oldCodes = new ArrayList<>();
for(int i = 0; i < codes.length; i++){
onData(anything()).inAdapterView(withId(R.id.listView))
.atPosition(i)
.onChildView(withId(R.id.textViewLabel))
.check(matches(withText(codes[i][0])));
String otp = TOTPHelper.generate(codes[i][1].getBytes());
oldCodes.add(otp);
onData(anything()).inAdapterView(withId(R.id.listView))
.atPosition(i)
.onChildView(withId(R.id.textViewOTP))
.check(matches(withText(otp)));
}
Thread.sleep(30*1000);
for(int i = 0; i < codes.length; i++){
onData(anything()).inAdapterView(withId(R.id.listView))
.atPosition(i)
.onChildView(withId(R.id.textViewLabel))
.check(matches(withText(codes[i][0])));
String otp = TOTPHelper.generate(codes[i][1].getBytes());
assertTrue(!oldCodes.get(i).equals(otp));
onData(anything()).inAdapterView(withId(R.id.listView))
.atPosition(i)
.onChildView(withId(R.id.textViewOTP))
.check(matches(withText(otp)));
}
}
public void test004Rearrange() throws InterruptedException, UiObjectNotFoundException {
UiDevice mDevice = UiDevice.getInstance(getInstrumentation());
UiObject start = mDevice.findObject(new UiSelector().textContains(codes[0][0]));
UiObject end = mDevice.findObject(new UiSelector().textContains(codes[1][0]));
start.dragTo(start, 10);
start.dragTo(end, 10);
mDevice.pressBack();
Thread.sleep(2000);
String t = codes[0][0];
codes[0][0] = codes[1][0];
codes[1][0] = t;
for(int i = 0; i < codes.length; i++){
onData(anything()).inAdapterView(withId(R.id.listView))
.atPosition(i)
.onChildView(withId(R.id.textViewLabel))
.check(matches(withText(codes[i][0])));
}
start = mDevice.findObject(new UiSelector().textContains(codes[0][0]));
end = mDevice.findObject(new UiSelector().textContains(codes[1][0]));
start.dragTo(start, 10);
start.dragTo(end, 10);
mDevice.pressBack();
Thread.sleep(2000);
t = codes[0][0];
codes[0][0] = codes[1][0];
codes[1][0] = t;
for(int i = 0; i < codes.length; i++){
onData(anything()).inAdapterView(withId(R.id.listView))
.atPosition(i)
.onChildView(withId(R.id.textViewLabel))
.check(matches(withText(codes[i][0])));
}
}
public void test005EditMode() throws InterruptedException {
onView(withId(R.id.action_edit)).check(doesNotExist());
onData(anything()).inAdapterView(withId(R.id.listView))
.atPosition(0)
.perform(longClick());
onView(withId(R.id.action_edit)).check(matches(isDisplayed()));
onView(withId(R.id.action_delete)).check(matches(isDisplayed()));
ActionBarContextView.class.getCanonicalName();
onView(allOf(isDescendantOfA(withClassName(Matchers.containsString("ActionBarContextView"))), withText(codes[0][0]))).check(matches(isDisplayed()));
onData(anything()).inAdapterView(withId(R.id.listView))
.atPosition(1)
.perform(longClick());
onView(withId(R.id.action_edit)).check(matches(isDisplayed()));
onView(withId(R.id.action_delete)).check(matches(isDisplayed()));
onView(allOf(isDescendantOfA(withClassName(Matchers.containsString("ActionBarContextView"))), withText(codes[1][0]))).check(matches(isDisplayed()));
onView(withId(R.id.listView)).perform(pressBack());
onView(withId(R.id.action_edit)).check(doesNotExist());
}
public void test005RenameCancel(){
onData(anything()).inAdapterView(withId(R.id.listView))
.atPosition(1)
.perform(longClick());
onView(withId(R.id.action_edit)).check(matches(isDisplayed()));
onView(withId(R.id.action_edit)).perform(click());
onView(withText(codes[1][0])).perform(click()).perform(typeText(" VERY TEST"));
onView(withText("Cancel")).perform(click());
onData(anything()).inAdapterView(withId(R.id.listView))
.atPosition(1)
.onChildView(withId(R.id.textViewLabel))
.check(matches(withText(codes[1][0])));
}
public void test006Rename(){
onData(anything()).inAdapterView(withId(R.id.listView))
.atPosition(1)
.perform(longClick());
onView(withId(R.id.action_edit)).check(matches(isDisplayed()));
onView(withId(R.id.action_edit)).perform(click());
onView(withText(codes[1][0])).perform(click()).perform(typeText(" VERY TEST"));
onView(withText("Save")).perform(click());
onData(anything()).inAdapterView(withId(R.id.listView))
.atPosition(1)
.onChildView(withId(R.id.textViewLabel))
.check(matches(withText(codes[1][0] + " VERY TEST")));
}
public void test007DeleteCancel() throws InterruptedException, EncoderException {
onData(anything()).inAdapterView(withId(R.id.listView))
.atPosition(0)
.perform(longClick());
onView(withId(R.id.action_delete)).check(matches(isDisplayed()));
onView(withId(R.id.action_delete)).perform(click());
onView(withText("Remove")).check(matches(isDisplayed()));
onView(withText("Cancel")).check(matches(isDisplayed()));
onView(withText("Cancel")).perform(click());
onView(withText("Remove")).check(doesNotExist());
onView(withId(R.id.listView)).check(matches(withListSize(codes.length)));
}
public void test008Delete() throws InterruptedException, EncoderException {
// remove test
for(int i = codes.length; i > 0; i--){
onData(anything()).inAdapterView(withId(R.id.listView))
.atPosition(0)
.perform(longClick());
onView(withId(R.id.action_delete)).check(matches(isDisplayed()));
onView(withId(R.id.action_delete)).perform(click());
onView(withText("Remove")).check(matches(isDisplayed()));
onView(withText("Remove")).perform(click());
onView(withId(R.id.listView)).check(matches(withListSize(i - 1)));
if(i > 1){
onView(withText("Account removed")).check(matches(isDisplayed()));
}
else {
onView(withText(R.string.no_accounts)).check(matches(isDisplayed()));
}
}
}
public static Matcher<View> withListSize (final int size) {
return new TypeSafeMatcher<View> () {
@Override public boolean matchesSafely (final View view) {
return ((ListView) view).getChildCount () == size;
}
@Override public void describeTo (final Description description) {
description.appendText ("ListView should have " + size + " items");
}
};
}
public static Matcher<View> withResourceName(String resourceName) {
return withResourceName(is(resourceName));
}
public static Matcher<View> withResourceName(final Matcher<String> resourceNameMatcher) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("with resource name: ");
resourceNameMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
int id = view.getId();
return id != View.NO_ID && id != 0 && view.getResources() != null
&& resourceNameMatcher.matches(view.getResources().getResourceName(id));
}
};
}
}

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="net.bierbaumer.otp_authenticator">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_launcher"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".CaptureActivityAnyOrientation"
android:screenOrientation="fullSensor"
android:stateNotNeeded="true"
android:theme="@style/zxing_CaptureTheme"
android:windowSoftInputMode="stateAlwaysHidden" />
</application>
</manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View file

@ -0,0 +1,7 @@
package net.bierbaumer.otp_authenticator;
import com.journeyapps.barcodescanner.CaptureActivity;
public class CaptureActivityAnyOrientation extends CaptureActivity {
}

View file

@ -0,0 +1,96 @@
package net.bierbaumer.otp_authenticator;
import android.content.Context;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Arrays;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import static net.bierbaumer.otp_authenticator.Utils.readFully;
import static net.bierbaumer.otp_authenticator.Utils.writeFully;
public class EncryptionHelper {
public final static int KEY_LENGTH = 16;
public final static int IV_LENGTH = 12;
public final static String ALGORITHM = "AES/GCM/NoPadding";
public static byte[] encrypt(SecretKey secretKey, IvParameterSpec iv, byte[] plainText) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, UnsupportedEncodingException, BadPaddingException, IllegalBlockSizeException {
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv);
return cipher.doFinal(plainText);
}
public static byte[] decrypt(SecretKey secretKey, IvParameterSpec iv, byte[] cipherText) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, secretKey, iv);
return cipher.doFinal(cipherText);
}
public static byte[] encrypt(SecretKey secretKey, byte[] plaintext) throws NoSuchPaddingException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, UnsupportedEncodingException, InvalidAlgorithmParameterException {
final byte[] iv = new byte[IV_LENGTH];
new SecureRandom().nextBytes(iv);
byte[] cipherText = encrypt(secretKey, new IvParameterSpec(iv), plaintext);
byte[] combined = new byte[iv.length + cipherText.length];
System.arraycopy(iv, 0, combined, 0, iv.length);
System.arraycopy(cipherText, 0, combined, iv.length, cipherText.length);
return combined;
}
public static byte[] decrypt(SecretKey secretKey, byte[] cipherText) throws NoSuchPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException {
byte[] iv = Arrays.copyOfRange(cipherText, 0, IV_LENGTH);
byte[] cipher = Arrays.copyOfRange(cipherText, IV_LENGTH,cipherText.length);
return decrypt(secretKey,new IvParameterSpec(iv), cipher );
}
/**
* Load our symmetric secret key.
* The symmetric secret key is stored securely on disk by wrapping
* it with a public/private key pair, possibly backed by hardware.
*/
public static SecretKey loadOrGenerateKeys(Context context, File keyFile)
throws GeneralSecurityException, IOException {
final SecretKeyWrapper wrapper = new SecretKeyWrapper(context, "settings");
// Generate secret key if none exists
if (!keyFile.exists()) {
final byte[] raw = new byte[KEY_LENGTH];
new SecureRandom().nextBytes(raw);
final SecretKey key = new SecretKeySpec(raw, "AES");
final byte[] wrapped = wrapper.wrap(key);
writeFully(keyFile, wrapped);
}
// Even if we just generated the key, always read it back to ensure we
// can read it successfully.
final byte[] wrapped = readFully(keyFile);
final SecretKey key = wrapper.unwrap(wrapped);
return key;
}
}

View file

@ -0,0 +1,134 @@
package net.bierbaumer.otp_authenticator;
import android.content.ClipData;
import android.graphics.Color;
import android.view.DragEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import java.util.List;
public class EntriesAdapter extends BaseAdapter {
private List<Entry> entries;
private Entry currentSelection;
@Override
public int getCount() {
return getEntries().size();
}
@Override
public Entry getItem(int i) {
return getEntries().get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
View v = convertView;
if (v == null) {
final LayoutInflater vi;
vi = LayoutInflater.from(parent.getContext());
v = vi.inflate(R.layout.row, null);
}
v.setBackgroundColor(Color.TRANSPARENT);
if(getEntries().get(position) == getCurrentSelection()){
v.setBackgroundColor(parent.getResources().getColor(R.color.primary_light));
}
final TextView tt1 = (TextView) v.findViewById(R.id.textViewLabel);
tt1.setText(getItem(position).getLabel());
TextView tt2 = (TextView) v.findViewById(R.id.textViewOTP);
v.setTag(position);
tt2.setText(getItem(position).getCurrentOTP());
v.setOnDragListener(new View.OnDragListener() {
@Override
public boolean onDrag(View v, DragEvent event) {
final int action = event.getAction();
switch (action) {
case DragEvent.ACTION_DRAG_STARTED:
break;
case DragEvent.ACTION_DRAG_EXITED:
break;
case DragEvent.ACTION_DRAG_ENTERED:
break;
case DragEvent.ACTION_DROP: {
int from = Integer.parseInt(event.getClipData().getDescription().getLabel()+"");
int to = (Integer) v.getTag();
Entry e = getEntries().remove(from);
getEntries().add(to, e);
notifyDataSetChanged();
return true;
}
case DragEvent.ACTION_DRAG_ENDED: {
return true;
}
default:
break;
}
return true;
}
});
v.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent arg1) {
if (getCurrentSelection() != getEntries().get(position)) {
return false;
}
ClipData data = ClipData.newPlainText(v.getTag() + "", "");
View.DragShadowBuilder shadow = new View.DragShadowBuilder(v);
v.startDrag(data, shadow, null, 0);
return false;
}
});
return v;
}
public List<Entry> getEntries() {
return entries;
}
public void setEntries(List<Entry> entries) {
this.entries = entries;
}
public Entry getCurrentSelection() {
return currentSelection;
}
public void setCurrentSelection(Entry currentSelection) {
this.currentSelection = currentSelection;
}
}

View file

@ -0,0 +1,105 @@
package net.bierbaumer.otp_authenticator;
import android.net.Uri;
import org.apache.commons.codec.binary.Base32;
import org.json.JSONException;
import org.json.JSONObject;
import java.net.URL;
import java.util.Arrays;
public class Entry {
public static final String JSON_SECRET = "secret";
public static final String JSON_LABEL = "label";
private byte[] secret;
private String label;
private String currentOTP;
public Entry (){
}
public Entry(String contents) throws Exception {
contents = contents.replaceFirst("otpauth", "http");
Uri uri = Uri.parse(contents);
URL url = new URL(contents);
if(!url.getProtocol().equals("http")){
throw new Exception("Invalid Protocol");
}
if(!url.getHost().equals("totp")){
throw new Exception();
}
String secret = uri.getQueryParameter("secret");
String label = uri.getPath().substring(1);
String issuer = uri.getQueryParameter("issuer");
if(issuer != null){
label = issuer +" - "+label;
}
this.label = label;
this.secret = new Base32().decode(secret.toUpperCase());
}
public Entry (JSONObject jsonObj ) throws JSONException {
this.setSecret(new Base32().decode(jsonObj.getString(JSON_SECRET)));
this.setLabel(jsonObj.getString(JSON_LABEL));
}
public JSONObject toJSON() throws JSONException {
JSONObject jsonObj = new JSONObject();
jsonObj.put(JSON_SECRET, new String(new Base32().encode(getSecret())));
jsonObj.put(JSON_LABEL, getLabel());
return jsonObj;
}
public byte[] getSecret() {
return secret;
}
public void setSecret(byte[] secret) {
this.secret = secret;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getCurrentOTP() {
return currentOTP;
}
public void setCurrentOTP(String currentOTP) {
this.currentOTP = currentOTP;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Entry entry = (Entry) o;
if (!Arrays.equals(secret, entry.secret)) return false;
return !(label != null ? !label.equals(entry.label) : entry.label != null);
}
@Override
public int hashCode() {
int result = secret != null ? Arrays.hashCode(secret) : 0;
result = 31 * result + (label != null ? label.hashCode() : 0);
return result;
}
}

View file

@ -0,0 +1,281 @@
package net.bierbaumer.otp_authenticator;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.ActionMode;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.LinearInterpolator;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.ProgressBar;
import com.google.zxing.client.android.Intents;
import com.google.zxing.integration.android.IntentIntegrator;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity implements ActionMode.Callback {
private ArrayList<Entry> entries;
private EntriesAdapter adapter;
private Entry nextSelection = null;
private void showNoAccount(){
Snackbar noAccountSnackbar = Snackbar.make(findViewById(R.id.listView), R.string.no_accounts, Snackbar.LENGTH_INDEFINITE)
.setAction("Add", new View.OnClickListener() {
@Override
public void onClick(View view) {
scanQRCode();
}
});
noAccountSnackbar.show();
}
private void scanQRCode(){
new IntentIntegrator(MainActivity.this)
.setCaptureActivity(CaptureActivityAnyOrientation.class)
.setOrientationLocked(false)
.initiateScan();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.app_name);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final ListView listView = (ListView) findViewById(R.id.listView);
final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
entries = SettingsHelper.load(this);
adapter = new EntriesAdapter();
adapter.setEntries(entries);
listView.setAdapter(adapter);
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
nextSelection = entries.get(i);
startActionMode(MainActivity.this);
return true;
}
});
if(entries.isEmpty()){
showNoAccount();
}
int progress = ((int) (System.currentTimeMillis() / 1000) % 30);
progressBar.setProgress((int) (1000.0 * progress / 30.0));
ObjectAnimator animation = ObjectAnimator.ofInt(progressBar, "progress", 1000);
animation.setDuration((30 - progress) * 1000);
animation.setInterpolator(new LinearInterpolator());
animation.start();
final Handler handler = new Handler();
final Runnable handlerTask = new Runnable()
{
@Override
public void run() {
int progress = (int) (System.currentTimeMillis() / 1000) % 30 ;
if(progress == 0){
progressBar.setProgress(progress);
ObjectAnimator animation = ObjectAnimator.ofInt(progressBar, "progress", 1000);
animation.setDuration(30 * 1000);
animation.setInterpolator(new LinearInterpolator());
animation.start();
}
for(int i =0;i< adapter.getCount();i++){
if(progress == 0 || adapter.getItem(i).getCurrentOTP() == null){
adapter.getItem(i).setCurrentOTP(TOTPHelper.generate(adapter.getItem(i).getSecret()));
}
}
adapter.notifyDataSetChanged();
handler.postDelayed(this, 1000);
}
};
handlerTask.run();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == IntentIntegrator.REQUEST_CODE && resultCode == Activity.RESULT_OK) {
try {
Entry e = new Entry(intent.getStringExtra(Intents.Scan.RESULT));
e.setCurrentOTP(TOTPHelper.generate(e.getSecret()));
entries.add(e);
SettingsHelper.store(this, entries);
adapter.notifyDataSetChanged();
Snackbar.make(findViewById(R.id.listView), "Account added", Snackbar.LENGTH_LONG).show();
} catch (Exception e) {
Snackbar.make(findViewById(R.id.listView), "Invalid QR Code", Snackbar.LENGTH_LONG).setCallback(new Snackbar.Callback() {
@Override
public void onDismissed(Snackbar snackbar, int event) {
super.onDismissed(snackbar, event);
if(entries.isEmpty()){
showNoAccount();
}
}
}).show();
return;
}
}
if(entries.isEmpty()){
showNoAccount();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_scan) {
scanQRCode();
return true;
} else if(id == R.id.action_about){
WebView view = (WebView) LayoutInflater.from(this).inflate(R.layout.dialog_about, null);
view.loadUrl("file:///android_res/raw/about.html");
new AlertDialog.Builder(this).setView(view).show();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
MenuInflater inflater = actionMode.getMenuInflater();
inflater.inflate(R.menu.menu_edit, menu);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
adapter.setCurrentSelection(nextSelection);
adapter.notifyDataSetChanged();
actionMode.setTitle(adapter.getCurrentSelection().getLabel());
return true;
}
@Override
public boolean onActionItemClicked(final ActionMode actionMode, MenuItem menuItem) {
int id = menuItem.getItemId();
if (id == R.id.action_delete) {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Remove " + adapter.getCurrentSelection().getLabel() + "?");
alert.setMessage("Are you sure you want do remove this account?");
alert.setPositiveButton("Remove", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
entries.remove(adapter.getCurrentSelection());
Snackbar.make(findViewById(R.id.listView), "Account removed", Snackbar.LENGTH_LONG).setCallback(new Snackbar.Callback() {
@Override
public void onDismissed(Snackbar snackbar, int event) {
super.onDismissed(snackbar, event);
if (entries.isEmpty()) {
showNoAccount();
}
}
}).show();
actionMode.finish();
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.cancel();
actionMode.finish();
}
});
alert.show();
return true;
}
else if (id == R.id.action_edit) {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Rename");
final EditText input = new EditText(this);
input.setText(adapter.getCurrentSelection().getLabel());
alert.setView(input);
alert.setPositiveButton("Save", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
adapter.getCurrentSelection().setLabel(input.getEditableText().toString());
actionMode.finish();
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.cancel();
actionMode.finish();
}
});
alert.show();
return true;
}
return false;
}
@Override
public void onDestroyActionMode(ActionMode actionMode) {
adapter.setCurrentSelection(null);
adapter.notifyDataSetChanged();
SettingsHelper.store(this, entries);
}
}

View file

@ -0,0 +1,119 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.bierbaumer.otp_authenticator;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.security.KeyPairGeneratorSpec;
import java.io.IOException;
import java.math.BigInteger;
import java.security.GeneralSecurityException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.KeyStore;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.security.auth.x500.X500Principal;
/**
* Wraps {@link SecretKey} instances using a public/private key pair stored in
* the platform {@link KeyStore}. This allows us to protect symmetric keys with
* hardware-backed crypto, if provided by the device.
* <p>
* See <a href="http://en.wikipedia.org/wiki/Key_Wrap">key wrapping</a> for more
* details.
* <p>
* Not inherently thread safe.
*/
public class SecretKeyWrapper {
private final Cipher mCipher;
private final KeyPair mPair;
/**
* Create a wrapper using the public/private key pair with the given alias.
* If no pair with that alias exists, it will be generated.
*/
public SecretKeyWrapper(Context context, String alias)
throws GeneralSecurityException, IOException {
mCipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
final KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
keyStore.load(null);
if (!keyStore.containsAlias(alias)) {
generateKeyPair(context, alias);
}
// Even if we just generated the key, always read it back to ensure we
// can read it successfully.
final KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(
alias, null);
mPair = new KeyPair(entry.getCertificate().getPublicKey(), entry.getPrivateKey());
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private static void generateKeyPair(Context context, String alias)
throws GeneralSecurityException {
final Calendar start = new GregorianCalendar();
final Calendar end = new GregorianCalendar();
end.add(Calendar.YEAR, 100);
final KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(context)
.setAlias(alias)
.setSubject(new X500Principal("CN=" + alias))
.setSerialNumber(BigInteger.ONE)
.setStartDate(start.getTime())
.setEndDate(end.getTime())
.build();
final KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA", "AndroidKeyStore");
gen.initialize(spec);
gen.generateKeyPair();
}
/**
* Wrap a {@link SecretKey} using the public key assigned to this wrapper.
* Use {@link #unwrap(byte[])} to later recover the original
* {@link SecretKey}.
*
* @return a wrapped version of the given {@link SecretKey} that can be
* safely stored on untrusted storage.
*/
public byte[] wrap(SecretKey key) throws GeneralSecurityException {
mCipher.init(Cipher.WRAP_MODE, mPair.getPublic());
return mCipher.wrap(key);
}
/**
* Unwrap a {@link SecretKey} using the private key assigned to this
* wrapper.
*
* @param blob a wrapped {@link SecretKey} as previously returned by
* {@link #wrap(SecretKey)}.
*/
public SecretKey unwrap(byte[] blob) throws GeneralSecurityException {
mCipher.init(Cipher.UNWRAP_MODE, mPair.getPrivate());
return (SecretKey) mCipher.unwrap(blob, "AES", Cipher.SECRET_KEY);
}
}

View file

@ -0,0 +1,68 @@
package net.bierbaumer.otp_authenticator;
import android.content.Context;
import android.os.Build;
import org.json.JSONArray;
import org.json.JSONException;
import java.io.File;
import java.util.ArrayList;
import javax.crypto.SecretKey;
import static net.bierbaumer.otp_authenticator.Utils.readFully;
import static net.bierbaumer.otp_authenticator.Utils.writeFully;
public class SettingsHelper {
public static final String KEY_FILE = "otp.key";
public static final String SETTINGS_FILE = "secrets.dat";
public static void store(Context context, ArrayList<Entry> entries){
JSONArray a = new JSONArray();
for(Entry e: entries){
try {
a.put(e.toJSON());
} catch (JSONException e1) {
}
}
try {
byte[] data = a.toString().getBytes();
int currentApiVersion = android.os.Build.VERSION.SDK_INT;
if (currentApiVersion >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
SecretKey key = EncryptionHelper.loadOrGenerateKeys(context, new File(context.getFilesDir() + "/" + KEY_FILE));
data = EncryptionHelper.encrypt(key,data);
}
writeFully(new File(context.getFilesDir() + "/" + SETTINGS_FILE), data);
} catch (Exception e) {
}
}
public static ArrayList<Entry> load(Context context){
ArrayList<Entry> entries = new ArrayList<>();
try {
byte[] data = readFully(new File(context.getFilesDir() + "/" + SETTINGS_FILE));
int currentApiVersion = android.os.Build.VERSION.SDK_INT;
if (currentApiVersion >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
SecretKey key = EncryptionHelper.loadOrGenerateKeys(context, new File(context.getFilesDir() + "/" + KEY_FILE));
data = EncryptionHelper.decrypt(key, data);
}
JSONArray a = new JSONArray(new String(data));
for(int i=0;i< a.length(); i++){
entries.add(new Entry(a.getJSONObject(i) ));
}
}
catch (Exception e) {
}
return entries;
}
}

View file

@ -0,0 +1,52 @@
package net.bierbaumer.otp_authenticator;
import org.apache.commons.codec.binary.Base32;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
public class TOTPHelper {
public static final String SHA1 = "HmacSHA1";
public static String generate(byte[] secret) {
return String.format("%06d", generate(secret, System.currentTimeMillis() / 1000, 6));
}
public static int generate(byte[] key, long t, int digits)
{
int r = 0;
try {
t /= 30;
byte[] data = new byte[8];
long value = t;
for (int i = 8; i-- > 0; value >>>= 8) {
data[i] = (byte) value;
}
SecretKeySpec signKey = new SecretKeySpec(key, SHA1);
Mac mac = Mac.getInstance(SHA1);
mac.init(signKey);
byte[] hash = mac.doFinal(data);
int offset = hash[20 - 1] & 0xF;
long truncatedHash = 0;
for (int i = 0; i < 4; ++i) {
truncatedHash <<= 8;
truncatedHash |= (hash[offset + i] & 0xFF);
}
truncatedHash &= 0x7FFFFFFF;
truncatedHash %= Math.pow(10,digits);
r = (int) truncatedHash;
}
catch(Exception e){
}
return r;
}
}

View file

@ -0,0 +1,51 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.bierbaumer.otp_authenticator;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class Utils {
public static void writeFully(File file, byte[] data) throws IOException {
final OutputStream out = new FileOutputStream(file);
try {
out.write(data);
} finally {
out.close();
}
}
public static byte[] readFully(File file) throws IOException {
final InputStream in = new FileInputStream(file);
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int count;
while ((count = in.read(buffer)) != -1) {
bytes.write(buffer, 0, count);
}
return bytes.toByteArray();
} finally {
in.close();
}
}
}

View file

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="net.bierbaumer.otp_authenticator.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<RelativeLayout
android:gravity="top"
android:background="?attr/colorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:max="1000"
android:progress="500"
android:layout_alignBottom="@id/toolbar"
/>
</RelativeLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>

View file

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="net.bierbaumer.otp_authenticator.MainActivity"
tools:showIn="@layout/activity_main">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
tools:listitem="@android:layout/simple_list_item_2"
/>
</RelativeLayout>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webViewAbout"
/>

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28sp"
android:textStyle="bold"
android:text="123456"
android:id="@+id/textViewOTP"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/textViewLabel"
android:layout_below="@+id/textViewOTP"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
/>
</RelativeLayout>

View file

@ -0,0 +1,18 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
>
<item
android:id="@+id/action_edit"
android:orderInCategory="100"
android:icon="@android:drawable/ic_menu_edit"
app:showAsAction="always"
android:label="Edit" />
<item
android:id="@+id/action_delete"
android:orderInCategory="100"
android:icon="@android:drawable/ic_menu_delete"
app:showAsAction="always"
android:label="Delete" />
</menu>

View file

@ -0,0 +1,16 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<item
android:id="@+id/action_scan"
android:orderInCategory="100"
android:title="Scan QR Code"
android:icon="@android:drawable/ic_menu_camera"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_about"
android:orderInCategory="100"
android:title="About"
app:showAsAction="never" />
</menu>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View file

@ -0,0 +1,27 @@
<html>
<head>
<meta charset="utf-8"/>
<style>
* {
margin:5px;
color: #212121;
}
p { font-size:120%;}
body { font-family: sans-serif; }
pre { background-color: #eeeeee; padding: 1em; white-space: pre-wrap; }
a, a:visited, a:hover, a:active {
color: #727272;
}
</style>
</head>
<body>
<center>
<img width="72" src="file:///android_res/mipmap/ic_launcher.png">
<h2>OTP Authenticator 1.0</h2>
<p>© 2015 - Bruno Bierbaumer</p>
<p><a href="https://github.com/0xbb/otp-authenticator">Project Homepage</a></p>
<p><a href="file:///android_res/raw/opensource.html">Acknowledgments</a></p>
</center>
</body>
</html>

View file

@ -0,0 +1,31 @@
<html>
<head>
<meta charset="utf-8"/>
<style>
* {
margin:5px;
color: #212121;
}
body { font-family: sans-serif; }
pre { background-color: #eeeeee; padding: 1em; white-space: pre-wrap; }
a, a:visited, a:hover, a:active {
color: #727272;
}
ul {
padding-left:20px;
margin:0;
font-size:80%;
}
</style>
</head>
<div>
<h3>Acknowledgments:</h3>
<ul>
<li><a href="https://commons.apache.org/proper/commons-codec/">Apache Commons Code</a>
<li><a href="https://android.googlesource.com/platform/development/+/master/samples/Vault/src/com/example/android/vault">Code Parts from Google's Android Samples</a>
<li><a href="https://github.com/zxing/zxing">ZXing</a>
<li><a href="https://github.com/journeyapps/zxing-android-embedded">ZXing Android Embedded</a>
</ul>
</div>
</body>
</html>

View file

@ -0,0 +1,10 @@
<resources>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="windowActionModeOverlay">true</item>
</style>
</resources>

View file

@ -0,0 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#607D8B</color>
<color name="colorPrimaryDark">#455A64</color>
<color name="primary_light">#CFD8DC</color>
<color name="colorAccent">#FFC107</color>
<color name="primary_text">#212121</color>
<color name="secondary_text">#727272</color>
<color name="icons">#FFFFFF</color>
<color name="divider">#B6B6B6</color>
</resources>

View file

@ -0,0 +1,6 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
</resources>

View file

@ -0,0 +1,7 @@
<resources>
<string name="app_name">OTP Authenticator</string>
<string name="app_launcher">Authenticator</string>
<string name="action_settings">Settings</string>
<string name="action_scan">Scan QR-Code</string>
<string name="no_accounts">No Account has been added yet</string>
</resources>

View file

@ -0,0 +1,19 @@
<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>

23
build.gradle Normal file
View file

@ -0,0 +1,23 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

18
gradle.properties Normal file
View file

@ -0,0 +1,18 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View file

@ -0,0 +1,6 @@
#Wed Oct 21 11:34:03 PDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip

160
gradlew vendored Executable file
View file

@ -0,0 +1,160 @@
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

90
gradlew.bat vendored Normal file
View file

@ -0,0 +1,90 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

1
settings.gradle Normal file
View file

@ -0,0 +1 @@
include ':app'