public static boolean isTLSv12(TlsContext context) { return isTLSv12(context.getServerVersion()); }
public static SignatureAndHashAlgorithm getSignatureAndHashAlgorithm(TlsContext context, TlsSignerCredentials signerCredentials) throws IOException { SignatureAndHashAlgorithm signatureAndHashAlgorithm = null; if (TlsUtils.isTLSv12(context)) { signatureAndHashAlgorithm = signerCredentials.getSignatureAndHashAlgorithm(); if (signatureAndHashAlgorithm == null) { throw new TlsFatalAlert(AlertDescription.internal_error); } } return signatureAndHashAlgorithm; }
public static SignatureAndHashAlgorithm getSignatureAndHashAlgorithm(TlsContext context, TlsSignerCredentials signerCredentials) throws IOException { SignatureAndHashAlgorithm signatureAndHashAlgorithm = null; if (isTLSv12(context)) { signatureAndHashAlgorithm = signerCredentials.getSignatureAndHashAlgorithm(); if (signatureAndHashAlgorithm == null) { throw new TlsFatalAlert(AlertDescription.internal_error); } } return signatureAndHashAlgorithm; }
public byte[] generateCertificateSignature(byte[] hash) throws IOException { try { if (TlsUtils.isTLSv12(context)) { return signer.generateRawSignature(signatureAndHashAlgorithm, privateKey, hash); } else { return signer.generateRawSignature(privateKey, hash); } } catch (CryptoException e) { throw new TlsFatalAlert(AlertDescription.internal_error, e); } }
if (TlsUtils.isTLSv12(context) && signatureAndHashAlgorithm == null)
public byte[] generateCertificateSignature(byte[] hash) throws IOException { try { if (TlsUtils.isTLSv12(context)) { return signer.generateRawSignature(signatureAndHashAlgorithm, privateKey, hash); } else { return signer.generateRawSignature(privateKey, hash); } } catch (CryptoException e) { throw new TlsFatalAlert(AlertDescription.internal_error, e); } }
/** * Parse a {@link DigitallySigned} from an {@link InputStream}. * * @param context * the {@link TlsContext} of the current connection. * @param input * the {@link InputStream} to parse from. * @return a {@link DigitallySigned} object. * @throws IOException */ public static DigitallySigned parse(TlsContext context, InputStream input) throws IOException { SignatureAndHashAlgorithm algorithm = null; if (TlsUtils.isTLSv12(context)) { algorithm = SignatureAndHashAlgorithm.parse(input); } byte[] signature = TlsUtils.readOpaque16(input); return new DigitallySigned(algorithm, signature); } }
/** * Parse a {@link DigitallySigned} from an {@link InputStream}. * * @param context * the {@link TlsContext} of the current connection. * @param input * the {@link InputStream} to parse from. * @return a {@link DigitallySigned} object. * @throws IOException */ public static DigitallySigned parse(TlsContext context, InputStream input) throws IOException { SignatureAndHashAlgorithm algorithm = null; if (TlsUtils.isTLSv12(context)) { algorithm = SignatureAndHashAlgorithm.parse(input); } byte[] signature = TlsUtils.readOpaque16(input); return new DigitallySigned(algorithm, signature); } }
if (TlsUtils.isTLSv12(context))
if (TlsUtils.isTLSv12(context))
protected Signer makeSigner(SignatureAndHashAlgorithm algorithm, boolean raw, boolean forSigning, CipherParameters cp) { if ((algorithm != null) != TlsUtils.isTLSv12(context)) { throw new IllegalStateException(); } if (algorithm != null && algorithm.getSignature() != getSignatureAlgorithm()) { throw new IllegalStateException(); } short hashAlgorithm = algorithm == null ? HashAlgorithm.sha1 : algorithm.getHash(); Digest d = raw ? new NullDigest() : TlsUtils.createHash(hashAlgorithm); Signer s = new DSADigestSigner(createDSAImpl(hashAlgorithm), d); s.init(forSigning, makeInitParameters(forSigning, cp)); return s; }
protected Signer makeSigner(SignatureAndHashAlgorithm algorithm, boolean raw, boolean forSigning, CipherParameters cp) { if ((algorithm != null) != TlsUtils.isTLSv12(context)) { throw new IllegalStateException(); } if (algorithm != null && algorithm.getSignature() != getSignatureAlgorithm()) { throw new IllegalStateException(); } short hashAlgorithm = algorithm == null ? HashAlgorithm.sha1 : algorithm.getHash(); Digest d = raw ? new NullDigest() : TlsUtils.createHash(hashAlgorithm); Signer s = new DSADigestSigner(createDSAImpl(hashAlgorithm), d); s.init(forSigning, makeInitParameters(forSigning, cp)); return s; }
protected Signer makeSigner(SignatureAndHashAlgorithm algorithm, boolean raw, boolean forSigning, CipherParameters cp) if ((algorithm != null) != TlsUtils.isTLSv12(context))
if (TlsUtils.isTLSv12(context))
if (TlsUtils.isTLSv12(context))
if (TlsUtils.isTLSv12(context))
public Chacha20Poly1305(TlsContext context) throws IOException { if (!TlsUtils.isTLSv12(context)) { throw new TlsFatalAlert(AlertDescription.internal_error); } this.context = context; byte[] key_block = TlsUtils.calculateKeyBlock(context, 64); KeyParameter client_write_key = new KeyParameter(key_block, 0, 32); KeyParameter server_write_key = new KeyParameter(key_block, 32, 32); this.encryptCipher = new ChaChaEngine(20); this.decryptCipher = new ChaChaEngine(20); KeyParameter encryptKey, decryptKey; if (context.isServer()) { encryptKey = server_write_key; decryptKey = client_write_key; } else { encryptKey = client_write_key; decryptKey = server_write_key; } byte[] dummyNonce = new byte[8]; this.encryptCipher.init(true, new ParametersWithIV(encryptKey, dummyNonce)); this.decryptCipher.init(false, new ParametersWithIV(decryptKey, dummyNonce)); }
if (TlsUtils.isTLSv12(context))
if (TlsUtils.isTLSv12(getContext()))
if (TlsUtils.isTLSv12(getContext()))