private async Task UploadFtpAsync(MikroTikConnection con, string certFileName, string certPrivKeyFileName, LetsEncryptCert cert) { // Включить FTP в микротике. EnableFtp(con, out int ftpPort, out bool enabledChanged, out bool allowedChanged, out string allowedAddresses); try { // Загружаем сертификат в микротик по FTP. await UploadFileAsync(con, ftpPort, cert.CertPem, certFileName).ConfigureAwait(false); // Загружаем закрытый ключ сертификата в микротик по FTP. await UploadFileAsync(con, ftpPort, cert.KeyPem, certPrivKeyFileName).ConfigureAwait(false); } finally { RestoreFtp(con, enabledChanged, allowedChanged, allowedAddresses); } }
private static void RenameOldCert(MikroTikConnection con, CertificateDto[] cert, LetsEncryptCert newCert) { // Может быть несколько сертификатор с одинаковым common-name. var newCertes = con.Command("/certificate print") .Query("fingerprint", newCert.Thumbprint) .Proplist(".id,name,invalid-after") .ToArray <CertificateDto>(); foreach (var mtNewCert in newCertes) { string newName = "new_" + mtNewCert.Name; while (CertExists(con, newName)) { newName = "new_" + newName; } con.Command("/certificate set") .Attribute("numbers", mtNewCert.Id) .Attribute("name", newName) .Send(); } RenameOldMtCerts(con, cert); }