Skip to content

Commit f2ecb60

Browse files
authored
Merge pull request #40 from getsumio/develop
Develop
2 parents 22ef442 + b03d26f commit f2ecb60

File tree

11 files changed

+76
-24
lines changed

11 files changed

+76
-24
lines changed

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ RUN apt install openssl
66
RUN update-ca-certificates --fresh
77
ARG listen=0.0.0.0
88
ARG port=8088
9+
ARG tlskey=""
10+
ARG tlscert=""
911
ENV listen=$listen
1012
ENV port=$port
13+
ENV tlskey=$tlskey
14+
ENV tlscert=$tlscert
1115
COPY builds/linux/amd64/getsum ./
12-
CMD /app/getsum -s -l $listen -p $port -dir /tmp
16+
CMD ls -laZ && /app/getsum -s -l $listen -p $port -dir /tmp -tk ""$tlskey -tc ""$tlscert
1317
EXPOSE $port

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.0.2
1+
v2.0.3

internal/config/config.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,27 @@ package config
22

33
//config dto
44
type Config struct {
5-
File *string `json:"file"`
6-
LocalOnly *bool
7-
Proxy *string `json:"proxy"`
8-
Algorithm []string `json:"algorithm"`
9-
Cheksum *string `json:"cheksum"`
10-
RemoteOnly *bool
11-
LogLevel *string
12-
Timeout *int `json:"timeout"`
13-
All *bool `json:"all"`
14-
Key *string `json:"key"`
15-
Supplier *string `json:"supplier"`
16-
Serve *bool
17-
Listen *string
18-
Port *int
19-
Servers ServerConfigs
20-
Dir *string
21-
TLSKey *string
22-
TLSCert *string
23-
ServerConfig *string
24-
Keep *bool
5+
File *string `json:"file"`
6+
LocalOnly *bool
7+
Proxy *string `json:"proxy"`
8+
Algorithm []string `json:"algorithm"`
9+
Cheksum *string `json:"cheksum"`
10+
RemoteOnly *bool
11+
LogLevel *string
12+
Timeout *int `json:"timeout"`
13+
All *bool `json:"all"`
14+
Key *string `json:"key"`
15+
Supplier *string `json:"supplier"`
16+
Serve *bool
17+
Listen *string
18+
Port *int
19+
Servers ServerConfigs
20+
Dir *string
21+
TLSKey *string
22+
TLSCert *string
23+
ServerConfig *string
24+
Keep *bool
25+
InsecureSkipVerify *bool
2526
}
2627

2728
//this is for collecting server info from yaml files

