From: Nathaniel Wesley Filardo Date: Thu, 8 Jul 2010 05:21:43 +0000 (-0400) Subject: Initial checkin X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=eb7f1ddcd78f71cf479d7f717b9242204c09f679;p=android-vcpass Initial checkin --- eb7f1ddcd78f71cf479d7f717b9242204c09f679 diff --git a/AndroidManifest.xml b/AndroidManifest.xml new file mode 100644 index 0000000..c982d87 --- /dev/null +++ b/AndroidManifest.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build.properties b/build.properties new file mode 100644 index 0000000..edc7f23 --- /dev/null +++ b/build.properties @@ -0,0 +1,17 @@ +# This file is used to override default values used by the Ant build system. +# +# This file must be checked in Version Control Systems, as it is +# integral to the build system of your project. + +# This file is only used by the Ant script. + +# You can use this to override default values such as +# 'source.dir' for the location of your java source folder and +# 'out.dir' for the location of your output folder. + +# You can also use it define how the release builds are signed by declaring +# the following properties: +# 'key.store' for the location of your keystore and +# 'key.alias' for the name of the key to use. +# The password will be asked during the build when you use the 'release' target. + diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..af37263 --- /dev/null +++ b/build.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/default.properties b/default.properties new file mode 100644 index 0000000..9d79b12 --- /dev/null +++ b/default.properties @@ -0,0 +1,11 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system use, +# "build.properties", and override values to adapt the script to your +# project structure. + +# Project target. +target=android-4 diff --git a/host/org/ietfng/ns/android/vcpass/VCSlideGen.java b/host/org/ietfng/ns/android/vcpass/VCSlideGen.java new file mode 100644 index 0000000..5329e7d --- /dev/null +++ b/host/org/ietfng/ns/android/vcpass/VCSlideGen.java @@ -0,0 +1,201 @@ +/** Host-side slide generator. + * + * Required classpath entries: + * /usr/share/java/bcprov.jar + * /usr/share/java/commons-codec.jar + * /usr/share/java/commons-cli.jar + * $HOME/src/zxing/core/core.jar + * + * Build with: + * javac -d bin/classes -cp bin/classes:... \ + * host/org/ietfng/ns/android/vcpass/VCSlideGen.java + * + */ + +package org.ietfng.ns.android.vcpass; + +import java.io.FileWriter; +import java.security.SecureRandom; +import java.security.Provider; +import java.security.Security; +import javax.crypto.SecretKey; + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatWriter; +import com.google.zxing.common.ByteMatrix; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.PosixParser; +import org.apache.commons.codec.binary.Base64; + +public final class VCSlideGen { + static final private int SEED_SIZE = 16; + + private static final int QR_SIZEX = 400; + private static final int QR_SIZEY = 400; + + static final private Options cliopts = new Options(); + static final private String OPT_SS_HELP = "h"; + static final private String OPT_SS_QRFILE = "b"; + static final private String OPT_SS_SECRET = "S"; + static final private String OPT_SS_SLIDEF = "s"; + static final private String OPT_SS_VOCABS = "v"; + + private static final int crpix = VCParameters.DISP_X + / VCParameters.GRID_X; + private static final int ccpix = VCParameters.DISP_Y + / VCParameters.GRID_Y; + + private static final void + printPBMHeader(FileWriter f, int v, int x, int y) + throws java.io.IOException + { + StringBuilder sb = new StringBuilder(); + sb.append("P"); + sb.append(v); + sb.append(" "); + sb.append(x); + sb.append(" "); + sb.append(y); + sb.append("\n"); + f.write(sb.toString(), 0, sb.length()); + } + + static { + cliopts.addOption(OPT_SS_HELP, "help", false, "Show this help"); + cliopts.addOption(OPT_SS_QRFILE, "qrfile", true, + "Barcode PNM file basename"); + cliopts.addOption(OPT_SS_SECRET, "secretseed", true, + "Secret seed (for development)"); + cliopts.addOption(OPT_SS_SLIDEF, "slidefile", true, + "Slide PNM file basename"); + cliopts.addOption(OPT_SS_VOCABS, "vocabfile", true, + "Vocabulary PNM file basename"); + } + + public static void main(String[] args) throws Exception { + CommandLineParser parser = new PosixParser(); + CommandLine cmd = parser.parse(cliopts, args); + + if(cmd.hasOption(OPT_SS_HELP)) { + HelpFormatter formatter = new HelpFormatter(); + formatter.printHelp( "VCSlideGen" , cliopts ); + return; + } + + Security.addProvider(VCParameters.CSPROV); + +/* XXX */ + char[] useed = "foo".toCharArray(); + char[] vseed = "bar".toCharArray(); + +/* XXX + byte[] useed = new byte[SEED_SIZE]; + byte[] vseed = new byte[SEED_SIZE]; + + { + SecureRandom seedsr = SecureRandom.getInstance( + VCParameters.CSPRNG + ); + if(cmd.hasOption(OPT_SS_SECRET)) { + System.err.println("WARN: Using given seed."); + seedsr.setSeed(cmd.getOptionValue(OPT_SS_SECRET) + .getBytes("UTF-8")); + } else { + // seedsr will initialize from the system's RNG when + // we first pull some data out of it. + } + seedsr.nextBytes(useed); + seedsr.nextBytes(vseed); + } +*/ + + if(cmd.hasOption(OPT_SS_QRFILE)) { + String encodedseeds = null; + { + StringBuilder esb = new StringBuilder(); + Base64 b64 = new Base64(80,new byte[0]); + // XXX esb.append(b64.encodeToString(useed)); + esb.append(" "); + // XXX esb.append(b64.encodeToString(vseed)); + encodedseeds = esb.toString(); + System.out.printf("QRSTR: %s\n", encodedseeds); + } + FileWriter qrout = new FileWriter( + cmd.getOptionValue(OPT_SS_QRFILE) + +".pbm" + ); + printPBMHeader(qrout, 1, QR_SIZEX, QR_SIZEY); + ByteMatrix qrbm = new MultiFormatWriter().encode( + encodedseeds, + BarcodeFormat.QR_CODE, + QR_SIZEX, QR_SIZEY); + byte[][] qr = qrbm.getArray(); + for(int x = 0; x < qr.length; x++) { + for(int y = 0; y < qr[x].length; y++) { + qrout.write('1' - (qr[x][y] & 0x1)); + } + qrout.write('\n'); + } + qrout.flush(); + qrout.close(); + } + + if(cmd.hasOption(OPT_SS_SLIDEF)) { + FileWriter sout = new FileWriter( + cmd.getOptionValue(OPT_SS_SLIDEF) + +".pbm" + ); + printPBMHeader(sout, 1, VCParameters.DISP_X, + VCParameters.DISP_Y); + + Integer[][] slide = VCGenerator.generateSlide(useed, null); + + int[][] pixels = VCGenerator.vcArrayToPixels(slide); + for(int r = 0; r < pixels.length; r++) { + for(int c = 0; c < pixels[r].length; c++) { + sout.write(pixels[r][c] == VCParameters.white ? + '0' : '1'); + } + sout.write('\n'); + } + sout.flush(); + sout.close(); + } + + if(cmd.hasOption(OPT_SS_VOCABS)) { + int[] plain = new int[VCParameters.GRID_X + *VCParameters.GRID_Y]; + for(int i = 0; i < VCParameters.VCVOC_SIZE; i++) { + FileWriter vout = new FileWriter( + cmd.getOptionValue(OPT_SS_VOCABS) + +"-" + +Integer.toString(i) + +".pbm" + ); + printPBMHeader(vout, 1, VCParameters.DISP_X, + VCParameters.DISP_Y); + + for(int j = 0; j < plain.length; j++) { + plain[j] = i; + } + + Integer[][] vocab = VCGenerator.generateChallenge( + vseed, useed, plain, null + ); + int[][] pixels = VCGenerator.vcArrayToPixels(vocab); + for(int r = 0; r < pixels.length; r++) { + for(int c = 0; c < pixels[r].length; c++) { + vout.write(pixels[r][c] == VCParameters.white ? + '1' : '0'); + } + vout.write('\n'); + } + vout.flush(); + vout.close(); + } + } + } +} diff --git a/host/org/ietfng/ns/android/vcpass/VCTestVocGen.java b/host/org/ietfng/ns/android/vcpass/VCTestVocGen.java new file mode 100644 index 0000000..bc871e6 --- /dev/null +++ b/host/org/ietfng/ns/android/vcpass/VCTestVocGen.java @@ -0,0 +1,207 @@ +/** Host-side slide generator. + * + * Required classpath entries: + * /usr/share/java/bcprov.jar + * /usr/share/java/commons-codec.jar + * /usr/share/java/commons-cli.jar + * $HOME/src/zxing/core/core.jar + * + * Build with: + * javac -d bin/classes -cp bin/classes:... \ + * host/org/ietfng/ns/android/vcpass/VCTestVocGen.java + * + */ + +package org.ietfng.ns.android.vcpass; + +import java.io.FileWriter; +import java.security.SecureRandom; +import java.security.Provider; +import java.security.Security; +import javax.crypto.SecretKey; + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatWriter; +import com.google.zxing.common.ByteMatrix; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.PosixParser; +import org.apache.commons.codec.binary.Base64; + +public final class VCTestVocGen { + static final private int SEED_SIZE = 16; + + private static final int QR_SIZEX = 400; + private static final int QR_SIZEY = 400; + + static final private Options cliopts = new Options(); + static final private String OPT_SS_HELP = "h"; + static final private String OPT_SS_SECRET = "S"; + static final private String OPT_SS_VOCSEC = "V"; + static final private String OPT_SS_GENEXC = "c"; + static final private String OPT_SS_GENEXV = "v"; + + private static final int crpix = VCParameters.DISP_X + / VCParameters.GRID_X; + private static final int ccpix = VCParameters.DISP_Y + / VCParameters.GRID_Y; + + private static final void + printPBMHeader(FileWriter f, int v, int x, int y) + throws java.io.IOException + { + StringBuilder sb = new StringBuilder(); + sb.append("P"); + sb.append(v); + sb.append(" "); + sb.append(x); + sb.append(" "); + sb.append(y); + sb.append("\n"); + f.write(sb.toString(), 0, sb.length()); + } + + static { + cliopts.addOption(OPT_SS_HELP, "help", false, "Show this help"); + cliopts.addOption(OPT_SS_SECRET, "secretseed", true, + "Secret seed (for development)"); + cliopts.addOption(OPT_SS_SECRET, "slideseed", true, + "Slide seed (for development)"); + cliopts.addOption(OPT_SS_VOCSEC, "vocseed", true, + "Vocabulary seed (for development)"); + cliopts.addOption(OPT_SS_GENEXC, "chalfile", true, + "Example challenge file name"); + cliopts.addOption(OPT_SS_GENEXV, "vocfile", true, + "Example vocabulary file name"); + } + + public static void main(String[] args) throws Exception { + CommandLineParser parser = new PosixParser(); + CommandLine cmd = parser.parse(cliopts, args); + + if(cmd.hasOption(OPT_SS_HELP)) { + HelpFormatter formatter = new HelpFormatter(); + formatter.printHelp( "VCSlideGen" , cliopts ); + return; + } + + Security.addProvider(VCParameters.CSPROV); + + char[] useed; + if(cmd.hasOption(OPT_SS_SECRET)) { + useed = cmd.getOptionValue(OPT_SS_SECRET).toCharArray(); + } else { + // XXX + useed = "foo".toCharArray(); + } + + char[] vseed; + if(cmd.hasOption(OPT_SS_VOCSEC)) { + vseed = cmd.getOptionValue(OPT_SS_VOCSEC).toCharArray(); + } else { + // XXX + vseed = "bar".toCharArray(); + } + + if(cmd.hasOption(OPT_SS_GENEXV)) { + Integer[][] vocab = new Integer[VCParameters.VCVOC_SIZE][]; + Integer[][] vslide = new Integer[VCParameters.VCVOC_SIZE][]; + + { + Integer[][] slide = VCGenerator.generateSlide( useed, null ); + for(int i = 0; i < vslide.length; i++) { + vslide[i] = slide[0]; + } + } + + for(int i = 0; i < vocab.length; i++) { + int[] plain = new int[VCParameters.GRID_X + *VCParameters.GRID_Y]; + plain[0] = i; + + Integer[][] vocabi = VCGenerator.generateChallenge( + vseed, useed, plain, null + ); + + vocab[i] = vocabi[0]; + } + + FileWriter vout = new FileWriter( + cmd.getOptionValue(OPT_SS_GENEXV) + ); + printPBMHeader(vout, 1, VCParameters.DISP_X, + VCParameters.DISP_Y); + + /* XXX */ + int[][] spixels = VCGenerator.vcArrayToPixels(vslide); + int[][] vpixels = VCGenerator.vcArrayToPixels(vocab); + + for(int i = crpix-1; i < VCParameters.DISP_X-1; i += crpix){ + for(int r = 0; r < vpixels.length; r++) { + vpixels[i][r] = VCParameters.black; + vpixels[i+1][r] = VCParameters.black; + vpixels[r][i] = VCParameters.black; + vpixels[r][i+1] = VCParameters.black; + }} + + for(int r = 0; r < vpixels.length; r++) { + for(int c = 0; c < vpixels[r].length; c++) { + if(spixels[r][c] == VCParameters.black) { + vout.write('1'); + } else { + vout.write(vpixels[r][c] == VCParameters.white ? + '0' : '1'); + } + } + vout.write('\n'); + } + vout.flush(); + vout.close(); + } + + if(cmd.hasOption(OPT_SS_GENEXC)) { + int[] plain = new int[VCParameters.GRID_X + *VCParameters.GRID_Y]; + for(int i = 0; i < plain.length; i++ ){ + plain[i] = (i*7+8) % VCParameters.VCVOC_SIZE; + } + FileWriter vout = new FileWriter( + cmd.getOptionValue(OPT_SS_GENEXC) + ); + printPBMHeader(vout, 1, VCParameters.DISP_X, + VCParameters.DISP_Y); + + Integer[][] vocab = VCGenerator.generateChallenge( + vseed, useed, plain, null + ); + int[][] vpixels = VCGenerator.vcArrayToPixels(vocab); + + Integer[][] slide = VCGenerator.generateSlide( useed, null ); + int[][] spixels = VCGenerator.vcArrayToPixels(slide); + + for(int i = crpix-1; i < VCParameters.DISP_X-1; i += crpix){ + for(int r = 0; r < vpixels.length; r++) { + vpixels[i][r] = VCParameters.black; + vpixels[i+1][r] = VCParameters.black; + vpixels[r][i] = VCParameters.black; + vpixels[r][i+1] = VCParameters.black; + }} + + for(int r = 0; r < vpixels.length; r++) { + for(int c = 0; c < vpixels[r].length; c++) { + if(spixels[r][c] == VCParameters.black) { + vout.write('1'); + } else { + vout.write(vpixels[r][c] == VCParameters.white ? + '0' : '1'); + } + } + vout.write('\n'); + } + vout.flush(); + vout.close(); + } + } +} diff --git a/res/drawable-hdpi/icon.png b/res/drawable-hdpi/icon.png new file mode 100644 index 0000000..8074c4c Binary files /dev/null and b/res/drawable-hdpi/icon.png differ diff --git a/res/drawable-ldpi/icon.png b/res/drawable-ldpi/icon.png new file mode 100644 index 0000000..1095584 Binary files /dev/null and b/res/drawable-ldpi/icon.png differ diff --git a/res/drawable-mdpi/icon.png b/res/drawable-mdpi/icon.png new file mode 100644 index 0000000..a07c69f Binary files /dev/null and b/res/drawable-mdpi/icon.png differ diff --git a/res/layout/main.xml b/res/layout/main.xml new file mode 100644 index 0000000..28fb834 --- /dev/null +++ b/res/layout/main.xml @@ -0,0 +1,13 @@ + + + + + diff --git a/res/layout/vcpact.xml b/res/layout/vcpact.xml new file mode 100644 index 0000000..14ab14e --- /dev/null +++ b/res/layout/vcpact.xml @@ -0,0 +1,30 @@ + + + +