@@ -3,8 +3,10 @@ package com.coder.toolbox.cli
33import com.coder.toolbox.CoderToolboxContext
44import com.coder.toolbox.cli.downloader.CoderDownloadApi
55import com.coder.toolbox.cli.downloader.CoderDownloadService
6+ import com.coder.toolbox.cli.downloader.DownloadResult.Downloaded
67import com.coder.toolbox.cli.ex.MissingVersionException
78import com.coder.toolbox.cli.ex.SSHConfigFormatException
9+ import com.coder.toolbox.cli.ex.UnsignedBinaryExecutionDeniedException
810import com.coder.toolbox.sdk.v2.models.Workspace
911import com.coder.toolbox.sdk.v2.models.WorkspaceAgent
1012import com.coder.toolbox.util.CoderHostnameVerifier
@@ -27,6 +29,7 @@ import retrofit2.Retrofit
2729import java.io.EOFException
2830import java.io.FileNotFoundException
2931import java.net.URL
32+ import java.nio.file.Files
3033import java.nio.file.Path
3134import javax.net.ssl.X509TrustManager
3235
@@ -170,6 +173,31 @@ class CoderCLIManager(
170173 singatureDownloadResult = downloader.downloadReleasesSignature(showTextProgress)
171174 }
172175
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+
173201 return cliDownloadResult.isDownloaded()
174202 }
175203
0 commit comments