Exemplo n.º 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new handshake response(server-side) and returns it.
        /// </summary>
        /// <param name="link">The ServerLink to create the resposne packet for.</param>
        /// <returns>The created message.</returns>
        public static Message CreateAuthResponse(EncryptedLink link)
        {
            Message msg = new Message(MessageType.AuthResponse, 0x00);

            byte[] timestamp = GetTimestamp();

            msg.Store["rsa_public_key"]  = Encoding.UTF8.GetBytes(RsaHelpers.PemSerialize(link.Certificate.Public));
            msg.Store["rsa_signature"]   = link.Signature;
            msg.Store["ecdh_public_key"] = link.Suite.GetKeyExchangeData().Concat(timestamp).ToArray();
            msg.Store["ecdh_signature"]  = RsaHelpers.SignData(msg.Store["ecdh_public_key"], link.Certificate);

            msg.Store["shared_salt"]           = link.Suite.SharedSalt;
            msg.Store["shared_salt_signature"] = RsaHelpers.SignData(link.Suite.SharedSalt, link.Certificate);

            msg.Store["timestamp"] = timestamp;

            return(msg);
        }