Skip to content

Commit

Permalink
[INJIMOB-2160] add UUID as id to mdoc data
Browse files Browse the repository at this point in the history
Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>
  • Loading branch information
KiruthikaJeyashankar committed Nov 5, 2024
1 parent 14d4d7c commit 0024b3f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import io.mosip.certify.util.CBORConverter
import io.mosip.certify.util.JwkToKeyConverter
import io.mosip.certify.util.KeyPairAndCertificate
import io.mosip.certify.util.PKCS12Reader
import io.mosip.certify.util.UUIDGenerator
import java.io.ByteArrayOutputStream
import java.time.Instant
import java.time.LocalDate
Expand All @@ -34,6 +35,7 @@ class MdocGenerator {
holderId: String,
issuerKeyAndCertificate: String
): String? {
println("uuid ${UUID.randomUUID()}")
val issuerDetails: KeyPairAndCertificate = PKCS12Reader().extract(issuerKeyAndCertificate)

if (issuerDetails.keyPair == null) {
Expand Down Expand Up @@ -71,6 +73,7 @@ class MdocGenerator {
mobileSecurityObjectGenerator.addDigestIdsForNamespace(NAMESPACE, calculateDigestsForNameSpace)
//Validity of MSO & its signature is assigned here
val currentTimestamp = Timestamp.now()
println("currentTimestamp: $currentTimestamp")
val validUntil = Timestamp.ofEpochMilli(addYearsToDate(currentTimestamp.toEpochMilli(), 2))
mobileSecurityObjectGenerator.setValidityInfo(
currentTimestamp,
Expand Down Expand Up @@ -111,6 +114,7 @@ data class MDoc(val docType: String, val issuerSigned: IssuerSigned) {
CborEncoder(byteArrayOutputStream).encode(
CborBuilder().addMap()
.put("docType", docType)
.put("id", UUIDGenerator().generate())
.put(CBORConverter.toDataItem("issuerSigned"), CBORConverter.toDataItem(issuerSigned.toMap()))
.end()
.build()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.mosip.certify.util;

import java.util.UUID;

public class UUIDGenerator {
public String generate() {
return "urn:uuid:" + UUID.randomUUID();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.mosip.certify.util;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;

class UUIDGeneratorTest {
@Test
void shouldReturnUUIDInRequiredFormatWhenGenerated() {
String generatedUUID = new UUIDGenerator().generate();

assertTrue(generatedUUID.matches("^urn:uuid:[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$"));
}
}

0 comments on commit 0024b3f

Please sign in to comment.