From 5013770f14604743ee653219fe9800f8324fec26 Mon Sep 17 00:00:00 2001 From: Henrik Oehmke Date: Fri, 23 Sep 2022 13:24:58 +0200 Subject: [PATCH] Add CertificateType attribute to CertificateRequest --- .../sdk/certificate/CertificateRequest.java | 1 + .../sdk/certificate/CertificateType.java | 36 +++++++++++++++++++ .../connectors/tpp/AbstractTppConnector.java | 2 +- .../sdk/connectors/tpp/TppConnector.java | 7 ++-- 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/venafi/vcert/sdk/certificate/CertificateType.java diff --git a/src/main/java/com/venafi/vcert/sdk/certificate/CertificateRequest.java b/src/main/java/com/venafi/vcert/sdk/certificate/CertificateRequest.java index bd89041..9ce3c31 100644 --- a/src/main/java/com/venafi/vcert/sdk/certificate/CertificateRequest.java +++ b/src/main/java/com/venafi/vcert/sdk/certificate/CertificateRequest.java @@ -74,6 +74,7 @@ public class CertificateRequest { private String issuerHint; private Collection customFields; private DataFormat dataFormat; + private CertificateType certificateType; public CertificateRequest() { this.dnsNames = emptyList(); diff --git a/src/main/java/com/venafi/vcert/sdk/certificate/CertificateType.java b/src/main/java/com/venafi/vcert/sdk/certificate/CertificateType.java new file mode 100644 index 0000000..68d5e54 --- /dev/null +++ b/src/main/java/com/venafi/vcert/sdk/certificate/CertificateType.java @@ -0,0 +1,36 @@ +package com.venafi.vcert.sdk.certificate; + + +import lombok.Getter; + +public enum CertificateType { + Auto("Auto"), + CodeSigning("Code Signing: X.509 Code Signing Certificate"), + Device("Device: X.509 Device Certificate"), + Server("Server: X.509 Server Certificate"), + User("User: X.509 User Certificate"); + + public static CertificateType from(String value) { + switch (value.toLowerCase()) { + case "auto": + return Auto; + case "code signing: x.509 code signing certificate": + return CodeSigning; + case "device: x.509 device certificate": + return Device; + case "server: x.509 server certificate": + return Server; + case "user: x.509 user certificate": + return User; + default: + throw new IllegalArgumentException(String.format("unknown certificate type: %s", value)); + } + } + + @Getter + private final String value; + + CertificateType(String value) { + this.value = value; + } +} \ No newline at end of file diff --git a/src/main/java/com/venafi/vcert/sdk/connectors/tpp/AbstractTppConnector.java b/src/main/java/com/venafi/vcert/sdk/connectors/tpp/AbstractTppConnector.java index ef7e3ca..94bccb2 100644 --- a/src/main/java/com/venafi/vcert/sdk/connectors/tpp/AbstractTppConnector.java +++ b/src/main/java/com/venafi/vcert/sdk/connectors/tpp/AbstractTppConnector.java @@ -350,7 +350,7 @@ public static class CertificateRequestsPayload { private String ellipticCurve; private boolean disableAutomaticRenewal; private String origin; - + private String certificateType; @SerializedName("CustomFields") private ArrayList customFields; } diff --git a/src/main/java/com/venafi/vcert/sdk/connectors/tpp/TppConnector.java b/src/main/java/com/venafi/vcert/sdk/connectors/tpp/TppConnector.java index 2fb6cf7..10173dd 100644 --- a/src/main/java/com/venafi/vcert/sdk/connectors/tpp/TppConnector.java +++ b/src/main/java/com/venafi/vcert/sdk/connectors/tpp/TppConnector.java @@ -290,8 +290,11 @@ protected CertificateRequestsPayload prepareRequest(CertificateRequest request, break; } } - - + + if (request.certificateType() != null) { + payload.certificateType(request.certificateType().value()); + } + //support for validity hours begins VCertUtils.addExpirationDateAttribute(request, payload); //support for validity hours ends