mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 02:12:58 +08:00
chore: RDP encrypt password on Windows
This commit is contained in:
@@ -82,12 +82,25 @@ internal class RDPProtocolProvider private constructor() : GenericProtocolProvid
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val file = FileUtils.getFile(Application.getTemporaryDir(), randomUUID() + ".rdp")
|
|
||||||
file.outputStream().use { IOUtils.write(sb.toString(), it, Charsets.UTF_8) }
|
|
||||||
|
|
||||||
if (host.authentication.type == AuthenticationType.Password) {
|
if (host.authentication.type == AuthenticationType.Password) {
|
||||||
val systemClipboard = windowScope.window.toolkit.systemClipboard
|
|
||||||
val password = host.authentication.password
|
val password = host.authentication.password
|
||||||
|
var ep = StringUtils.EMPTY
|
||||||
|
|
||||||
|
if (SystemInfo.isWindows) {
|
||||||
|
val cmd = "ConvertTo-SecureString '${password}' -AsPlainText -Force | ConvertFrom-SecureString"
|
||||||
|
val process = ProcessBuilder("powershell.exe", "-Command", cmd).start()
|
||||||
|
if (process.waitFor() == 0) {
|
||||||
|
ep = String(process.inputStream.readAllBytes())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ep.isNotBlank()) {
|
||||||
|
sb.append("password 51:b:").append(ep).appendLine()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果获取加密密码失败,那么依然要走剪切板
|
||||||
|
if (ep.isBlank() || SystemInfo.isMacOS) {
|
||||||
|
val systemClipboard = windowScope.window.toolkit.systemClipboard
|
||||||
systemClipboard.setContents(StringSelection(password), null)
|
systemClipboard.setContents(StringSelection(password), null)
|
||||||
// clear password
|
// clear password
|
||||||
swingCoroutineScope.launch(Dispatchers.IO) {
|
swingCoroutineScope.launch(Dispatchers.IO) {
|
||||||
@@ -99,6 +112,11 @@ internal class RDPProtocolProvider private constructor() : GenericProtocolProvid
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
val file = FileUtils.getFile(Application.getTemporaryDir(), randomUUID() + ".rdp")
|
||||||
|
file.outputStream().use { IOUtils.write(sb.toString(), it, Charsets.UTF_8) }
|
||||||
|
|
||||||
if (SystemInfo.isMacOS) {
|
if (SystemInfo.isMacOS) {
|
||||||
ProcessBuilder("open", file.absolutePath).start()
|
ProcessBuilder("open", file.absolutePath).start()
|
||||||
|
|||||||
Reference in New Issue
Block a user