org.bouncycastle.tls.TlsSRPUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of impersonator Show documentation
Show all versions of impersonator Show documentation
Spoof TLS/JA3/JA4 and HTTP/2 fingerprints in Java
package org.bouncycastle.tls;
import org.bouncycastle.util.BigIntegers;
import org.bouncycastle.util.Integers;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigInteger;
import java.util.Map;
public class TlsSRPUtils
{
public static final Integer EXT_SRP = Integers.valueOf(ExtensionType.srp);
public static void addSRPExtension(Map extensions, byte[] identity) throws IOException
{
extensions.put(EXT_SRP, createSRPExtension(identity));
}
public static byte[] getSRPExtension(Map extensions) throws IOException
{
byte[] extensionData = TlsUtils.getExtensionData(extensions, EXT_SRP);
return extensionData == null ? null : readSRPExtension(extensionData);
}
public static byte[] createSRPExtension(byte[] identity) throws IOException
{
if (identity == null)
{
throw new TlsFatalAlert(AlertDescription.internal_error);
}
return TlsUtils.encodeOpaque8(identity);
}
public static byte[] readSRPExtension(byte[] extensionData) throws IOException
{
if (extensionData == null)
{
throw new IllegalArgumentException("'extensionData' cannot be null");
}
return TlsUtils.decodeOpaque8(extensionData, 1);
}
public static BigInteger readSRPParameter(InputStream input) throws IOException
{
return new BigInteger(1, TlsUtils.readOpaque16(input, 1));
}
public static void writeSRPParameter(BigInteger x, OutputStream output) throws IOException
{
TlsUtils.writeOpaque16(BigIntegers.asUnsignedByteArray(x), output);
}
public static boolean isSRPCipherSuite(int cipherSuite)
{
switch (TlsUtils.getKeyExchangeAlgorithm(cipherSuite))
{
case KeyExchangeAlgorithm.SRP:
case KeyExchangeAlgorithm.SRP_DSS:
case KeyExchangeAlgorithm.SRP_RSA:
return true;
default:
return false;
}
}
}