Skip to content

Commit 760f515

Browse files
committed
Add option to disable SSL certificate verification
Fixes #70
1 parent 4eb4ee3 commit 760f515

File tree

6 files changed

+43
-21
lines changed

6 files changed

+43
-21
lines changed

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -137,25 +137,25 @@ Usage:
137137
eget [OPTIONS] TARGET
138138
139139
Application Options:
140-
-t, --tag= tagged release to use instead of latest
141-
--pre-release include pre-releases when fetching the latest version
142-
--source download the source code for the target repo instead of a release
143-
--to= move to given location after extracting
144-
-s, --system= target system to download for (use "all" for all choices)
145-
-f, --file= glob to select files for extraction
146-
--all extract all candidate files
147-
-q, --quiet only print essential output
148-
-d, --download-only stop after downloading the asset (no extraction)
149-
-D --download-all download all projects defined in the configuration file
150-
--upgrade-only only download if release is more recent than current version
151-
-a, --asset= download a specific asset containing the given string; can be specified
152-
multiple times for additional filtering; use ^ for anti-match
153-
--sha256 show the SHA-256 hash of the downloaded asset
154-
--verify-sha256= verify the downloaded asset checksum against the one provided
155-
--rate show GitHub API rate limiting information
156-
-r, --remove remove the given file from $EGET_BIN or the current directory
157-
-v, --version show version information
158-
-h, --help show this help message
140+
-t, --tag= tagged release to use instead of latest
141+
--pre-release include pre-releases when fetching the latest version
142+
--source download the source code for the target repo instead of a release
143+
--to= move to given location after extracting
144+
-s, --system= target system to download for (use "all" for all choices)
145+
-f, --file= glob to select files for extraction
146+
--all extract all candidate files
147+
-q, --quiet only print essential output
148+
-d, --download-only stop after downloading the asset (no extraction)
149+
--upgrade-only only download if release is more recent than current version
150+
-a, --asset= download a specific asset containing the given string; can be specified multiple times for additional filtering; use ^ for anti-match
151+
--sha256 show the SHA-256 hash of the downloaded asset
152+
--verify-sha256= verify the downloaded asset checksum against the one provided
153+
--rate show GitHub API rate limiting information
154+
-r, --remove remove the given file from $EGET_BIN or the current directory
155+
-v, --version show version information
156+
-h, --help show this help message
157+
-D, --download-all download all projects defined in the config file
158+
-k, --disable-ssl disable SSL verification for download
159159
```
160160

161161
# Configuration

config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type ConfigRepository struct {
3737
Target string `toml:"target"`
3838
UpgradeOnly bool `toml:"upgrade_only"`
3939
Verify string `toml:"verify_sha256"`
40+
DisableSSL bool `toml:"disable_ssl"`
4041
}
4142

4243
type Config struct {
@@ -237,6 +238,7 @@ func SetOptionsFromConfig(config *Config, parser *flags.Parser, opts *Flags, cli
237238
opts.Hash = update(config.Global.ShowHash, cli.Hash)
238239
opts.Verify = update("", cli.Verify)
239240
opts.Remove = update(false, cli.Remove)
241+
opts.DisableSSL = update(false, cli.DisableSSL)
240242

241243
for name, repo := range config.Repositories {
242244
if name == projectName {
@@ -256,6 +258,7 @@ func SetOptionsFromConfig(config *Config, parser *flags.Parser, opts *Flags, cli
256258
opts.Tag = update(repo.Tag, cli.Tag)
257259
opts.UpgradeOnly = update(repo.UpgradeOnly, cli.UpgradeOnly)
258260
opts.Verify = update(repo.Verify, cli.Verify)
261+
opts.DisableSSL = update(repo.DisableSSL, cli.DisableSSL)
259262
break
260263
}
261264
}

dl.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"crypto/tls"
45
"encoding/json"
56
"fmt"
67
"io"
@@ -27,6 +28,10 @@ func SetAuthHeader(req *http.Request) *http.Request {
2728
}
2829

2930
if req.URL.Scheme == "https" && req.Host == "api.github.com" && hasTokenEnvVar {
31+
if opts.DisableSSL {
32+
fmt.Fprintln(os.Stderr, "error: cannot use GitHub token if SSL verification is disabled")
33+
os.Exit(1)
34+
}
3035
req.Header.Set("Authorization", fmt.Sprintf("token %s", githubEnvToken))
3136
}
3237

@@ -42,7 +47,10 @@ func Get(url string) (*http.Response, error) {
4247

4348
req = SetAuthHeader(req)
4449

45-
proxyClient := &http.Client{Transport: &http.Transport{Proxy: http.ProxyFromEnvironment}}
50+
proxyClient := &http.Client{Transport: &http.Transport{
51+
Proxy: http.ProxyFromEnvironment,
52+
TLSClientConfig: &tls.Config{InsecureSkipVerify: opts.DisableSSL},
53+
}}
4654

4755
return proxyClient.Do(req)
4856
}

eget.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ func downloadConfigRepositories(config *Config) error {
323323
return nil
324324
}
325325

326+
var opts Flags
327+
326328
func main() {
327329
var cli CliFlags
328330

@@ -359,7 +361,6 @@ func main() {
359361
target = args[0]
360362
}
361363

362-
var opts Flags
363364
config := InitializeConfig()
364365
err = SetOptionsFromConfig(config, flagparser, &opts, cli, target)
365366
if err != nil {
@@ -382,6 +383,10 @@ func main() {
382383
os.Exit(0)
383384
}
384385

386+
if opts.DisableSSL {
387+
fmt.Fprintln(os.Stderr, "warning: SSL verification is disabled")
388+
}
389+
385390
if opts.Remove {
386391
ebin := os.Getenv("EGET_BIN")
387392
err := os.Remove(filepath.Join(ebin, target))

flags.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Flags struct {
1515
Hash bool
1616
Verify string
1717
Remove bool
18+
DisableSSL bool
1819
}
1920

2021
type CliFlags struct {
@@ -36,4 +37,5 @@ type CliFlags struct {
3637
Version bool `short:"v" long:"version" description:"show version information"`
3738
Help bool `short:"h" long:"help" description:"show this help message"`
3839
DownloadAll bool `short:"D" long:"download-all" description:"download all projects defined in the config file"`
40+
DisableSSL *bool `short:"k" long:"disable-ssl" description:"disable SSL verification for download requests"`
3941
}

man/eget.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ header: Eget Manual
116116

117117
: Remove the target file from `$EGET_BIN` (or the current directory if unset). Note that this flag is boolean, and means eget will treat `TARGET` as a file to be removed.
118118

119+
`-k, --disable-ssl`
120+
121+
: Disable SSL certificate verification for GET requests. Cannot be used in combination with a `GITHUB_TOKEN`.
122+
119123
`-v, --version`
120124

121125
: Show version information.

0 commit comments

Comments
 (0)