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
c0c7437f
Commit
c0c7437f
authored
Aug 28, 2017
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
caddytls: Fix data race in test (close #1844)
The race was in the test only; not in the production code
parent
01f3593f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
7 deletions
+15
-7
caddytls/crypto.go
caddytls/crypto.go
+9
-4
caddytls/crypto_test.go
caddytls/crypto_test.go
+6
-3
No files found.
caddytls/crypto.go
View file @
c0c7437f
...
@@ -21,6 +21,7 @@ import (
...
@@ -21,6 +21,7 @@ import (
"net"
"net"
"os"
"os"
"path/filepath"
"path/filepath"
"sync"
"time"
"time"
"golang.org/x/crypto/ocsp"
"golang.org/x/crypto/ocsp"
...
@@ -243,8 +244,9 @@ func RotateSessionTicketKeys(cfg *tls.Config) chan struct{} {
...
@@ -243,8 +244,9 @@ func RotateSessionTicketKeys(cfg *tls.Config) chan struct{} {
// Functions that may be swapped out for testing
// Functions that may be swapped out for testing
var
(
var
(
runTLSTicketKeyRotation
=
standaloneTLSTicketKeyRotation
runTLSTicketKeyRotation
=
standaloneTLSTicketKeyRotation
setSessionTicketKeysTestHook
=
func
(
keys
[][
32
]
byte
)
[][
32
]
byte
{
return
keys
}
setSessionTicketKeysTestHook
=
func
(
keys
[][
32
]
byte
)
[][
32
]
byte
{
return
keys
}
setSessionTicketKeysTestHookMu
sync
.
Mutex
)
)
// standaloneTLSTicketKeyRotation governs over the array of TLS ticket keys used to de/crypt TLS tickets.
// standaloneTLSTicketKeyRotation governs over the array of TLS ticket keys used to de/crypt TLS tickets.
...
@@ -271,7 +273,10 @@ func standaloneTLSTicketKeyRotation(c *tls.Config, ticker *time.Ticker, exitChan
...
@@ -271,7 +273,10 @@ func standaloneTLSTicketKeyRotation(c *tls.Config, ticker *time.Ticker, exitChan
c
.
SessionTicketsDisabled
=
true
// bail if we don't have the entropy for the first one
c
.
SessionTicketsDisabled
=
true
// bail if we don't have the entropy for the first one
return
return
}
}
c
.
SetSessionTicketKeys
(
setSessionTicketKeysTestHook
(
keys
))
setSessionTicketKeysTestHookMu
.
Lock
()
setSessionTicketKeysHook
:=
setSessionTicketKeysTestHook
setSessionTicketKeysTestHookMu
.
Unlock
()
c
.
SetSessionTicketKeys
(
setSessionTicketKeysHook
(
keys
))
for
{
for
{
select
{
select
{
...
@@ -298,7 +303,7 @@ func standaloneTLSTicketKeyRotation(c *tls.Config, ticker *time.Ticker, exitChan
...
@@ -298,7 +303,7 @@ func standaloneTLSTicketKeyRotation(c *tls.Config, ticker *time.Ticker, exitChan
keys
[
0
]
=
newTicketKey
keys
[
0
]
=
newTicketKey
}
}
// pushes the last key out, doesn't matter that we don't have a new one
// pushes the last key out, doesn't matter that we don't have a new one
c
.
SetSessionTicketKeys
(
setSessionTicketKeys
Test
Hook
(
keys
))
c
.
SetSessionTicketKeys
(
setSessionTicketKeysHook
(
keys
))
}
}
}
}
}
}
...
...
caddytls/crypto_test.go
View file @
c0c7437f
...
@@ -86,17 +86,20 @@ func TestStandaloneTLSTicketKeyRotation(t *testing.T) {
...
@@ -86,17 +86,20 @@ func TestStandaloneTLSTicketKeyRotation(t *testing.T) {
tlsGovChan
:=
make
(
chan
struct
{})
tlsGovChan
:=
make
(
chan
struct
{})
defer
close
(
tlsGovChan
)
defer
close
(
tlsGovChan
)
callSync
:=
make
(
chan
*
syncPkt
,
1
)
callSync
:=
make
(
chan
syncPkt
)
defer
close
(
callSync
)
setSessionTicketKeysTestHookMu
.
Lock
()
oldHook
:=
setSessionTicketKeysTestHook
oldHook
:=
setSessionTicketKeysTestHook
defer
func
()
{
defer
func
()
{
setSessionTicketKeysTestHookMu
.
Lock
()
setSessionTicketKeysTestHook
=
oldHook
setSessionTicketKeysTestHook
=
oldHook
setSessionTicketKeysTestHookMu
.
Unlock
()
}()
}()
setSessionTicketKeysTestHook
=
func
(
keys
[][
32
]
byte
)
[][
32
]
byte
{
setSessionTicketKeysTestHook
=
func
(
keys
[][
32
]
byte
)
[][
32
]
byte
{
callSync
<-
&
syncPkt
{
keys
[
0
],
len
(
keys
)}
callSync
<-
syncPkt
{
keys
[
0
],
len
(
keys
)}
return
keys
return
keys
}
}
setSessionTicketKeysTestHookMu
.
Unlock
()
c
:=
new
(
tls
.
Config
)
c
:=
new
(
tls
.
Config
)
timer
:=
time
.
NewTicker
(
time
.
Millisecond
*
1
)
timer
:=
time
.
NewTicker
(
time
.
Millisecond
*
1
)
...
...
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