我正在開發一個 C# WinForms 應用程式來自動化在 Windows cmd 視窗中執行的手動 TLS/SSL 證書請求。CA 提供了一個桌面客戶端,它與 CA 的服務器進行通信,CA 的服務器發出域所有權“挑戰”并執行所有權驗證。
基本上這是一個三步程序:
- CA 提出挑戰
- 用戶創建包含相關域挑戰的 DNS TXT 記錄
- CA 檢查記錄;如果發現頒發新的 SSL 證書
在質詢發布期間,請求中列出的每個域的處理暫停并等待用戶按 ENTER。在發出最終質詢后,下次按下 ENTER 時,它會啟動驗證。在 CMD 視窗中手動運行該行程會導致
J:\Verify_DNS>le64 --key account.key --email "[email protected]"
--csr example.csr --csr-key example.key
--crt example.crt --generate-missing
--domains "example.com,*.example.com"
--handle-as dns
[ Crypt::LE64 client v0.38 started. ]
Challenge for example.com requires the following DNS record to be created:
Host: _acme-challenge.example.com, type: TXT, value:
cb4XNLh_ZnkwkuD7EiwlV9wk7qsP8QHLHUlQ2OO5DX8
Check for DNS propagation using:
nslookup -q=TXT _acme-challenge.example.com
When you see a text record returned, press <Enter>
Challenge for *.example.com requires the following DNS record to be created:
Host: _acme-challenge.example.com, type: TXT, value:
nUhw1Xy9H219nfiEx0vZuGDVbpe5KXuUenFoOlc3-4Q
Check for DNS propagation using:
nslookup -q=TXT _acme-challenge.example.com
When you see a text record returned, press <Enter>
Processing the 'dns' verification
Verification result for 'example.com': success.
Verification result for '*.example.com': success.
Saving the full cert chain to example.crt.
The job is done.
J:\Verify_DNS>
由于 DNS 傳播時間是不可預測的,因此可以通過將“延遲”標志附加到引數來將程序分為兩個步驟。拆分時 步驟 1 在發出挑戰后停止,并將控制權交還給用戶。
成功運行第一步和nslookup的代碼
ProcessStartInfo si = new ProcessStartInfo();
si.FileName = @"C:\Windows\System32\cmd.exe";
si.RedirectStandardOutput = true;
si.RedirectStandardError = true;
si.RedirectStandardInput = true;
si.UseShellExecute = false;
si.CreateNoWindow = true;
si.WorkingDirectory = Terms.dir_DNS;
si.Verb = "runas";
using (Process proc = new Process())
{
proc.StartInfo = si;
proc.ErrorDataReceived = cmd_DataReceived_DNS;
proc.OutputDataReceived = cmd_DataReceived_DNS;
proc.EnableRaisingEvents = true;
proc.Start();
proc.PriorityClass = ProcessPriorityClass.RealTime;
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
if (nslookup) proc.StandardInput.WriteLine(@"ipconfig /flushdns");
proc.StandardInput.WriteLine(arg);
proc.StandardInput.WriteLine("exit");
proc.WaitForExit();
}
在第二步中,該程序從頂部完全運行,服務員暫停等待用戶按 ENTER。為了自動化這個程序,我需要在 cmd 視窗中按 ENTER 來“模擬/模擬”。
這個問題似乎是一個阻礙;任何想法將不勝感激。
[編輯] 洗掉了不恰當地嘗試通過 SendKeys 輸入 { ENTER } 的令人困惑的失敗嘗試
uj5u.com熱心網友回復:
只需proc.StandardInput.WriteLine()在不帶任何引數的情況下呼叫,因為在控制臺視窗中按 enter 只是將行終止符寫入標準輸入,通常是\r\n(Windows) 或\n(*nix),又名CR/LF.
由于 DNS 傳播時間是不可預測的,因此可以通過將“延遲”標志附加到引數來將程序分為兩個步驟。
一種理想的方法是等待所需的輸出并繼續執行。在這種情況下,您可能希望同步讀取輸出,而不是使用BeginOutputReadLine():
string output = null;
// Replace "completed_message" with the termination message you want, maybe "The job is done" here.
while(!(output = proc.StandardOutput.ReadLine()).Contains("completed_message"))
{
ProcessOutput(output);
}
// continue execution or exit the process here
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/523306.html
標籤:C#表格ssl
下一篇:標簽文本從右到左移動形式
