1 11 package org.eclipse.update.internal.verifier; 12 13 import java.security.*; 14 import java.security.cert.*; 15 import java.text.DateFormat ; 16 import java.util.Date ; 17 18 import org.eclipse.osgi.internal.provisional.verifier.CertificateChain; 19 import org.eclipse.osgi.util.NLS; 20 import org.eclipse.update.core.*; 21 import org.eclipse.update.internal.core.Messages; 22 23 26 public class CertVerificationResult implements IVerificationResult { 27 28 29 private int resultCode; 30 private int verificationCode; 31 private Exception resultException; 32 33 private CertificateChain[] chains; 34 private CertificateChain foundChain; 36 private String signerInfo; 37 private String verifierInfo; 38 private ContentReference contentReference; 39 private IFeature feature; 40 private boolean featureVerification; 41 private boolean alreadySeen; 42 43 public CertVerificationResult() { 44 } 45 46 49 public int getResultCode() { 50 return resultCode; 51 } 52 53 56 public Exception getVerificationException() { 57 return resultException; 58 } 59 60 63 public void setResultCode(int newResultCode) { 64 resultCode = newResultCode; 65 } 66 67 70 public void setResultException(Exception newResultException) { 71 resultException = newResultException; 72 } 73 74 77 public int getVerificationCode() { 78 return verificationCode; 79 } 80 81 84 public void setVerificationCode(int verificationCode) { 85 this.verificationCode = verificationCode; 86 } 87 88 void setChains(CertificateChain[] chains) { 89 this.chains = chains; 90 } 91 92 public CertificateChain[] getchains() { 93 return chains; 94 } 95 96 99 private CertificateChain getFoundChain() { 100 return foundChain; 101 } 102 103 106 public void setFoundChain(CertificateChain foundChain) { 107 this.foundChain = foundChain; 108 } 109 110 111 114 private void initializeCertificates(){ 115 X509Certificate certRoot = null; 116 X509Certificate certIssuer = null; 117 CertificateChain trustedChain; 118 if (getFoundChain() == null) { 119 CertificateChain[] certs = getchains(); 120 if (certs.length == 0) 121 return; 122 trustedChain = certs[0]; 123 } else { 124 trustedChain = getFoundChain(); 125 } 126 certRoot = (X509Certificate) trustedChain.getRoot(); 127 certIssuer = (X509Certificate) trustedChain.getSigner(); 128 129 StringBuffer strb = new StringBuffer (); 130 strb.append(issuerString(certIssuer.getSubjectDN())); 131 strb.append("\r\n"); strb.append(NLS.bind(Messages.JarVerificationResult_ValidBetween, (new String [] { dateString(certIssuer.getNotBefore()), dateString(certIssuer.getNotAfter()) }))); 133 strb.append(checkValidity(certIssuer)); 134 signerInfo = strb.toString(); 135 if (certIssuer != null && !certIssuer.equals(certRoot)) { 136 strb = new StringBuffer (); 137 strb.append(issuerString(certIssuer.getIssuerDN())); 138 strb.append("\r\n"); strb.append(NLS.bind(Messages.JarVerificationResult_ValidBetween, (new String [] { dateString(certRoot.getNotBefore()), dateString(certRoot.getNotAfter()) }))); 140 strb.append(checkValidity(certRoot)); 141 verifierInfo = strb.toString(); 142 } 143 144 } 145 146 149 private String checkValidity(X509Certificate cert) { 150 151 try { 152 cert.checkValidity(); 153 } catch (CertificateExpiredException e) { 154 return ("\r\n" + Messages.JarVerificationResult_ExpiredCertificate); } catch (CertificateNotYetValidException e) { 156 return ("\r\n" + Messages.JarVerificationResult_CertificateNotYetValid); } 158 return ("\r\n" + Messages.JarVerificationResult_CertificateValid); } 160 161 164 private String issuerString(Principal principal) { 165 return principal.toString(); 182 } 183 184 187 private String dateString(Date date) { 188 return DateFormat.getDateInstance().format(date); 189 } 190 191 194 public String getSignerInfo() { 195 if (signerInfo==null) initializeCertificates(); 196 return signerInfo; 197 } 198 199 202 public String getVerifierInfo() { 203 if (signerInfo==null) initializeCertificates(); 204 return verifierInfo; 205 } 206 207 210 public ContentReference getContentReference() { 211 return contentReference; 212 } 213 214 217 public void setContentReference(ContentReference ref) { 218 this.contentReference = ref; 219 } 220 221 222 225 public IFeature getFeature() { 226 return feature; 227 } 228 229 232 public void setFeature(IFeature feature) { 233 this.feature = feature; 234 } 235 236 239 public String getText() { 240 return null; 241 } 242 243 244 247 public boolean isFeatureVerification() { 248 return featureVerification; 249 } 250 251 254 public void isFeatureVerification(boolean featureVerification) { 255 this.featureVerification = featureVerification; 256 } 257 258 261 public boolean alreadySeen() { 262 return alreadySeen; 263 } 264 265 268 public boolean alreadySeen(boolean seen) { 269 return this.alreadySeen = seen; 270 } 271 272 } 273 | Popular Tags |