use of com.upokecenter.cbor.CBORObject in project java-webauthn-server by Yubico.
the class WebAuthnCodecs method importCosePublicKey.
static PublicKey importCosePublicKey(ByteArray key) throws CoseException, IOException, InvalidKeySpecException, NoSuchAlgorithmException {
CBORObject cose = CBORObject.DecodeFromBytes(key.getBytes());
final int kty = cose.get(CBORObject.FromObject(1)).AsInt32();
switch(kty) {
case 1:
return importCoseEdDsaPublicKey(cose);
case 2:
return importCoseP256PublicKey(cose);
case 3:
return importCoseRsaPublicKey(cose);
default:
throw new IllegalArgumentException("Unsupported key type: " + kty);
}
}
use of com.upokecenter.cbor.CBORObject in project CovidCertificate-Management-Service by admin-ch.
the class DGCTestJSONGenerator method addCborToJSON.
/**
* Gets and adds the CBOR encoded certificate JSON.
*/
private static byte[] addCborToJSON(DGCTestJSON dgcTestJSON, byte[] qrCodeContentDecompressedBytes) {
CBORObject coseCBORObject = CBORObject.DecodeFromBytes(qrCodeContentDecompressedBytes);
byte[] cosePayloadBytes = coseCBORObject.get(2).GetByteString();
CBORObject cosePayloadCBORObject = CBORObject.DecodeFromBytes(cosePayloadBytes);
byte[] hCertCBORBytes = cosePayloadCBORObject.get(-260).get(1).EncodeToBytes();
String hCertHexString = Hex.encodeHexString(hCertCBORBytes);
dgcTestJSON.setCbor(hCertHexString);
return hCertCBORBytes;
}
use of com.upokecenter.cbor.CBORObject in project CovidCertificate-Management-Service by admin-ch.
the class CBORService method getSignatureData.
public byte[] getSignatureData(byte[] protectedHeader, byte[] payload) {
if (protectedHeader == null || protectedHeader.length == 0) {
throw new IllegalArgumentException("ProtectedHeader must not be empty.");
}
if (payload == null || payload.length == 0) {
throw new IllegalArgumentException("Payload must not be empty.");
}
CBORObject cborObject = CBORObject.NewArray();
cborObject.Add(CONTEXT);
cborObject.Add(protectedHeader);
cborObject.Add(EXTERNAL_AAD);
cborObject.Add(payload);
return cborObject.EncodeToBytes();
}
use of com.upokecenter.cbor.CBORObject in project CovidCertificate-Management-Service by admin-ch.
the class CBORService method getCOSESign1.
public byte[] getCOSESign1(byte[] protectedHeader, byte[] payload, byte[] signature) {
if (protectedHeader == null || protectedHeader.length == 0) {
throw new IllegalArgumentException("ProtectedHeader must not be empty.");
}
if (payload == null || payload.length == 0) {
throw new IllegalArgumentException("Payload must not be empty.");
}
if (signature == null || signature.length == 0) {
throw new IllegalArgumentException("Signature must not be empty.");
}
CBORObject cborObject = CBORObject.NewArray();
cborObject.Add(protectedHeader);
cborObject.Add(UNPROTECTED_HEADER);
cborObject.Add(payload);
cborObject.Add(signature);
cborObject = CBORObject.FromObjectAndTag(cborObject, MESSAGE_TAG);
return cborObject.EncodeToBytes();
}
use of com.upokecenter.cbor.CBORObject in project leshan by eclipse.
the class LwM2mNodeCborDecoder method decode.
@Override
@SuppressWarnings("unchecked")
public <T extends LwM2mNode> T decode(byte[] content, LwM2mPath path, LwM2mModel model, Class<T> nodeClass) throws CodecException {
// Support only single value
if (!path.isResource() && !path.isResourceInstance())
throw new CodecException("Invalid path %s : CborDecoder decodes resource OR resource instance only", path);
if (content == null)
return null;
// Parse CBOR
CBORObject cborObject;
try {
cborObject = CBORObject.DecodeFromBytes(content);
} catch (CBORException e) {
throw new CodecException(e, "Unable to parse CBORD value %s for resource %s", content, path);
}
// Find model to know expected type
Type expectedType;
ResourceModel rDesc = model.getResourceModel(path.getObjectId(), path.getResourceId());
if (rDesc != null) {
expectedType = rDesc.type;
} else {
// try to guess type from CBOR ?
expectedType = guessTypeFromCbor(cborObject, path);
LOG.debug("Decoding CBOR resource or resource instance without model, type guessed {}", expectedType);
}
// Get Node Value
Object nodeValue = parseCborValue(cborObject, expectedType, path);
// Create Node
if (path.isResource()) {
return (T) LwM2mSingleResource.newResource(path.getResourceId(), nodeValue, expectedType);
} else {
return (T) LwM2mResourceInstance.newInstance(path.getResourceInstanceId(), nodeValue, expectedType);
}
}
Aggregations