@@ -3,8 +3,10 @@ package com.coder.toolbox.cli
3
3
import com.coder.toolbox.CoderToolboxContext
4
4
import com.coder.toolbox.cli.downloader.CoderDownloadApi
5
5
import com.coder.toolbox.cli.downloader.CoderDownloadService
6
+ import com.coder.toolbox.cli.downloader.DownloadResult.Downloaded
6
7
import com.coder.toolbox.cli.ex.MissingVersionException
7
8
import com.coder.toolbox.cli.ex.SSHConfigFormatException
9
+ import com.coder.toolbox.cli.ex.UnsignedBinaryExecutionDeniedException
8
10
import com.coder.toolbox.sdk.v2.models.Workspace
9
11
import com.coder.toolbox.sdk.v2.models.WorkspaceAgent
10
12
import com.coder.toolbox.util.CoderHostnameVerifier
@@ -27,6 +29,7 @@ import retrofit2.Retrofit
27
29
import java.io.EOFException
28
30
import java.io.FileNotFoundException
29
31
import java.net.URL
32
+ import java.nio.file.Files
30
33
import java.nio.file.Path
31
34
import javax.net.ssl.X509TrustManager
32
35
@@ -170,6 +173,31 @@ class CoderCLIManager(
170
173
singatureDownloadResult = downloader.downloadReleasesSignature(showTextProgress)
171
174
}
172
175
176
+ // if we could not find any signature and the user wants to explicitly
177
+ // confirm whether we run an unsigned cli
178
+ if (cliDownloadResult.isNotDownloaded()) {
179
+ val cli = cliDownloadResult as Downloaded
180
+ if (context.settingsStore.allowUnsignedBinaryWithoutPrompt) {
181
+ context.logger.warn(" Running unsigned CLI from ${cli.source} " )
182
+ } else {
183
+ val acceptsUnsignedBinary = context.ui.showYesNoPopup(
184
+ context.i18n.ptrl(" Security Warning" ),
185
+ context.i18n.pnotr(" Can't verify the integrity of the Coder CLI pulled from ${cli.source} " ),
186
+ context.i18n.ptrl(" Accept" ),
187
+ context.i18n.ptrl(" Abort" ),
188
+ )
189
+
190
+ if (acceptsUnsignedBinary) {
191
+ return true
192
+ } else {
193
+ // remove the cli, otherwise next time the user tries to login the cached cli is picked up
194
+ // and we don't verify cached cli signatures
195
+ Files .delete(cli.dst)
196
+ throw UnsignedBinaryExecutionDeniedException (" Running unsigned CLI from ${cli.source} was denied by the user" )
197
+ }
198
+ }
199
+ }
200
+
173
201
return cliDownloadResult.isDownloaded()
174
202
}
175
203
0 commit comments