use of com.upokecenter.cbor.CBORObject in project californium by eclipse.
the class EncryptCommon method decryptWithKey.
protected byte[] decryptWithKey(byte[] rgbKey) throws CoseException {
CBORObject algX = findAttribute(HeaderKeys.Algorithm);
AlgorithmID alg = AlgorithmID.FromCBOR(algX);
if (rgbEncrypt == null)
throw new CoseException("No Encrypted Content Specified");
if (!isSupportedAesCcm(alg)) {
throw new CoseException("Unsupported Algorithm Specified");
}
AES_CCM_Decrypt(alg, rgbKey);
return rgbContent;
}
use of com.upokecenter.cbor.CBORObject in project californium by eclipse.
the class EncryptCommon method encryptWithKey.
void encryptWithKey(byte[] rgbKey) throws CoseException, IllegalStateException {
CBORObject algX = findAttribute(HeaderKeys.Algorithm);
AlgorithmID alg = AlgorithmID.FromCBOR(algX);
if (rgbContent == null)
throw new CoseException("No Content Specified");
if (!isSupportedAesCcm(alg)) {
throw new CoseException("Unsupported Algorithm Specified");
}
AES_CCM_Encrypt(alg, rgbKey);
}
use of com.upokecenter.cbor.CBORObject in project californium by eclipse.
the class Message method EncodeToCBORObject.
/**
* Encode the COSE message object to a CBORObject tree. This function call will force cryptographic operations to be executed as needed.
*
* @return CBORObject representing the message.
* @throws CoseException Internal COSE Exception
*/
public CBORObject EncodeToCBORObject() throws CoseException {
CBORObject obj;
obj = EncodeCBORObject();
if (emitTag) {
obj = CBORObject.FromObjectAndTag(obj, messageTag.value);
}
return obj;
}
use of com.upokecenter.cbor.CBORObject in project java-webauthn-server by Yubico.
the class WebAuthnCodecs method getCoseKeyAlg.
static Optional<COSEAlgorithmIdentifier> getCoseKeyAlg(ByteArray key) {
CBORObject cose = CBORObject.DecodeFromBytes(key.getBytes());
final int alg = cose.get(CBORObject.FromObject(3)).AsInt32();
return COSEAlgorithmIdentifier.fromId(alg);
}
use of com.upokecenter.cbor.CBORObject in project java-webauthn-server by Yubico.
the class AuthenticatorData method parseAttestedCredentialData.
private static VariableLengthParseResult parseAttestedCredentialData(AuthenticatorDataFlags flags, byte[] bytes) {
final int AAGUID_INDEX = 0;
final int AAGUID_END = AAGUID_INDEX + 16;
final int CREDENTIAL_ID_LENGTH_INDEX = AAGUID_END;
final int CREDENTIAL_ID_LENGTH_END = CREDENTIAL_ID_LENGTH_INDEX + 2;
ExceptionUtil.assure(bytes.length >= CREDENTIAL_ID_LENGTH_END, "Attested credential data must contain at least %d bytes, was %d: %s", CREDENTIAL_ID_LENGTH_END, bytes.length, new ByteArray(bytes).getHex());
byte[] credentialIdLengthBytes = Arrays.copyOfRange(bytes, CREDENTIAL_ID_LENGTH_INDEX, CREDENTIAL_ID_LENGTH_END);
final int L;
try {
L = BinaryUtil.getUint16(credentialIdLengthBytes);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Invalid credential ID length bytes: " + Arrays.asList(credentialIdLengthBytes), e);
}
final int CREDENTIAL_ID_INDEX = CREDENTIAL_ID_LENGTH_END;
final int CREDENTIAL_ID_END = CREDENTIAL_ID_INDEX + L;
final int CREDENTIAL_PUBLIC_KEY_INDEX = CREDENTIAL_ID_END;
final int CREDENTIAL_PUBLIC_KEY_AND_EXTENSION_DATA_END = bytes.length;
ExceptionUtil.assure(bytes.length >= CREDENTIAL_ID_END, "Expected credential ID of length %d, but attested credential data and extension data is only %d bytes: %s", CREDENTIAL_ID_END, bytes.length, new ByteArray(bytes).getHex());
ByteArrayInputStream indefiniteLengthBytes = new ByteArrayInputStream(Arrays.copyOfRange(bytes, CREDENTIAL_PUBLIC_KEY_INDEX, CREDENTIAL_PUBLIC_KEY_AND_EXTENSION_DATA_END));
final CBORObject credentialPublicKey = CBORObject.Read(indefiniteLengthBytes);
final CBORObject extensions;
if (indefiniteLengthBytes.available() > 0) {
if (flags.ED) {
try {
extensions = CBORObject.Read(indefiniteLengthBytes);
} catch (CBORException e) {
throw new IllegalArgumentException("Failed to parse extension data", e);
}
} else {
throw new IllegalArgumentException(String.format("Flags indicate no extension data, but %d bytes remain after attested credential data.", indefiniteLengthBytes.available()));
}
} else {
if (flags.ED) {
throw new IllegalArgumentException("Flags indicate there should be extension data, but no bytes remain after attested credential data.");
} else {
extensions = null;
}
}
return new VariableLengthParseResult(AttestedCredentialData.builder().aaguid(new ByteArray(Arrays.copyOfRange(bytes, AAGUID_INDEX, AAGUID_END))).credentialId(new ByteArray(Arrays.copyOfRange(bytes, CREDENTIAL_ID_INDEX, CREDENTIAL_ID_END))).credentialPublicKey(new ByteArray(credentialPublicKey.EncodeToBytes())).build(), extensions);
}
Aggregations