Perform case changes using Locale.ROOT where applicable

Fixes #777
This commit is contained in:
Alexander Bakker 2021-06-23 18:06:01 +02:00
parent 6585513120
commit 327b7ccbae
8 changed files with 21 additions and 12 deletions

View file

@ -2,6 +2,8 @@ package com.beemdevelopment.aegis.encoding;
import com.google.common.io.BaseEncoding; import com.google.common.io.BaseEncoding;
import java.util.Locale;
public class Base32 { public class Base32 {
private Base32() { private Base32() {
@ -9,7 +11,7 @@ public class Base32 {
public static byte[] decode(String s) throws EncodingException { public static byte[] decode(String s) throws EncodingException {
try { try {
return BaseEncoding.base32().decode(s.toUpperCase()); return BaseEncoding.base32().decode(s.toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw new EncodingException(e); throw new EncodingException(e);
} }

View file

@ -2,6 +2,8 @@ package com.beemdevelopment.aegis.encoding;
import com.google.common.io.BaseEncoding; import com.google.common.io.BaseEncoding;
import java.util.Locale;
public class Hex { public class Hex {
private Hex() { private Hex() {
@ -9,7 +11,7 @@ public class Hex {
public static byte[] decode(String s) throws EncodingException { public static byte[] decode(String s) throws EncodingException {
try { try {
return BaseEncoding.base16().decode(s.toUpperCase()); return BaseEncoding.base16().decode(s.toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw new EncodingException(e); throw new EncodingException(e);
} }

View file

@ -2,6 +2,8 @@ package com.beemdevelopment.aegis.icons;
import com.google.common.io.Files; import com.google.common.io.Files;
import java.util.Locale;
public enum IconType { public enum IconType {
INVALID, INVALID,
SVG, SVG,
@ -23,7 +25,7 @@ public enum IconType {
@SuppressWarnings("UnstableApiUsage") @SuppressWarnings("UnstableApiUsage")
public static IconType fromFilename(String filename) { public static IconType fromFilename(String filename) {
switch (Files.getFileExtension(filename).toLowerCase()) { switch (Files.getFileExtension(filename).toLowerCase(Locale.ROOT)) {
case "svg": case "svg":
return SVG; return SVG;
case "png": case "png":

View file

@ -38,6 +38,7 @@ import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException; import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec; import java.security.spec.KeySpec;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale;
import javax.crypto.BadPaddingException; import javax.crypto.BadPaddingException;
import javax.crypto.Cipher; import javax.crypto.Cipher;
@ -225,7 +226,7 @@ public class AndOtpImporter extends DatabaseImporter {
private static VaultEntry convertEntry(JSONObject obj) throws DatabaseImporterEntryException { private static VaultEntry convertEntry(JSONObject obj) throws DatabaseImporterEntryException {
try { try {
String type = obj.getString("type").toLowerCase(); String type = obj.getString("type").toLowerCase(Locale.ROOT);
String algo = obj.getString("algorithm"); String algo = obj.getString("algorithm");
int digits = obj.getInt("digits"); int digits = obj.getInt("digits");
byte[] secret = Base32.decode(obj.getString("secret")); byte[] secret = Base32.decode(obj.getString("secret"));

View file

@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale;
public class FreeOtpImporter extends DatabaseImporter { public class FreeOtpImporter extends DatabaseImporter {
private static final String _subPath = "shared_prefs/tokens.xml"; private static final String _subPath = "shared_prefs/tokens.xml";
@ -83,7 +84,7 @@ public class FreeOtpImporter extends DatabaseImporter {
private static VaultEntry convertEntry(JSONObject obj) throws DatabaseImporterEntryException { private static VaultEntry convertEntry(JSONObject obj) throws DatabaseImporterEntryException {
try { try {
String type = obj.getString("type").toLowerCase(); String type = obj.getString("type").toLowerCase(Locale.ROOT);
String algo = obj.getString("algo"); String algo = obj.getString("algo");
int digits = obj.getInt("digits"); int digits = obj.getInt("digits");
byte[] secret = toBytes(obj.getJSONArray("secret")); byte[] secret = toBytes(obj.getJSONArray("secret"));

View file

@ -8,6 +8,7 @@ import org.json.JSONObject;
import java.io.Serializable; import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale;
public abstract class OtpInfo implements Serializable { public abstract class OtpInfo implements Serializable {
public static final int DEFAULT_DIGITS = 6; public static final int DEFAULT_DIGITS = 6;
@ -32,7 +33,7 @@ public abstract class OtpInfo implements Serializable {
public abstract String getTypeId(); public abstract String getTypeId();
public String getType() { public String getType() {
return getTypeId().toUpperCase(); return getTypeId().toUpperCase(Locale.ROOT);
} }
public JSONObject toJson() { public JSONObject toJson() {
@ -76,7 +77,7 @@ public abstract class OtpInfo implements Serializable {
if (algorithm.startsWith("Hmac")) { if (algorithm.startsWith("Hmac")) {
algorithm = algorithm.substring(4); algorithm = algorithm.substring(4);
} }
algorithm = algorithm.toUpperCase(); algorithm = algorithm.toUpperCase(Locale.ROOT);
if (!isAlgorithmValid(algorithm)) { if (!isAlgorithmValid(algorithm)) {
throw new OtpInfoException(String.format("unsupported algorithm: %s", algorithm)); throw new OtpInfoException(String.format("unsupported algorithm: %s", algorithm));

View file

@ -5,6 +5,7 @@ import com.beemdevelopment.aegis.crypto.otp.TOTP;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Locale;
public class SteamInfo extends TotpInfo { public class SteamInfo extends TotpInfo {
public static final String ID = "steam"; public static final String ID = "steam";
@ -36,6 +37,6 @@ public class SteamInfo extends TotpInfo {
@Override @Override
public String getType() { public String getType() {
String id = getTypeId(); String id = getTypeId();
return id.substring(0, 1).toUpperCase() + id.substring(1); return id.substring(0, 1).toUpperCase(Locale.ROOT) + id.substring(1);
} }
} }

View file

@ -22,8 +22,6 @@ import android.widget.AutoCompleteTextView;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -73,6 +71,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@ -234,7 +233,7 @@ public class EditEntryActivity extends AegisActivity {
// show/hide period and counter fields on type change // show/hide period and counter fields on type change
_dropdownType.setOnItemClickListener((parent, view, position, id) -> { _dropdownType.setOnItemClickListener((parent, view, position, id) -> {
String type = _dropdownType.getText().toString().toLowerCase(); String type = _dropdownType.getText().toString().toLowerCase(Locale.ROOT);
switch (type) { switch (type) {
case SteamInfo.ID: case SteamInfo.ID:
_dropdownAlgo.setText(OtpInfo.DEFAULT_ALGORITHM, false); _dropdownAlgo.setText(OtpInfo.DEFAULT_ALGORITHM, false);
@ -646,7 +645,7 @@ public class EditEntryActivity extends AegisActivity {
OtpInfo info; OtpInfo info;
try { try {
switch (type.toLowerCase()) { switch (type.toLowerCase(Locale.ROOT)) {
case TotpInfo.ID: case TotpInfo.ID:
info = new TotpInfo(secret, algo, digits, parsePeriod()); info = new TotpInfo(secret, algo, digits, parsePeriod());
break; break;