/// <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["ca_public_key"] = Encoding.UTF8.GetBytes(RsaHelpers.PemSerialize(link.CertificateAuthority)); 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["cert_name"] = Encoding.UTF8.GetBytes(Environment.MachineName); 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); }
/// <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); }