luisgoncalves / xades4j

A Java library for XAdES signature services
GNU Lesser General Public License v3.0
111 stars 66 forks source link

BindingSourceRestriction uses some methods missing in Java implementation for Android #265

Closed RafaRioFal4699 closed 2 years ago

RafaRioFal4699 commented 2 years ago

I'm trying to make a signature method in order to accomplish some governmental requirements in my app. I followed the steps mentioned in this issue https://github.com/luisgoncalves/xades4j/issues/134 but at the moment of sign my XML, i found this exception:

FATAL EXCEPTION: main
    Process: com.example.xmlsigning, PID: 6946
    java.lang.NoSuchMethodError: No virtual method getAnnotatedSuperclass()Ljava/lang/reflect/AnnotatedType; in class Ljava/lang/Class; or its super classes (declaration of 'java.lang.Class' appears in /apex/com.android.art/javalib/core-oj.jar)
    at com.google.inject.spi.BindingSourceRestriction.getPermits(BindingSourceRestriction.java:343)
    at com.google.inject.spi.BindingSourceRestriction.access$500(BindingSourceRestriction.java:50)
    at com.google.inject.spi.BindingSourceRestriction$PermitMapConstruction.pushModule(BindingSourceRestriction.java:306)
    at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:396)
    at com.google.inject.spi.Elements.getElements(Elements.java:108)
    at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:160)
    at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107)
    at com.google.inject.Guice.createInjector(Guice.java:87)
    at com.google.inject.Guice.createInjector(Guice.java:69)
    at com.google.inject.Guice.createInjector(Guice.java:59)
    at xades4j.utils.XadesProfileCore.getInstance(XadesProfileCore.java:236)
    at xades4j.production.XadesSigningProfile.newSigner(XadesSigningProfile.java:110)
    at com.example.xmlsigning.MainActivity.SignXML(MainActivity.java:196)
    at com.example.xmlsigning.MainActivity$1.onClick(MainActivity.java:74)
    at android.view.View.performClick(View.java:7792)
    at android.view.View.performClickInternal(View.java:7769)
    at android.view.View.access$3800(View.java:910)
    at android.view.View$PerformClick.run(View.java:30218)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at android.app.ActivityThread.main(ActivityThread.java:8751)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

After a while, I found Android's implementation of Class Java class haven't got this specific method getAnnotatedSuperClass() and also it differs so much from Java's classic class Class: image Source: java.lang.Class reference from Android Developers (https://developer.android.com/reference/java/lang/Class)

So here it goes my question: Is this intended? Or haven't this API been desinged for Android? In any case, I will thank you If you could provide me some help.

Thank you in advance

Addition: I don't know if it's important, but I'm using the EPES Signer Profile

luisgoncalves commented 2 years ago

As you probably noticed in the stack trace, xades4j internally uses Guice for dependency injection. Guice relies on reflection and other stuff that doesn't seem to work well on Android. I've had the goal to remove the DI container altogether, but that's a big task, probably with breaking changes, so I never did it.

In any case, xades4j was not developed nor tested with Android in mind.

Also see the info on: https://github.com/luisgoncalves/xades4j/issues/154

RafaRioFal4699 commented 2 years ago

Okey, thanks for your answer. One last question, do you know or have you heard about another API with the same function but made for Android?

luisgoncalves commented 2 years ago

I don't know :/

There's a library endorsed by the EC: https://ec.europa.eu/digital-building-blocks/DSS/webapp-demo/doc/dss-documentation.html. It supports more than xades4j. Never tested it, though.

RafaRioFal4699 commented 2 years ago

Thanks, I will take a look