public static SignatureAndHashAlgorithm getSignatureAndHashAlgorithm(SignatureAlgorithm signatureAlgo, HashAlgorithm hashAlgo) { for (SignatureAndHashAlgorithm algo : values()) { if (algo.getHashAlgorithm() == hashAlgo && algo.getSignatureAlgorithm() == signatureAlgo) { return algo; } } throw new UnsupportedOperationException("Requested SignatureHashAlgorithm is not supported. Requested Sign:" + signatureAlgo + " Hash:" + hashAlgo); }
public String getJavaName() { String hashAlgorithmName = getHashAlgorithm().getJavaName(); if (!hashAlgorithmName.contains("GOST")) { hashAlgorithmName = hashAlgorithmName.replace("-", ""); } String signatureAlgorithmName = getSignatureAlgorithm().getJavaName(); return hashAlgorithmName + "with" + signatureAlgorithmName; }
@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); }