示例#1
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;

            if (link.AuthenticateSelf)
            {
                msg.Store["rsa_public_key"] = Encoding.UTF8.GetBytes(RsaHelpers.PemSerialize(link.Certificate.Public));
                msg.Store["rsa_signature"]  = link.Signature;
                msg.Store["ecdh_signature"] = RsaHelpers.SignData(msg.Store["ecdh_public_key"], link.Certificate);
            }
            else
            {
                msg.Store["rsa_public_key"] = new byte[0];
                msg.Store["rsa_signature"]  = new byte[0];
                msg.Store["ecdh_signature"] = new byte[0];
            }

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

            return(msg);
        }
示例#2
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);
        }