brazdil / dexter

1 stars 1 forks source link

JarSigner crashes on Android #5

Closed brazdil closed 11 years ago

brazdil commented 11 years ago

I hope this can be solved somehow :-/

07-22 11:45:14.307  15902-15931/uk.ac.cam.db538.dexter.android E/AndroidRuntime: FATAL EXCEPTION: Thread-820
        java.lang.InternalError: Could not obtain X500Principal access
        at sun.security.x509.X500Name.<clinit>(X500Name.java:1403)
        at com.rx201.jarsigner.KeyGenerator.generateSigningKey(KeyGenerator.java:65)
        at com.rx201.jarsigner.KeyGenerator.getCertificateChain(KeyGenerator.java:36)
        at uk.ac.cam.db538.dexter.apk.Apk.produceAPK(Apk.java:108)
        at uk.ac.cam.db538.dexter.android.InstrumentActivity$2.run(InstrumentActivity.java:173)
        at java.lang.Thread.run(Thread.java:856)
        Caused by: java.security.PrivilegedActionException: java.lang.NoSuchMethodException: <init> [class sun.security.x509.X500Name]
        at java.security.AccessController.doPrivileged(AccessController.java:64)
        at sun.security.x509.X500Name.<clinit>(X500Name.java:1399)
        ... 5 more
        Caused by: java.lang.NoSuchMethodException: <init> [class sun.security.x509.X500Name]
        at java.lang.Class.getConstructorOrMethod(Class.java:460)
        at java.lang.Class.getDeclaredConstructor(Class.java:588)
        at sun.security.x509.X500Name$1.run(X500Name.java:1391)
        at sun.security.x509.X500Name$1.run(X500Name.java:1)
        at java.security.AccessController.doPrivileged(AccessController.java:60)
        ... 6 more
xurubin commented 11 years ago

OK I have prepared a new jar that contains the missing class. However the compiler emits an error because I'm defining a core class javax/security/auth/x500/X500PrivateCredential.class:

Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.

This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.

However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.

If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.

If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.

If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.
xurubin commented 11 years ago

OK I figured it out. java.util.jar.Manifest.java is behaving differently (Manifest-Version cf Signature-Version) on Android. ( See also the latest five commits with funny messages https://android.googlesource.com/platform/libcore/+log/master/luni/src/main/java/java/util/jar/Manifest.java). I see that you included the latest platform/libcore source in libdexter presumably for dex compiler. I think that version will work. Is it possible to refer to use this Manifest class in our code somehow?

brazdil commented 11 years ago

Wow, that must have been terrible debugging... Libcore is included but only the 'dex' subproject is being compiled and included in Dexter. So if I understand this correctly, the class in the framework is wrong and you want to replace with the newer version from AOSP? In that case, it should suffice to compile it from the libcore repo and include in the APK. We can try that tomorrow.