Skip to content

Commit 46a0fc8

Browse files
committed
Web server is running over TLS to protect imported data.
1 parent de92a33 commit 46a0fc8

File tree

6 files changed

+43
-5
lines changed

6 files changed

+43
-5
lines changed

cmd/go-graphkb/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
port: 8090
2+
tls_key: keys/server.key
3+
tls_cert: keys/server.crt
24

35
mariadb:
46
username: graphkb

cmd/go-graphkb/keys/server.crt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIICNDCCAbqgAwIBAgIUSmERk1D8uB791zb2aJZGwQl1okswCgYIKoZIzj0EAwIw
3+
UTELMAkGA1UEBhMCVVMxDTALBgNVBAgMBE9oaW8xITAfBgNVBAoMGEludGVybmV0
4+
IFdpZGdpdHMgUHR5IEx0ZDEQMA4GA1UEAwwHZ3JhcGhrYjAeFw0yMDAxMDgyMzIw
5+
MzFaFw0zMDAxMDUyMzIwMzFaMFExCzAJBgNVBAYTAlVTMQ0wCwYDVQQIDARPaGlv
6+
MSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxEDAOBgNVBAMMB2dy
7+
YXBoa2IwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAATBjcX+Dcg1Ls03AHAlddFpSVIF
8+
d6LNo44r1baCTwd2n/6KBdjcia2UHtMf+6qVsmsq53Jb2tpaq9u7WZg+yOLSzY8x
9+
+8Sir6XuroyDXdOrxkoDDSzseB2xzAsCodw3+Z6jUzBRMB0GA1UdDgQWBBRyX37c
10+
14nGLtJzIhHJsvqC4Hxr6TAfBgNVHSMEGDAWgBRyX37c14nGLtJzIhHJsvqC4Hxr
11+
6TAPBgNVHRMBAf8EBTADAQH/MAoGCCqGSM49BAMCA2gAMGUCMQD/LkIPAOWaeups
12+
J3EEnV9e93OQ4sSze1gmWooJEDMoF/at4yjZ4RiDeQeyFPXgQeUCMGVkuIWgxQMZ
13+
DK8nTIDVUhczH289kLRVt7ZqCx0Zyi8yfRkUW4t6MAd00p7czQt+pw==
14+
-----END CERTIFICATE-----

cmd/go-graphkb/keys/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+
MIGkAgEBBDBaSW8z5Km2GRlJEDftOgmFMlbpOuVHJTbKMNhrgedbQUs0OrQ3Nrk+
6+
xDp9GENurB2gBwYFK4EEACKhZANiAATBjcX+Dcg1Ls03AHAlddFpSVIFd6LNo44r
7+
1baCTwd2n/6KBdjcia2UHtMf+6qVsmsq53Jb2tpaq9u7WZg+yOLSzY8x+8Sir6Xu
8+
royDXdOrxkoDDSzseB2xzAsCodw3+Z4=
9+
-----END EC PRIVATE KEY-----

cmd/importer-csv/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
graphkb:
2-
url: "http://localhost:8090"
2+
url: "https://localhost:8090"
33
auth_token: "token_auth_for_csv_importer"
4+
skip_verify: true
45

56
path: "../../examples/example-data.csv"

internal/knowledge/graph_api.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,36 @@ package knowledge
22

33
import (
44
"bytes"
5+
"crypto/tls"
56
"encoding/json"
67
"fmt"
7-
"github.com/clems4ever/go-graphkb/internal/schema"
88
"io/ioutil"
99
"net/http"
10+
11+
"github.com/clems4ever/go-graphkb/internal/schema"
12+
"github.com/spf13/viper"
1013
)
1114

1215
// GraphEmitter an emitter of full source graph
1316
type GraphAPI struct {
1417
// GraphKB URL and auth token
1518
url string
1619
authToken string
20+
21+
client *http.Client
1722
}
1823

1924
// NewGraphEmitter create an emitter of graph
2025
func NewGraphAPI(url string, authToken string) *GraphAPI {
26+
tr := &http.Transport{
27+
TLSClientConfig: &tls.Config{InsecureSkipVerify: viper.GetBool("graphkb.skip_verify")},
28+
}
29+
client := &http.Client{Transport: tr}
30+
2131
return &GraphAPI{
2232
url: url,
2333
authToken: authToken,
34+
client: client,
2435
}
2536
}
2637

@@ -33,7 +44,7 @@ func (gapi *GraphAPI) ReadCurrentGraph() (*Graph, error) {
3344
return nil, err
3445
}
3546

36-
res, err := http.DefaultClient.Do(req)
47+
res, err := gapi.client.Do(req)
3748
if err != nil {
3849
return nil, err
3950
}
@@ -72,7 +83,7 @@ func (gapi *GraphAPI) UpdateGraph(sg schema.SchemaGraph, updates GraphUpdatesBul
7283
return err
7384
}
7485

75-
res, err := http.DefaultClient.Do(req)
86+
res, err := gapi.client.Do(req)
7687
if err != nil {
7788
return err
7889
}

internal/server/server.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ func StartServer(database knowledge.GraphDB, schemaPersistor schema.Persistor,
364364
bindInterface := fmt.Sprintf(":%d", viper.GetInt32("port"))
365365
fmt.Printf("Listening on %s\n", bindInterface)
366366

367-
err := http.ListenAndServe(bindInterface, r)
367+
err := http.ListenAndServeTLS(bindInterface, viper.GetString("tls_cert"),
368+
viper.GetString("tls_key"), r)
368369
if err != nil {
369370
log.Fatal(err)
370371
}

0 commit comments

Comments
 (0)