Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fingerprints stored in hex

  • Loading branch information...
commit a7aa7e2ccd771df17fb18655c11736702b987bf2 1 parent 3bd2ddf
Dev Random authored April 10, 2012
38  src/info/guardianproject/otr/OtrAndroidKeyManagerImpl.java
@@ -33,7 +33,7 @@
33 33
 
34 34
 public class OtrAndroidKeyManagerImpl implements OtrKeyManager {
35 35
 
36  
-	private OtrKeyManagerStore store;
  36
+	private SimplePropertiesStore store;
37 37
 
38 38
 	private OtrCryptoEngineImpl cryptoEngine;
39 39
 	
@@ -53,16 +53,16 @@ public static synchronized OtrAndroidKeyManagerImpl getInstance (String filepath
53 53
 	}
54 54
 	
55 55
 	private OtrAndroidKeyManagerImpl(String filepath) throws IOException {
56  
-		this.store = new DefaultPropertiesStore(filepath);
  56
+		this.store = new SimplePropertiesStore(filepath);
57 57
 
58 58
 		cryptoEngine = new OtrCryptoEngineImpl();
59 59
 	}
60 60
 
61  
-	class DefaultPropertiesStore implements OtrKeyManagerStore {
  61
+	class SimplePropertiesStore implements OtrKeyManagerStore {
62 62
 		private Properties properties = new Properties();
63 63
 		private File mStoreFile;
64 64
 		
65  
-		public DefaultPropertiesStore(String filepath) {
  65
+		public SimplePropertiesStore(String filepath) {
66 66
 			mStoreFile = new File(filepath);
67 67
 			properties.clear();
68 68
 			
@@ -138,6 +138,17 @@ public void setProperty(String id, byte[] value) {
138 138
 			}
139 139
 		}
140 140
 
  141
+		// Store as hex bytes
  142
+		public void setPropertyHex(String id, byte[] value) {
  143
+			properties.setProperty(id, new String(Hex.encode(value)));
  144
+			
  145
+			try {
  146
+				this.store();
  147
+			} catch (Exception e) {
  148
+				OtrDebugLogger.log("store not saved",e);
  149
+			}
  150
+		}
  151
+
141 152
 		public void removeProperty(String id) {
142 153
 			properties.remove(id);
143 154
 
@@ -152,6 +163,17 @@ public void removeProperty(String id) {
152 163
 				null;
153 164
 		}
154 165
 
  166
+
  167
+		// Load from hex bytes
  168
+		public byte[] getPropertyHexBytes(String id) {
  169
+			String value = properties.getProperty(id);
  170
+			
  171
+			if (value != null)
  172
+				return Hex.decode(value);
  173
+			return 
  174
+				null;
  175
+		}
  176
+
155 177
 		public boolean getPropertyBoolean(String id, boolean defaultValue) {
156 178
 			try {
157 179
 				return Boolean.valueOf(properties.get(id).toString());
@@ -223,7 +245,7 @@ public void generateLocalKeyPair(String accountID) {
223 245
 		// Stash fingerprint for consistency.
224 246
 		try {
225 247
 			String fingerprintString = new OtrCryptoEngineImpl().getFingerprint(pubKey);
226  
-			this.store.setProperty(accountID + ".fingerprint",
  248
+			this.store.setPropertyHex(accountID + ".fingerprint",
227 249
 					Hex.decode(fingerprintString));
228 250
 		} catch (OtrCryptoException e) {
229 251
 			e.printStackTrace();
@@ -260,7 +282,7 @@ public String getRemoteFingerprint(SessionID sessionID) {
260 282
 	}
261 283
 
262 284
 	public String getRemoteFingerprint(String userId) {
263  
-		byte[] fingerprint = this.store.getPropertyBytes(userId + ".fingerprint");
  285
+		byte[] fingerprint = this.store.getPropertyHexBytes(userId + ".fingerprint");
264 286
 		if (fingerprint != null) {
265 287
 			// If we have a fingerprint stashed, assume it is correct.
266 288
 			return new String(Hex.encode(fingerprint, 0, fingerprint.length));
@@ -272,7 +294,7 @@ public String getRemoteFingerprint(String userId) {
272 294
 			// Store the fingerprint, for posterity.
273 295
 			String fingerprintString =
274 296
 					new OtrCryptoEngineImpl().getFingerprint(remotePublicKey);
275  
-			this.store.setProperty(userId + ".fingerprint", Hex.decode(fingerprintString));
  297
+			this.store.setPropertyHex(userId + ".fingerprint", Hex.decode(fingerprintString));
276 298
 			return fingerprintString;
277 299
 		} catch (OtrCryptoException e) {
278 300
 			e.printStackTrace();
@@ -393,7 +415,7 @@ public void savePublicKey(SessionID sessionID, PublicKey pubKey) {
393 415
 		// and is useful for transferring rosters to other apps.
394 416
 		try {
395 417
 			String fingerprintString = new OtrCryptoEngineImpl().getFingerprint(pubKey);
396  
-			this.store.setProperty(userId + ".fingerprint",
  418
+			this.store.setPropertyHex(userId + ".fingerprint",
397 419
 					Hex.decode(fingerprintString));
398 420
 		} catch (OtrCryptoException e) {
399 421
 			e.printStackTrace();

0 notes on commit a7aa7e2

Please sign in to comment.
Something went wrong with that request. Please try again.