Skip to content

Commit 985451a

Browse files
committed
solution prototype
1 parent 11f8fdf commit 985451a

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/main/kotlin/com/vk/admstorm/ssh/YubikeyHandler.kt

+17-12
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ class YubikeyHandler {
4444
PasswordSafe.instance.getPassword(credentialAttributes)!!
4545
}
4646

47-
val killOutput = CommandRunner.runLocally(project, "pkill ssh-agen")
48-
if (killOutput.exitCode != 0) {
49-
LOG.warn("pkill ssh-agen exited with non-zero code while Yubikey reset")
47+
val openscPath = if (SystemInfo.isLinux) {
48+
"usr/lib/x86_64-linux-gnu/opensc-pkcs11.so"
49+
} else {
50+
"/usr/local/lib/opensc-pkcs11.so"
5051
}
5152

5253
val evalOutput = CommandRunner.runLocallyEval("ssh-agent -s")
@@ -63,11 +64,15 @@ class YubikeyHandler {
6364

6465
val echoBuilder = ProcessBuilder("echo", password)
6566

66-
val openscPath = if (SystemInfo.isLinux) {
67-
"usr/lib/x86_64-linux-gnu/opensc-pkcs11.so"
68-
} else {
69-
"/usr/local/lib/opensc-pkcs11.so"
67+
val sshResetKey = CommandRunner.runLocally(project,"ssh-add -e $openscPath")
68+
69+
val resetOk = sshResetKey.stderr.contains("Card removed")
70+
71+
if (!resetOk) {
72+
LOG.warn("Yubikey reset error: ${sshResetKey.stderr}")
73+
showYubikeyResetFailNotification(project, "Unable to reset yubikey", null, onFail)
7074
}
75+
7176
val sshAddBuilder = ProcessBuilder("ssh-add", "-s", openscPath)
7277

7378
sshAddBuilder.environment().apply {
@@ -82,9 +87,9 @@ class YubikeyHandler {
8287
sshAddBuilder
8388
)
8489
)
85-
} catch (e: IOException) {
86-
LOG.warn("Unexpected exception while startPipeline for Yubikey reset", e)
87-
showYubikeyResetFailNotification(project, "Unable to run reset commands", null, onFail)
90+
} catch (ex: IOException) {
91+
LOG.warn("Unexpected exception while startPipeline for Yubikey add", ex)
92+
showYubikeyResetFailNotification(project, "Unable to run add commands", null, onFail)
8893
return false
8994
}
9095

@@ -160,12 +165,12 @@ class YubikeyHandler {
160165
)
161166
return null
162167
}
163-
} catch (e: Exception) {
168+
} catch (ex: Exception) {
164169
MessageDialog.showWarning(
165170
"""
166171
Can't create script '${GitUIUtil.code(resetScript.absolutePath)}' for reset Yubikey:
167172
168-
${e.message}
173+
${ex.message}
169174
""".trimIndent(),
170175
"Problem with creating Yubikey reset script"
171176
)

0 commit comments

Comments
 (0)