internal/config/parser.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ func parseYaml(config *Config) error {
7676
func ParseConfig() (*Config, error) {
7777
c := new(Config)
7878
var algo *string
79+
c.InsecureSkipVerify = flag.Bool("insecureSkipVerify", false, "Skip TLS verification,will be used to reaching out to servers. If set TRUE and if remote servers are present servers also will skip verification while reaching out to file only for this process. So in case of file or server located behind custom certificate that can not be verified set this parameter true.")
80+
flag.BoolVar(c.InsecureSkipVerify, "skipVerify", false, "shorthand for -insecureSkipVerify")
7981
c.ServerConfig = flag.String("serverconfig", "", "config file location for remote servers")
8082
flag.StringVar(c.ServerConfig, "sc", "", "shorthand for -serverconfig")
8183
c.Serve = flag.Bool("serve", defaultServe, "Run in server mode default address 127.0.0.1:8088 otherwise set -listen and -port params")

internal/file/file.go

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

33
import (
4+
"crypto/tls"
45
"errors"
56
"io"
67
"io/ioutil"
@@ -35,6 +36,7 @@ type File struct {
3536
Size int64
3637
Proxy string
3738
StoragePath string
39+
SkipVerify bool
3840
}
3941

4042
//file location on local host
@@ -213,7 +215,8 @@ func getHttpClient(f *File, timeout int) *http.Client {
213215
proxyUrl = http.ProxyURL(proxy)
214216
}
215217
tr := &http.Transport{
216-
Proxy: proxyUrl,
218+
Proxy: proxyUrl,
219+
TLSClientConfig: &tls.Config{InsecureSkipVerify: f.SkipVerify},
217220
}
218221
client := &http.Client{
219222
Transport: tr,

internal/provider/providerfactory.go

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

33
import (
4+
"crypto/tls"
45
"net/http"
56
"net/url"
67
"strings"
@@ -71,7 +72,8 @@ func getHttpClient(config *Config) *http.Client {
7172
proxyUrl = http.ProxyURL(proxy)
7273
}
7374
tr := &http.Transport{
74-
Proxy: proxyUrl,
75+
Proxy: proxyUrl,
76+
TLSClientConfig: &tls.Config{InsecureSkipVerify: *config.InsecureSkipVerify},
7577
}
7678
client := &http.Client{
7779
Transport: tr,

internal/supplier/supplierfactory.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func setFields(base *BaseSupplier, algo Algorithm, config *Config) {
8686
base.File.Status = base.status
8787
base.File.Proxy = *config.Proxy
8888
base.File.StoragePath = *config.Dir
89+
base.File.SkipVerify = *config.InsecureSkipVerify
8990

9091
base.TimeOut = *config.Timeout
9192
}

tests/blackbox_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const (
2727
validDir = "-dir /tmp "
2828
keep = "-keep "
2929
serve = "-s " + validDir
30+
tlsServe = "-logLevel TRACE -tk ./server.key -tc ./server.crt " + validDir
3031

3132
MD4 = "bb137fd4893ab9d85906257ede37dfaf"
3233
MD5 = "22e38a8a7d90c088064a0bbc882a69e5"
@@ -217,6 +218,18 @@ func TestServeAlgoFail(t *testing.T) {
217218
execForError(commandStr, fileName, false, t, "you can only run single algorithm")
218219
}
219220

221+
func TestTLS(t *testing.T) {
222+
commandStr := serve + tlsServe
223+
cmd := getCommand(commandStr)
224+
err := cmd.Start()
225+
defer killServer(cmd, t)
226+
if err != nil {
227+
t.Errorf("Can not start server instance! %s", err.Error())
228+
}
229+
commandStr = "-a MD5 -sc tlsservers.yml -skipVerify " + geturl + " " + MD5
230+
execCommand(commandStr, fileName, true, t, "VALIDATED")
231+
}
232+
220233
func killServer(cmd *exec.Cmd, t *testing.T) {
221234
if cmd != nil && cmd.Process != nil {
222235
err := cmd.Process.Kill()

tests/server.crt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIICFjCCAZygAwIBAgIUMP5SAlK1s2pdtYMMPT9PybMaoR0wCgYIKoZIzj0EAwIw
3+
QjELMAkGA1UEBhMCWFgxFTATBgNVBAcMDERlZmF1bHQgQ2l0eTEcMBoGA1UECgwT
4+
RGVmYXVsdCBDb21wYW55IEx0ZDAeFw0xOTExMDQxMjQ1MzJaFw0yOTExMDExMjQ1
5+
MzJaMEIxCzAJBgNVBAYTAlhYMRUwEwYDVQQHDAxEZWZhdWx0IENpdHkxHDAaBgNV
6+
BAoME0RlZmF1bHQgQ29tcGFueSBMdGQwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAARm
7+
emzoxVgWAuBCLAHwyNZi7hdbKCZ5ZglFCLW4VhufpUg4eEK7qNsDNj6soOvTIbGL
8+
OfHF8MJm7dRuxCurLwfTD+JKm2giNMNDL9yonyNA/Dp+9YYEEJUaxZ2k6jttX2+j
9+
UzBRMB0GA1UdDgQWBBR/RaSQ6Y1RvWaC4M7BtClhq6hE1jAfBgNVHSMEGDAWgBR/
10+
RaSQ6Y1RvWaC4M7BtClhq6hE1jAPBgNVHRMBAf8EBTADAQH/MAoGCCqGSM49BAMC
11+
A2gAMGUCMCKFQ8MCrG0tdhtxNTtmXhn+pQ0kugI0JKdlcdUnOYz2G6vSIaKGGWwb
12+
JnDV856eAAIxAM/tbgFfoqBgfo0OOmqZft84svZANugQWeUt/+6/wAqRUcr1kDhj
13+
bAxQd4UfArXINg==
14+
-----END CERTIFICATE-----

tests/server.key

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-----BEGIN EC PARAMETERS-----
2+
BgUrgQQAIg==
3+
-----END EC PARAMETERS-----
4+
-----BEGIN EC PRIVATE KEY-----
5+
MIGkAgEBBDBwXz8RTNm1ZwzWc39g+7jbjVn672EofECAR47mF0LtxcSxT6p83mEm
6+
+gSS4x6fwD2gBwYFK4EEACKhZANiAARmemzoxVgWAuBCLAHwyNZi7hdbKCZ5ZglF
7+
CLW4VhufpUg4eEK7qNsDNj6soOvTIbGLOfHF8MJm7dRuxCurLwfTD+JKm2giNMND
8+
L9yonyNA/Dp+9YYEEJUaxZ2k6jttX28=
9+
-----END EC PRIVATE KEY-----

0 commit comments

Comments
 (0)