mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2024-11-24 16:28:23 -05:00
wpadebug: Add support for QR Code scanning and display via zxing
Enhance wpadebug application to support scanning and displaying of QR codes. This depends on a third-party source: zxing (https://github.com/zxing/zxing). Shell command to launch scanner/viewer via wpadebug is: >adb root >adb shell Scanner: >am start -n w1.fi.wpadebug/w1.fi.wpadebug.QrCodeScannerActivity Viewer: >am start -n w1.fi.wpadebug/w1.fi.wpadebug.QrCodeDisplayActivity QR code string input/output file would be generated in '/sdcard/wpadebug_qrdata.txt' in the device. Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
This commit is contained in:
parent
8f7a50a63e
commit
717f236dce
@ -8,6 +8,7 @@
|
|||||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
<application android:label="wpadebug">
|
<application android:label="wpadebug">
|
||||||
<activity android:name="w1.fi.wpadebug.MainActivity"
|
<activity android:name="w1.fi.wpadebug.MainActivity"
|
||||||
android:label="wpadebug">
|
android:label="wpadebug">
|
||||||
@ -45,6 +46,14 @@
|
|||||||
android:label="Credential"
|
android:label="Credential"
|
||||||
android:parentActivityName="w1.fi.wpadebug.WpaCredActivity">
|
android:parentActivityName="w1.fi.wpadebug.WpaCredActivity">
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity android:name="w1.fi.wpadebug.QrCodeScannerActivity"
|
||||||
|
android:label="QR Code Reader"
|
||||||
|
android:parentActivityName="w1.fi.wpadebug.MainActivity">
|
||||||
|
</activity>
|
||||||
|
<activity android:name="w1.fi.wpadebug.QrCodeDisplayActivity"
|
||||||
|
android:label="QR Code Display"
|
||||||
|
android:parentActivityName="w1.fi.wpadebug.MainActivity">
|
||||||
|
</activity>
|
||||||
<activity android:name="w1.fi.wpadebug.WpaWebViewActivity"
|
<activity android:name="w1.fi.wpadebug.WpaWebViewActivity"
|
||||||
android:label="WebView"
|
android:label="WebView"
|
||||||
android:launchMode="singleTop"
|
android:launchMode="singleTop"
|
||||||
|
@ -20,6 +20,19 @@ Build
|
|||||||
-----
|
-----
|
||||||
|
|
||||||
- Install Android SDK and build tools
|
- Install Android SDK and build tools
|
||||||
|
|
||||||
|
wpadebug depends on zxing core to launch QR code display/scanning.
|
||||||
|
To build zxing core:
|
||||||
|
|
||||||
|
- mkdir hostap/wpadebug/libs # target for the jar file
|
||||||
|
- Install maven tool
|
||||||
|
- clone latest zxing code [git clone https://github.com/zxing/zxing.git]
|
||||||
|
- cd zxing/core
|
||||||
|
- run: mvn install -DskipTests
|
||||||
|
- copy target/core-*.*.*-SNAPSHOT.jar to hostap/wpadebug/libs
|
||||||
|
|
||||||
|
To build wpadebug application:
|
||||||
|
|
||||||
- update project target if desired; for example:
|
- update project target if desired; for example:
|
||||||
android list targets
|
android list targets
|
||||||
android update project --target 1 --path $PWD
|
android update project --target 1 --path $PWD
|
||||||
|
13
wpadebug/res/layout/qrcode.xml
Normal file
13
wpadebug/res/layout/qrcode.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center_horizontal">
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/qrCode"
|
||||||
|
android:layout_width="350dp"
|
||||||
|
android:layout_height="350dp"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
109
wpadebug/src/w1/fi/wpadebug/QrCodeDisplayActivity.java
Normal file
109
wpadebug/src/w1/fi/wpadebug/QrCodeDisplayActivity.java
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* wpadebug - wpa_supplicant and Wi-Fi debugging app for Android
|
||||||
|
* Copyright (c) 2018, The Linux Foundation
|
||||||
|
*
|
||||||
|
* This software may be distributed under the terms of the BSD license.
|
||||||
|
* See README for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package w1.fi.wpadebug;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
import com.google.zxing.BarcodeFormat;
|
||||||
|
import com.google.zxing.MultiFormatWriter;
|
||||||
|
import com.google.zxing.WriterException;
|
||||||
|
import com.google.zxing.common.BitMatrix;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
|
public class QrCodeDisplayActivity extends Activity {
|
||||||
|
|
||||||
|
private static final String TAG = "wpadebug";
|
||||||
|
private static final String FILE_NAME = "wpadebug_qrdata.txt";
|
||||||
|
private ImageView imageView;
|
||||||
|
|
||||||
|
// Below set of configs are used for QR code display window
|
||||||
|
private final static int WHITE = 0xFFFFFFFF;
|
||||||
|
private final static int BLACK = 0xFF000000;
|
||||||
|
private final static int WIDTH = 400;
|
||||||
|
private final static int HEIGHT = 400;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
// create imageview for this and attach to this activity.
|
||||||
|
setContentView(R.layout.qrcode);
|
||||||
|
imageView = (ImageView) findViewById(R.id.qrCode);
|
||||||
|
String str = readFromFile(FILE_NAME);
|
||||||
|
|
||||||
|
//Encode and launch qrcode now
|
||||||
|
try {
|
||||||
|
Bitmap bitmap = (TextUtils.isEmpty(str)) ? null : encodeAsBitmap(str);
|
||||||
|
if (bitmap != null) {
|
||||||
|
imageView.setImageBitmap(bitmap);
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Failed to generate bitmap for uri=" + str);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
} catch (WriterException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Bitmap encodeAsBitmap(String str) throws WriterException {
|
||||||
|
BitMatrix result;
|
||||||
|
try {
|
||||||
|
result = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, WIDTH, HEIGHT, null);
|
||||||
|
} catch (IllegalArgumentException iae) {
|
||||||
|
// Unsupported format
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int width = result.getWidth();
|
||||||
|
int height = result.getHeight();
|
||||||
|
int[] pixels = new int[width * height];
|
||||||
|
for (int y = 0; y < height; y++) {
|
||||||
|
int offset = y * width;
|
||||||
|
for (int x = 0; x < width; x++) {
|
||||||
|
pixels[offset + x] = result.get(x, y) ? BLACK : WHITE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||||
|
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String readFromFile(String filePath) {
|
||||||
|
try {
|
||||||
|
FileInputStream fis = new FileInputStream(new File("/sdcard", filePath));
|
||||||
|
BufferedReader br = new BufferedReader(new InputStreamReader(fis, "UTF-8"));
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
String line;
|
||||||
|
while(( line = br.readLine()) != null ) {
|
||||||
|
sb.append( line );
|
||||||
|
sb.append( '\n' );
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException e) {
|
||||||
|
Log.e(TAG, "File not found: " + e.toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(TAG, "Can not read file: " + e.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
75
wpadebug/src/w1/fi/wpadebug/QrCodeScannerActivity.java
Normal file
75
wpadebug/src/w1/fi/wpadebug/QrCodeScannerActivity.java
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* wpadebug - wpa_supplicant and Wi-Fi debugging app for Android
|
||||||
|
* Copyright (c) 2018, The Linux Foundation
|
||||||
|
*
|
||||||
|
* This software may be distributed under the terms of the BSD license.
|
||||||
|
* See README for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package w1.fi.wpadebug;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.ActivityNotFoundException;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
|
||||||
|
public class QrCodeScannerActivity extends Activity {
|
||||||
|
|
||||||
|
private static final String TAG = "wpadebug";
|
||||||
|
private static final String RESULT = "SCAN_RESULT";
|
||||||
|
private static final String FILE_NAME = "wpadebug_qrdata.txt";
|
||||||
|
private static final String ACTION = "com.google.zxing.client.android.SCAN";
|
||||||
|
|
||||||
|
private static final int QRCODE = 1;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.setAction(ACTION);
|
||||||
|
try {
|
||||||
|
startActivityForResult(intent, QRCODE);
|
||||||
|
} catch (ActivityNotFoundException e) {
|
||||||
|
Log.e(TAG, "No QR code scanner found with name=" + ACTION);
|
||||||
|
Toast.makeText(QrCodeScannerActivity.this, "QR code scanner not found", Toast.LENGTH_SHORT).show();
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
if (requestCode == QRCODE && resultCode == RESULT_OK) {
|
||||||
|
writeToFile(data.getStringExtra(RESULT));
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeToFile(String data)
|
||||||
|
{
|
||||||
|
File file = new File("/sdcard", FILE_NAME);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
file.createNewFile();
|
||||||
|
FileOutputStream fOut = new FileOutputStream(file);
|
||||||
|
OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
|
||||||
|
myOutWriter.append(data);
|
||||||
|
|
||||||
|
myOutWriter.close();
|
||||||
|
|
||||||
|
fOut.flush();
|
||||||
|
fOut.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
Log.e(TAG, "File write failed: " + e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user