Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OpenADRHTTPClient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.avob.openadr</groupId>
<artifactId>OpenADR</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>0.1.0-bitinity</version>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kommentar aus File Changes

</parent>
<dependencies>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion OpenADRHTTPClient20a/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.avob.openadr</groupId>
<artifactId>OpenADR</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>0.1.0-bitinity</version>
</parent>
<dependencies>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion OpenADRHTTPClient20b/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.avob.openadr</groupId>
<artifactId>OpenADR</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>0.1.0-bitinity</version>
</parent>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,24 @@ public class OadrHttpClient20b {

private boolean validateXmlPayload = false;

public OadrHttpClient20b(OadrHttpClient client) throws JAXBException, OadrSecurityException {
this(client, null, null, null, null);
private boolean acceptUnsignedResponse = false;


public OadrHttpClient20b(OadrHttpClient client, Boolean acceptUnsignedResponse) throws JAXBException, OadrSecurityException {
this(client, null, null, null, null, acceptUnsignedResponse);
}

public OadrHttpClient20b(OadrHttpClient client, String privateKeyPath, String clientCertificatePath,
Long replayProtectAcceptedDelaySecond) throws JAXBException, OadrSecurityException {
this(client, privateKeyPath, clientCertificatePath, replayProtectAcceptedDelaySecond, null);
Long replayProtectAcceptedDelaySecond, Boolean acceptUnsignedResponse) throws JAXBException, OadrSecurityException {
this(client, privateKeyPath, clientCertificatePath, replayProtectAcceptedDelaySecond, null, acceptUnsignedResponse);
}

public OadrHttpClient20b(OadrHttpClient client, String privateKeyPath, String clientCertificatePath,
Long replayProtectAcceptedDelaySecond, Boolean validateXmlPayload)
Long replayProtectAcceptedDelaySecond, Boolean validateXmlPayload, Boolean acceptUnsignedResponse)
throws JAXBException, OadrSecurityException {
this.jaxbContext = Oadr20bJAXBContext.getInstance("src/test/resources/oadr20b_schema/");
this.client = client;
this.acceptUnsignedResponse = acceptUnsignedResponse;

if (privateKeyPath != null && clientCertificatePath != null) {
this.privateKey = OadrPKISecurity.parsePrivateKey(privateKeyPath);
Expand Down Expand Up @@ -125,21 +129,24 @@ public <O, I extends JAXBElement<?>> O post(String host, String path, HttpClient

StringEntity stringEntity = new StringEntity(marshal);
post.setEntity(stringEntity);
post.setHeader("content-type", "application/xml");
HttpResponse response = client.execute(post, host, Oadr20bUrlPath.OADR_BASE_PATH + path, context);

// if request did not result in 200 http code throw exception
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
EntityUtils.consumeQuietly(response.getEntity());
throw new Oadr20bHttpLayerException(response.getStatusLine().getStatusCode(),
String.valueOf(response.getStatusLine().getStatusCode()));
}
}

// if request was a success, validate xml signature if required and then
// unmarshall response
if (isXmlSignatureEnabled()) {
// if request was a success, validate xml signature if required and then
// unmarshall response
if (isXmlSignatureEnabled()) {
String entity = EntityUtils.toString(response.getEntity(), "UTF-8");
OadrPayload unmarshal = jaxbContext.unmarshal(entity, OadrPayload.class, validateXmlPayload);
this.validate(entity, unmarshal);
if(unmarshal.getSignature() == null && !acceptUnsignedResponse) {
this.validate(entity, unmarshal);
}
EntityUtils.consumeQuietly(response.getEntity());
if (Object.class.equals(responseKlass)) {
Object signedObjectFromOadrPayload = Oadr20bFactory.getSignedObjectFromOadrPayload(unmarshal);
Expand All @@ -166,6 +173,9 @@ private String sign(Object object) throws Oadr20bXMLSignatureException {

private void validate(String raw, OadrPayload payload) throws Oadr20bXMLSignatureValidationException {
long nowDate = System.currentTimeMillis();
if(payload.getSignature() == null) {
throw new Oadr20bXMLSignatureValidationException("Signature is not provided and unsigned repsonse is not accepted.");
}
OadrXMLSignatureHandler.validate(raw, payload, nowDate, replayProtectAcceptedDelaySecond * 1000L);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void givenValidUnsignedPost_DoNotRaiseException() throws ClientProtocolEx
HttpResponse response = this.createHttpResponse(scOk, marshal);
when(oadrHttpClient.execute(Matchers.<HttpPost>anyObject(), any(), any(), any())).thenReturn(response);

OadrHttpClient20b client = new OadrHttpClient20b(oadrHttpClient);
OadrHttpClient20b client = new OadrHttpClient20b(oadrHttpClient, false);

OadrDistributeEventType mockDistributeEvent = this.createOadrDistributeEvent();
OadrResponseType post = client.post(Oadr20bFactory.createOadrDistributeEvent(mockDistributeEvent),
Expand All @@ -157,7 +157,7 @@ public void givenNotSignedResponse_RaiseException() throws ClientProtocolExcepti
when(oadrHttpClient.execute(Matchers.<HttpPost>anyObject(), any(), any(), any())).thenReturn(response);

String certPath = "src/test/resources/cert/test";
OadrHttpClient20b client = new OadrHttpClient20b(oadrHttpClient, certPath + ".key", certPath + ".crt", 1200L);
OadrHttpClient20b client = new OadrHttpClient20b(oadrHttpClient, certPath + ".key", certPath + ".crt", 1200L, false);

OadrDistributeEventType mockDistributeEvent = this.createOadrDistributeEvent();
boolean exception = false;
Expand All @@ -181,7 +181,7 @@ public void givenHttpError_RaiseException() throws ClientProtocolException, IOEx
HttpResponse response = this.createHttpResponse(HttpStatus.SC_FORBIDDEN, "");
when(oadrHttpClient.execute(Matchers.<HttpPost>anyObject(), any(), any(), any())).thenReturn(response);

OadrHttpClient20b client = new OadrHttpClient20b(oadrHttpClient);
OadrHttpClient20b client = new OadrHttpClient20b(oadrHttpClient, false);

OadrDistributeEventType mockDistributeEvent = this.createOadrDistributeEvent();

Expand Down Expand Up @@ -211,7 +211,7 @@ public void givenApplicationError_DoNotRaiseException() throws ClientProtocolExc
HttpResponse response = this.createHttpResponse(HttpStatus.SC_OK, marshal);
when(oadrHttpClient.execute(Matchers.<HttpPost>anyObject(), any(), any(), any())).thenReturn(response);

OadrHttpClient20b client = new OadrHttpClient20b(oadrHttpClient);
OadrHttpClient20b client = new OadrHttpClient20b(oadrHttpClient, false);

OadrDistributeEventType mockDistributeEvent = this.createOadrDistributeEvent();

Expand All @@ -236,7 +236,7 @@ public void givenUnmarshallingRequest_RaiseException() throws ClientProtocolExce
HttpResponse response = this.createHttpResponse(scOk, marshal);
when(oadrHttpClient.execute(Matchers.<HttpPost>anyObject(), any(), any(), any())).thenReturn(response);

OadrHttpClient20b client = new OadrHttpClient20b(oadrHttpClient, null, null, null, true);
OadrHttpClient20b client = new OadrHttpClient20b(oadrHttpClient, null, null, null, true, false);

OadrDistributeEventType mockDistributeEvent = this.createOadrDistributeEvent();
mockDistributeEvent.setVtnID(null);
Expand Down Expand Up @@ -264,7 +264,7 @@ public void givenUnmarshallingResponse_RaiseException() throws ClientProtocolExc
HttpResponse response = this.createHttpResponse(scOk, marshal);
when(oadrHttpClient.execute(Matchers.<HttpPost>anyObject(), any(), any(), any())).thenReturn(response);

OadrHttpClient20b client = new OadrHttpClient20b(oadrHttpClient);
OadrHttpClient20b client = new OadrHttpClient20b(oadrHttpClient, false);

OadrDistributeEventType mockDistributeEvent = this.createOadrDistributeEvent();

Expand Down Expand Up @@ -295,7 +295,7 @@ public void responseNotSignedErrorPostTest() throws ClientProtocolException, IOE

String keyFile = CERT_FOLDER_PATH + "test.key";
String certFile = CERT_FOLDER_PATH + "test.crt";
OadrHttpClient20b client = new OadrHttpClient20b(oadrHttpClient, keyFile, certFile, 1200L);
OadrHttpClient20b client = new OadrHttpClient20b(oadrHttpClient, keyFile, certFile, 1200L, false);

OadrDistributeEventType mockDistributeEvent = this.createOadrDistributeEvent();
mockDistributeEvent.setVtnID("vtnId");
Expand Down Expand Up @@ -337,7 +337,7 @@ public void givenValidReponse_DoNotRaiseException() throws ClientProtocolExcepti
HttpResponse response = this.createHttpResponse(scOk, sign);
when(oadrHttpClient.execute(Matchers.<HttpPost>anyObject(), any(), any(), any())).thenReturn(response);

OadrHttpClient20b client = new OadrHttpClient20b(oadrHttpClient, keyFile, certFile, 1200L);
OadrHttpClient20b client = new OadrHttpClient20b(oadrHttpClient, keyFile, certFile, 1200L, false);

OadrDistributeEventType mockDistributeEvent = this.createOadrDistributeEvent();
mockDistributeEvent.setVtnID("vtnId");
Expand Down
2 changes: 1 addition & 1 deletion OpenADRModel20a/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.avob.openadr</groupId>
<artifactId>OpenADR</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>0.1.0-bitinity</version>
</parent>
<build>
<resources>
Expand Down
2 changes: 1 addition & 1 deletion OpenADRModel20b/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.avob.openadr</groupId>
<artifactId>OpenADR</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>0.1.0-bitinity</version>
</parent>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Oadr20bHttpLayerException extends Exception {
private String errorMessage;

public Oadr20bHttpLayerException(int errorCode, String errorMessage) {
super(String.format("error-code:%s error-message:%s", errorCode, errorMessage));
this.setErrorMessage(errorMessage);
this.setErrorCode(errorCode);
}
Expand All @@ -31,4 +32,11 @@ private void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}

@Override
public String toString() {
return "Oadr20bHttpLayerException [errorCode=" + errorCode + ", errorMessage=" + errorMessage + "]";
}



}
2 changes: 1 addition & 1 deletion OpenADRSecurity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>com.avob.openadr</groupId>
<artifactId>OpenADR</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>0.1.0-bitinity</version>
</parent>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
import org.bouncycastle.cert.jcajce.JcaX509CertificateHolder;
import org.bouncycastle.crypto.util.PrivateKeyFactory;
import org.bouncycastle.openssl.PEMKeyPair;
import org.bouncycastle.openssl.PEMParser;
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
import org.bouncycastle.operator.ContentSigner;
Expand Down Expand Up @@ -101,6 +102,9 @@ public static PrivateKey parsePrivateKey(FileReader fileReader) throws OadrSecur
Object readObject;
try {
readObject = parsePem(fileReader);
if (readObject instanceof PEMKeyPair) {
readObject = ((PEMKeyPair) readObject).getPrivateKeyInfo();
}
if (readObject instanceof PrivateKeyInfo) {
PrivateKeyInfo privateKeyInfo = (PrivateKeyInfo) readObject;
return new JcaPEMKeyConverter().setProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider())
Expand Down
12 changes: 6 additions & 6 deletions OpenADRServerVEN20b/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.avob.openadr</groupId>
<artifactId>OpenADR</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>0.1.0-bitinity</version>
</parent>
<dependencies>
<dependency>
Expand Down Expand Up @@ -84,11 +84,11 @@

<build>
<plugins>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- TODO we want to build a lib so no stand alone spring boot app -->
<!-- <plugin> -->
<!-- <groupId>org.springframework.boot</groupId> -->
<!-- <artifactId>spring-boot-maven-plugin</artifactId> -->
<!-- </plugin> -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ private void configureClient(VtnSessionConfiguration session)
client = new OadrHttpVenClient20b(
new OadrHttpClient20b(builder.build(), session.getVenSessionConfig().getVenPrivateKeyPath(),
session.getVenSessionConfig().getVenCertificatePath(),
session.getVenSessionConfig().getReplayProtectAcceptedDelaySecond()));
session.getVenSessionConfig().getReplayProtectAcceptedDelaySecond(), venConfig.getAcceptUnsignedResponse()));
} else {
client = new OadrHttpVenClient20b(new OadrHttpClient20b(builder.build()));
client = new OadrHttpVenClient20b(new OadrHttpClient20b(builder.build(), venConfig.getAcceptUnsignedResponse()));
}

getMultiHttpClientConfig().put(session.getVtnId(), client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class VEN20bApplicationStartupConf implements Oadr20bVENEiRegisterPartySe
private MultiVtnConfig multiVtnConfig;

@Resource
private Oadr20bVENEiReportService reportService;
private Oadr20bVENEiReportService oadrReportService;

@Resource
private Oadr20bVENEiRegisterPartyService oadr20bVENEiRegisterPartyService;
Expand Down Expand Up @@ -103,7 +103,7 @@ private void initReport(VtnSessionConfiguration vtnConfiguration) throws XmppStr
// send VEN RegisterReport to VTN
String requestId = "0";
String reportRequestId = "0";
OadrRegisterReportType payload = reportService.selfOadrRegisterReport(requestId, venConfig.getVenId(),
OadrRegisterReportType payload = oadrReportService.selfOadrRegisterReport(requestId, venConfig.getVenId(),
reportRequestId);

multiVtnConfig.oadrRegisterReport(vtnConfiguration, payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class VenConfig {
@Value("${oadr.venUrl:#{null}}")
private String venUrl;

@Value("${oadr.acceptUnsignedResponse:false}")
private Boolean acceptUnsignedResponse;

@Value("#{'${oadr.security.vtn.trustcertificate}'.split(',')}")
private List<String> trustCertificates;

Expand Down Expand Up @@ -96,6 +99,7 @@ public VenConfig(VenConfig clone) {
this.venUrl = clone.getVenUrl();
this.xmlSignature = clone.getXmlSignature();
this.validateOadrPayloadAgainstXsdFilePath = clone.getValidateOadrPayloadAgainstXsdFilePath();
this.acceptUnsignedResponse = clone.getAcceptUnsignedResponse();
}

@PostConstruct
Expand Down Expand Up @@ -146,6 +150,10 @@ public Boolean getXmlSignature() {
return xmlSignature;
}

public Boolean getAcceptUnsignedResponse() {
return acceptUnsignedResponse;
}

public Boolean getPullModel() {
return pullModel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
public class Oadr20bVENEiReportController {

@Resource
private Oadr20bVENEiReportService reportService;
private Oadr20bVENEiReportService oadrReportService;

@RequestMapping(value = Oadr20bUrlPath.EI_REPORT_SERVICE, method = RequestMethod.POST)
@ResponseBody
public String request(@RequestBody String payload, Principal principal)
throws Oadr20bMarshalException, Oadr20bUnmarshalException, Oadr20bApplicationLayerException,
Oadr20bXMLSignatureValidationException, Oadr20bXMLSignatureException, OadrSecurityException {

return reportService.request(principal.getName(), payload);
return oadrReportService.request(principal.getName(), payload);
}

}
Loading