2017-07-25 1 views
-2

x509証明書情報を読み取ってTableViewに表示できるJavaアプリケーションを作成しようとしています。 java.security.cert.CertificateExceptionjava.io.IOException:DERの長さを短く読み取る


しかし、私は次の例外を肝炎、私はそれを実行しようとすると、私は

@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; 

     for (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(); 
      for (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); 

      } 


      } 

     } 
    } 

以下のコードでこれらの情報を表示しようとしている問題をしました

これは完全な例外スタックです。

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException 
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774) 
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657) 
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86) 
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) 
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) 
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) 
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) 
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) 
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54) 
at javafx.event.Event.fireEvent(Event.java:198) 
at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3470) 
at javafx.scene.Scene$ClickGenerator.access$8100(Scene.java:3398) 
at javafx.scene.Scene$MouseHandler.process(Scene.java:3766) 
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485) 
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762) 
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494) 
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381) 
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295) 
at java.security.AccessController.doPrivileged(Native Method) 
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:417) 
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389) 
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416) 
at com.sun.glass.ui.View.handleMouseEvent(View.java:555) 
at com.sun.glass.ui.View.notifyMouse(View.java:937) 
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191) 
at java.lang.Thread.run(Thread.java:748) 
Caused by: java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71) 
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275) 
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771) 
    ... 33 more 
Caused by: java.security.cert.CertificateException: Unable to initialize, java.io.IOException: Short read of DER length 
    at sun.security.x509.X509CertImpl.<init>(X509CertImpl.java:198) 
    at sun.security.provider.X509Factory.engineGenerateCertificate(X509Factory.java:102) 
    at java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:339) 
    at cm.camgovca.view.CertificateOverviewController.handleHDD(CertificateOverviewController.java:98) 
    ... 43 more 
Caused by: java.io.IOException: Short read of DER length 
    at sun.security.util.DerInputStream.getLength(DerInputStream.java:582) 
    at sun.security.util.DerValue.<init>(DerValue.java:252) 
    at sun.security.util.DerInputStream.getDerValue(DerInputStream.java:451) 
    at sun.security.x509.X509CertImpl.parse(X509CertImpl.java:1784) 
    at sun.security.x509.X509CertImpl.<init>(X509CertImpl.java:195) 
    ... 46 more 

CertificateOverviの98行目ew.javaは

X509Certificate cert = (X509Certificate) cf.generateCertificate(input); 

ですそして、私の証明書があるDERエンコードあなたはそれが言うCertificateFactory#generateCertificateのドキュメントを見てみると(.DER)

+2

証明書ファイルの形式が正しくありません。 –

+1

答えに例外スタックを提供できますか? – Lino

答えて

1

例外:CertificateException - 構文解析エラーには。

コメントに示唆されているように、ほとんどの場合、証明書ファイルは期待された形式ではありません。

は、特にドキュメントの次の行は、関心のものであってもよい。

X.509証明書の証明書ファクトリの場合は、DER符号化されなければならず、中に供給することができるあるinStreamに設けられた証明書バイナリまたは印刷可能な(Base64)エンコーディング。証明書がBase64エンコーディングで提供されている場合は、最初は----- BEGIN CERTIFICATE -----で区切られていなければなりません。最後に----- END CERTIFICATE ----- 。

詳細な例外メッセージを含む例外スタックを投稿すると、おそらくもっと役立つことがあります。

関連する問題