private void doImport ( ) { if ( checkExistingCertificate ( ) ) { // prevent overwriting return ; } final JFileChooser fc = new JFileChooser ( System . getProperty ( "user.home" ) ) ; fc . setFileSelectionMode ( JFileChooser . FILES_ONLY ) ; fc . setMultiSelectionEnabled ( false ) ; fc . setSelectedFile ( new File ( CONFIGURATION_FILENAME ) ) ; fc . setFileFilter ( new FileFilter ( ) { @ Override public String getDescription ( ) { // config.xml or *.pem files return Constant . messages . getString ( "dynssl.filter.file" ) ; } @ Override public boolean accept ( File f ) { String lcFileName = f . getName ( ) . toLowerCase ( Locale . ROOT ) ; return lcFileName . endsWith ( CONFIGURATION_FILENAME ) || lcFileName . endsWith ( "pem" ) || f . isDirectory ( ) ; } } ) ; final int result = fc . showOpenDialog ( this ) ; final File f = fc . getSelectedFile ( ) ; if ( result == JFileChooser . APPROVE_OPTION && f . exists ( ) ) { if ( logger . isInfoEnabled ( ) ) { logger . info ( "Loading Root CA certificate from " + f ) ; } KeyStore ks = null ; if ( f . getName ( ) . toLowerCase ( ) . endsWith ( "pem" ) ) { ks = convertPemFileToKeyStore ( f . toPath ( ) ) ; } else { try { final ZapXmlConfiguration conf = new ZapXmlConfiguration ( f ) ; final String rootcastr = conf . getString ( DynSSLParam . PARAM_ROOT_CA ) ; if ( rootcastr == null || rootcastr . isEmpty ( ) ) { JOptionPane . showMessageDialog ( this , Constant . messages . getString ( "dynssl.message.nocertinconf" ) , Constant . messages . getString ( "dynssl.message.nocertinconf.title" ) , JOptionPane . ERROR_MESSAGE ) ; return ; } ks = SslCertificateUtils . string2Keystore ( rootcastr ) ; } catch ( final Exception e ) { logger . error ( "Error importing Root CA cert from config file:" , e ) ; JOptionPane . showMessageDialog ( this , Constant . messages . getString ( "dynssl.message1.filecouldntloaded" ) , Constant . messages . getString ( "dynssl.message1.title" ) , JOptionPane . ERROR_MESSAGE ) ; return ; } } if ( ks != null ) { setRootca ( ks ) ; } } }
Import Root CA certificate from other ZAP configuration files .