@@ -59,6 +59,9 @@ func (lr *LuksRunner) Run(oc *fleet.OrbitConfig) error {
59
59
if keyslot != nil {
60
60
salt , err := getSaltforKeySlot (ctx , devicePath , * keyslot )
61
61
if err != nil {
62
+ if err := removeKeySlot (ctx , devicePath , * keyslot ); err != nil {
63
+ log .Error ().Err (err ).Msgf ("failed to remove key slot %d" , * keyslot )
64
+ }
62
65
return fmt .Errorf ("Failed to get salt for key slot: %w" , err )
63
66
}
64
67
response .Salt = salt
@@ -105,9 +108,6 @@ func (lr *LuksRunner) getEscrowKey(ctx context.Context, devicePath string) ([]by
105
108
return nil , nil , fmt .Errorf ("Failed to show passphrase entry prompt: %w" , err )
106
109
}
107
110
108
- cancelProgress := lr .progressPrompt (ctx , "Validating passphrase" )
109
- defer cancelProgress ()
110
-
111
111
// Validate the passphrase
112
112
for {
113
113
valid , err := lr .passphraseIsValid (ctx , device , devicePath , passphrase )
@@ -119,25 +119,17 @@ func (lr *LuksRunner) getEscrowKey(ctx context.Context, devicePath string) ([]by
119
119
break
120
120
}
121
121
122
- cancelProgress ()
123
-
124
122
passphrase , err = lr .entryPrompt (ctx , entryDialogTitle , retryEntryDialogText )
125
123
if err != nil {
126
124
return nil , nil , fmt .Errorf ("Failed re-prompting for passphrase: %w" , err )
127
125
}
128
-
129
- cancelProgress = lr .progressPrompt (ctx , "Validating passphrase" )
130
126
}
131
127
132
128
if len (passphrase ) == 0 {
133
129
log .Debug ().Msg ("Passphrase is empty, no password supplied, dialog was canceled, or timed out" )
134
130
return nil , nil , nil
135
131
}
136
132
137
- cancelProgress ()
138
- cancelProgress = lr .progressPrompt (ctx , "Key escrow in progress" )
139
- defer cancelProgress ()
140
-
141
133
escrowPassphrase , err := generateRandomPassphrase ()
142
134
if err != nil {
143
135
return nil , nil , fmt .Errorf ("Failed to generate random passphrase: %w" , err )
@@ -166,6 +158,15 @@ func (lr *LuksRunner) getEscrowKey(ctx context.Context, devicePath string) ([]by
166
158
break
167
159
}
168
160
161
+ valid , err := lr .passphraseIsValid (ctx , device , devicePath , escrowPassphrase )
162
+ if err != nil {
163
+ return nil , nil , fmt .Errorf ("Error while validating escrow passphrase: %w" , err )
164
+ }
165
+
166
+ if ! valid {
167
+ return nil , nil , errors .New ("Failed to validate escrow passphrase" )
168
+ }
169
+
169
170
return escrowPassphrase , & keySlot , nil
170
171
}
171
172
@@ -174,7 +175,7 @@ func (lr *LuksRunner) passphraseIsValid(ctx context.Context, device *luksdevice.
174
175
return false , nil
175
176
}
176
177
177
- valid , err := device .CheckKey (ctx , devicePath , encryption .NewKey (0 , passphrase ))
178
+ valid , err := device .CheckKey (ctx , devicePath , encryption .NewKey (userKeySlot , passphrase ))
178
179
if err != nil {
179
180
return false , fmt .Errorf ("Error validating passphrase: %w" , err )
180
181
}
0 commit comments