-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
702 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,5 @@ hs_err_pid* | |
replay_pid* | ||
/.idea | ||
|
||
*.iml | ||
*.iml | ||
/jzlint-server/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>de.mtg</groupId> | ||
<artifactId>jzlint-server</artifactId> | ||
<version>1.0.1</version> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>3.3.4</version> | ||
<relativePath/> | ||
</parent> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>de.mtg</groupId> | ||
<artifactId>jzlint</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.bouncycastle</groupId> | ||
<artifactId>bcprov-jdk18on</artifactId> | ||
<version>1.78.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
88 changes: 88 additions & 0 deletions
88
jzlint-server/src/main/java/de/mtg/jzlint/server/CliUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package de.mtg.jzlint.server; | ||
|
||
import java.security.cert.X509CRL; | ||
import java.security.cert.X509Certificate; | ||
import java.util.List; | ||
|
||
import de.mtg.jzlint.Source; | ||
|
||
public class CliUtils { | ||
|
||
public static final String CHECK_APPLIES = "checkApplies"; | ||
public static final String EXECUTE = "execute"; | ||
|
||
private CliUtils() { | ||
// empty | ||
} | ||
|
||
public static boolean isCertificateIssuerLint(Class<?> lintClass) { | ||
try { | ||
lintClass.getMethod(CHECK_APPLIES, X509Certificate.class, X509Certificate.class); | ||
return true; | ||
} catch (NoSuchMethodException e) { | ||
return false; | ||
} | ||
} | ||
|
||
public static boolean isCRLIssuerLint(Class<?> lintClass) { | ||
try { | ||
lintClass.getMethod(CHECK_APPLIES, X509CRL.class, X509Certificate.class); | ||
return true; | ||
} catch (NoSuchMethodException e) { | ||
return false; | ||
} | ||
} | ||
|
||
public static boolean isOCSPResponseIssuerLint(Class<?> lintClass) { | ||
try { | ||
lintClass.getMethod(CHECK_APPLIES, byte[].class, X509Certificate.class); | ||
return true; | ||
} catch (NoSuchMethodException e) { | ||
return false; | ||
} | ||
} | ||
|
||
public static boolean isCertificateLint(Class<?> lintClass) { | ||
try { | ||
lintClass.getMethod(CHECK_APPLIES, X509Certificate.class); | ||
return true; | ||
} catch (NoSuchMethodException e) { | ||
return false; | ||
} | ||
} | ||
|
||
public static boolean isCRLLint(Class<?> lintClass) { | ||
try { | ||
lintClass.getMethod(CHECK_APPLIES, X509CRL.class); | ||
return true; | ||
} catch (NoSuchMethodException e) { | ||
return false; | ||
} | ||
} | ||
|
||
public static boolean isOCSPResponseLint(Class<?> lintClass) { | ||
try { | ||
lintClass.getMethod(CHECK_APPLIES, byte[].class); | ||
return true; | ||
} catch (NoSuchMethodException e) { | ||
return false; | ||
} | ||
} | ||
|
||
public static boolean includeLint(Source lintSource, List<String> includeSources, List<String> excludeSources) { | ||
|
||
boolean includeIsEmpty = includeSources == null || includeSources.isEmpty(); | ||
boolean excludeIsEmpty = excludeSources == null || excludeSources.isEmpty(); | ||
|
||
if (!includeIsEmpty) { | ||
return includeSources.contains(lintSource.getSourceName()); | ||
} | ||
|
||
if (!excludeIsEmpty) { | ||
return !excludeSources.contains(lintSource.getSourceName()); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
jzlint-server/src/main/java/de/mtg/jzlint/server/JZLintServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package de.mtg.jzlint.server; | ||
|
||
import java.security.Security; | ||
|
||
import org.bouncycastle.jce.provider.BouncyCastleProvider; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class JZLintServer { | ||
|
||
public static void main(String[] args) { | ||
Security.addProvider(new BouncyCastleProvider()); | ||
SpringApplication.run(JZLintServer.class, args); | ||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
jzlint-server/src/main/java/de/mtg/jzlint/server/LintController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package de.mtg.jzlint.server; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.security.cert.X509Certificate; | ||
import java.util.concurrent.ForkJoinPool; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.context.request.async.DeferredResult; | ||
|
||
import de.mtg.jzlint.LintJSONResults; | ||
import de.mtg.jzlint.utils.ParsedDomainNameUtils; | ||
|
||
@RestController | ||
public class LintController { | ||
|
||
@Value("${request.timeout:15000}") | ||
private long requestTimeout; | ||
|
||
@PostMapping(value = "/certificate/lint", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) | ||
public DeferredResult<ResponseEntity<?>> lintCertificate(@RequestBody TBLCertificate tblCertificate) { | ||
DeferredResult<ResponseEntity<?>> response = new DeferredResult<>(requestTimeout, new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR)); | ||
|
||
ForkJoinPool.commonPool().submit(() -> { | ||
try { | ||
byte[] rawPKIObject = tblCertificate.getCertificate().getBytes(StandardCharsets.US_ASCII); | ||
LintJSONResults lint = ServerUtils.lint(rawPKIObject, null, tblCertificate.getIncludeNames(), tblCertificate.getIncludeSources(), tblCertificate.getExcludeNames(), tblCertificate.getExcludeSources()); | ||
X509Certificate certificate = ServerUtils.getCertificate(rawPKIObject); | ||
ParsedDomainNameUtils.cleanCacheEntry(certificate); | ||
response.setResult(new ResponseEntity<>(ServerUtils.convertResultToResponse(lint), HttpStatus.OK)); | ||
} catch (Exception ex) { | ||
response.setResult(new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR)); | ||
} | ||
}); | ||
|
||
return response; | ||
} | ||
|
||
@PostMapping("/crl/lint") | ||
DeferredResult<ResponseEntity<?>> lintCRL(@RequestBody TBLCRL tblCrl) { | ||
DeferredResult<ResponseEntity<?>> response = new DeferredResult<>(requestTimeout, new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR)); | ||
|
||
ForkJoinPool.commonPool().submit(() -> { | ||
try { | ||
byte[] rawPKIObject = tblCrl.getCrl().getBytes(StandardCharsets.US_ASCII); | ||
LintJSONResults lint = ServerUtils.lint(rawPKIObject, null, tblCrl.getIncludeNames(), tblCrl.getIncludeSources(), tblCrl.getExcludeNames(), tblCrl.getExcludeSources()); | ||
response.setResult(new ResponseEntity<>(ServerUtils.convertResultToResponse(lint), HttpStatus.OK)); | ||
} catch (Exception ex) { | ||
response.setResult(new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR)); | ||
} | ||
}); | ||
|
||
return response; | ||
} | ||
|
||
@PostMapping("/ocspresponse/lint") | ||
DeferredResult<ResponseEntity<?>> lintOCSP(@RequestBody TBLOCPResponse tblocpResponse) { | ||
DeferredResult<ResponseEntity<?>> response = new DeferredResult<>(requestTimeout, new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR)); | ||
|
||
ForkJoinPool.commonPool().submit(() -> { | ||
try { | ||
byte[] rawPKIObject = tblocpResponse.getOcspResponse().getBytes(StandardCharsets.US_ASCII); | ||
LintJSONResults lint = ServerUtils.lint(rawPKIObject, null, tblocpResponse.getIncludeNames(), tblocpResponse.getIncludeSources(), tblocpResponse.getExcludeNames(), tblocpResponse.getExcludeSources()); | ||
response.setResult(new ResponseEntity<>(ServerUtils.convertResultToResponse(lint), HttpStatus.OK)); | ||
} catch (Exception ex) { | ||
response.setResult(new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR)); | ||
} | ||
}); | ||
|
||
return response; | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
jzlint-server/src/main/java/de/mtg/jzlint/server/LintResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package de.mtg.jzlint.server; | ||
|
||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class LintResponse { | ||
|
||
private List<String> warnings; | ||
|
||
private List<String> errors; | ||
|
||
public LintResponse() { | ||
// empty | ||
} | ||
|
||
public List<String> getWarnings() { | ||
return warnings; | ||
} | ||
|
||
public void setWarnings(List<String> warnings) { | ||
this.warnings = warnings; | ||
} | ||
|
||
public List<String> getErrors() { | ||
return errors; | ||
} | ||
|
||
public void setErrors(List<String> errors) { | ||
this.errors = errors; | ||
} | ||
|
||
} |
Oops, something went wrong.