See: Description
Package | Description |
---|---|
com.guardtime.ksi |
KSI API interface
|
com.guardtime.ksi.blocksigner |
Classes and interfaces to create multiple signatures with one signing request
|
com.guardtime.ksi.concurrency |
Classes for concurrency handling
|
com.guardtime.ksi.exceptions |
KSI exception classes
|
com.guardtime.ksi.hashing |
Classes to create and represent data hashes
|
com.guardtime.ksi.pdu |
PDU (Protocol Data Unit) interfaces
|
com.guardtime.ksi.pdu.exceptions |
PDU exception classes
|
com.guardtime.ksi.pdu.v2 |
PDU v2 implementation
|
com.guardtime.ksi.publication |
Interfaces to decode and encode publications files
|
com.guardtime.ksi.publication.adapter |
Adapters for publications file client
|
com.guardtime.ksi.publication.inmemory |
Implementation to decode and encode in-memory publications files
|
com.guardtime.ksi.service |
Classes and interfaces to sign and extend, advanced version
|
com.guardtime.ksi.service.client |
Classes and interfaces to sign and extend, basic version
|
com.guardtime.ksi.service.client.http |
Common classes for KSI Apache HTTP client and KSI Simple HTTP client
|
com.guardtime.ksi.service.client.http.apache |
Apache HTTP client for KSI
|
com.guardtime.ksi.service.ha |
High Availability KSI service, combines other services to achieve redundancy
|
com.guardtime.ksi.service.http.simple |
Simple HTTP client for KSI
|
com.guardtime.ksi.service.tcp |
KSI TCP client
|
com.guardtime.ksi.tlv |
Classes and interfaces to decode and encode TLV elements
|
com.guardtime.ksi.tree |
Classes and interfaces to build a hash tree
|
com.guardtime.ksi.trust |
Trust provider classes
|
com.guardtime.ksi.unisignature |
Interfaces to decode and encode KSI signatures
|
com.guardtime.ksi.unisignature.inmemory |
Classes to decode and encode in-memory KSI signatures
|
com.guardtime.ksi.unisignature.verifier |
Classes and interfaces to verify KSI signatures
|
com.guardtime.ksi.unisignature.verifier.policies |
KSI signature verification policies
|
com.guardtime.ksi.unisignature.verifier.rules |
KSI signature verification rules
|
com.guardtime.ksi.util |
Internal utility classes
|
This is the Java SDK for KSI service. It provides functionality to create, extend and verify KSI signatures.
The following is a list of compile dependencies for this project. These dependencies are required to compile and run the application:
Optional libraries:
All libraries are bundled with source, including optional libraries. If these are not required, the SDK user must exclude them.
KSI Java SDK uses SLF4J for logging, SLF4J is a facade for different logging frameworks(e.g. java.util.logging, logback, log4j). By default simple implementation is included with API that logs to standard output.
SLF4J allows developers to send KSI Java SDK logs to the logging framework used in their application. To enable it, logging framework support must be downloaded from SLF4J homepage and added to classpath.
Java SDK API is provided by com.guardtime.ksi.KSI interface
To obtain a instance of com.guardtime.ksi.KSI the com.guardtime.ksi.KSIBuilder class can be used. com.guardtime.ksi.KSIBuilder class checks that at least the following parameters are present:
SimpleHttpClient simpleHttpClient = ...
KSIBuilder builder = new KSIBuilder().
setKsiProtocolSignerClient(simpleHttpClient).
setKsiProtocolExtenderClient(simpleHttpClient).
setKsiProtocolPublicationsFileClient(simpleHttpClient).
setPublicationsFileTrustedCertSelector(new X509CertificateSubjectRdnSelector("E=test@test.com"));
KSI ksi = builder.build();
// use KSI object
// release resources
ksi.close();
The following clients are currently implemented:
SimpleHttpClient simpleHttpClient = ...
KeyStore trustStore = loadKeyStore();
KSIBuilder builder = new KSIBuilder().
setKsiProtocolSignerClient(simpleHttpClient).
setKsiProtocolExtenderClient(simpleHttpClient).
setKsiProtocolPublicationsFileClient(simpleHttpClient).
setPublicationsFilePkiTrustStore(trustStore).
setPublicationsFileTrustedCertSelector(new X509CertificateSubjectRdnSelector("E=test@test.com, CN=My Test CN"));
KSI ksi = builder.build();
Method setDefaultSigningHashAlgorithm(HashAlgorithm algorithm) from com.guardtime.ksi.KSIBuilder class
is used to specify the default signing hash algorithm.
For all the following operations, KSI object can be used. There are also separate interfaces created. The following examples cover
usage of KSI interface and also operation specific ones.
// KSI
KSI ksi = ...
// read signature from disk
KSISignature signature = ksi.read(new File("signature.ksig"));
// read using input stream
KSISignature signature2 = ksi.read(new FileInputStream("signature.ksig"));
// read using byte array
byte[] bytes = getSignatureBytes();
KSISignature signature3 = ksi.read(bytes);
// using Reader interface
Reader reader = new SignatureReader();
KSISignature signature = reader.read(new File("signature.ksig"));
// KSI
KSI ksi = ...
// synchronous signing
KSISignature sig = ksi.sign(new File("file.txt"));
// asynchronous signing
Future<KSISignature> future = ksi.asyncSign(new File("asyncFile.txt"));
KSISignature signature2 = future.getResult();
// using Signer interface
CredentialsAwareHttpSettings settings = new CredentialsAwareHttpSettings("signing-service-url", KSIServiceCredentials);
SimpleHttpSigningClient signingClient = new SimpleHttpSigningClient(settings);
Signer signer = new SignerBuilder().setSigningService(new KSISigningClientServiceAdapter(signingClient)).build();
KSISignature signature = signer.sign(new File("file.txt"));
// KSI
KSI ksi = ...
// read signature from disk
KSISignature signature = ksi.read(new File("signature.ksig"));
// synchronous extending
KSISignature extendedSignature = ksi.extend(signature);
// asynchronous extending
Future<KSISignature> future = ksi.asyncExtend(signature);
KSISignature extendedSignature2 = future.getResult();
// using Extender interface
CredentialsAwareHttpSettings settings = new CredentialsAwareHttpSettings("extender-service-url", KSIServiceCredentials);
SimpleHttpExtenderClient extenderClient = new SimpleHttpExtenderClient(settings);
Extender extender = new ExtenderBuilder().setExtendingService(new KSIExtendingClientServiceAdapter(extenderClient))
.setPublicationsHandler(publicationsHandler).build();
KSISignature extendedSignature = extender.extend(signature);
KSI ksi = ...
SimpleHttpClient simpleHttpClient = ...
PublicationsFile publicationsFile = ...
KSISignature signature = ksi.read(new File("signature.ksig"));
VerificationContextBuilder builder = new VerificationContextBuilder().
setSignature(signature).
setExtenderClient(simpleHttpClient).
setPublicationsFile(publicationsFile);
VerificationContext context = builder.createVerificationContext();
The following code can be used to verify the signature:
// KSI
KSI ksi = ...
VerificationContext context = ...
Policy policy = new KeyBasedVerificationPolicy();
VerificationResult result = ksi.verify(context, policy);
// using Verifier interface
Verifier verifier = new SignatureVerifier();
VerificationResult result = verifier.verify(signature, ContextAwarePolicyAdapter.createKeyPolicy(publicationsHandler));
KSISigningClient signingClient = ...
signingClient.registerAggregatorConfigurationListener(new ConfigurationListener<AggregatorConfiguration> {
public void updated(AggregatorConfiguration aggregatorConfiguration) {
// do something with the updated configuration
}
public void updateFailed(Throwable t) {
// do something with the exception that made the configuration update fail
}
});
signingClient.getAggregationConfiguration(); // Invokes a configuration request. Does not block until it responds. Gives back a Future which can be used as an alternative way in addition to listeners to access the result.
KSIServiceCredentials credentials = new KSIServiceCredentials("user", "key");
HttpClientSettings settings = new HttpClientSettings("signing_url", "extending_url",
"publications_file_url", credentials);
HTTPConnectionParameters parameters = new HTTPConnectionParameters();
parameters.setProxyUrl(new URL("proxy_url"));
parameters.setProxyUser("proxy_username");
parameters.setProxyPassword("proxy_password");
settings.setParameters(parameters);
SimpleHttpClient httpClient = new SimpleHttpClient(settings);
NB! When the proxy server uses username/password for authentication then the HTTPConnectionParameters class must be used to configure proxy.
More redundant connection to gateway can be achieved using HAService. HAService combines multiple other services, sends requests to all of them in parallel and gives back the first successful one.
To configure HAService, initialize the services it uses and build a HA services with those instances:
KSISigningClient signingClient1 = ... KSISigningClient signingClient2 = ... KSISigningClient signingClient3 = ... KSIExtenderClient extenderClient1 = ... KSIExtenderClient extenderClient2 = ... KSIExtenderClient extenderClient3 = ... SigningHAService signingHaService = new SigningHAService.Builder() .addClients(Arrays.asList(signingClient1, signingClient2, signingClient3)) .build(); ExtendingHaService extendingHaService = new ExtendingHAService.Builder() .addClients(Arrays.asList(extenderClient1, extenderClient2, extenderClient3)) .build(); KSI ksi = new KSIBuilder() .setSigningService(signingHaService) .setExtendingService(extendingHaService) // set everything else .build();
This product relies on software developed by the Legion of the Bouncy Castle (www.bouncycastle.org).
This product includes software developed by The Apache Software Foundation (www.apache.org/).
Copyright © 2024 Guardtime. All rights reserved.