diff --git a/src/main/java/io/dimeformat/Crypto.java b/src/main/java/io/dimeformat/Crypto.java index a79fafc..6320435 100644 --- a/src/main/java/io/dimeformat/Crypto.java +++ b/src/main/java/io/dimeformat/Crypto.java @@ -113,8 +113,6 @@ public static Key generateSharedSecret(Key clientKey, Key serverKey) throws Dime } else { throw new DimeKeyMismatchException("Invalid keys provided."); } - System.out.println("shared: " + Utility.toHex(shared)); - System.out.println("---"); return new Key(UUID.randomUUID(), KeyType.ENCRYPTION, shared, null); } diff --git a/src/main/java/io/dimeformat/Message.java b/src/main/java/io/dimeformat/Message.java index 46e2939..c68108c 100644 --- a/src/main/java/io/dimeformat/Message.java +++ b/src/main/java/io/dimeformat/Message.java @@ -160,6 +160,15 @@ public Message(UUID issuerId, long validFor) { this(null, issuerId, validFor, null); } + /** + * Creates a message to a specified audience (receiver) from a specified issuer (sender). + * @param audienceId The audience identifier. Providing -1 as validFor will skip setting an expiration date. + * @param issuerId The issuer identifier. + */ + public Message(UUID audienceId, UUID issuerId) { + this(audienceId, issuerId, -1, null); + } + /** * Creates a message to a specified audience (receiver) from a specified issuer (sender), with an expiration date. * @param audienceId The audience identifier. Providing -1 as validFor will skip setting an expiration date. @@ -216,8 +225,10 @@ public void verify(Key key) throws DimeDateException, DimeIntegrityException { // Verify IssuedAt and ExpiresAt Instant now = Instant.now(); if (this.getIssuedAt().compareTo(now) > 0) { throw new DimeDateException("Issuing date in the future."); } - if (this.getIssuedAt().compareTo(this.getExpiresAt()) > 0) { throw new DimeDateException("Expiration before issuing date."); } - if (this.getExpiresAt().compareTo(now) < 0) { throw new DimeDateException("Passed expiration date."); } + if (this.getExpiresAt() != null) { + if (this.getIssuedAt().compareTo(this.getExpiresAt()) > 0) { throw new DimeDateException("Expiration before issuing date."); } + if (this.getExpiresAt().compareTo(now) < 0) { throw new DimeDateException("Passed expiration date."); } + } super.verify(key); } diff --git a/src/test/java/io/dimeformat/MessageTest.java b/src/test/java/io/dimeformat/MessageTest.java index d0ae52a..42b53cc 100644 --- a/src/test/java/io/dimeformat/MessageTest.java +++ b/src/test/java/io/dimeformat/MessageTest.java @@ -158,6 +158,19 @@ void verifyTest3() { } } + @Test + void verifyTest4() { + try { + Identity.setTrustedIdentity(Commons.getTrustedIdentity()); + Message message = new Message(Commons.getAudienceIdentity().getSubjectId(), Commons.getIssuerIdentity().getSubjectId()); + message.setPayload("Racecar is racecar backwards.".getBytes(StandardCharsets.UTF_8)); + message.sign(Commons.getIssuerKey()); + message.verify(Commons.getIssuerIdentity().getPublicKey()); + } catch (Exception e) { + fail("Unexpected exception thrown: " + e); + } + } + @Test void importTest1() { try {