Skip to content

Commit

Permalink
Prepare for moar securiteee!
Browse files Browse the repository at this point in the history
  • Loading branch information
gbl08ma committed Jul 27, 2017
1 parent 09e413c commit 532c808
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 24 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ google-services.json
freeline.py
freeline/
freeline_project_description.json

# Ospylac
app/src/debug/java/im/tny/segvault/disturbances/Ospylac.java
app/src/release/java/im/tny/segvault/disturbances/Ospylac.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package im.tny.segvault.disturbances;

import android.content.Context;

import java.io.IOException;
import java.io.InputStream;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;

/**
* Created by Gabriel on 27/07/2017.
*/

final class Ospylac {
public static PrivateKey getPrivateKey(Context context, String param) {
try {
InputStream is = context.getAssets().open(param);
byte[] keyBytes = new byte[is.available()];
is.read(keyBytes);
is.close();

PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory kf = KeyFactory.getInstance("EC");
return kf.generatePrivate(spec);
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (InvalidKeySpecException e) {
e.printStackTrace();
return null;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void pair() {
byte[] sigBytes;
try {
Signature signer = Signature.getInstance("SHA256withECDSA");
signer.initSign(Util.getPrivateKeyFromAsset(context, "trusted.der"));
signer.initSign(Ospylac.getPrivateKey(context, "trusted.der"));
byte[] strByte = toSign.getBytes("UTF-8");
signer.update(strByte);
sigBytes = signer.sign();
Expand Down
23 changes: 0 additions & 23 deletions app/src/main/java/im/tny/segvault/disturbances/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,6 @@ public static Locale getCurrentLocale(Context context) {
}
}

public static PrivateKey getPrivateKeyFromAsset(Context context, String path) {
try {
InputStream is = context.getAssets().open(path);
byte[] keyBytes = new byte[is.available()];
is.read(keyBytes);
is.close();

PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory kf = KeyFactory.getInstance("EC");
return kf.generatePrivate(spec);
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (InvalidKeySpecException e) {
e.printStackTrace();
return null;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}


public static String encodeRFC3339(Date date) {
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(date)
.replaceAll("(\\d\\d)(\\d\\d)$", "$1:$2");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package im.tny.segvault.disturbances;

import android.content.Context;

import java.io.IOException;
import java.io.InputStream;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;

/**
* Created by Gabriel on 27/07/2017.
*/

final class Ospylac {
public static PrivateKey getPrivateKey(Context context, String param) {
try {
InputStream is = context.getAssets().open(param);
byte[] keyBytes = new byte[is.available()];
is.read(keyBytes);
is.close();

PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory kf = KeyFactory.getInstance("EC");
return kf.generatePrivate(spec);
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (InvalidKeySpecException e) {
e.printStackTrace();
return null;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}
}

0 comments on commit 532c808

Please sign in to comment.