javafx - java.io.IOException: Short read of DER length -
i'm trying create java application can read x509 certificates informations , display them in tableview
.
but i've problem when i'm trying display informations code below
@fxml private void handlehdd() throws certificateexception, ioexception{ string userdir = system.getproperty("user.home"); file folder = new file(userdir +"\\desktop\\certificate_folder"); file[] certificates = folder.listfiles(); if (certificates!=null){ string columnheader[] = {"nom","version","n°série","algorithme de signature","emetteur","valide à partir de","valide jusqu'au","objet","clé publique"}; int sizecolumns = 9; (file file : certificates){ if(file.isfile()){ certificatefactory cf = certificatefactory.getinstance("x.509"); inputstream input = new fileinputstream(file); x509certificate cert = (x509certificate) cf.generatecertificate(input); input.close(); (int j = 0; j < sizecolumns; j++) { data.add(new certificatemodel(file.getname().replace(".der", ""),cert.getversion(),cert.getserialnumber().tostring(),cert.getsigalgname(),cert.getissuerdn().tostring(),cert.getnotbefore(),cert.getnotafter(),cert.getsubjectdn().tostring(),cert.getpublickey().tostring())); tablecolumn col = new tablecolumn(); col.settext(columnheader[j]); col.setminwidth(200); col.setcellvaluefactory(new propertyvaluefactory<certificatemodel, string>(columnheader[j])); table.getcolumns().addall(col); } table.setitems(data); } } } }
when try execute it, hav following exception: java.security.cert.certificateexception
this full exception stack:
exception in thread "javafx application thread" java.lang.runtimeexception: java.lang.reflect.invocationtargetexception @ javafx.fxml.fxmlloader$methodhandler.invoke(fxmlloader.java:1774) @ javafx.fxml.fxmlloader$controllermethodeventhandler.handle(fxmlloader.java:1657) @ com.sun.javafx.event.compositeeventhandler.dispatchbubblingevent(compositeeventhandler.java:86) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:238) @ com.sun.javafx.event.eventhandlermanager.dispatchbubblingevent(eventhandlermanager.java:191) @ com.sun.javafx.event.compositeeventdispatcher.dispatchbubblingevent(compositeeventdispatcher.java:59) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:58) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.basiceventdispatcher.dispatchevent(basiceventdispatcher.java:56) @ com.sun.javafx.event.eventdispatchchainimpl.dispatchevent(eventdispatchchainimpl.java:114) @ com.sun.javafx.event.eventutil.fireeventimpl(eventutil.java:74) @ com.sun.javafx.event.eventutil.fireevent(eventutil.java:54) @ javafx.event.event.fireevent(event.java:198) @ javafx.scene.scene$clickgenerator.postprocess(scene.java:3470) @ javafx.scene.scene$clickgenerator.access$8100(scene.java:3398) @ javafx.scene.scene$mousehandler.process(scene.java:3766) @ javafx.scene.scene$mousehandler.access$1500(scene.java:3485) @ javafx.scene.scene.impl_processmouseevent(scene.java:1762) @ javafx.scene.scene$scenepeerlistener.mouseevent(scene.java:2494) @ com.sun.javafx.tk.quantum.glassvieweventhandler$mouseeventnotification.run(glassvieweventhandler.java:381) @ com.sun.javafx.tk.quantum.glassvieweventhandler$mouseeventnotification.run(glassvieweventhandler.java:295) @ java.security.accesscontroller.doprivileged(native method) @ com.sun.javafx.tk.quantum.glassvieweventhandler.lambda$handlemouseevent$354(glassvieweventhandler.java:417) @ com.sun.javafx.tk.quantum.quantumtoolkit.runwithoutrenderlock(quantumtoolkit.java:389) @ com.sun.javafx.tk.quantum.glassvieweventhandler.handlemouseevent(glassvieweventhandler.java:416) @ com.sun.glass.ui.view.handlemouseevent(view.java:555) @ com.sun.glass.ui.view.notifymouse(view.java:937) @ com.sun.glass.ui.win.winapplication._runloop(native method) @ com.sun.glass.ui.win.winapplication.lambda$null$148(winapplication.java:191) @ java.lang.thread.run(thread.java:748) caused by: java.lang.reflect.invocationtargetexception @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:498) @ sun.reflect.misc.trampoline.invoke(methodutil.java:71) @ sun.reflect.generatedmethodaccessor1.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:498) @ sun.reflect.misc.methodutil.invoke(methodutil.java:275) @ javafx.fxml.fxmlloader$methodhandler.invoke(fxmlloader.java:1771) ... 33 more caused by: java.security.cert.certificateexception: unable initialize, java.io.ioexception: short read of der length @ sun.security.x509.x509certimpl.<init>(x509certimpl.java:198) @ sun.security.provider.x509factory.enginegeneratecertificate(x509factory.java:102) @ java.security.cert.certificatefactory.generatecertificate(certificatefactory.java:339) @ cm.camgovca.view.certificateoverviewcontroller.handlehdd(certificateoverviewcontroller.java:98) ... 43 more caused by: java.io.ioexception: short read of der length @ sun.security.util.derinputstream.getlength(derinputstream.java:582) @ sun.security.util.dervalue.<init>(dervalue.java:252) @ sun.security.util.derinputstream.getdervalue(derinputstream.java:451) @ sun.security.x509.x509certimpl.parse(x509certimpl.java:1784) @ sun.security.x509.x509certimpl.<init>(x509certimpl.java:195) ... 46 more
the line 98 of certificateoverview.java is
x509certificate cert = (x509certificate) cf.generatecertificate(input);
and certificate der encoded (.der)
if @ documentation of certificatefactory#generatecertificate
says:
throws: certificateexception - on parsing errors.
so, suggested in comments, certificate file not in expected format.
especially following line in documentation may of interest:
in case of certificate factory x.509 certificates, certificate provided in instream must der-encoded , may supplied in binary or printable (base64) encoding. if certificate provided in base64 encoding, must bounded @ beginning -----begin certificate-----, , must bounded @ end -----end certificate-----.
if post exception stack, detailed exception messages, can more.
Comments
Post a Comment