Révision bf9c3717
Ajouté par Remy Menard il y a environ 11 ans
SigMa/SigMa-Test/src/main/java/fr/unicaen/iota/sigma/test/controler/Controler.java | ||
---|---|---|
/*
|
||
* This program is a part of the IoTa Project.
|
||
* This program is a part of the IoTa project.
|
||
*
|
||
* Copyright © 2013 Université de Caen Basse-Normandie, GREYC
|
||
*
|
||
... | ... | |
|
||
import fr.unicaen.iota.eta.capture.ETaCaptureClient;
|
||
import fr.unicaen.iota.mu.Constants;
|
||
import fr.unicaen.iota.mu.Utils;
|
||
import fr.unicaen.iota.sigma.SigMaFunctions;
|
||
import fr.unicaen.iota.sigma.client.SigMaClient;
|
||
import fr.unicaen.iota.sigma.xsd.VerifyResponse;
|
||
... | ... | |
import javax.xml.datatype.DatatypeConfigurationException;
|
||
import javax.xml.datatype.DatatypeFactory;
|
||
import javax.xml.datatype.XMLGregorianCalendar;
|
||
import javax.xml.namespace.QName;
|
||
import javax.xml.parsers.ParserConfigurationException;
|
||
import org.fosstrak.epcis.captureclient.CaptureClientException;
|
||
import org.fosstrak.epcis.model.ActionType;
|
||
... | ... | |
import org.w3c.dom.Element;
|
||
import org.xml.sax.SAXException;
|
||
|
||
/**
|
||
*
|
||
* @author doud
|
||
*/
|
||
public class Controler {
|
||
|
||
private String sigmaKeyStore = "/srv/sigma-cert.p12";
|
||
private String sigmaKsPassword = "store_pw";
|
||
private String captureUrl = "https://localhost:8443/eta/capture";
|
||
private String sigmaAddress = "https://localhost:8443/sigma";
|
||
|
||
private String TLSKeyStore = "/srv/keystore.jks";
|
||
private String TLSKsPassword = "store_pw";
|
||
private String TLSTrustStore = "/srv/truststore.jks";
|
||
private String TLSTsPassword = "trust_pw";
|
||
|
||
public Controler() {
|
||
private String captureUrl;
|
||
private String sigmaUrl;
|
||
private String tlsKeystore;
|
||
private String tlsKsPassword;
|
||
private String tlsTruststore;
|
||
private String tlsTsPassword;
|
||
private String signKeystore;
|
||
private String signKsPassword;
|
||
|
||
public Controler(String captureUrl, String sigmaUrl, String tlsKeystore, String tlsKsPassword,
|
||
String tlsTruststore, String tlsTsPassword, String signKeystore, String signKsPassword) {
|
||
this.captureUrl = captureUrl;
|
||
this.sigmaUrl = sigmaUrl;
|
||
this.tlsKeystore = tlsKeystore;
|
||
this.tlsKsPassword = tlsKsPassword;
|
||
this.tlsTruststore = tlsTruststore;
|
||
this.tlsTsPassword = tlsTsPassword;
|
||
this.signKeystore = signKeystore;
|
||
this.signKsPassword = signKsPassword;
|
||
}
|
||
|
||
public ObjectEventType sign(String epcCode, String bizStepCode, String dispositionCode, String readPointCode, String bizLocationCode) {
|
||
... | ... | |
EPCISBodyType epcisBody = new EPCISBodyType();
|
||
EventListType eventList = new EventListType();
|
||
try {
|
||
SigMaFunctions sigMAFunctions = new SigMaFunctions(sigmaKeyStore, sigmaKsPassword);
|
||
SigMaFunctions sigMAFunctions = new SigMaFunctions(signKeystore, signKsPassword);
|
||
sigMAFunctions.sign(objEvent);
|
||
} catch (Exception e) {
|
||
System.err.println("Exception during signing");
|
||
... | ... | |
epcisDoc.setSchemaVersion(new BigDecimal("1.0"));
|
||
epcisDoc.setCreationDate(now);
|
||
|
||
ETaCaptureClient client = new ETaCaptureClient(captureUrl, TLSKeyStore, TLSKsPassword, TLSTrustStore, TLSTsPassword);
|
||
ETaCaptureClient client = new ETaCaptureClient(captureUrl, tlsKeystore, tlsKsPassword, tlsTruststore, tlsTsPassword);
|
||
int httpResponseCode;
|
||
try {
|
||
httpResponseCode = client.capture(epcisDoc);
|
||
... | ... | |
}
|
||
|
||
public VerifyResponse verify(ObjectEventType event){
|
||
SigMaClient sigMaClient = new SigMaClient(sigmaAddress,TLSKeyStore, TLSKsPassword, TLSTrustStore, TLSTsPassword);
|
||
SigMaClient sigMaClient = new SigMaClient(sigmaUrl,tlsKeystore, tlsKsPassword, tlsTruststore, tlsTsPassword);
|
||
return sigMaClient.verify(event).getVerifyResponse();
|
||
}
|
||
|
||
... | ... | |
return null;
|
||
}
|
||
for (Object object : extensions) {
|
||
// we really don’t know what’s in an extension
|
||
JAXBElement elem = (JAXBElement) object;
|
||
if ((Constants.EXTENSION_SIGNATURE.equals(elem.getName().getLocalPart()))) {
|
||
signature = elem.getValue().toString();
|
||
Element elem = (Element) object;
|
||
if (Constants.URN_IOTA.equals(elem.getNamespaceURI())
|
||
&& Constants.EXTENSION_SIGNATURE.equals(elem.getLocalName())) {
|
||
signature = elem.getTextContent();
|
||
break;
|
||
}
|
||
// Element elem = (Element) object;
|
||
// if (("signature".equals(elem.getLocalName()))) {
|
||
// signature = elem.getTextContent().toString();
|
||
// }
|
||
}
|
||
return signature;
|
||
}
|
||
... | ... | |
}
|
||
|
||
private void insertWrongSignature(EPCISEventType event, String signature) throws IOException, ParserConfigurationException, SAXException {
|
||
JAXBElement<String> elem = new JAXBElement<String>(new QName(Constants.URN_IOTA, Constants.EXTENSION_SIGNATURE), String.class, signature);
|
||
if (event instanceof ObjectEventType) {
|
||
((ObjectEventType) event).getAny().clear();
|
||
((ObjectEventType) event).getAny().add(elem);
|
||
} else if (event instanceof AggregationEventType) {
|
||
((AggregationEventType) event).getAny().clear();
|
||
((AggregationEventType) event).getAny().add(elem);
|
||
} else if (event instanceof QuantityEventType) {
|
||
((QuantityEventType) event).getAny().clear();
|
||
((QuantityEventType) event).getAny().add(elem);
|
||
} else if (event instanceof TransactionEventType) {
|
||
((TransactionEventType) event).getAny().clear();
|
||
((TransactionEventType) event).getAny().add(elem);
|
||
}
|
||
Utils.insertExtension(event, Constants.URN_IOTA, Constants.EXTENSION_SIGNATURE, signature);
|
||
}
|
||
|
||
}
|
Formats disponibles : Unified diff
Version 1.99
- a few bugs fixed!
- new testing application to capture events
- new options to the command line to configure the public/private keys
for TLS and for signature
- new method more accurate than "traceEPC": the events are sorted by
EPCIS
- New options added to the command line
- user can be identified by alias, if the DN of his certificate is
incompatible with the LDAP directory
- new shell script to configure the LDAP directory (same
functionnalities as IoTa-Installer)
- installs and configures LaMBDa
- finer certificate mangagement
- EpcILoN correctly subscribe with TLS to ETa
- new figure for LaMBDa
- shows data flows between PHI and YPSilon
- sets DS and DSeTa in different schemas