transform: Updated HIP02 to use MainForm's task

This commit is contained in:
Nathan Woodburn 2023-06-24 11:34:02 +10:00
parent cbf1bc3e38
commit ffd1372eca
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

View File

@ -95,7 +95,7 @@ namespace FireWallet
this.Close(); this.Close();
} }
private void updateAddress() private async void updateAddress()
{ {
labelError.Hide(); labelError.Hide();
@ -108,82 +108,17 @@ namespace FireWallet
{ {
string domain = textBoxAddress.Text.Substring(1); string domain = textBoxAddress.Text.Substring(1);
try string address = await MainForm.HIP02Lookup(domain);
if (address == "ERROR")
{ {
IPAddress iPAddress = null;
// Create an instance of LookupClient using the custom options
NameServer nameServer = new NameServer(IPAddress.Parse("127.0.0.1"), 5350);
var options = new LookupClientOptions(nameServer);
options.EnableAuditTrail = true;
options.UseTcpOnly = true;
options.Recursion = true;
options.UseCache = false;
options.RequestDnsSecRecords = true;
options.Timeout = TimeSpan.FromSeconds(5);
var client = new LookupClient(options);
// Perform the DNS lookup for the specified domain using DNSSec
var result = client.Query(domain, QueryType.A);
// Display the DNS lookup results
foreach (var record in result.Answers.OfType<ARecord>())
{
iPAddress = record.Address;
}
if (iPAddress == null)
{
labelError.Show();
labelError.Text = "HIP-02 lookup failed";
return;
}
// Get TLSA record
var resultTLSA = client.Query("_443._tcp." + domain, QueryType.TLSA);
foreach (var record in resultTLSA.Answers.OfType<TlsaRecord>())
{
MainForm.TLSA = record.CertificateAssociationDataAsString;
}
string url = "https://" + iPAddress.ToString() + "/.well-known/wallets/HNS";
var handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = MainForm.ValidateServerCertificate;
// Create an instance of HttpClient with the custom handler
using (var httpclient = new HttpClient(handler))
{
httpclient.DefaultRequestHeaders.Add("Host", domain);
// Send a GET request to the specified URL
HttpResponseMessage response = httpclient.GetAsync(url).Result;
// Response
string address = response.Content.ReadAsStringAsync().Result;
labelSendingHIPAddress.Text = address;
this.address = address;
labelSendingHIPAddress.Show();
labelHIPArrow.Show();
}
}
catch (Exception ex)
{
MainForm.AddLog(ex.Message);
labelError.Show(); labelError.Show();
labelError.Text = "HIP-02 lookup failed"; labelError.Text = "HIP-02 lookup failed";
} else
{
labelSendingHIPAddress.Text = address;
this.address = address;
labelSendingHIPAddress.Show();
labelHIPArrow.Show();
} }
} else } else
{ {