public override void GenerateClient (TlsContext ctx)
{
// Compute pre master secret
using (var preMasterSecret = ctx.Session.GetSecureRandomBytes (48)) {
preMasterSecret.Buffer [0] = (byte)((short)ctx.Configuration.RequestedProtocol >> 8);
preMasterSecret.Buffer [1] = (byte)ctx.Configuration.RequestedProtocol;
RSA rsa = null;
// Create a new RSA key
var serverCertificates = ctx.Session.PendingCrypto.ServerCertificates;
if (serverCertificates == null || serverCertificates.Count == 0) {
// FIXME: Should have received ServerKeyExchange message.
throw new TlsException (AlertDescription.IlegalParameter);
} else {
rsa = new RSAManaged (serverCertificates [0].RSA.KeySize);
rsa.ImportParameters (serverCertificates [0].RSA.ExportParameters (false));
}
ComputeMasterSecret (ctx, preMasterSecret);
// Encrypt premaster_sercret
var formatter = new RSAPKCS1KeyExchangeFormatter (rsa);
encryptedPreMasterSecret = formatter.CreateKeyExchange (preMasterSecret.Buffer);
rsa.Clear ();
}
}