Search in sources :

Example 26 with CBORObject

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());
}
Also used : CBORObject(com.upokecenter.cbor.CBORObject)

Example 27 with CBORObject

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();
}
Also used : CBORObject(com.upokecenter.cbor.CBORObject)

Example 28 with CBORObject

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();
}
Also used : CBORObject(com.upokecenter.cbor.CBORObject)

Example 29 with CBORObject

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();
}
Also used : CBORInstantConverter(se.digg.dgc.signatures.cwt.support.CBORInstantConverter) CBORObject(com.upokecenter.cbor.CBORObject)

Example 30 with CBORObject

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;
}
Also used : VaccinationCertificateQrCode(ch.admin.bag.covidcertificate.service.domain.VaccinationCertificateQrCode) RecoveryCertificateQrCode(ch.admin.bag.covidcertificate.service.domain.RecoveryCertificateQrCode) CBORObject(com.upokecenter.cbor.CBORObject) CBORObject(com.upokecenter.cbor.CBORObject)

Aggregations

CBORObject (com.upokecenter.cbor.CBORObject)30 CBORException (com.upokecenter.cbor.CBORException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 CBORNumber (com.upokecenter.cbor.CBORNumber)2 CBORType (com.upokecenter.cbor.CBORType)2 BigInteger (java.math.BigInteger)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SecretKeySpec (javax.crypto.spec.SecretKeySpec)2 OptionSet (org.eclipse.californium.core.coap.OptionSet)2 Request (org.eclipse.californium.core.coap.Request)2 UdpDataParser (org.eclipse.californium.core.network.serialization.UdpDataParser)2 Encrypt0Message (org.eclipse.californium.cose.Encrypt0Message)2 DatagramReader (org.eclipse.californium.elements.util.DatagramReader)2 SenMLException (org.eclipse.leshan.senml.SenMLException)2 SenMLRecord (org.eclipse.leshan.senml.SenMLRecord)2 RecoveryCertificateQrCode (ch.admin.bag.covidcertificate.service.domain.RecoveryCertificateQrCode)1 VaccinationCertificateQrCode (ch.admin.bag.covidcertificate.service.domain.VaccinationCertificateQrCode)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1