浏览代码

IMGPROXY_IGNORE_SSL_VERIFICATION option

DarthSim 6 年之前
父节点
当前提交
b9cf4a054a
共有 2 个文件被更改,包括 27 次插入11 次删除
  1. 20 11
      config.go
  2. 7 0
      download.go

+ 20 - 11
config.go

@@ -98,6 +98,8 @@ type config struct {
 
 	AllowOrigin string
 
+	IgnoreSslVerification bool
+
 	LocalFileSystemRoot string
 
 	ETagEnabled bool
@@ -106,17 +108,18 @@ type config struct {
 }
 
 var conf = config{
-	Bind:             ":8080",
-	ReadTimeout:      10,
-	WriteTimeout:     10,
-	DownloadTimeout:  5,
-	Concurrency:      runtime.NumCPU() * 2,
-	TTL:              3600,
-	MaxSrcDimension:  8192,
-	MaxSrcResolution: 16800000,
-	Quality:          80,
-	GZipCompression:  5,
-	ETagEnabled:      false,
+	Bind:                  ":8080",
+	ReadTimeout:           10,
+	WriteTimeout:          10,
+	DownloadTimeout:       5,
+	Concurrency:           runtime.NumCPU() * 2,
+	TTL:                   3600,
+	IgnoreSslVerification: false,
+	MaxSrcDimension:       8192,
+	MaxSrcResolution:      16800000,
+	Quality:               80,
+	GZipCompression:       5,
+	ETagEnabled:           false,
 }
 
 func init() {
@@ -161,6 +164,8 @@ func init() {
 
 	strEnvConfig(&conf.AllowOrigin, "IMGPROXY_ALLOW_ORIGIN")
 
+	boolEnvConfig(&conf.IgnoreSslVerification, "IMGPROXY_IGNORE_SSL_VERIFICATION")
+
 	strEnvConfig(&conf.LocalFileSystemRoot, "IMGPROXY_LOCAL_FILESYSTEM_ROOT")
 
 	boolEnvConfig(&conf.ETagEnabled, "IMGPROXY_USE_ETAG")
@@ -222,6 +227,10 @@ func init() {
 		log.Fatalf("GZip compression can't be greater than 9, now - %d\n", conf.GZipCompression)
 	}
 
+	if conf.IgnoreSslVerification {
+		log.Println("Ignoring SSL verification is very unsafe. Hope you know what you're doing")
+	}
+
 	if conf.LocalFileSystemRoot != "" {
 		stat, err := os.Stat(conf.LocalFileSystemRoot)
 		if err != nil {

+ 7 - 0
download.go

@@ -3,6 +3,7 @@ package main
 import (
 	"bufio"
 	"bytes"
+	"crypto/tls"
 	"errors"
 	"fmt"
 	"image"
@@ -59,9 +60,15 @@ func initDownloading() {
 	transport := &http.Transport{
 		Proxy: http.ProxyFromEnvironment,
 	}
+
+	if conf.IgnoreSslVerification {
+		transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
+	}
+
 	if conf.LocalFileSystemRoot != "" {
 		transport.RegisterProtocol("local", http.NewFileTransport(http.Dir(conf.LocalFileSystemRoot)))
 	}
+
 	downloadClient = &http.Client{
 		Timeout:   time.Duration(conf.DownloadTimeout) * time.Second,
 		Transport: transport,