Skip to content

Commit e78602e

Browse files
authored
Mapper doesn't write for empty domains (#173)
1 parent 75544e8 commit e78602e

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

examples/ct/ct_mapper/mapper/mapper.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ type CTMapper struct {
3030

3131
func updateDomainMap(m map[string]ct_mapper.EntryList, cert x509.Certificate, index int64, isPrecert bool) {
3232
domains := make(map[string]bool)
33-
domains[cert.Subject.CommonName] = true
33+
if len(cert.Subject.CommonName) > 0 {
34+
domains[cert.Subject.CommonName] = true
35+
}
3436
for _, n := range cert.DNSNames {
35-
domains[n] = true
37+
if len(n) > 0 {
38+
domains[n] = true
39+
}
3640
}
3741

3842
for k := range domains {
@@ -42,11 +46,13 @@ func updateDomainMap(m map[string]ct_mapper.EntryList, cert x509.Certificate, in
4246
} else {
4347
el.CertIndex = append(el.CertIndex, index)
4448
}
49+
el.Domain = k
4550
m[k] = el
4651
}
4752
}
4853

4954
func (m *CTMapper) oneMapperRun() (bool, error) {
55+
start := time.Now()
5056
glog.Info("starting mapping batch")
5157
getRootReq := &trillian.GetSignedMapRootRequest{m.mapID}
5258
getRootResp, err := m.vmap.GetSignedMapRoot(context.Background(), getRootReq)
@@ -125,15 +131,22 @@ func (m *CTMapper) oneMapperRun() (bool, error) {
125131
}
126132
//glog.Info("Get resp: %v", getResp)
127133

134+
proofs := 0
128135
for _, v := range getResp.KeyValue {
129136
e := ct_mapper.EntryList{}
137+
if len(v.Inclusion) > 0 {
138+
proofs++
139+
}
130140
if err := proto.Unmarshal(v.KeyValue.Value.LeafValue, &e); err != nil {
131141
return false, err
132142
}
143+
glog.Infof("Got %#v", e)
133144
el := domains[e.Domain]
134145
proto.Merge(&el, &e)
135146
domains[e.Domain] = el
147+
glog.Infof("will update for %s", e.Domain)
136148
}
149+
glog.Infof("Got %d values, and %d proofs", len(getResp.KeyValue), proofs)
137150

138151
glog.Info("Storing updated map values for domains...")
139152
// Store updated map values:
@@ -158,6 +171,8 @@ func (m *CTMapper) oneMapperRun() (bool, error) {
158171
return false, err
159172
}
160173
glog.Infof("Set resp: %v", setResp)
174+
d := time.Now().Sub(start)
175+
glog.Infof("Map run complete, took %.1f secs to update %d values (%0.2f/s)", d.Seconds(), len(setReq.KeyValue), float64(len(setReq.KeyValue))/d.Seconds())
161176
return true, nil
162177
}
163178

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package main
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
7+
"github.com/google/certificate-transparency/go/x509"
8+
"github.com/google/certificate-transparency/go/x509/pkix"
9+
"github.com/google/trillian/examples/ct/ct_mapper"
10+
)
11+
12+
func TestUpdateDomainMap(t *testing.T) {
13+
vector := []struct {
14+
commonName string
15+
subjectNames []string
16+
index int64
17+
precert bool
18+
}{
19+
{"commonName", nil, 0, false},
20+
{"commonName", nil, 10, false},
21+
{"", []string{"commonName"}, 11, false},
22+
{"commonName", []string{"commonName"}, 12, false},
23+
{"", []string{"commonName", "commonName"}, 13, false},
24+
25+
{"anotherName", []string{"alt1", "alt2"}, 20, false},
26+
{"anotherName", []string{"alt1", "alt2"}, 21, true},
27+
{"", []string{"", ""}, 30, false},
28+
}
29+
30+
expected := map[string]ct_mapper.EntryList{
31+
"commonName": ct_mapper.EntryList{Domain: "commonName", CertIndex: []int64{0, 10, 11, 12, 13}},
32+
"anotherName": ct_mapper.EntryList{Domain: "anotherName", CertIndex: []int64{20}, PrecertIndex: []int64{21}},
33+
"alt1": ct_mapper.EntryList{Domain: "alt1", CertIndex: []int64{20}, PrecertIndex: []int64{21}},
34+
"alt2": ct_mapper.EntryList{Domain: "alt2", CertIndex: []int64{20}, PrecertIndex: []int64{21}},
35+
}
36+
37+
m := make(map[string]ct_mapper.EntryList)
38+
39+
for _, v := range vector {
40+
c := x509.Certificate{}
41+
if len(v.commonName) > 0 {
42+
c.Subject = pkix.Name{CommonName: v.commonName}
43+
}
44+
if len(v.subjectNames) > 0 {
45+
c.DNSNames = v.subjectNames
46+
}
47+
updateDomainMap(m, c, v.index, v.precert)
48+
}
49+
50+
if !reflect.DeepEqual(m, expected) {
51+
t.Fatalf("Built incorrect map:\n%#v\nexpected:\n%#v", m, expected)
52+
}
53+
}

0 commit comments

Comments
 (0)