diff --git a/app/src/main/java/me/impy/aegis/ScannerActivity.java b/app/src/main/java/me/impy/aegis/ScannerActivity.java index e15b6618..1aec10f9 100644 --- a/app/src/main/java/me/impy/aegis/ScannerActivity.java +++ b/app/src/main/java/me/impy/aegis/ScannerActivity.java @@ -60,7 +60,7 @@ public class ScannerActivity extends Activity implements ZXingScannerView.Result KeyInfo info = KeyInfo.FromURL("otpauth://totp/ACME%20Co:john@example.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ"); KeyProfile keyProfile = new KeyProfile(); keyProfile.KeyInfo = info; - keyProfile.Name = info.getLabel(); + keyProfile.Name = String.format("%s/%s", info.getIssuer(), info.getAccountName()); Intent resultIntent = new Intent(); resultIntent.putExtra("KeyProfile", keyProfile); @@ -85,7 +85,7 @@ public class ScannerActivity extends Activity implements ZXingScannerView.Result KeyInfo info = KeyInfo.FromURL(rawResult.getText()); KeyProfile keyProfile = new KeyProfile(); keyProfile.KeyInfo = info; - keyProfile.Name = info.getLabel(); + keyProfile.Name = String.format("%s/%s", info.getIssuer(), info.getAccountName()); Intent resultIntent = new Intent(); resultIntent.putExtra("KeyProfile", keyProfile); diff --git a/app/src/main/java/me/impy/aegis/crypto/KeyInfo.java b/app/src/main/java/me/impy/aegis/crypto/KeyInfo.java index b6a915de..1d46398d 100644 --- a/app/src/main/java/me/impy/aegis/crypto/KeyInfo.java +++ b/app/src/main/java/me/impy/aegis/crypto/KeyInfo.java @@ -8,23 +8,23 @@ import me.impy.aegis.encoding.Base32; public class KeyInfo implements Serializable { private String type; - private String label; private byte[] secret; + private String accountName; private String issuer; + private long counter; private String algorithm = "HmacSHA1"; private int digits = 6; - private long counter; private int period = 30; public String getType() { return type; } - public String getLabel() { - return label; - } public byte[] getSecret() { return secret; } + public String getAccountName() { + return accountName; + } public String getIssuer() { return issuer; } @@ -65,11 +65,28 @@ public class KeyInfo implements Serializable { info.secret = Base32.decode(secret); // provider info used to disambiguate accounts - // these parameters are not required but I don't want them to be null either - String issuer = url.getQueryParameter("issuer"); - String label = url.getPath(); - info.issuer = issuer != null ? issuer : ""; - info.label = label != null ? label.substring(1) : ""; + String path = url.getPath(); + String label = path != null ? path.substring(1) : ""; + + if (label.contains(":")) { + // a label can only contain one colon + // it's ok to fail if that's not the case + String[] strings = label.split(":"); + + if (strings.length == 2) { + info.issuer = strings[0]; + info.accountName = strings[1]; + } else { + // at this point, just dump the whole thing into the accountName + info.accountName = label; + } + } else { + // label only contains the account name + // grab the issuer's info from the 'issuer' parameter if it's present + String issuer = url.getQueryParameter("issuer"); + info.issuer = issuer != null ? issuer : ""; + info.accountName = label; + } // just use the defaults if these parameters aren't set String algorithm = url.getQueryParameter("algorithm");