1 7 package org.jahia.security.license; 8 9 import java.io.BufferedInputStream ; 10 import java.io.IOException ; 11 import java.io.InputStream ; 12 import java.util.ArrayList ; 13 import java.util.Iterator ; 14 15 import org.jahia.utils.xml.XmlWriter; 16 17 23 public class LicensePackage { 24 private String formatVersion = null; 25 private String productName = null; 26 private String releaseVersion = null; 27 private ArrayList licenses = null; 28 29 35 public LicensePackage( 36 String formatVersion, 37 String productName, 38 String releaseVersion, 39 ArrayList licenses) { 40 this.formatVersion = formatVersion; 41 this.productName = productName; 42 this.releaseVersion = releaseVersion; 43 this.licenses = licenses; 44 } 45 46 49 public String getFormatVersion() { 50 return formatVersion; 51 } 52 53 56 public ArrayList getLicenses() { 57 return licenses; 58 } 59 60 63 public String getProductName() { 64 return productName; 65 } 66 67 70 public String getReleaseVersion() { 71 return releaseVersion; 72 } 73 74 public void toXML(XmlWriter xmlWriter) throws IOException { 75 xmlWriter.writeEntity("license-package"); 76 xmlWriter.writeAttribute("format", formatVersion); 77 xmlWriter.writeAttribute("product", productName); 78 xmlWriter.writeAttribute("release", releaseVersion); 79 Iterator licenseIter = licenses.iterator(); 80 while (licenseIter.hasNext()) { 81 License curLicense = (License) licenseIter.next(); 82 curLicense.toXML(xmlWriter); 83 } 84 xmlWriter.endEntity(); 85 } 86 87 public boolean verifyAllSignatures( 88 InputStream keystoreIn, 89 String keystorePassword) 90 throws IOException { 91 BufferedInputStream bufIn = new BufferedInputStream (keystoreIn); 92 bufIn.mark(100000); 93 Iterator licenseIter = licenses.iterator(); 94 while (licenseIter.hasNext()) { 95 License curLicense = (License) licenseIter.next(); 96 if (!curLicense.verifySignature(bufIn, keystorePassword)) { 97 return false; 98 } 99 bufIn.reset(); 100 } 101 return true; 102 } 103 104 public boolean updateAllSignatures( 105 InputStream keystoreIn, 106 String keystorePassword, 107 String privateKeyAlias, 108 String privateKeyPassword, 109 String certAlias) 110 throws IOException { 111 BufferedInputStream bufIn = new BufferedInputStream (keystoreIn); 112 bufIn.mark(100000); 113 Iterator licenseIter = licenses.iterator(); 114 while (licenseIter.hasNext()) { 115 License curLicense = (License) licenseIter.next(); 116 curLicense.updateSignature( 117 bufIn, 118 keystorePassword, 119 privateKeyAlias, 120 privateKeyPassword, 121 certAlias); 122 bufIn.reset(); 123 } 124 return true; 125 } 126 127 public License getLicense(String componentName) { 128 Iterator licenseIter = licenses.iterator(); 129 while (licenseIter.hasNext()) { 130 License curLicense = (License) licenseIter.next(); 131 if (curLicense.getComponentName().equals(componentName)) { 132 return curLicense; 133 } 134 } 135 return null; 136 } 137 138 } 139 | Popular Tags |