Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
e1ea58b7
Commit
e1ea58b7
authored
Oct 03, 2016
by
elcore
Committed by
Matt Holt
Oct 03, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Customize curve preferences, closes #1117 (#1159)
* Feature Request: #1117 * The order of the curves matter
parent
e9ce45ce
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
0 deletions
+65
-0
caddytls/config.go
caddytls/config.go
+20
-0
caddytls/setup.go
caddytls/setup.go
+8
-0
caddytls/setup_test.go
caddytls/setup_test.go
+37
-0
No files found.
caddytls/config.go
View file @
e1ea58b7
...
...
@@ -35,6 +35,9 @@ type Config struct {
// Whether to prefer server cipher suites
PreferServerCipherSuites
bool
// The list of preferred curves
CurvePreferences
[]
tls
.
CurveID
// Client authentication policy
ClientAuth
tls
.
ClientAuthType
...
...
@@ -220,6 +223,7 @@ func MakeTLSConfig(configs []*Config) (*tls.Config, error) {
config
:=
new
(
tls
.
Config
)
ciphersAdded
:=
make
(
map
[
uint16
]
struct
{})
curvesAdded
:=
make
(
map
[
tls
.
CurveID
]
struct
{})
configMap
:=
make
(
configGroup
)
for
i
,
cfg
:=
range
configs
{
...
...
@@ -264,6 +268,14 @@ func MakeTLSConfig(configs []*Config) (*tls.Config, error) {
}
config
.
PreferServerCipherSuites
=
cfg
.
PreferServerCipherSuites
// Union curves
for
_
,
curv
:=
range
cfg
.
CurvePreferences
{
if
_
,
ok
:=
curvesAdded
[
curv
];
!
ok
{
curvesAdded
[
curv
]
=
struct
{}{}
config
.
CurvePreferences
=
append
(
config
.
CurvePreferences
,
curv
)
}
}
// Go with the widest range of protocol versions
if
config
.
MinVersion
==
0
||
cfg
.
ProtocolMinVersion
<
config
.
MinVersion
{
config
.
MinVersion
=
cfg
.
ProtocolMinVersion
...
...
@@ -441,6 +453,14 @@ var defaultCiphers = []uint16{
tls
.
TLS_RSA_WITH_AES_128_CBC_SHA
,
}
// Map of supported curves
// https://golang.org/pkg/crypto/tls/#CurveID
var
supportedCurvesMap
=
map
[
string
]
tls
.
CurveID
{
"P256"
:
tls
.
CurveP256
,
"P384"
:
tls
.
CurveP384
,
"P521"
:
tls
.
CurveP521
,
}
const
(
// HTTPChallengePort is the officially designated port for
// the HTTP challenge.
...
...
caddytls/setup.go
View file @
e1ea58b7
...
...
@@ -105,6 +105,14 @@ func setupTLS(c *caddy.Controller) error {
}
config
.
Ciphers
=
append
(
config
.
Ciphers
,
value
)
}
case
"curves"
:
for
c
.
NextArg
()
{
value
,
ok
:=
supportedCurvesMap
[
strings
.
ToUpper
(
c
.
Val
())]
if
!
ok
{
return
c
.
Errf
(
"Wrong curve name or curve not supported: '%s'"
,
c
.
Val
())
}
config
.
CurvePreferences
=
append
(
config
.
CurvePreferences
,
value
)
}
case
"clients"
:
clientCertList
:=
c
.
RemainingArgs
()
if
len
(
clientCertList
)
==
0
{
...
...
caddytls/setup_test.go
View file @
e1ea58b7
...
...
@@ -179,6 +179,18 @@ func TestSetupParseWithWrongOptionalParams(t *testing.T) {
if
err
==
nil
{
t
.
Errorf
(
"Expected errors, but no error returned"
)
}
// Test curves wrong params
params
=
`tls {
curves ab123, cd456, ef789
}`
cfg
=
new
(
Config
)
RegisterConfigGetter
(
""
,
func
(
c
*
caddy
.
Controller
)
*
Config
{
return
cfg
})
c
=
caddy
.
NewTestController
(
""
,
params
)
err
=
setupTLS
(
c
)
if
err
==
nil
{
t
.
Errorf
(
"Expected errors, but no error returned"
)
}
}
func
TestSetupParseWithClientAuth
(
t
*
testing
.
T
)
{
...
...
@@ -269,6 +281,31 @@ func TestSetupParseWithKeyType(t *testing.T) {
}
}
func
TestSetupParseWithCurves
(
t
*
testing
.
T
)
{
params
:=
`tls {
curves p256 p384 p521
}`
cfg
:=
new
(
Config
)
RegisterConfigGetter
(
""
,
func
(
c
*
caddy
.
Controller
)
*
Config
{
return
cfg
})
c
:=
caddy
.
NewTestController
(
""
,
params
)
err
:=
setupTLS
(
c
)
if
err
!=
nil
{
t
.
Errorf
(
"Expected no errors, got: %v"
,
err
)
}
if
len
(
cfg
.
CurvePreferences
)
!=
3
{
t
.
Errorf
(
"Expected 3 curves, got %v"
,
len
(
cfg
.
CurvePreferences
))
}
expectedCurveOrder
:=
[]
tls
.
CurveID
{
tls
.
CurveP256
,
tls
.
CurveP384
,
tls
.
CurveP521
}
for
i
:=
range
cfg
.
CurvePreferences
{
if
cfg
.
CurvePreferences
[
i
]
!=
expectedCurveOrder
[
i
]
{
t
.
Errorf
(
"Expected %v as curve, got %v"
,
expectedCurveOrder
[
i
],
cfg
.
CurvePreferences
[
i
])
}
}
}
func
TestSetupParseWithOneTLSProtocol
(
t
*
testing
.
T
)
{
params
:=
`tls {
protocols tls1.2
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment