Changeset 163

Show
Ignore:
Timestamp:
02/28/08 09:13:55 (9 months ago)
Author:
Stuart Thiel
Message:

-Fixed access to mac certfile... which isn't access to the certfile, but access to the mac specific KeyStore? ('login')

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • setCert/trunk/src/setCert.java

    r161 r163  
    11import java.io.File; 
     2import java.io.FileInputStream; 
    23import java.io.FileNotFoundException; 
     4import java.io.FileOutputStream; 
    35import java.io.IOException; 
    46import java.security.KeyStore; 
    57import java.security.KeyStoreException; 
    68import java.security.NoSuchAlgorithmException; 
     9import java.security.NoSuchProviderException; 
    710import java.security.cert.Certificate; 
    811import java.security.cert.CertificateException; 
     
    1922 */ 
    2023public class setCert { 
    21  
     24         
    2225        /** 
    2326         * We assume that trusted.certs lives here: 
     
    3033         */ 
    3134        public static void main(String[] args) { 
    32                  
    33                 String certFile = (System.getProperty("user.home") + "\\Application Data\\Sun\\Java\\Deployment\\security\\trusted.certs").replace('\\', File.separatorChar); 
    34                  
    35             KeyStore ks = null; 
     35                if(System.getProperty("os.name").contains("Mac OS")) { 
     36                        processMac(); 
     37                } else { 
     38                        processPC(); 
     39                } 
     40        } 
     41 
     42        private static void processPC() { 
     43                FileOutputStream fos = null; 
     44                FileInputStream fis = null; 
    3645                try { 
    37                         ks = KeyStore.getInstance(KeyStore.getDefaultType()); 
    38                 } catch (KeyStoreException e1) { 
    39                         // TODO Auto-generated catch block 
    40                         e1.printStackTrace(); 
    41                 } 
    42  
    43             // empty user password 
    44             char[] password = {}; 
    45  
    46  
    47             java.io.FileInputStream fis = null; 
    48             java.io.FileOutputStream fos = null; 
    49             try { 
    50                 fis = new java.io.FileInputStream(certFile); 
    51                  
    52                 try { 
    53                                 ks.load(fis, password); 
    54                                 fis.close(); 
    55                                 Certificate cert = getCert(); 
    56                                 ks.setCertificateEntry("MACert", cert); 
    57                                 System.out.println(ks.size()); 
    58                                  
    59                                 fos = new java.io.FileOutputStream(certFile); 
    60                                 ks.store(fos, password); 
    61                                 fos.flush(); 
    62                                 fos.close(); 
    63                         }  finally { 
    64                                 if (fis != null) { 
    65                     fis.close(); 
     46                        String certFile = (System.getProperty("user.home") +  
     47                                        "\\Application Data\\Sun\\Java\\Deployment\\security\\trusted.certs") 
     48                                        .replace('\\', File.separatorChar); 
     49                        KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); 
     50                        char[] password = {}; 
     51                        fis = new FileInputStream(certFile); 
     52                        ks.load(fis, password); 
     53                        fis.close(); 
     54                        ks.setCertificateEntry("MACert", getCert()); 
     55                        fos = new FileOutputStream(certFile); 
     56                        ks.store(fos, password); 
     57                } catch (Exception e) { 
     58                        e.printStackTrace(); 
     59                        System.exit(1); 
     60                } finally { 
     61                        if(fos != null) { 
     62                                try { 
     63                                        fos.flush(); 
     64                                        fos.close(); 
     65                                } catch (IOException e) { 
    6666                                } 
    6767                        } 
    68                 } catch (Exception e) { 
    69                         e.printStackTrace(); 
    7068                } 
    7169                 
     70        } 
     71 
     72        private static void processMac() { 
     73                try { 
     74                        KeyStore ks = KeyStore.getInstance("KeychainStore", "Apple"); 
     75                        char[] password = {}; 
     76                        ks.load(null, password); 
     77                        ks.setCertificateEntry("MACert", getCert()); 
     78                        ks.store(null, password); 
     79                } catch (Exception e) { 
     80                        // TODO Auto-generated catch block 
     81                        e.printStackTrace(); 
     82                        System.exit(1); 
     83                }  
    7284        } 
    7385