Skip to content

Commit 3778098

Browse files
author
Freddy Zhang
committed
Use MinDistinctOperators instead of MaxSubmissionsPerOperator to reduce confusion
1 parent 8f78848 commit 3778098

File tree

6 files changed

+43
-66
lines changed

6 files changed

+43
-66
lines changed

ctpolicy/chromepolicy.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import (
2222
)
2323

2424
const (
25-
dayDuration = 86400 * time.Second // time.Duration of one day
25+
dayDuration = 86400 * time.Second // time.Duration of one day
26+
minDistinctOperators = 2 // Number of distinct CT log operators that submit an SCT
2627
)
2728

2829
// ChromeCTPolicy implements logic for complying with Chrome's CT log policy
@@ -44,20 +45,18 @@ func (chromeP ChromeCTPolicy) LogsByGroup(cert *x509.Certificate, approved *logl
4445
}
4546
groups[info.Name] = info
4647
}
47-
var incCount, maxSubmissionsPerOperator int
48+
var incCount int
4849
switch t := certLifetime(cert); {
4950
case t <= 180*dayDuration:
5051
incCount = 2
51-
maxSubmissionsPerOperator = 1
5252
default:
5353
incCount = 3
54-
maxSubmissionsPerOperator = 2
5554
}
5655
baseGroup, err := BaseGroupFor(approved, incCount)
5756
if err != nil {
5857
return nil, err
5958
}
60-
baseGroup.MaxSubmissionsPerOperator = maxSubmissionsPerOperator
59+
baseGroup.MinDistinctOperators = minDistinctOperators
6160
groups[baseGroup.Name] = baseGroup
6261
return groups, nil
6362
}

