Skip to content

Commit 38861cf

Browse files
committed
demo: Catch up to plants-05
The only wire format change is a maxSerial field. In doing so, expand the JSON format a bit, because expressing log << 48 | index in decimal is unreadable. (It's a pity we can't express the index in hex with JSON but ah well.)
1 parent 3f06f9d commit 38861cf

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

demo/config.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const (
2424
VersionPlants01
2525
VersionPlants02
2626
VersionPlants04
27+
VersionPlants05
2728
)
2829

2930
func (v DraftVersion) String() string {
@@ -38,6 +39,8 @@ func (v DraftVersion) String() string {
3839
return "plants-02"
3940
case VersionPlants04:
4041
return "plants-04"
42+
case VersionPlants05:
43+
return "plants-05"
4144
}
4245
panic(fmt.Sprintf("unknown version %d", v))
4346
}
@@ -67,6 +70,8 @@ func DraftVersionFromString(s string) (v DraftVersion, ok bool) {
6770
return VersionPlants02, true
6871
case "plants-04":
6972
return VersionPlants04, true
73+
case "plants-05":
74+
return VersionPlants05, true
7075

7176
default:
7277
return 0, false
@@ -150,9 +155,14 @@ type CosignerConfig struct {
150155
PrivateKey []byte
151156
}
152157

158+
type SerialConfig struct {
159+
Log uint16
160+
Index uint64
161+
}
162+
153163
type CACertConfig struct {
154164
CertConfigBase
155-
MinSerial uint64
165+
MinSerial, MaxSerial SerialConfig
156166
}
157167

158168
type CertConfigBase struct {

demo/encode.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ func addSubject(b *cryptobyte.Builder, entry *EntryConfig) {
128128
}
129129

130130
type mtcCAInfo struct {
131+
version DraftVersion
131132
cosigner *Cosigner
132133
minSerial uint64
134+
maxSerial uint64
133135
}
134136

135137
func addExtensions(b *cryptobyte.Builder, config *CertConfigBase, mtcCA *mtcCAInfo) {
@@ -242,6 +244,9 @@ func addExtensions(b *cryptobyte.Builder, config *CertConfigBase, mtcCA *mtcCAIn
242244
}
243245
})
244246
seq.AddASN1Uint64(mtcCA.minSerial)
247+
if mtcCA.version >= VersionPlants05 {
248+
seq.AddASN1Uint64(mtcCA.maxSerial)
249+
}
245250
})
246251
})
247252
})
@@ -423,6 +428,15 @@ func CreateCACertificate(config *CAConfig, cosigner *Cosigner) ([]byte, error) {
423428
return nil, err
424429
}
425430

431+
if config.CACert.MinSerial.Index >= 1<<48 {
432+
return nil, fmt.Errorf("invalid MinSerial index")
433+
}
434+
if config.CACert.MaxSerial.Index >= 1<<48 {
435+
return nil, fmt.Errorf("invalid MinSerial index")
436+
}
437+
minSerial := (uint64(config.CACert.MinSerial.Log) << 48) | config.CACert.MinSerial.Index
438+
maxSerial := (uint64(config.CACert.MaxSerial.Log) << 48) | config.CACert.MaxSerial.Index
439+
426440
b := cryptobyte.NewBuilder(nil)
427441
b.AddASN1(cbasn1.SEQUENCE, func(cert *cryptobyte.Builder) {
428442
cert.AddASN1(cbasn1.SEQUENCE, func(tbs *cryptobyte.Builder) {
@@ -433,9 +447,12 @@ func CreateCACertificate(config *CAConfig, cosigner *Cosigner) ([]byte, error) {
433447
addValidity(tbs, &config.CACert.CertConfigBase)
434448
addX509Name(tbs, config.ID) // Subject
435449
tbs.AddBytes(spki)
450+
436451
addExtensions(tbs, &config.CACert.CertConfigBase, &mtcCAInfo{
452+
version: config.Version,
437453
cosigner: cosigner,
438-
minSerial: config.CACert.MinSerial,
454+
minSerial: minSerial,
455+
maxSerial: maxSerial,
439456
})
440457
})
441458
addUnsignedSigAlg(cert)

demo/mtc.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"Version": "plants-04",
2+
"Version": "plants-05",
33
"ID": "32473.1",
44
"LogNumber": 1,
55
"Cosigners": [
@@ -28,7 +28,9 @@
2828
"NotBefore": "2020-01-01T00:00:00Z",
2929
"NotAfter": "2030-12-31T23:59:59Z",
3030
"IsCA": true,
31-
"KeyUsage": ["CertSign"]
31+
"KeyUsage": ["CertSign"],
32+
"MinSerial": {"Log": 1, "Index": 0},
33+
"MaxSerial": {"Log": 5, "Index": 281474976710655}
3234
},
3335
"Entries": [
3436
{

0 commit comments

Comments
 (0)