Skip to content

Commit

Permalink
Merge pull request #61 from jobot0/fix_bad_behavior_raw_cert
Browse files Browse the repository at this point in the history
🐛 Fix bug with resource Id for raw file
  • Loading branch information
nabla-c0d3 authored Dec 6, 2019
2 parents c3363cf + e26e637 commit 8efb743
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;
import androidx.annotation.NonNull;
import android.text.TextUtils;

import com.datatheorem.android.trustkit.utils.TrustKitLog;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -45,6 +46,7 @@ public static TrustKitConfiguration fromXmlPolicy(
builderList.addAll(readDomainConfig(parser, null));
} else if ("debug-overrides".equals(parser.getName())) {
// The debug-overrides option is global and not tied to a specific domain

debugOverridesTag = readDebugOverrides(context, parser);
}
}
Expand Down Expand Up @@ -262,6 +264,8 @@ private static DebugOverridesTag readDebugOverrides(@NonNull Context context,
// Parse the supplied certificate file
String caPathFromUser = parser.getAttributeValue(null, "src").trim();

caPathFromUser = formatCertPathResourceWhenId(context, caPathFromUser);

// Parse the path to the certificate bundle for src=@raw - we ignore system or user
// as the src
if (!TextUtils.isEmpty(caPathFromUser) && !caPathFromUser.equals("user")
Expand Down Expand Up @@ -293,4 +297,14 @@ private static DebugOverridesTag readDebugOverrides(@NonNull Context context,
}
return result;
}

private static String formatCertPathResourceWhenId(@NonNull Context context, String caPathFromUser) {
if(TextUtils.isDigitsOnly(caPathFromUser.replace("@", ""))){
caPathFromUser = "@" + context.getResources()
.getResourceName(Integer.parseInt(caPathFromUser.replace("@", "")))
.replace(context.getPackageName()+":", "");
}

return caPathFromUser;
}
}

0 comments on commit 8efb743

Please sign in to comment.