ctpolicy/chromepolicy_test.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ func wantedGroups(base int, minusBob bool) LogPolicyData {
6161
"https://ct.googleapis.com/racketeer/": true,
6262
"https://log.bob.io": true,
6363
},
64-
MinInclusions: base,
65-
IsBase: true,
64+
MinInclusions: base,
65+
MinDistinctOperators: minDistinctOperators,
66+
IsBase: true,
6667
LogWeights: map[string]float32{
6768
"https://ct.googleapis.com/logs/argon2020/": 1.0,
6869
"https://ct.googleapis.com/aviator/": 1.0,
@@ -73,12 +74,6 @@ func wantedGroups(base int, minusBob bool) LogPolicyData {
7374
},
7475
},
7576
}
76-
switch base {
77-
case 2:
78-
gi[BaseName].MaxSubmissionsPerOperator = 1
79-
case 3:
80-
gi[BaseName].MaxSubmissionsPerOperator = 2
81-
}
8277
if minusBob {
8378
delete(gi[BaseName].LogURLs, "https://log.bob.io")
8479
delete(gi[BaseName].LogWeights, "https://log.bob.io")

ctpolicy/ctpolicy.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ const (
3131

3232
// LogGroupInfo holds information on a single group of logs specified by Policy.
3333
type LogGroupInfo struct {
34-
Name string
35-
LogURLs map[string]bool // set of members
36-
MinInclusions int // Required number of submissions.
37-
MaxSubmissionsPerOperator int // Maximum number of submissions from a CT log operator.
38-
IsBase bool // True only for Log-group covering all logs.
39-
LogWeights map[string]float32 // weights used for submission, default weight is 1
40-
wMu sync.RWMutex // guards weights
34+
Name string
35+
LogURLs map[string]bool // set of members
36+
MinInclusions int // Required number of submissions.
37+
MinDistinctOperators int // Required number of distinct CT log operators that submit an SCT.
38+
IsBase bool // True only for Log-group covering all logs.
39+
LogWeights map[string]float32 // weights used for submission, default weight is 1
40+
wMu sync.RWMutex // guards weights
4141
}
4242

4343
func (group *LogGroupInfo) setMinInclusions(i int) error {

submission/distributor_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ func buildStubCTPolicy(n int) stubCTPolicy {
242242

243243
func (stubP stubCTPolicy) LogsByGroup(cert *x509.Certificate, approved *loglist3.LogList) (ctpolicy.LogPolicyData, error) {
244244
baseGroup, err := ctpolicy.BaseGroupFor(approved, stubP.baseNum)
245-
baseGroup.MaxSubmissionsPerOperator = 1
246245
groups := ctpolicy.LogPolicyData{baseGroup.Name: baseGroup}
247246
return groups, err
248247
}

submission/races.go

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ type groupState struct {
5252
// When some group is complete cancels all requests that are not needed by any
5353
// group.
5454
type safeSubmissionState struct {
55-
mu sync.Mutex
56-
logToGroups map[string]ctpolicy.GroupSet
57-
groupNeeds map[string]int // number of logs that need to be submitted for each group.
58-
maxSubmissionsPerGroup int // maximum number of logs that can be submitted to a group.
55+
mu sync.Mutex
56+
logToGroups map[string]ctpolicy.GroupSet
57+
groupNeeds map[string]int // number of logs that need to be submitted for each group.
58+
minDistinctGroups int // number of groups that need a submission
5959

60-
groups map[string]int // number of logs submitted to each group..
60+
groups map[string]bool // groups that have a stored result
6161
results map[string]*submissionResult
6262
cancels map[string]context.CancelFunc
6363
}
@@ -70,9 +70,9 @@ func newSafeSubmissionState(groups ctpolicy.LogPolicyData) *safeSubmissionState
7070
s.groupNeeds[g.Name] = g.MinInclusions
7171
}
7272
if baseGroup, ok := groups[ctpolicy.BaseName]; ok {
73-
s.maxSubmissionsPerGroup = baseGroup.MaxSubmissionsPerOperator
73+
s.minDistinctGroups = baseGroup.MinDistinctOperators
7474
}
75-
s.groups = make(map[string]int)
75+
s.groups = make(map[string]bool)
7676
s.results = make(map[string]*submissionResult)
7777
s.cancels = make(map[string]context.CancelFunc)
7878
return &s
@@ -90,10 +90,6 @@ func (sub *safeSubmissionState) request(logURL string, cancel context.CancelFunc
9090
sub.results[logURL] = &submissionResult{}
9191
isAwaited := false
9292
for g := range sub.logToGroups[logURL] {
93-
if g != ctpolicy.BaseName && sub.groups[g] < sub.maxSubmissionsPerGroup {
94-
isAwaited = true
95-
break
96-
}
9793
if sub.groupNeeds[g] > 0 {
9894
isAwaited = true
9995
break
@@ -119,21 +115,21 @@ func (sub *safeSubmissionState) setResult(logURL string, sct *ct.SignedCertifica
119115
}
120116
// group name associated with logURL outside of BaseName.
121117
// (this assumes the logURL is associated with only one group ignoring BaseName)
122-
var nonBaseGroupName string
123118
// If at least one group needs that SCT, result is set. Otherwise dumped.
124119
for groupName := range sub.logToGroups[logURL] {
125120
// Ignore the base group (All-logs) here to check separately.
126121
if groupName == ctpolicy.BaseName {
127122
continue
128123
}
129-
nonBaseGroupName = groupName
130-
if sub.groups[groupName] < sub.maxSubmissionsPerGroup {
124+
// Set the result if the group does not have a submission.
125+
if !sub.groups[groupName] {
131126
sub.results[logURL] = &submissionResult{sct: sct, err: err}
127+
sub.groups[groupName] = true
132128
}
133129
if sub.groupNeeds[groupName] > 0 {
134130
sub.results[logURL] = &submissionResult{sct: sct, err: err}
131+
sub.groups[groupName] = true
135132
}
136-
sub.groups[groupName]++
137133
sub.groupNeeds[groupName]--
138134
}
139135

@@ -143,19 +139,12 @@ func (sub *safeSubmissionState) setResult(logURL string, sct *ct.SignedCertifica
143139
// It is already processed in a non-base group, so we can reduce the groupNeeds for the base group as well.
144140
sub.groupNeeds[ctpolicy.BaseName]--
145141
} else if sub.groupNeeds[ctpolicy.BaseName] > 0 {
146-
minInclusionsForOtherGroup := 0
147-
for g, cnt := range sub.groupNeeds {
148-
if g != ctpolicy.BaseName && cnt > 0 {
149-
minInclusionsForOtherGroup += cnt
150-
}
151-
}
142+
extraSubmissions := sub.minDistinctGroups - len(sub.groups)
152143
// Set the result only if the base group still needs SCTs more than total counts
153144
// of minimum inclusions for other groups.
154-
if sub.groupNeeds[ctpolicy.BaseName] > minInclusionsForOtherGroup {
155-
if sub.groups[nonBaseGroupName] < sub.maxSubmissionsPerGroup {
156-
sub.results[logURL] = &submissionResult{sct: sct, err: err}
157-
sub.groupNeeds[ctpolicy.BaseName]--
158-
}
145+
if sub.groupNeeds[ctpolicy.BaseName] > extraSubmissions {
146+
sub.results[logURL] = &submissionResult{sct: sct, err: err}
147+
sub.groupNeeds[ctpolicy.BaseName]--
159148
}
160149
}
161150
}
@@ -165,10 +154,6 @@ func (sub *safeSubmissionState) setResult(logURL string, sct *ct.SignedCertifica
165154
for logURL, groupSet := range sub.logToGroups {
166155
isAwaited := false
167156
for g := range groupSet {
168-
if g != ctpolicy.BaseName && sub.groups[g] < sub.maxSubmissionsPerGroup {
169-
isAwaited = true
170-
break
171-
}
172157
if sub.groupNeeds[g] > 0 {
173158
isAwaited = true
174159
break
@@ -189,10 +174,8 @@ func (sub *safeSubmissionState) groupComplete(groupName string) bool {
189174
if !ok {
190175
return true
191176
}
192-
for _, submission := range sub.groups {
193-
if submission < sub.maxSubmissionsPerGroup {
194-
return false
195-
}
177+
if len(sub.groups) < sub.minDistinctGroups {
178+
return false
196179
}
197180
return needs <= 0
198181
}

submission/races_test.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ func TestGetSCTs(t *testing.T) {
136136
LogWeights: map[string]float32{"b1.com": 1.0, "b2.com": 1.0, "b3.com": 1.0, "b4.com": 1.0},
137137
},
138138
ctpolicy.BaseName: {
139-
Name: ctpolicy.BaseName,
140-
LogURLs: map[string]bool{"a1.com": true, "a2.com": true, "a3.com": true, "a4.com": true, "b1.com": true, "b2.com": true, "b3.com": true, "b4.com": true},
141-
MinInclusions: 2,
142-
MaxSubmissionsPerOperator: 1,
143-
IsBase: true,
144-
LogWeights: map[string]float32{"a1.com": 1.0, "a2.com": 1.0, "a3.com": 1.0, "a4.com": 1.0, "b1.com": 1.0, "b2.com": 1.0, "b3.com": 1.0, "b4.com": 1.0},
139+
Name: ctpolicy.BaseName,
140+
LogURLs: map[string]bool{"a1.com": true, "a2.com": true, "a3.com": true, "a4.com": true, "b1.com": true, "b2.com": true, "b3.com": true, "b4.com": true},
141+
MinInclusions: 2,
142+
MinDistinctOperators: 2,
143+
IsBase: true,
144+
LogWeights: map[string]float32{"a1.com": 1.0, "a2.com": 1.0, "a3.com": 1.0, "a4.com": 1.0, "b1.com": 1.0, "b2.com": 1.0, "b3.com": 1.0, "b4.com": 1.0},
145145
},
146146
},
147147
resultTrail: map[string]int{"a": 1, "b": 1, ctpolicy.BaseName: 2},
@@ -158,11 +158,12 @@ func TestGetSCTs(t *testing.T) {
158158
LogWeights: map[string]float32{"a1.com": 1.0, "a2.com": 1.0, "a3.com": 1.0, "a4.com": 1.0},
159159
},
160160
ctpolicy.BaseName: {
161-
Name: ctpolicy.BaseName,
162-
LogURLs: map[string]bool{"a1.com": true, "a2.com": true, "a3.com": true, "a4.com": true},
163-
MinInclusions: 2,
164-
IsBase: true,
165-
LogWeights: map[string]float32{"a1.com": 1.0, "a2.com": 1.0, "a3.com": 1.0, "a4.com": 1.0},
161+
Name: ctpolicy.BaseName,
162+
LogURLs: map[string]bool{"a1.com": true, "a2.com": true, "a3.com": true, "a4.com": true},
163+
MinInclusions: 2,
164+
MinDistinctOperators: 2,
165+
IsBase: true,
166+
LogWeights: map[string]float32{"a1.com": 1.0, "a2.com": 1.0, "a3.com": 1.0, "a4.com": 1.0},
166167
},
167168
},
168169
errRegexp: regexp.MustCompile("didn't receive enough SCTs"),

0 commit comments

Comments
 (0)