Skip to content

Commit

Permalink
add tool to sign licenses
Browse files Browse the repository at this point in the history
  • Loading branch information
rodesai committed Nov 19, 2024
1 parent 339b2d7 commit d5056d5
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 1 deletion.
2 changes: 2 additions & 0 deletions kafka-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,6 @@ dependencies {
testImplementation(testlibs.bundles.base)
testImplementation(testlibs.bundles.testcontainers)
testImplementation(libs.kafka.streams.test.utils)
testImplementation("software.amazon.awssdk:kms:2.20.0")
testImplementation("software.amazon.awssdk:sso:2.20.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ public abstract class LicenseDocument {
public LicenseDocument(@JsonProperty("version") final String version) {
this.version = version;
}

@JsonProperty("version")
public String version() {
return version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,22 @@ public LicenseDocumentV1(
this.algo = algo;
}

@JsonProperty("info")
public String info() {
return info;
}

@JsonProperty("key")
public String key() {
return key;
}

@JsonProperty("signature")
public String signature() {
return signature;
}

@JsonProperty("algo")
public String algo() {
return algo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ public abstract class LicenseInfo {
LicenseInfo(@JsonProperty("type") final String type) {
this.type = type;
}

@JsonProperty("type")
public String type() {
return type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,18 @@ public TimedTrialV1(
this.expiresAt = expiresAt;
}

@JsonProperty("email")
public String email() {
return email;
}

@JsonProperty("expiresAt")
public long expiresAt() {
return expiresAt;
}

@JsonProperty("issuedAt")
public long issuedAt() {
return issuedAt;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA37LvpjgfWmlVAY/wefQ+
2cL79J7UNJePfsQWjzMc4p8ITBcTGpX/RalhdLJQjbD/SJymAOEfy56RHbuG8vS0
u79as6yhby8NWFaT1vNsYKOLfoUwqxi49TvxzXkBwdrLPXLbgIW7TNQpYIyM17Tl
tuceASZJGY7dECzeZY303XsmXgsLjaNHqdLlxtdzl8i8i/diqK8/I6oKL0/AsIaC
ZPfuPdQebtko4eE6p4pKjNu3qxNNdV73nV2WwHHMCE/U4CiTbH1nvpSVgr8sLBcW
EtbjDwJi+wp3OX5vblWHskLJDjdjAGbNH89UYyaWTV6C58dTGH4zmffw649Ib+80
ywB8uH8IuoAJMXgECDT5XygXX2362z8MI4apMV6ouT90KyvamIVXLV1VpNyTn9ZY
AYXkZxImUujhB89Lz/b5ctK/epzi+5/ZDQyrgNaPCwFoPnE/QLeuHmrT2gM381S8
3Y7fJmAa7sSRF0aPvTDM7hfmP2TRA29106qrEqPh2EX64mqoKCMkM6ZngCpiJgFZ
usvCRRUdBHnXKfyqFux6TBOVrKGrahJVLgkKMaFXma0U+peuXHSE1sktjtb2zUP9
kqP1bwBtPD43epWPnVxWBqIcXD3poLBu+Hj8lVBV+NQ+XtTPzWmcD8+MSC0zzCUK
umd9JPEA9pzJAqlpRYTEGaUCAwEAAQ==
-----END PUBLIC KEY-----
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
{"keys": []}
{
"keys": [
{
"type": "RSA_4096",
"keyId": "license-signing-key-0",
"path": "/responsive-license-keys/keys/license-signing-key-0.pem"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package dev.responsive.kafka.internal.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import dev.responsive.kafka.internal.license.model.LicenseDocumentV1;
import dev.responsive.kafka.internal.license.model.TimedTrialV1;
import java.io.IOException;
import java.time.Instant;
import java.util.Base64;
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.kms.KmsClient;
import software.amazon.awssdk.services.kms.model.MessageType;
import software.amazon.awssdk.services.kms.model.SignRequest;
import software.amazon.awssdk.services.kms.model.SignResponse;
import software.amazon.awssdk.services.kms.model.SigningAlgorithmSpec;

public class GenerateTrialLicense {
private static final ObjectMapper MAPPER = new ObjectMapper();
private static final String SIGNING_KEY_ARN = System.getenv("SIGNING_KEY_ARN");
private static final String SIGNING_KEY_ID = System.getenv("SIGNING_KEY_ID");
private static final String AWS_PROFILE = System.getenv("AWS_PROFILE");
private static final String SIGNING_ALGO = "RSASSA_PSS_SHA_256";

public static void main(final String[] args) throws IOException {
final var info = new TimedTrialV1(
"timed_trial_v1",
"[email protected]",
Instant.now().getEpochSecond(),
Instant.MAX.getEpochSecond()
);
final byte[] serialized = MAPPER.writeValueAsBytes(info);
final Region region = Region.US_WEST_2;
final byte[] signature;
try (final KmsClient kmsClient = KmsClient.builder()
.credentialsProvider(ProfileCredentialsProvider.create(AWS_PROFILE))
.region(region)
.build()
) {
final SdkBytes sdkBytes = SdkBytes.fromByteArray(serialized);
final SignRequest signRequest = SignRequest.builder()
.keyId(SIGNING_KEY_ARN)
.message(sdkBytes)
.messageType(MessageType.RAW)
.signingAlgorithm(SigningAlgorithmSpec.RSASSA_PSS_SHA_256)
.build();
final SignResponse signResponse = kmsClient.sign(signRequest);
final SdkBytes sdkSignature = signResponse.signature();
signature = sdkSignature.asByteArray();
}
final LicenseDocumentV1 license = new LicenseDocumentV1(
"1",
Base64.getEncoder().encodeToString(serialized),
Base64.getEncoder().encodeToString(signature),
SIGNING_KEY_ID,
SIGNING_ALGO
);
System.out.println(MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(license));
}
}

0 comments on commit d5056d5

Please sign in to comment.