Skip to content

Commit 9a81ccc

Browse files
Merge pull request #623 from alexbakker/fixup-gauth-proto
Make the Google Authenticator Protobuf parser more complete
2 parents 2c6be39 + 6a5323b commit 9a81ccc

File tree

2 files changed

+52
-10
lines changed

2 files changed

+52
-10
lines changed

app/src/main/java/com/beemdevelopment/aegis/otp/GoogleAuthInfo.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,46 @@ public static Export parseExportUri(Uri uri) throws GoogleAuthInfoException {
216216
for (GoogleAuthProtos.MigrationPayload.OtpParameters params : payload.getOtpParametersList()) {
217217
OtpInfo otp;
218218
try {
219+
int digits;
220+
switch (params.getDigits()) {
221+
case DIGIT_COUNT_UNSPECIFIED:
222+
// intentional fallthrough
223+
case DIGIT_COUNT_SIX:
224+
digits = 6;
225+
break;
226+
case DIGIT_COUNT_EIGHT:
227+
digits = 8;
228+
break;
229+
default:
230+
throw new GoogleAuthInfoException(String.format("Unsupported digits: %d", params.getDigits().ordinal()));
231+
}
232+
233+
String algo;
234+
switch (params.getAlgorithm()) {
235+
case ALGORITHM_UNSPECIFIED:
236+
// intentional fallthrough
237+
case ALGORITHM_SHA1:
238+
algo = "SHA1";
239+
break;
240+
case ALGORITHM_SHA256:
241+
algo = "SHA256";
242+
break;
243+
case ALGORITHM_SHA512:
244+
algo = "SHA512";
245+
break;
246+
default:
247+
throw new GoogleAuthInfoException(String.format("Unsupported hash algorithm: %d", params.getAlgorithm().ordinal()));
248+
}
249+
219250
byte[] secret = params.getSecret().toByteArray();
220251
switch (params.getType()) {
221-
case OTP_HOTP:
222-
otp = new HotpInfo(secret, params.getCounter());
252+
case OTP_TYPE_UNSPECIFIED:
253+
// intentional fallthrough
254+
case OTP_TYPE_TOTP:
255+
otp = new TotpInfo(secret, algo, digits, 30);
223256
break;
224-
case OTP_TOTP:
225-
otp = new TotpInfo(secret);
257+
case OTP_TYPE_HOTP:
258+
otp = new HotpInfo(secret, algo, digits, params.getCounter());
226259
break;
227260
default:
228261
throw new GoogleAuthInfoException(String.format("Unsupported algorithm: %d", params.getType().ordinal()));

app/src/main/proto/google_auth.proto

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,31 @@ option java_outer_classname = "GoogleAuthProtos";
55

66
message MigrationPayload {
77
enum Algorithm {
8-
ALGO_INVALID = 0;
9-
ALGO_SHA1 = 1;
8+
ALGORITHM_UNSPECIFIED = 0;
9+
ALGORITHM_SHA1 = 1;
10+
ALGORITHM_SHA256 = 2;
11+
ALGORITHM_SHA512 = 3;
12+
ALGORITHM_MD5 = 4;
13+
}
14+
15+
enum DigitCount {
16+
DIGIT_COUNT_UNSPECIFIED = 0;
17+
DIGIT_COUNT_SIX = 1;
18+
DIGIT_COUNT_EIGHT = 2;
1019
}
1120

1221
enum OtpType {
13-
OTP_INVALID = 0;
14-
OTP_HOTP = 1;
15-
OTP_TOTP = 2;
22+
OTP_TYPE_UNSPECIFIED = 0;
23+
OTP_TYPE_HOTP = 1;
24+
OTP_TYPE_TOTP = 2;
1625
}
1726

1827
message OtpParameters {
1928
bytes secret = 1;
2029
string name = 2;
2130
string issuer = 3;
2231
Algorithm algorithm = 4;
23-
int32 digits = 5;
32+
DigitCount digits = 5;
2433
OtpType type = 6;
2534
int64 counter = 7;
2635
}

0 commit comments

Comments
 (0)