SeCuris client

Usage securis-cient API

The applications that need to manage licenses should use the class `net.curisit.securis.LicenseManager `

There are 3 actions that the application can execute in the API:

Currently, there is no server communication (License server API is not implemented yet), so, only local actions are available.


Config file

The SeCuris client library needs a config file that has to be located in classpath, in "`/securis-client.properties`"

There are 3 parameters in the config file:

``` public.key.file = /Path/to/public/key/file/securis.pub app.code = AP01 customer.code = XX ```

All parameters are mandatory

Validate license file

Validate the current license is as simple as call to `validateLicense()`method passing it the license file location.

For instance:

``` File file = new File("pathtolicense.lic_file"); try { LicenseManager.getInstance().validateLicense(file); log.info("License file {} is valid", file.getAbsolutePath()); } catch (SeCurisException e) { log.info("License file {} is NOT valid", file.getAbsolutePath()); }

```

If license file is not valid an exception is thrown. The application can store the license file in whatever place in filesystem.

Request a new license

THIS ACTION IS NOT YET IMPLEMENTED

The method to get a new license doesn't need parameters, the request data is generated by the method using the host hardware info and other paramters as application and customer code.

``` try { LicenseBean lic = LicenseManager.getInstance().requestLicense(); log.info("License {} got from server sucessfully", lic); LicenseManager.getInstance().save(lic, new File("pathtolicense.lic_file")); } catch (SeCurisException e) { log.info("Error getting License: " + e); }

```

Renew an existing license

THIS ACTION IS NOT YET IMPLEMENTED

All licenses have an expiration date, the application should ask for a new license to server before it expires.

``` try { File licenseFile = new File("pathtolicense.lic_file"); LicenseBean lic = LicenseManager.getInstance().load(licenseFile); long MONTHLIMITMS = 30 * 24 * 3600 * 1000; if (licBean.getExpirationDate().before(new Date(new Date().getTime() + MONTHLIMITMS))) { LicenseBean newLic = LicenseManager.getInstance().renew(licenseFile); LicenseManager.getInstance().save(newLic, licenseFile); } } catch (SeCurisException e) { log.info("Error renewing License: " + e); }

```

The application will check if the expiration date is close (in the example we've used a month as date limit) and then it will ask for a new license. The `renew()` method will validate the current license, if it is not valid an exception will be launch.

Usage securis-cient CLI

The securis-client tool also provides a CLI (Command Line Interface) to be used by an administrator outside of application, we can use the same actons that from API and some additional one.

NOTE: The file `securis.sh`used in following examples are not included, but can be created easily, for instance:

``` #!/bin/bash export CLASSPATH=libs/*.jar java -cp $CLASSPATH -jar libs/securis-client-*.jar $@ ```

Creation of a request file

For a manual activation, a request file should be sent to SeCuris administrator, to create a request file we can execute:

``` $ ./securis.sh --gen_request --rfile=/tmp/curisapp.req

```

Validate license file

``` $ ./securis.sh --validate=/path/to/license/file/curisapp.lic

```

Request a new license to server

``` $ ./securis.sh --create=/path/to/license/file/curisapp.lic --server="http://server:0000/securis/api/create"

```

Renew an existing license

``` $ securis.sh --renew=/path/to/license/file/curisapp.lic --server="http://server:0000/securis/api/create"

```

Request and License files

The request and license file are json files and the content can be read easily

Example of request file:

``` { "customerCode" : "BP01", "appCode" : "CD01", "macAddresses" : [ "E0-F8-47-43-E1-D2", "70-CD-60-F2-A5-4B" ], "osName" : "Mac OS X", "arch" : "x86_64" }

```

Example of license file:

``` { "licenseCode" : "LIC-9812987123-12837129873", "licenseType" : "L01", "expirationDate" : 1393266018149, "appCode" : "CD01", "arch" : "x86_64", "osName" : "Mac OS X", "customerCode" : "BP01", "macAddresses" : [ "E0-F8-47-43-E1-D2", "70-CD-60-F2-A5-4B" ], "metadata" : { "maxInstances" : 12, "maxUsers" : 23 }, "signature" : "bZTzW5JYTIQOclwObnBXu250IB5o2xHhIbWyHaIf57H+0Xr7Gqtphj0/nT/SSfr6yMjPVaZ/BW7d\r\nFX/I7bA8xMfIXMpPG9qcqna2iRxwKw/j8rROydHs4vn9c1VYGpDG0NowJewdJJyKTSrlMvUDM/9L\r\n2VPVQl11UwgHm+AkLD42Qj/UassBrpdnoU4PuAn8Odc8hXnnj2jiUUeQFrK0DHMAaewOw+lKY1yfB\r\nCF/5y/z+6iyBTvrGw2kBh521Yu7siL9NK7KtE7R3t9h8+XIozgXdunMRxZ1+jLwKJKK+l7InY7UA\r\nsDgXSJofR/S2/hwKkXiAiSfAUt04rnMHTrRtIQ==\r\n" }

```