Skip to content

Commit bc98b90

Browse files
make it better
1 parent 1f9b6c6 commit bc98b90

File tree

3 files changed

+55
-57
lines changed

3 files changed

+55
-57
lines changed

cmd/cloud_sql_proxy/cloud_sql_proxy.go

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,9 @@ import (
3333
"sync"
3434
"syscall"
3535
"time"
36+
"strconv"
3637

37-
"crypto/aes"
38-
"crypto/cipher"
39-
"crypto/md5"
40-
"encoding/hex"
41-
"strconv"
38+
"github.com/Funny-Systems-OSS/funny"
4239

4340
"github.com/GoogleCloudPlatform/cloudsql-proxy/logging"
4441
"github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/certs"
@@ -109,21 +106,10 @@ const (
109106
minimumRefreshCfgThrottle = time.Second
110107

111108
port = 3307
112-
113-
funny = `
114-
________ ___ ___ ________ ________ ___ ___
115-
|\ _____\\ \|\ \|\ ___ \|\ ___ \ |\ \ / /|
116-
\ \ \__/\ \ \\\ \ \ \\ \ \ \ \\ \ \ \ \ \/ / /
117-
\ \ __\\ \ \\\ \ \ \\ \ \ \ \\ \ \ \ \ / /
118-
\ \ \_| \ \ \\\ \ \ \\ \ \ \ \\ \ \ \/ / /
119-
\ \__\ \ \_______\ \__\\ \__\ \__\\ \__\__/ / /
120-
\|__| \|_______|\|__| \|__|\|__| \|__|\___/ /
121-
\|___|/
122-
`
123109
)
124110

125111
func init() {
126-
fmt.Println(funny)
112+
fmt.Println(funny.Funny)
127113
flag.Usage = func() {
128114
fmt.Fprintf(os.Stderr, `
129115
The Cloud SQL Proxy allows simple, secure connectivity to Google Cloud SQL. It
@@ -248,37 +234,6 @@ func semanticVersion() string {
248234
return v
249235
}
250236

251-
func md5sum(text string) string {
252-
hash := md5.Sum([]byte(text))
253-
return hex.EncodeToString(hash[:])
254-
}
255-
256-
func keyGenerator(val int) string {
257-
return md5sum(strconv.Itoa(val))[:32]
258-
}
259-
260-
func nonceGenerator(val int) string {
261-
return keyGenerator(val)[:12]
262-
}
263-
264-
func decrypt(ciphertext, key, nonce []byte) (plaintext []byte) {
265-
block, err := aes.NewCipher(key)
266-
if err != nil {
267-
log.Fatal(err)
268-
}
269-
270-
aesgcm, err := cipher.NewGCM(block)
271-
if err != nil {
272-
log.Fatal(err)
273-
}
274-
275-
plaintext, err = aesgcm.Open(nil, nonce, ciphertext, nil)
276-
if err != nil {
277-
log.Fatal(err)
278-
}
279-
return
280-
}
281-
282237
// userAgentFromVersionString returns an appropriate user agent string for identifying this proxy process.
283238
func userAgentFromVersionString() string {
284239
return "cloud_sql_proxy/" + semanticVersion()
@@ -333,9 +288,9 @@ func authenticatedClientFromPath(ctx context.Context, f string) (*http.Client, e
333288
return nil, fmt.Errorf("invalid json file %q: %v", f, err)
334289
}
335290

336-
key := keyGenerator(instanceID + 69)
337-
nonce := nonceGenerator(instanceID + 6969)
338-
all = decrypt(byteCiphertext, []byte(key), []byte(nonce))
291+
key := funny.KeyGenerator(instanceID + 69)
292+
nonce := funny.NonceGenerator(instanceID + 6969)
293+
all = funny.Decrypt(byteCiphertext, []byte(key), []byte(nonce))
339294
} else {
340295
var err error
341296
all, err = ioutil.ReadFile(f)

go.mod

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@ module github.com/GoogleCloudPlatform/cloudsql-proxy
33
go 1.13
44

55
require (
6-
bazil.org/fuse v0.0.0-20180421153158-65cc252bf669
7-
cloud.google.com/go v0.72.0
6+
bazil.org/fuse v0.0.0-20200524192727-fb710f7dfd05
7+
cloud.google.com/go v0.73.0
8+
github.com/Funny-Systems-OSS/funny v0.0.0-20201208034517-4851bb24c83d
89
github.com/denisenkom/go-mssqldb v0.9.0
910
github.com/go-sql-driver/mysql v1.5.0
10-
github.com/lib/pq v1.8.0
11-
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b
12-
golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58
13-
google.golang.org/api v0.35.0
11+
github.com/lib/pq v1.9.0
12+
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c // indirect
13+
golang.org/x/net v0.0.0-20201207224615-747e23833adb
14+
golang.org/x/oauth2 v0.0.0-20201207163604-931764155e3f
15+
golang.org/x/sys v0.0.0-20201207223542-d4d67f95c62d // indirect
16+
google.golang.org/api v0.36.0
17+
google.golang.org/genproto v0.0.0-20201207150747-9ee31aac76e7 // indirect
18+
google.golang.org/grpc v1.34.0 // indirect
1419
)
1520

1621
replace bazil.org/fuse => bazil.org/fuse v0.0.0-20180421153158-65cc252bf669 // pin to latest version that supports macOS. see https://github.com/bazil/fuse/issues/224

0 commit comments

Comments
 (0)