use of io.jans.fido2.ctap.CoseEC2Algorithm in project jans by JanssenProject.
the class AttestationService method preparePublicKeyCredentialSelection.
private ArrayNode preparePublicKeyCredentialSelection() {
List<String> requestedCredentialTypes = appConfiguration.getFido2Configuration().getRequestedCredentialTypes();
ArrayNode credentialParametersNode = dataMapperService.createArrayNode();
if ((requestedCredentialTypes == null) || requestedCredentialTypes.isEmpty()) {
// Add default requested credential types
// FIDO2 RS256
ObjectNode credentialParametersNodeRS256 = credentialParametersNode.addObject();
credentialParametersNodeRS256.arrayNode().addObject();
credentialParametersNodeRS256.put("type", "public-key");
credentialParametersNodeRS256.put("alg", CoseRSAAlgorithm.RS256.getNumericValue());
// FIDO2 ES256
ObjectNode credentialParametersNodeES256 = credentialParametersNode.addObject();
credentialParametersNodeES256.arrayNode().addObject();
credentialParametersNodeES256.put("type", "public-key");
credentialParametersNodeES256.put("alg", CoseEC2Algorithm.ES256.getNumericValue());
} else {
for (String requestedCredentialType : requestedCredentialTypes) {
CoseRSAAlgorithm coseRSAAlgorithm = null;
try {
coseRSAAlgorithm = CoseRSAAlgorithm.valueOf(requestedCredentialType);
} catch (IllegalArgumentException ex) {
}
if (coseRSAAlgorithm != null) {
ObjectNode credentialParametersNodeRS256 = credentialParametersNode.addObject();
credentialParametersNodeRS256.arrayNode().addObject();
credentialParametersNodeRS256.put("type", "public-key");
credentialParametersNodeRS256.put("alg", coseRSAAlgorithm.getNumericValue());
break;
}
}
for (String requestedCredentialType : requestedCredentialTypes) {
CoseEC2Algorithm coseEC2Algorithm = null;
try {
coseEC2Algorithm = CoseEC2Algorithm.valueOf(requestedCredentialType);
} catch (IllegalArgumentException ex) {
}
if (coseEC2Algorithm != null) {
ObjectNode credentialParametersNodeRS256 = credentialParametersNode.addObject();
credentialParametersNodeRS256.arrayNode().addObject();
credentialParametersNodeRS256.put("type", "public-key");
credentialParametersNodeRS256.put("alg", coseEC2Algorithm.getNumericValue());
break;
}
}
}
return credentialParametersNode;
}
use of io.jans.fido2.ctap.CoseEC2Algorithm in project jans by JanssenProject.
the class CoseService method createUncompressedPointFromCOSEPublicKey.
public PublicKey createUncompressedPointFromCOSEPublicKey(JsonNode uncompressedECPointNode) {
int keyToUse = uncompressedECPointNode.get("1").asInt();
int algorithmToUse = uncompressedECPointNode.get("3").asInt();
CoseKeyType keyType = CoseKeyType.fromNumericValue(keyToUse);
switch(keyType) {
case RSA:
{
CoseRSAAlgorithm coseRSAAlgorithm = CoseRSAAlgorithm.fromNumericValue(algorithmToUse);
switch(coseRSAAlgorithm) {
case RS65535:
case RS256:
{
byte[] rsaKey_n = base64Service.decode(uncompressedECPointNode.get("-1").asText());
byte[] rsaKey_e = base64Service.decode(uncompressedECPointNode.get("-2").asText());
return convertUncompressedPointToRSAKey(rsaKey_n, rsaKey_e);
}
default:
{
throw new Fido2RuntimeException("Don't know what to do with this key" + keyType);
}
}
}
case EC2:
{
CoseEC2Algorithm coseEC2Algorithm = CoseEC2Algorithm.fromNumericValue(algorithmToUse);
switch(coseEC2Algorithm) {
case ES256:
{
int curve = uncompressedECPointNode.get("-1").asInt();
byte[] x = base64Service.decode(uncompressedECPointNode.get("-2").asText());
byte[] y = base64Service.decode(uncompressedECPointNode.get("-3").asText());
byte[] buffer = ByteBuffer.allocate(1 + x.length + y.length).put(UNCOMPRESSED_POINT_INDICATOR).put(x).put(y).array();
return convertUncompressedPointToECKey(buffer, curve);
}
default:
{
throw new Fido2RuntimeException("Don't know what to do with this key" + keyType + " and algorithm " + coseEC2Algorithm);
}
}
}
case OKP:
{
throw new Fido2RuntimeException("Don't know what to do with this key" + keyType);
}
default:
throw new Fido2RuntimeException("Don't know what to do with this key" + keyType);
}
}
Aggregations