pom.xml
.. .. @@ -13,6 +13,17 @@ 13 13 <target>1.7</target> 14 14 </configuration> 15 15 </plugin> 16 + <plugin>17 + <artifactId>maven-assembly-plugin</artifactId>18 + <version>2.4</version>19 + <configuration>20 + <archive>21 + <manifest>22 + <mainClass>net.curisit.securis.License</mainClass>23 + </manifest>24 + </archive>25 + </configuration>26 + </plugin>16 27 </plugins> 17 28 </build> 18 29 <dependencies> .. .. @@ -46,5 +57,11 @@ 46 57 <artifactId>log4j-core</artifactId> 47 58 <version>2.0-rc1</version> 48 59 </dependency> 60 + <dependency>61 + <groupId>org.apache.maven.plugins</groupId>62 + <artifactId>maven-assembly-plugin</artifactId>63 + <version>2.4</version>64 + <type>maven-plugin</type>65 + </dependency>49 66 </dependencies> 50 67 </project> src/main/java/net/curisit/securis/HWInfo.java
.. .. @@ -79,7 +79,7 @@ 79 79 for (byte[] mac : macs) { 80 80 macAddresses.add(printMacAddress(mac)); 81 81 } 82 - log.info("MAC Addresses: {}", macAddresses);82 + log.debug("MAC Addresses: {}", macAddresses);83 83 return macAddresses; 84 84 85 85 } catch (UnknownHostException e) { src/main/java/net/curisit/securis/License.java
.. .. @@ -2,7 +2,6 @@ 2 2 3 3 import java.io.File; 4 4 import java.net.URISyntaxException; 5 -import java.util.Date;6 5 7 6 import net.curisit.securis.utils.Params; 8 7 .. .. @@ -16,21 +15,45 @@ 16 15 import org.apache.logging.log4j.LogManager; 17 16 import org.apache.logging.log4j.Logger; 18 17 18 +/**19 + * Main class when SeCuris client is used from command line.20 + *21 + * <pre>22 + * usage: securis-client [-c] [-g] [-h] [-l <lic_file>] [-r <lic_file>] [-s23 + * <url_license_server>] [-t]24 + * -c,--create Request a license file from server.25 + * --rfile and --server parameters are26 + * mandatory.27 + * -g,--gen_request Generate request file. If --rfile28 + * parameter is missing then It is29 + * generated in current directory.30 + * -h,--help Show help.31 + * -l,--validate <lic_file> Validate lic file.32 + * -r,--renew <lic_file> Synchronize/renew the current license33 + * file. --server parameter is mandatory.34 + * -s,--server <url_license_server> License server url.35 + * -t,--test_lc Test if License Server (LC) is36 + * available. --server parameter is37 + * mandatory.38 + * </pre>39 + *40 + * @author roberto <roberto.sanchez@curisit.net>41 + *42 + */19 43 public class License { 20 44 21 - static {22 - // BasicConfigurator.configure(new ConsoleAppender());23 - // PropertyConfigurator.configure("/log4j.xml");24 - // LogManager.getRootLogger().25 - }26 -27 - // private static final Logger log = LoggerFactory.getLogger(License.class);28 45 private static final Logger log = LogManager.getLogger(License.class); 29 46 47 + /**48 + * Aplication entry point when it used as CLI49 + *50 + * @param args51 + * @throws URISyntaxException52 + */30 53 public static void main(String[] args) throws URISyntaxException { 31 54 // Configuration conf = XMLConfigurationFactory.getInstance().getConfiguration("config", License.class.getResource("/log4j.xml").toURI()); 32 55 33 - log.info("Tool init {}", new Date());56 + log.debug("SeCuris client tool init ");34 57 35 58 checkConfigFile(); 36 59 CommandLine cmd = getCommandLine(args); .. .. @@ -61,8 +84,43 @@ 61 84 System.exit(0); 62 85 } 63 86 87 + if (cmd.hasOption('c')) {88 + String reqFilename = cmd.getOptionValue("rfile");89 + checkMandatoryParameter(reqFilename, "rfile");90 + String server = cmd.getOptionValue("server");91 + checkMandatoryParameter(server, "server");92 +93 + log.warn("This command is not yet implemented");94 + System.exit(0);95 + }96 +97 + if (cmd.hasOption('t')) {98 + String server = cmd.getOptionValue("server");99 + checkMandatoryParameter(server, "server");100 +101 + log.warn("This command is not yet implemented");102 + System.exit(0);103 + }104 +105 + if (cmd.hasOption('r')) {106 + String licFilename = cmd.getOptionValue("sync");107 + checkMandatoryParameter(licFilename, "sync");108 + String server = cmd.getOptionValue("server");109 + checkMandatoryParameter(server, "server");110 +111 + log.warn("This command is not yet implemented");112 + System.exit(0);113 + }114 +64 115 } catch (SeCurisException e) { 65 116 log.error("The command generated an error: {}", e.toString()); 117 + }118 + }119 +120 + private static void checkMandatoryParameter(String value, String param) {121 + if (value == null) {122 + log.error("Parameter {} is mandatory. Use --help to get information about parameters", param);123 + System.exit(-5);66 124 } 67 125 } 68 126 .. .. @@ -120,7 +178,7 @@ 120 178 options.addOption("g", "gen_request", false, "Generate request file. If --rfile parameter is missing then It is generated in current directory."); 121 179 options.addOption("c", "create", false, "Request a license file from server. --rfile and --server parameters are mandatory."); 122 180 options.addOption("t", "test_lc", false, "Test if License Server (LC) is available. --server parameter is mandatory."); 123 - options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("sync").withDescription("Synchronize/renew the current license file. --server parameter is mandatory.").hasArg(true).create('y'));181 + options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("renew").withDescription("Synchronize/renew the current license file. --server parameter is mandatory.").hasArg(true).create('r'));124 182 125 183 return options; 126 184 } src/main/java/net/curisit/securis/LicenseManager.java
.. .. @@ -38,9 +38,7 @@ 38 38 * </p> 39 39 * 40 40 * @param licFile 41 - * @param appCode42 - * @param customerCode43 - * @return41 + * @return The license bean stored in file44 42 * @throws SeCurisException 45 43 */ 46 44 public LicenseBean validateLicense(File licFile) throws SeCurisException { .. .. @@ -58,7 +56,7 @@ 58 56 } 59 57 60 58 /** 61 - * Creates a new request file with current hardware in the File passed as paramter59 + * Creates a new request file with current hardware in the File passed as parameter62 60 * 63 61 * @param outputRequestFile 64 62 * File where the request data will be saved .. .. @@ -83,6 +81,8 @@ 83 81 */ 84 82 public LicenseBean sync(File licenseFile) throws SeCurisException { 85 83 LicenseBean lic = validateLicense(licenseFile); 84 + if (true)85 + throw new SeCurisException("Action not implemented yet");86 86 // TODO: Send the current LicenseBean to server to check if a new one is prepared. 87 87 return lic; 88 88 } src/main/java/net/curisit/securis/ReqGenerator.java
.. .. @@ -71,7 +71,7 @@ 71 71 byte[] json; 72 72 try { 73 73 json = JsonUtils.toJSON(req, true).getBytes("utf-8"); 74 - Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE);74 + Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);75 75 } catch (UnsupportedEncodingException e) { 76 76 log.error("Error creating json doc from request: " + req, e); 77 77 throw new SeCurisException("Error creating json doc from request: " + req, e); .. .. @@ -80,13 +80,15 @@ 80 80 throw new SeCurisException("Error creating request file: " + file, e); 81 81 } 82 82 83 - log.info("License saved in {}", file);83 + log.debug("License saved in {}", file);84 84 85 85 } 86 86 87 87 private String getCrcLogo() { 88 88 String logResource = "images/logo_customer.png"; 89 89 InputStream is = getClass().getClassLoader().getResourceAsStream(logResource); 90 + if (is == null)91 + return null;90 92 try { 91 93 String shaLogo = LicUtils.sha256(IOUtils.toByteArray(is), LOGO_SECRET); 92 94 return shaLogo; src/main/java/net/curisit/securis/SignatureHelper.java
.. .. @@ -14,13 +14,8 @@ 14 14 import java.security.spec.InvalidKeySpecException; 15 15 import java.security.spec.PKCS8EncodedKeySpec; 16 16 import java.security.spec.X509EncodedKeySpec; 17 -import java.util.Date;18 -import java.util.HashMap;19 -import java.util.Map;20 17 21 18 import net.curisit.securis.beans.LicenseBean; 22 -import net.curisit.securis.beans.RequestBean;23 -import net.curisit.securis.beans.SignedLicenseBean;24 19 import net.curisit.securis.utils.JsonUtils; 25 20 import net.curisit.securis.utils.Params; 26 21 .. .. @@ -124,24 +119,6 @@ 124 119 125 120 KeyPair kp = new KeyPair(publicKey, privateKey); 126 121 return kp; 127 - }128 -129 - public static void main(String[] args) throws SeCurisException {130 - // org.apache.log4j.Logger.getRootLogger().addAppender(new Appender);131 - // DOMConfigurator.configure("/Users/cproberto/Documents/wsCurisIT/SeCurisClient/src/main/resources/log4j.xml");132 - RequestBean req = ReqGenerator.getInstance().createRequest("CI", "Roberto");133 -134 - LicenseGenerator lg = LicenseGenerator.getInstance();135 - Map<String, Object> metadata = new HashMap<>();136 - metadata.put("maxUsers", 14);137 - metadata.put("timeThreshold", 5000);138 - metadata.put("123", 5000);139 - metadata.put("Basdads", 5000);140 - metadata.put("aasdads", 5000);141 - metadata.put("maxInstances", 50);142 - LicenseBean lic = lg.generateLicense(req, metadata, new Date(new Date().getTime() + 24 * 3600 * 1000 * 10), "L01", "LIC-TEST-001");143 - System.out.println(JsonUtils.toJSON(lic, true));144 - System.out.println(JsonUtils.toJSON(new SignedLicenseBean(lic), true));145 122 } 146 123 147 124 static { src/main/java/net/curisit/securis/beans/RequestBean.java
.. .. @@ -2,9 +2,9 @@ 2 2 3 3 import java.util.List; 4 4 5 -import org.codehaus.jackson.annotate.JsonAutoDetect;5 +import org.codehaus.jackson.map.annotate.JsonSerialize;6 6 7 -@JsonAutoDetect7 +@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)8 8 public class RequestBean { 9 9 private String customerCode; 10 10 private String crcLogo; src/main/java/net/curisit/securis/utils/Params.java
.. .. @@ -44,7 +44,7 @@ 44 44 */ 45 45 public static void loadParameters(String resource) throws IOException { 46 46 47 - log.info("Loading params from " + resource);47 + log.debug("Loading params from " + resource);48 48 InputStream fileis = Params.class.getResourceAsStream(resource); 49 49 50 50 params = new Properties(); src/main/resources/images/logo_customer.pngsimilarity index 100%rename from src/main/resources/images/logo_customer.pngrename to src/main/resources/images/logo_customer2.pngBinary files differ
src/main/resources/securis-client.properties
.. .. @@ -1,3 +1,3 @@ 1 -public.key.file = /Users/cproberto/Documents/wsPython/doky/tests/mykey.pub2 -app.code = CurisIntegrity3 -customer.code = ROB1 +public.key.file = __ADD_PUBLIC_KEY_FILE__2 +app.code = __ADD_APP_CODE__3 +customer.code = __ADD_APP_CODE__src/patch/java/net/curisit/securis/LicenseGenerator.java
.. .. @@ -80,7 +80,7 @@ 80 80 byte[] json; 81 81 try { 82 82 json = JsonUtils.toJSON(signedLic, true).getBytes("utf-8"); 83 - Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE);83 + Files.write(Paths.get(file.toURI()), json, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);84 84 } catch (UnsupportedEncodingException e) { 85 85 log.error("Error creating json doc from license: " + license, e); 86 86 throw new SeCurisException("Error creating json doc from license: " + license, e);