mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-23 07:19:13 +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");
|
||||
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);
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Add table
Reference in a new issue