use of com.upokecenter.cbor.CBORObject in project cwa-dcc-server by corona-warn-app.
the class DccService method replaceDccPayload.
/**
* Parses a COSE SIGN1_MESSAGE and replaces the payload Binary-String with a new Payload.
*
* @param dcc the base64 encoded COSE SIGN1_MESSAGE
* @param newPayload the base64 encoded new payload
* @return base64 encoded COSE SIGN1_MESSAGE
*/
public String replaceDccPayload(String dcc, String newPayload) {
byte[] newPayloadBytes = Base64.getDecoder().decode(newPayload);
CBORObject cbor = CBORObject.DecodeFromBytes(Base64.getDecoder().decode(dcc));
cbor.set(2, CBORObject.FromObject(newPayloadBytes));
return Base64.getEncoder().encodeToString(cbor.EncodeToBytes());
}
use of com.upokecenter.cbor.CBORObject in project cwa-dcc-server by corona-warn-app.
the class TestUtils method generatePartialDcc.
public static byte[] generatePartialDcc() {
CBORObject unprotectedHeader = CBORObject.NewMap();
unprotectedHeader.set(4, CBORObject.FromObject("unprotected Header".getBytes()));
CBORObject cose = CBORObject.NewArray();
cose.Add(CBORObject.FromObject("protected Header".getBytes())).Add(unprotectedHeader).Add(CBORObject.FromObject("payload".getBytes())).Add(CBORObject.FromObject("signature".getBytes()));
return cose.EncodeToBytes();
}
use of com.upokecenter.cbor.CBORObject in project CovidCertificate-Management-Service by admin-ch.
the class CBORService method getProtectedHeader.
public byte[] getProtectedHeader(String keyIdentifier) throws DecoderException {
if (keyIdentifier == null || keyIdentifier.isBlank()) {
throw new IllegalArgumentException("KeyIdentifier must not be empty.");
}
CBORObject protectedHeaderMap = CBORObject.NewMap();
protectedHeaderMap.Add(CBORObject.FromObject(ALG_CBOR_MAJOR_TYPE), CBORObject.FromObject(SIGNING_ALGORITHM));
protectedHeaderMap.Add(CBORObject.FromObject(KID_CBOR_MAJOR_TYPE), CBORObject.FromObject(Hex.decodeHex(keyIdentifier)));
return protectedHeaderMap.EncodeToBytes();
}
use of com.upokecenter.cbor.CBORObject in project CovidCertificate-Management-Service by admin-ch.
the class CBORService method getPayload.
public byte[] getPayload(byte[] hcert, Instant expiredAt) {
if (hcert == null || hcert.length == 0) {
throw new IllegalArgumentException("Hcert must not be empty.");
}
CBORInstantConverter instantConverter = new CBORInstantConverter();
CBORObject cborObject = CBORObject.NewMap();
cborObject.Add(ISS_CLAIM_KEY, CBORObject.FromObject(Constants.ISO_3166_1_ALPHA_2_CODE_SWITZERLAND));
cborObject.set(IAT_CLAIM_KEY, instantConverter.ToCBORObject(coseTime.getIssuedAt()));
cborObject.set(EXP_CLAIM_KEY, instantConverter.ToCBORObject(expiredAt));
CBORObject hcertMap = CBORObject.NewMap();
hcertMap.set(HCERT_INNER_CLAIM_KEY, CBORObject.DecodeFromBytes(hcert));
cborObject.Add(HCERT_CLAIM_KEY, hcertMap);
return cborObject.EncodeToBytes();
}
use of com.upokecenter.cbor.CBORObject in project CovidCertificate-Management-Service by admin-ch.
the class DGCTestJSONGenerator method addJsonToJSON.
/**
* Gets and adds the certificate JSON as string.
*/
private static String addJsonToJSON(ObjectMapper objectMapper, DGCTestJSON dgcTestJSON, byte[] hCertCBORBytes) throws com.fasterxml.jackson.core.JsonProcessingException {
CBORObject hCertCBORObject = CBORObject.DecodeFromBytes(hCertCBORBytes);
String hCert = hCertCBORObject.ToJSONString();
Object hCertObject = null;
String certificateType = null;
if (hCert.contains(IDENTIFIER_VACCINATION)) {
hCertObject = objectMapper.readValue(hCert, VaccinationCertificateQrCode.class);
certificateType = "Vaccination";
} else if (hCert.contains(IDENTIFIER_TEST)) {
hCertObject = objectMapper.readValue(hCert, TestCertificateQrCode.class);
certificateType = "Test";
} else if (hCert.contains(IDENTIFIER_RECOVERY)) {
hCertObject = objectMapper.readValue(hCert, RecoveryCertificateQrCode.class);
certificateType = "Recovery";
}
dgcTestJSON.setJson(hCertObject);
return certificateType;
}
Aggregations