@@ -22,6 +22,12 @@ class YubikeyHandler {
22
22
private val LOG = logger<YubikeyHandler >()
23
23
}
24
24
25
+ private val openscPath = if (SystemInfo .isLinux) {
26
+ " usr/lib/x86_64-linux-gnu/opensc-pkcs11.so"
27
+ } else {
28
+ " /usr/local/lib/opensc-pkcs11.so"
29
+ }
30
+
25
31
fun autoReset (project : Project , onFail : Runnable ): Boolean {
26
32
LOG .info(" Try auto reset Yubikey" )
27
33
val resetScript = createScriptIfNotExists(project) ? : return false
@@ -44,10 +50,7 @@ class YubikeyHandler {
44
50
PasswordSafe .instance.getPassword(credentialAttributes)!!
45
51
}
46
52
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" )
50
- }
53
+
51
54
52
55
val evalOutput = CommandRunner .runLocallyEval(" ssh-agent -s" )
53
56
if (evalOutput == null ) {
@@ -63,11 +66,13 @@ class YubikeyHandler {
63
66
64
67
val echoBuilder = ProcessBuilder (" echo" , password)
65
68
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"
69
+ val sshResetKey = CommandRunner .runLocally(project, " ssh-add -e $openscPath " )
70
+ val resetOk = sshResetKey.stderr.contains(" Card removed" )
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