Skip to content

Commit

Permalink
Merge pull request #1 from Craftama/generate-psk
Browse files Browse the repository at this point in the history
Generate psk from passphrase and remove psk field and rename to craftbox config.
  • Loading branch information
michaelkuty authored Jan 28, 2018
2 parents fa131a2 + a98213f commit e08a27b
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 25 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
compileSdkVersion 27
buildToolsVersion "27.0.3"

defaultConfig {
applicationId "io.skygrid.bluetoothtest"
applicationId "io.craftbox.rpiconf"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.brendanmyers.rpiconf">
package="io.craftbox.rpiconf">

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
Expand All @@ -11,7 +11,7 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name="io.craftbox.rpiconf.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.brendanmyers.rpiconf;
package io.craftbox.rpiconf;

import android.bluetooth.BluetoothDevice;
import android.content.Context;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
package io.brendanmyers.rpiconf;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Set;
import java.util.UUID;
package io.craftbox.rpiconf;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
Expand All @@ -18,14 +11,28 @@
import android.widget.Spinner;
import android.widget.TextView;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Set;
import java.util.UUID;

import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;


public class MainActivity extends Activity {

BluetoothSocket mmSocket;

Spinner devicesSpinner;
Button refreshDevicesButton;
TextView ssidTextView;
TextView pskTextView;
TextView passphraseTextView;
Button startButton;
TextView messageTextView;

Expand All @@ -41,8 +48,8 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);

ssidTextView = (TextView) findViewById(R.id.ssid_text);
pskTextView = (TextView) findViewById(R.id.psk_text);
messageTextView = (TextView) findViewById(R.id.messages_text);
passphraseTextView = (TextView) findViewById(R.id.passphrase_text);

devicesSpinner = (Spinner) findViewById(R.id.devices_spinner);

Expand All @@ -60,7 +67,19 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
String ssid = ssidTextView.getText().toString();
String psk = pskTextView.getText().toString();
String passphrase = passphraseTextView.getText().toString();
String psk = "";

PBEKeySpec key_spec = new PBEKeySpec(passphrase.toCharArray(),
ssid.getBytes(), 4096, 256);

try {
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
try {
SecretKey psk_key = skf.generateSecret(key_spec);
psk = Utils.bytesToHex(psk_key.getEncoded()).toString().toLowerCase();
} catch (InvalidKeySpecException e) {}
} catch (NoSuchAlgorithmException e) {}

BluetoothDevice device = (BluetoothDevice) devicesSpinner.getSelectedItem();
(new Thread(new workerThread(ssid, psk, device))).start();
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/io/craftbox/rpiconf/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.craftbox.rpiconf;

public class Utils {
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();

public static String bytesToHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
for (int j = 0; j < bytes.length; j++) {
int v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
}
return new String(hexChars);
}

public static byte[] hexToBytes(String s) {
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
+ Character.digit(s.charAt(i+1), 16));
}
return data;
}
}
12 changes: 5 additions & 7 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,27 @@
android:layout_below="@+id/ssid_label"
android:layout_alignParentStart="true" />


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="PSK"
android:id="@+id/psk_label"
android:text="Passphrase"
android:id="@+id/passphrase_label"
android:layout_below="@+id/ssid_text" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/psk_text"
android:layout_below="@+id/psk_label"
android:id="@+id/passphrase_text"
android:layout_below="@+id/passphrase_label"
android:layout_alignParentStart="true" />


<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Configuration"
android:id="@+id/start_button"
android:layout_below="@+id/psk_text"
android:layout_below="@+id/passphrase_text"
android:layout_alignParentEnd="true" />

<TextView
Expand Down
Binary file modified app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">RPi3 Wifi Config Tool</string>
<string name="app_name">CraftBOX Config</string>
</resources>

0 comments on commit e08a27b

Please sign in to comment.