-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1084 from cuonglm/feature/remove-pre-go1.8-code
lib: support TLS 1.3 by default
- Loading branch information
Showing
14 changed files
with
368 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// +build !go1.12 | ||
|
||
/* | ||
* | ||
* k6 - a next-generation load testing tool | ||
* Copyright (C) 2019 Load Impact | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package http | ||
|
||
const expectedTLSVersion = "tls1.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// +build go1.12 | ||
|
||
/* | ||
* | ||
* k6 - a next-generation load testing tool | ||
* Copyright (C) 2019 Load Impact | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package http | ||
|
||
const expectedTLSVersion = "tls1.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// +build go1.12 | ||
|
||
/* | ||
* | ||
* k6 - a next-generation load testing tool | ||
* Copyright (C) 2019 Load Impact | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package http | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/loadimpact/k6/js/common" | ||
"github.com/loadimpact/k6/lib" | ||
"github.com/stretchr/testify/assert" | ||
null "gopkg.in/guregu/null.v3" | ||
) | ||
|
||
func TestTLS13Support(t *testing.T) { | ||
tb, state, _, rt, _ := newRuntime(t) | ||
defer tb.Cleanup() | ||
|
||
tb.Mux.HandleFunc("/tls-version", http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) { | ||
ver := req.TLS.Version | ||
fmt.Fprint(resp, lib.SupportedTLSVersionsToString[lib.TLSVersion(ver)]) | ||
})) | ||
|
||
// We don't expect any failed requests | ||
state.Options.Throw = null.BoolFrom(true) | ||
state.Options.Apply(lib.Options{TLSVersion: &lib.TLSVersions{Max: lib.TLSVersion13}}) | ||
|
||
_, err := common.RunString(rt, tb.Replacer.Replace(` | ||
let resp = http.get("HTTPSBIN_URL/tls-version"); | ||
if (resp.body != "tls1.3") { | ||
throw new Error("unexpected tls version: " + resp.body); | ||
} | ||
`)) | ||
assert.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// +build !go1.13 | ||
|
||
/* | ||
* | ||
* k6 - a next-generation load testing tool | ||
* Copyright (C) 2019 Load Impact | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package lib | ||
|
||
import ( | ||
"os" | ||
"sync" | ||
) | ||
|
||
//nolint: gochecknoglobals | ||
var once sync.Once | ||
|
||
// TLS 1.3 is available only on an opt-in basis in pre go1.13. | ||
// To enable it, set the GODEBUG environment variable to contains "tls13=1". | ||
// | ||
// Note that this function must be called before any usage of TLS. | ||
func enableTLS13() { | ||
once.Do(func() { | ||
if err := os.Setenv("GODEBUG", os.Getenv("GODEBUG")+",tls13=1"); err != nil { | ||
panic(err) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// +build go1.13 | ||
|
||
/* | ||
* | ||
* k6 - a next-generation load testing tool | ||
* Copyright (C) 2019 Load Impact | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package lib | ||
|
||
// TLS 1.3 is supported by default from go1.13, do nothing here. | ||
func enableTLS13() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// +build !go1.12 | ||
|
||
/* | ||
* | ||
* k6 - a next-generation load testing tool | ||
* Copyright (C) 2019 Load Impact | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package lib | ||
|
||
// TLSVersion13 represents tls1.3 version supports. | ||
const TLSVersion13 = 0x0304 | ||
|
||
// TLS 1.3 cipher suites. | ||
//nolint: golint | ||
const ( | ||
TLS13_CIPHER_SUITE_TLS_AES_128_GCM_SHA256 = 0x1301 | ||
TLS13_CIPHER_SUITE_TLS_AES_256_GCM_SHA384 = 0x1302 | ||
TLS13_CIPHER_SUITE_TLS_CHACHA20_POLY1305_SHA256 = 0x1303 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// +build go1.12 | ||
|
||
/* | ||
* | ||
* k6 - a next-generation load testing tool | ||
* Copyright (C) 2019 Load Impact | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package lib | ||
|
||
import "crypto/tls" | ||
|
||
// TLSVersion13 represents tls1.3 version supports. | ||
const TLSVersion13 = tls.VersionTLS13 | ||
|
||
// TLS 1.3 cipher suites. | ||
//nolint: golint | ||
const ( | ||
TLS13_CIPHER_SUITE_TLS_AES_128_GCM_SHA256 = tls.TLS_AES_128_GCM_SHA256 | ||
TLS13_CIPHER_SUITE_TLS_AES_256_GCM_SHA384 = tls.TLS_AES_256_GCM_SHA384 | ||
TLS13_CIPHER_SUITE_TLS_CHACHA20_POLY1305_SHA256 = tls.TLS_CHACHA20_POLY1305_SHA256 | ||
) |
Oops, something went wrong.