@@ -44,9 +44,10 @@ class YubikeyHandler {
44
44
PasswordSafe .instance.getPassword(credentialAttributes)!!
45
45
}
46
46
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"
50
51
}
51
52
52
53
val evalOutput = CommandRunner .runLocallyEval(" ssh-agent -s" )
@@ -63,11 +64,15 @@ class YubikeyHandler {
63
64
64
65
val echoBuilder = ProcessBuilder (" echo" , password)
65
66
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)
70
74
}
75
+
71
76
val sshAddBuilder = ProcessBuilder (" ssh-add" , " -s" , openscPath)
72
77
73
78
sshAddBuilder.environment().apply {
@@ -82,9 +87,9 @@ class YubikeyHandler {
82
87
sshAddBuilder
83
88
)
84
89
)
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)
88
93
return false
89
94
}
90
95
@@ -160,12 +165,12 @@ class YubikeyHandler {
160
165
)
161
166
return null
162
167
}
163
- } catch (e : Exception ) {
168
+ } catch (ex : Exception ) {
164
169
MessageDialog .showWarning(
165
170
"""
166
171
Can't create script '${GitUIUtil .code(resetScript.absolutePath)} ' for reset Yubikey:
167
172
168
- ${e .message}
173
+ ${ex .message}
169
174
""" .trimIndent(),
170
175
" Problem with creating Yubikey reset script"
171
176
)
0 commit comments