Changeset 163
- Timestamp:
- 02/28/08 09:13:55 (9 months ago)
- Files:
-
- setCert/trunk/src/setCert.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
setCert/trunk/src/setCert.java
r161 r163 1 1 import java.io.File; 2 import java.io.FileInputStream; 2 3 import java.io.FileNotFoundException; 4 import java.io.FileOutputStream; 3 5 import java.io.IOException; 4 6 import java.security.KeyStore; 5 7 import java.security.KeyStoreException; 6 8 import java.security.NoSuchAlgorithmException; 9 import java.security.NoSuchProviderException; 7 10 import java.security.cert.Certificate; 8 11 import java.security.cert.CertificateException; … … 19 22 */ 20 23 public class setCert { 21 24 22 25 /** 23 26 * We assume that trusted.certs lives here: … … 30 33 */ 31 34 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; 36 45 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) { 66 66 } 67 67 } 68 } catch (Exception e) {69 e.printStackTrace();70 68 } 71 69 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 } 72 84 } 73 85
