Exemplo n.º 1
0
        public static Message CreateClientHello(ClientLink link, List <CipherSuiteIdentifier> allowed_suites)
        {
            Message msg = new Message(MessageType.ClientHello, 0x00);

            MemoryStream ms = new MemoryStream();

            for (int i = 0; i < allowed_suites.Count; i++)
            {
                byte[] serialized = allowed_suites[i].Serialize();

                ms.Write(serialized, 0, serialized.Length);
            }

            msg.Store["allowed_suites"] = ms.ToArray();

            ms.Close();

            return(msg);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new handshake request(client-side) and returns it.
        /// </summary>
        /// <param name="link">The ClientLink to create the request packet for.</param>
        /// <returns>The created message.</returns>
        public static Message CreateAuthRequest(ClientLink link)
        {
            Message msg = new Message(MessageType.AuthRequest, 0x00);

            byte[] timestamp = GetTimestamp();

            msg.Store["ecdh_public_key"] = link.Suite.GetKeyExchangeData().Concat(timestamp).ToArray();
            msg.Store["timestamp"]       = timestamp;

            msg.Store["rsa_public_key"] = Encoding.UTF8.GetBytes(RsaHelpers.PemSerialize(link.Certificate.Public));
            msg.Store["ca_public_key"]  = Encoding.UTF8.GetBytes(RsaHelpers.PemSerialize(link.CertificateAuthority));
            msg.Store["rsa_signature"]  = link.Signature;
            msg.Store["ecdh_signature"] = RsaHelpers.SignData(msg.Store["ecdh_public_key"], link.Certificate);
            msg.Store["cert_name"]      = Encoding.UTF8.GetBytes(Environment.MachineName);

            if (link.AttestationToken != null)
            {
                msg.Store["attestation_token"] = link.AttestationToken;
            }

            return(msg);
        }