Skip to content

Commit e26e637

Browse files
committed
🐛 Fix bug with resource Id for raw file
1 parent c3363cf commit e26e637

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

trustkit/src/main/java/com/datatheorem/android/trustkit/config/TrustKitConfigurationParser.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.Context;
55
import androidx.annotation.NonNull;
66
import android.text.TextUtils;
7+
78
import com.datatheorem.android.trustkit.utils.TrustKitLog;
89
import java.io.IOException;
910
import java.io.InputStream;
@@ -45,6 +46,7 @@ public static TrustKitConfiguration fromXmlPolicy(
4546
builderList.addAll(readDomainConfig(parser, null));
4647
} else if ("debug-overrides".equals(parser.getName())) {
4748
// The debug-overrides option is global and not tied to a specific domain
49+
4850
debugOverridesTag = readDebugOverrides(context, parser);
4951
}
5052
}
@@ -262,6 +264,8 @@ private static DebugOverridesTag readDebugOverrides(@NonNull Context context,
262264
// Parse the supplied certificate file
263265
String caPathFromUser = parser.getAttributeValue(null, "src").trim();
264266

267+
caPathFromUser = formatCertPathResourceWhenId(context, caPathFromUser);
268+
265269
// Parse the path to the certificate bundle for src=@raw - we ignore system or user
266270
// as the src
267271
if (!TextUtils.isEmpty(caPathFromUser) && !caPathFromUser.equals("user")
@@ -293,4 +297,14 @@ private static DebugOverridesTag readDebugOverrides(@NonNull Context context,
293297
}
294298
return result;
295299
}
300+
301+
private static String formatCertPathResourceWhenId(@NonNull Context context, String caPathFromUser) {
302+
if(TextUtils.isDigitsOnly(caPathFromUser.replace("@", ""))){
303+
caPathFromUser = "@" + context.getResources()
304+
.getResourceName(Integer.parseInt(caPathFromUser.replace("@", "")))
305+
.replace(context.getPackageName()+":", "");
306+
}
307+
308+
return caPathFromUser;
309+
}
296310
}

0 commit comments

Comments
 (0)