Skip to content

Commit 5c444a5

Browse files
committed
1.3.0
1 parent 50a0c5f commit 5c444a5

23 files changed

+2398
-69
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@
2121
### V1.2.0-SNAPSHOT
2222
+ Bug fixes for null value checking
2323
+ Update basestring method to suppport use-case where value of queryparam or form value is empty
24-
+ Update nonce method to generate base64 encoded string value of 32 bytes characters
24+
+ Update nonce method to generate base64 encoded string value of 32 bytes characters
25+
### V1.3.0-SNAPSHOT
26+
+ Update test-suites framework to cover more use-case scenarios
27+
+ Add Utility to read from PKI Key with PEM format
28+
+ Update README documentation

README.md

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,53 @@ dependencies {
140140

141141
### Development
142142

143-
#### Constructing Signature BaseString
143+
#### Preparing HTTP Signature Token
144+
145+
Append this signature token into the Authorization header of the HTTP request
146+
147+
Params:
148+
* realm
149+
* authPrefix - Authorization Header scheme prefix , i.e 'Apex_l2_eg'
150+
* httpMethod
151+
* urlPath
152+
* appId - App ID created in Gateway
153+
* secret - set to null for REST L2 SHA256WITHRSA
154+
* formList - to support parameter for form data if any
155+
* password
156+
* alias
157+
* fileName
158+
* nonce - set to null for random generated number
159+
* timestamp - set to null for current timestamp
160+
161+
162+
```java
163+
String realm = "<<your_client_host_url>>"
164+
String authPrefix = "<<authPrefix>>
165+
String httpMethod = "get"
166+
String url = "https://<<Target_URL>>/api/v1/?param1=first&param2=123";
167+
String certFileName = "certificates/ssc.alpha.example.com.p12";
168+
String password = "<<passphrase>>";
169+
String alias = "alpha";
170+
String appId = "<<appId>>";
171+
String secret = null;
172+
ApiList formList = null;
173+
String nonce = null;
174+
String timestamp = null;
175+
176+
try {
177+
String signature = ApiSigning.getSignatureToken(authPrefix, authPrefix, httpMethod, url, appId, secret, formList, password, alias, certFileName, nonce, timestamp);
178+
} catch (ApiUtilException e) {
179+
e.printStackTrace();
180+
}
181+
```
182+
183+
#### Constructing Signature BaseString (for reference only)
144184

145185
Method:
146186
* getBaseString
147187

148188
Params:
149-
* authPrefix - Authorization Header scheme prefix , i.e 'prefix_appId'
189+
* authPrefix - Authorization Header scheme prefix , i.e 'Apex_l2_eg'
150190
* signatureMethod
151191
* appId - App ID created in Gateway
152192
* urlPath
@@ -156,7 +196,7 @@ Params:
156196
* timestamp - set to null for current timestamp
157197

158198
```java
159-
String url = "https://<<URL>>/api/v1/?param1=first&ab-param2=123";
199+
String url = "https://<<Target_URL>>/api/v1/?param1=first&param2=123";
160200

161201
ApiList formList = new ApiList();
162202
formList.add("param1", "data1");
@@ -183,7 +223,7 @@ System.out.println(baseString);
183223

184224
```
185225

186-
#### Constructing HMAC256 L1 Header
226+
#### Constructing HMAC256 L1 Header (for reference only)
187227

188228
Method:
189229
* getHMACSignature
@@ -207,7 +247,7 @@ try {
207247

208248
```
209249

210-
#### Constructing RSA256 L2 Header
250+
#### Constructing RSA256 L2 Header (for reference only)
211251

212252
Method:
213253
* getRSASignature
@@ -217,7 +257,7 @@ Params:
217257
* privateKey
218258

219259
```java
220-
String baseString = "GET&https://<<URL>/api/v1/&ap=裕廊坊 心邻坊&<<authPrefix>>_app_id=<<appId>>&<<authPrefix>>_nonce=7231415196459608363&<<authPrefix>>_signature_method=SHA256withRSA&<<authPrefix>>_timestamp=1502164219425&<<authPrefix>>_version=1.0&oq=c# nunit mac&q=c# nunit mac";
260+
String baseString = "GET&https://<<URL>/api/v1/&ap=裕廊坊 心邻坊&<<authPrefix>>_app_id=<<appId>>&<<authPrefix>>_nonce=7231415196459608363&<<authPrefix>>_signature_method=SHA256withRSA&<<authPrefix>>_timestamp=1502164219425&<<authPrefix>>_version=1.0&oq=123&q=abc";
221261
String alias = "alpha";
222262
String password = "<<passphrase>>";
223263
String keyStoreFileName = "certificates/ssc.alpha.example.com.p12";
@@ -240,43 +280,6 @@ try {
240280

241281
```
242282

243-
#### Preparing HTTP Signature Token
244-
245-
Append this signature token into the Authorization header of the HTTP request
246-
247-
Params:
248-
* realm
249-
* authPrefix - Authorization Header scheme prefix , i.e 'prefix_appId'
250-
* httpMethod
251-
* urlPath
252-
* appId - App ID created in Gateway
253-
* secret - set to null for REST L2 SHA256WITHRSA
254-
* formList
255-
* password
256-
* alias
257-
* fileName
258-
* nonce - set to null for random generated number
259-
* timestamp - set to null for current timestamp
260-
261-
262-
```java
263-
String url = "https://<<URL>>/api/v1/?ap=裕廊坊%20心邻坊";
264-
String certFileName = "certificates/ssc.alpha.example.com.p12";
265-
String password = "<<passphrase>>";
266-
String alias = "alpha";
267-
String appId = "<<appId>>";
268-
String secret = null;
269-
ApiList formList = null;
270-
String nonce = null;
271-
String timestamp = null;
272-
273-
try {
274-
String signature = ApiSigning.getSignatureToken("http://api.test.io/l2", "<<authPrefix>>", "get", url, appId, null, null, password, alias, certFileName, nonce, timestamp);
275-
} catch (ApiUtilException e) {
276-
e.printStackTrace();
277-
}
278-
```
279-
280283
## Contributing
281284
For more information about contributing PRs and issues, see [CONTRIBUTING.md](.github/CONTRIBUTING.md).
282285

build.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
id 'com.github.kt3k.coveralls' version '2.6.3'
55
}
66

7-
version '1.2.0-SNAPSHOT'
7+
version '1.3.0-SNAPSHOT'
88

99
tasks.withType(JavaCompile) {
1010
options.encoding = "UTF-8"
@@ -15,8 +15,12 @@ repositories {
1515
}
1616

1717
dependencies {
18-
compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.1'
18+
//compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.1'
19+
compile group: 'commons-lang', name: 'commons-lang', version: '2.4'
1920
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
21+
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.7'
22+
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
23+
compile group: 'org.bouncycastle', name: 'bcpkix-jdk15on', version: '1.60'
2024
testCompile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.25'
2125
testCompile group: 'junit', name: 'junit', version: '4.12'
2226
}

pom.xml

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>com.api.util</groupId>
44
<artifactId>ApiSecurity</artifactId>
5-
<version>1.2.0-SNAPSHOT</version>
5+
<version>1.3.0-SNAPSHOT</version>
66
<build>
77
<plugins>
88
<plugin>
@@ -29,6 +29,22 @@
2929
</descriptorRefs>
3030
</configuration>
3131
</plugin>
32+
<plugin>
33+
<groupId>org.jsonschema2pojo</groupId>
34+
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
35+
<version>0.5.1</version>
36+
<configuration>
37+
<sourceDirectory>src/main/resources/schema</sourceDirectory>
38+
<targetPackage>com.api.util.ApiSecurity</targetPackage>
39+
</configuration>
40+
<executions>
41+
<execution>
42+
<goals>
43+
<goal>generate</goal>
44+
</goals>
45+
</execution>
46+
</executions>
47+
</plugin>
3248
</plugins>
3349
</build>
3450
<dependencies>
@@ -56,8 +72,33 @@
5672
<artifactId>slf4j-log4j12</artifactId>
5773
<version>1.7.25</version>
5874
</dependency>
75+
<dependency>
76+
<groupId>commons-lang</groupId>
77+
<artifactId>commons-lang</artifactId>
78+
<version>2.4</version>
79+
</dependency>
80+
<dependency>
81+
<groupId>com.fasterxml.jackson.core</groupId>
82+
<artifactId>jackson-databind</artifactId>
83+
<version>2.9.7</version>
84+
</dependency>
85+
<dependency>
86+
<groupId>com.googlecode.json-simple</groupId>
87+
<artifactId>json-simple</artifactId>
88+
<version>1.1.1</version>
89+
</dependency>
90+
<dependency>
91+
<groupId>org.bouncycastle</groupId>
92+
<artifactId>bcpkix-jdk15on</artifactId>
93+
<version>1.60</version>
94+
</dependency>
5995
</dependencies>
6096
<properties>
6197
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
6298
</properties>
99+
<scm>
100+
<connection>scm:git:https://github.com/GovTechSG/test-suites-apex-api-security.git</connection>
101+
<developerConnection>scm:git:https://kelvinwijaya@github.com/GovTechSG/test-suites-apex-api-security.git</developerConnection>
102+
<url>https://github.com/GovTechSG</url>
103+
</scm>
63104
</project>

src/main/java/com/api/util/ApiSecurity/ApiList.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.api.util.ApiSecurity;
22
import java.util.AbstractMap.SimpleEntry;
33
import java.util.ArrayList;
4-
import java.util.Collections;
54
import java.util.List;
65
import java.util.Map.Entry;
76
import java.util.stream.Collectors;
@@ -13,7 +12,7 @@
1312
public class ApiList extends ArrayList<Entry<String,String>>{
1413

1514
private static final long serialVersionUID = 1L;
16-
15+
1716
public void add(String key, String value)
1817
{
1918
Entry<String, String> item = new SimpleEntry<String, String>(key, value);
@@ -43,7 +42,7 @@ public String toString(String delimiter, Boolean sort, Boolean quote, Boolean is
4342
return l1.getKey().equals(l2.getKey()) ? l1.getValue().compareTo(l2.getValue())
4443
: l1.getKey().compareTo(l2.getKey());
4544
})
46-
.map(e -> (null!= e.getValue() && e.getValue().equals("") && isBaseString) ? e.getKey() : String.format(format, e.getKey(), e.getValue()) )
45+
.map(e -> (null== e.getValue() || (null!= e.getValue() && e.getValue().isEmpty()) && isBaseString) ? e.getKey() : String.format(format, e.getKey(), e.getValue()) )
4746
.collect(Collectors.toList());
4847
} else{
4948
list = this.stream().map(e -> String.format(format, e.getKey(), e.getValue()))

0 commit comments

Comments
 (0)