mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-20 13:59:14 +00:00
Properly parse issuer and account name
This commit is contained in:
parent
58d60e2760
commit
59402d30ff
2 changed files with 29 additions and 12 deletions
|
@ -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");
|
KeyInfo info = KeyInfo.FromURL("otpauth://totp/ACME%20Co:john@example.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ");
|
||||||
KeyProfile keyProfile = new KeyProfile();
|
KeyProfile keyProfile = new KeyProfile();
|
||||||
keyProfile.KeyInfo = info;
|
keyProfile.KeyInfo = info;
|
||||||
keyProfile.Name = info.getLabel();
|
keyProfile.Name = String.format("%s/%s", info.getIssuer(), info.getAccountName());
|
||||||
|
|
||||||
Intent resultIntent = new Intent();
|
Intent resultIntent = new Intent();
|
||||||
resultIntent.putExtra("KeyProfile", keyProfile);
|
resultIntent.putExtra("KeyProfile", keyProfile);
|
||||||
|
@ -85,7 +85,7 @@ public class ScannerActivity extends Activity implements ZXingScannerView.Result
|
||||||
KeyInfo info = KeyInfo.FromURL(rawResult.getText());
|
KeyInfo info = KeyInfo.FromURL(rawResult.getText());
|
||||||
KeyProfile keyProfile = new KeyProfile();
|
KeyProfile keyProfile = new KeyProfile();
|
||||||
keyProfile.KeyInfo = info;
|
keyProfile.KeyInfo = info;
|
||||||
keyProfile.Name = info.getLabel();
|
keyProfile.Name = String.format("%s/%s", info.getIssuer(), info.getAccountName());
|
||||||
|
|
||||||
Intent resultIntent = new Intent();
|
Intent resultIntent = new Intent();
|
||||||
resultIntent.putExtra("KeyProfile", keyProfile);
|
resultIntent.putExtra("KeyProfile", keyProfile);
|
||||||
|
|
|
@ -8,23 +8,23 @@ import me.impy.aegis.encoding.Base32;
|
||||||
|
|
||||||
public class KeyInfo implements Serializable {
|
public class KeyInfo implements Serializable {
|
||||||
private String type;
|
private String type;
|
||||||
private String label;
|
|
||||||
private byte[] secret;
|
private byte[] secret;
|
||||||
|
private String accountName;
|
||||||
private String issuer;
|
private String issuer;
|
||||||
|
private long counter;
|
||||||
private String algorithm = "HmacSHA1";
|
private String algorithm = "HmacSHA1";
|
||||||
private int digits = 6;
|
private int digits = 6;
|
||||||
private long counter;
|
|
||||||
private int period = 30;
|
private int period = 30;
|
||||||
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
public String getLabel() {
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
public byte[] getSecret() {
|
public byte[] getSecret() {
|
||||||
return secret;
|
return secret;
|
||||||
}
|
}
|
||||||
|
public String getAccountName() {
|
||||||
|
return accountName;
|
||||||
|
}
|
||||||
public String getIssuer() {
|
public String getIssuer() {
|
||||||
return issuer;
|
return issuer;
|
||||||
}
|
}
|
||||||
|
@ -65,11 +65,28 @@ public class KeyInfo implements Serializable {
|
||||||
info.secret = Base32.decode(secret);
|
info.secret = Base32.decode(secret);
|
||||||
|
|
||||||
// provider info used to disambiguate accounts
|
// provider info used to disambiguate accounts
|
||||||
// these parameters are not required but I don't want them to be null either
|
String path = url.getPath();
|
||||||
String issuer = url.getQueryParameter("issuer");
|
String label = path != null ? path.substring(1) : "";
|
||||||
String label = url.getPath();
|
|
||||||
info.issuer = issuer != null ? issuer : "";
|
if (label.contains(":")) {
|
||||||
info.label = label != null ? label.substring(1) : "";
|
// 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
|
// just use the defaults if these parameters aren't set
|
||||||
String algorithm = url.getQueryParameter("algorithm");
|
String algorithm = url.getQueryParameter("algorithm");
|
||||||
|
|
Loading…
Add table
Reference in a new issue