Skip to content

Commit a1f293f

Browse files
hjonghtsenart
authored andcommitted
Add support for session tickets
Closes #533 Signed-off-by: Tomás Senart <[email protected]>
1 parent 5c9d86f commit a1f293f

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ attack command:
128128
List of addresses (ip:port) to use for DNS resolution. Disables use of local system DNS. (comma separated list)
129129
-root-certs value
130130
TLS root certificate files (comma separated list)
131+
-session-tickets
132+
Enable TLS session resumption support using session tickets (default false)
131133
-targets string
132134
Targets file (default "stdin")
133135
-timeout duration
@@ -384,6 +386,10 @@ the ones configured by the operating system. Works only on non Windows systems.
384386
Specifies the trusted TLS root CAs certificate files as a comma separated
385387
list. If unspecified, the default system CAs certificates will be used.
386388

389+
#### `-session-tickets`
390+
391+
Specifies whether to support TLS session resumption using session tickets.
392+
387393
#### `-targets`
388394

389395
Specifies the file from which to read targets, defaulting to stdin.

attack.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func attackCmd() command {
5757
fs.BoolVar(&opts.keepalive, "keepalive", true, "Use persistent connections")
5858
fs.StringVar(&opts.unixSocket, "unix-socket", "", "Connect over a unix socket. This overrides the host address in target URLs")
5959
fs.Var(&dnsTTLFlag{&opts.dnsTTL}, "dns-ttl", "Cache DNS lookups for the given duration [-1 = disabled, 0 = forever]")
60+
fs.BoolVar(&opts.sessionTickets, "session-tickets", false, "Support TLS session resumption using session tickets")
6061
systemSpecificFlags(fs, opts)
6162

6263
return command{fs, func(args []string) error {
@@ -101,6 +102,7 @@ type attackOpts struct {
101102
resolvers csl
102103
unixSocket string
103104
dnsTTL time.Duration
105+
sessionTickets bool
104106
}
105107

106108
// attack validates the attack arguments, sets up the
@@ -193,6 +195,7 @@ func attack(opts *attackOpts) (err error) {
193195
vegeta.ProxyHeader(proxyHdr),
194196
vegeta.ChunkedBody(opts.chunked),
195197
vegeta.DNSCaching(opts.dnsTTL),
198+
vegeta.SessionTickets(opts.sessionTickets),
196199
)
197200

198201
res := atk.Attack(tr, opts.rate, opts.duration, opts.name)

lib/attack.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,18 @@ func UnixSocket(socket string) func(*Attacker) {
246246
}
247247
}
248248

249+
// SessionTickets returns a functional option which configures usage of session
250+
// tickets for TLS session resumption.
251+
func SessionTickets(enabled bool) func(*Attacker) {
252+
return func(a *Attacker) {
253+
if enabled {
254+
cf := a.client.Transport.(*http.Transport).TLSClientConfig
255+
cf.SessionTicketsDisabled = false
256+
cf.ClientSessionCache = tls.NewLRUClientSessionCache(0)
257+
}
258+
}
259+
}
260+
249261
// Client returns a functional option that allows you to bring your own http.Client
250262
func Client(c *http.Client) func(*Attacker) {
251263
return func(a *Attacker) { a.client = *c }

lib/attack_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ func TestAttackDuration(t *testing.T) {
6363
}
6464

6565
func TestTLSConfig(t *testing.T) {
66-
t.Parallel()
6766
atk := NewAttacker()
6867
got := atk.client.Transport.(*http.Transport).TLSClientConfig
6968
if want := (&tls.Config{InsecureSkipVerify: true}); !reflect.DeepEqual(got, want) {
@@ -164,6 +163,20 @@ func TestKeepAlive(t *testing.T) {
164163
}
165164
}
166165

166+
// This test cannot be run in parallel with TestTLSConfig() because ClientSessionCache
167+
// is designed to be called concurrently from different goroutines.
168+
func TestSessionTickets(t *testing.T) {
169+
atk := NewAttacker(SessionTickets(true))
170+
cf := atk.client.Transport.(*http.Transport).TLSClientConfig
171+
got, want := cf.SessionTicketsDisabled, false
172+
if got != want {
173+
t.Fatalf("got: %v, want: %v", got, want)
174+
}
175+
if cf.ClientSessionCache == nil {
176+
t.Fatalf("ClientSessionCache is nil")
177+
}
178+
}
179+
167180
func TestConnections(t *testing.T) {
168181
t.Parallel()
169182
atk := NewAttacker(Connections(23))

0 commit comments

Comments
 (0)