Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fingerprints stored in hex

  • Loading branch information...
commit a7aa7e2ccd771df17fb18655c11736702b987bf2 1 parent 3bd2ddf
Dev Random authored
Showing with 30 additions and 8 deletions.
  1. +30 −8 src/info/guardianproject/otr/OtrAndroidKeyManagerImpl.java
38 src/info/guardianproject/otr/OtrAndroidKeyManagerImpl.java
View
@@ -33,7 +33,7 @@
public class OtrAndroidKeyManagerImpl implements OtrKeyManager {
- private OtrKeyManagerStore store;
+ private SimplePropertiesStore store;
private OtrCryptoEngineImpl cryptoEngine;
@@ -53,16 +53,16 @@ public static synchronized OtrAndroidKeyManagerImpl getInstance (String filepath
}
private OtrAndroidKeyManagerImpl(String filepath) throws IOException {
- this.store = new DefaultPropertiesStore(filepath);
+ this.store = new SimplePropertiesStore(filepath);
cryptoEngine = new OtrCryptoEngineImpl();
}
- class DefaultPropertiesStore implements OtrKeyManagerStore {
+ class SimplePropertiesStore implements OtrKeyManagerStore {
private Properties properties = new Properties();
private File mStoreFile;
- public DefaultPropertiesStore(String filepath) {
+ public SimplePropertiesStore(String filepath) {
mStoreFile = new File(filepath);
properties.clear();
@@ -138,6 +138,17 @@ public void setProperty(String id, byte[] value) {
}
}
+ // Store as hex bytes
+ public void setPropertyHex(String id, byte[] value) {
+ properties.setProperty(id, new String(Hex.encode(value)));
+
+ try {
+ this.store();
+ } catch (Exception e) {
+ OtrDebugLogger.log("store not saved",e);
+ }
+ }
+
public void removeProperty(String id) {
properties.remove(id);
@@ -152,6 +163,17 @@ public void removeProperty(String id) {
null;
}
+
+ // Load from hex bytes
+ public byte[] getPropertyHexBytes(String id) {
+ String value = properties.getProperty(id);
+
+ if (value != null)
+ return Hex.decode(value);
+ return
+ null;
+ }
+
public boolean getPropertyBoolean(String id, boolean defaultValue) {
try {
return Boolean.valueOf(properties.get(id).toString());
@@ -223,7 +245,7 @@ public void generateLocalKeyPair(String accountID) {
// Stash fingerprint for consistency.
try {
String fingerprintString = new OtrCryptoEngineImpl().getFingerprint(pubKey);
- this.store.setProperty(accountID + ".fingerprint",
+ this.store.setPropertyHex(accountID + ".fingerprint",
Hex.decode(fingerprintString));
} catch (OtrCryptoException e) {
e.printStackTrace();
@@ -260,7 +282,7 @@ public String getRemoteFingerprint(SessionID sessionID) {
}
public String getRemoteFingerprint(String userId) {
- byte[] fingerprint = this.store.getPropertyBytes(userId + ".fingerprint");
+ byte[] fingerprint = this.store.getPropertyHexBytes(userId + ".fingerprint");
if (fingerprint != null) {
// If we have a fingerprint stashed, assume it is correct.
return new String(Hex.encode(fingerprint, 0, fingerprint.length));
@@ -272,7 +294,7 @@ public String getRemoteFingerprint(String userId) {
// Store the fingerprint, for posterity.
String fingerprintString =
new OtrCryptoEngineImpl().getFingerprint(remotePublicKey);
- this.store.setProperty(userId + ".fingerprint", Hex.decode(fingerprintString));
+ this.store.setPropertyHex(userId + ".fingerprint", Hex.decode(fingerprintString));
return fingerprintString;
} catch (OtrCryptoException e) {
e.printStackTrace();
@@ -393,7 +415,7 @@ public void savePublicKey(SessionID sessionID, PublicKey pubKey) {
// and is useful for transferring rosters to other apps.
try {
String fingerprintString = new OtrCryptoEngineImpl().getFingerprint(pubKey);
- this.store.setProperty(userId + ".fingerprint",
+ this.store.setPropertyHex(userId + ".fingerprint",
Hex.decode(fingerprintString));
} catch (OtrCryptoException e) {
e.printStackTrace();
Please sign in to comment.
Something went wrong with that request. Please try again.