Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto/x509: Incorrect user trust store directory is used for Android #71258

Open
chenxiaolong opened this issue Jan 14, 2025 · 3 comments
Open
Labels
BugReport Issues describing a possible bug in the Go implementation. mobile Android, iOS, and x/mobile OS-Android

Comments

@chenxiaolong
Copy link

In #58922, the following user trust store directory was added to crypto/x509 for Android:

"/data/misc/keychain/certs-added", // User trusted CA folder

However, Android hasn't used this path since 2014 and instead uses /data/misc/user/<user ID>/cacerts-added, where <user ID> is the Android user ID (not Linux/POSIX UID).

I'm not sure if there's a good public API to get the user ID. UserHandle.myUserId() (on the Java side) is not public. However, the Android user ID is implemented as getuid() / 100000. As far as I can tell, this has never changed since Android got multi-user support ~14 years ago. Maybe it's good enough to rely on this implementation detail?

Some links:


Side note: For system CA certs, golang currently only loads /system/etc/security/cacerts, but ever since Android 14, the system CA certs became updatable and /apex/com.android.conscrypt/cacerts should have priority: https://android.googlesource.com/platform/frameworks/base/+/refs/tags/android-15.0.0_r12/core/java/android/security/net/config/SystemCertificateSource.java#48

@gabyhelp
Copy link

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Jan 14, 2025
@chenxiaolong
Copy link
Author

Hmm, there's another potential issue. The system and apex directories contain PEM-encoded certificates, but Android writes DER-encoded certificates to the user directory (regardless of what the original format was during import).

@ianlancetaylor
Copy link
Member

CC @golang/security @golang/android

@ianlancetaylor ianlancetaylor added OS-Android mobile Android, iOS, and x/mobile labels Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. mobile Android, iOS, and x/mobile OS-Android
Projects
None yet
Development

No branches or pull requests

3 participants