Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.crypto.tls;
  
  import java.util.Vector;
  
 
 public class TlsDHEKeyExchange
     extends TlsDHKeyExchange
 {
     protected TlsSignerCredentials serverCredentials = null;
 
     public TlsDHEKeyExchange(int keyExchangeVector supportedSignatureAlgorithmsDHParameters dhParameters)
     {
         super(keyExchangesupportedSignatureAlgorithmsdhParameters);
     }
 
     public void processServerCredentials(TlsCredentials serverCredentials)
         throws IOException
     {
         if (!(serverCredentials instanceof TlsSignerCredentials))
         {
             throw new TlsFatalAlert(.);
         }
 
         processServerCertificate(serverCredentials.getCertificate());
 
         this. = (TlsSignerCredentials)serverCredentials;
     }
 
     public byte[] generateServerKeyExchange()
         throws IOException
     {
         if (this. == null)
         {
             throw new TlsFatalAlert(.);
         }
 
         DigestInputBuffer buf = new DigestInputBuffer();
 
             this.buf);
 
         /*
          * RFC 5246 4.7. digitally-signed element needs SignatureAndHashAlgorithm from TLS 1.2
          */
         SignatureAndHashAlgorithm signatureAndHashAlgorithm = TlsUtils.getSignatureAndHashAlgorithm(
             );
 
         Digest d = TlsUtils.createHash(signatureAndHashAlgorithm);
 
         SecurityParameters securityParameters = .getSecurityParameters();
         d.update(securityParameters.clientRandom, 0, securityParameters.clientRandom.length);
         d.update(securityParameters.serverRandom, 0, securityParameters.serverRandom.length);
         buf.updateDigest(d);
 
         byte[] hash = new byte[d.getDigestSize()];
         d.doFinal(hash, 0);
 
         byte[] signature = .generateCertificateSignature(hash);
 
         DigitallySigned signed_params = new DigitallySigned(signatureAndHashAlgorithmsignature);
         signed_params.encode(buf);
 
         return buf.toByteArray();
     }
 
     public void processServerKeyExchange(InputStream input)
         throws IOException
     {
         SecurityParameters securityParameters = .getSecurityParameters();
 
         SignerInputBuffer buf = new SignerInputBuffer();
         InputStream teeIn = new TeeInputStream(inputbuf);
 
         ServerDHParams dhParams = ServerDHParams.parse(teeIn);
 
         DigitallySigned signed_params = DigitallySigned.parse(input);
 
         Signer signer = initVerifyer(signed_params.getAlgorithm(), securityParameters);
         buf.updateSigner(signer);
         if (!signer.verifySignature(signed_params.getSignature()))
         {
             throw new TlsFatalAlert(.);
         }
 
         this. = TlsDHUtils.validateDHPublicKey(dhParams.getPublicKey());
         this. = .getParameters();
     }
 
     protected Signer initVerifyer(TlsSigner tlsSignerSignatureAndHashAlgorithm algorithmSecurityParameters securityParameters)
     {
         Signer signer = tlsSigner.createVerifyer(algorithmthis.);
         signer.update(securityParameters.clientRandom, 0, securityParameters.clientRandom.length);
         signer.update(securityParameters.serverRandom, 0, securityParameters.serverRandom.length);
        return signer;
    }
New to GrepCode? Check out our FAQ X