1 19 20 package org.netbeans.modules.subversion.config; 21 22 import java.io.File ; 23 import java.security.cert.CertificateEncodingException ; 24 import java.security.cert.X509Certificate ; 25 import org.netbeans.modules.subversion.config.KVFile.Key; 26 import org.openide.filesystems.FileUtil; 27 28 33 public class CertificateFile extends SVNCredentialFile { 34 35 private final static Key CERT = new Key(0, "ascii_cert"); private final static Key FAILURES = new Key(1, "failures"); private final static Key REALMSTRING = new Key(2, "svn:realmstring"); 39 private static final String NEWLINE = System.getProperty("line.separator"); 41 public CertificateFile(X509Certificate cert, String realmString, int failures, boolean temporarily) throws CertificateEncodingException { 42 super(getNBCertFile(realmString)); 43 setCert(cert); 44 setFailures(failures); 45 setRealmString(realmString); 46 if(temporarily) { 47 getFile().deleteOnExit(); 48 } 49 } 50 51 private void setCert(X509Certificate cert) throws CertificateEncodingException { 52 String encodedCert = new sun.misc.BASE64Encoder().encode(cert.getEncoded()); 53 encodedCert = encodedCert.replace(NEWLINE, ""); setValue(getCertKey(), encodedCert.getBytes()); 55 } 56 57 protected void setRealmString(String realm) { 58 setValue(getRealmstringKey(), realm); 59 } 60 61 protected String getRealmString() { 62 return getStringValue(getRealmstringKey()); 63 } 64 65 private void setFailures(int failures) { 66 setValue(getFailuresKey(), String.valueOf(failures)); 67 } 68 69 public static File getSystemCertFile(String realmString) { 70 File file = new File (SvnConfigFiles.getUserConfigPath() + "auth/svn.ssl.server/" + getFileName(realmString)); return FileUtil.normalizeFile(file); 72 } 73 74 public static File getNBCertFile(String realmString) { 75 File file = new File (SvnConfigFiles.getNBConfigPath() + "auth/svn.ssl.server/" + getFileName(realmString)); return FileUtil.normalizeFile(file); 77 } 78 79 private Key getCertKey() { 80 return getKey(CERT); 81 } 82 83 private Key getFailuresKey() { 84 return getKey(FAILURES); 85 } 86 87 private Key getRealmstringKey() { 88 return getKey(REALMSTRING); 89 } 90 91 } 92 | Popular Tags |