public static List<SignatureAndHashAlgorithm> getSignatureAndHashAlgorithms(byte[] values) { List<SignatureAndHashAlgorithm> sigHashAlgoList = new LinkedList<>(); int pointer = 0; if (values.length % 2 != 0) { throw new UnknownSignatureAndHashAlgorithm("ByteArray is not divisible by 2!"); } while (pointer < values.length) { byte[] sigHashAlgo = new byte[2]; sigHashAlgo[0] = values[pointer]; sigHashAlgo[1] = values[pointer + 1]; sigHashAlgoList.add(getSignatureAndHashAlgorithm(sigHashAlgo)); pointer += 2; } return sigHashAlgoList; }
public static SignatureAndHashAlgorithm getSignatureAndHashAlgorithm(byte[] value) { return getSignatureAndHashAlgorithm(valueToInt(value)); }
private List<SignatureAndHashAlgorithm> convertSignatureAndHashAlgorithms(byte[] bytesToConvert) { if (bytesToConvert.length % 2 != 0) { LOGGER.warn("Cannot convert:" + ArrayConverter.bytesToHexString(bytesToConvert, false) + " to a List<SignatureAndHashAlgorithm>"); return new LinkedList<>(); } List<SignatureAndHashAlgorithm> list = new LinkedList<>(); for (int i = 0; i < bytesToConvert.length; i += 2) { byte[] copied = new byte[2]; copied[0] = bytesToConvert[i]; copied[1] = bytesToConvert[i + 1]; SignatureAndHashAlgorithm algo = SignatureAndHashAlgorithm.getSignatureAndHashAlgorithm(copied); list.add(algo); } return list; } }
@Override public void adjustTLSExtensionContext(SignatureAndHashAlgorithmsExtensionMessage message) { List<SignatureAndHashAlgorithm> algoList = new LinkedList<>(); byte[] signatureAndHashBytes = message.getSignatureAndHashAlgorithms().getValue(); if (signatureAndHashBytes.length % HandshakeByteLength.SIGNATURE_HASH_ALGORITHM != 0) { throw new AdjustmentException( "Cannot adjust ClientSupportedSignature and Hash algorithms to a resonable Value"); } for (int i = 0; i < signatureAndHashBytes.length; i += HandshakeByteLength.SIGNATURE_HASH_ALGORITHM) { byte[] algoBytes = Arrays.copyOfRange(signatureAndHashBytes, i, i + HandshakeByteLength.SIGNATURE_HASH_ALGORITHM); SignatureAndHashAlgorithm algo = SignatureAndHashAlgorithm.getSignatureAndHashAlgorithm(algoBytes); if (algo.getSignatureAlgorithm() == null || algo.getHashAlgorithm() == null) { LOGGER.warn("Unknown SignatureAndHashAlgorithm:" + ArrayConverter.bytesToHexString(algoBytes)); } else { algoList.add(algo); } } context.setClientSupportedSignatureAndHashAlgorithms(algoList); }
SignatureAndHashAlgorithm sigHashAlgo = SignatureAndHashAlgorithm.getSignatureAndHashAlgorithm( signatureAlgorithm, hashAlgorithm); LOGGER.debug("Setting selected SignatureAndHash algorithm to:" + sigHashAlgo);