Skip to content

Commit 14b2e02

Browse files
authored
feat: add missing is-confidentiality-protected operational flag (#228)
This commit adds the missing 'is-confidentiality-protected' flag to the FlagsMap structure, completing the implementation to match the latest IETF CoRIM specification. The flag is positioned at CBOR index 9 and JSON field 'is-confidentiality-protected' as specified in the IETF draft-ietf-rats-corim specification. Fixes #44 Signed-off-by: Kallal Mukherjee <[email protected]>
1 parent c6f31b5 commit 14b2e02

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

comid/flagsmap.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const (
2828
FlagIsRuntimeMeasured
2929
FlagIsImmutable
3030
FlagIsTcb
31+
FlagIsConfidentialityProtected
3132
)
3233

3334
// FlagsMap describes a number of boolean operational modes. If a value is nil,
@@ -60,6 +61,10 @@ type FlagsMap struct {
6061
// IsTcb indicates whether the measured environment is a trusted
6162
// computing base.
6263
IsTcb *bool `cbor:"8,keyasint,omitempty" json:"is-tcb,omitempty"`
64+
// IsConfidentialityProtected indicates whether the measured environment
65+
// is confidentiality protected. For example, if the measured environment consists of memory,
66+
// the sensitive values in memory are encrypted.
67+
IsConfidentialityProtected *bool `cbor:"9,keyasint,omitempty" json:"is-confidentiality-protected,omitempty"`
6368

6469
Extensions
6570
}
@@ -72,7 +77,8 @@ func NewFlagsMap() *FlagsMap {
7277
func (o FlagsMap) IsEmpty() bool {
7378
if o.IsConfigured != nil || o.IsSecure != nil || o.IsRecovery != nil ||
7479
o.IsDebug != nil || o.IsReplayProtected != nil || o.IsIntegrityProtected != nil ||
75-
o.IsRuntimeMeasured != nil || o.IsImmutable != nil || o.IsTcb != nil {
80+
o.IsRuntimeMeasured != nil || o.IsImmutable != nil || o.IsTcb != nil ||
81+
o.IsConfidentialityProtected != nil {
7682
return false
7783
}
7884

@@ -82,7 +88,8 @@ func (o FlagsMap) IsEmpty() bool {
8288
func (o *FlagsMap) AnySet() bool {
8389
if o.IsConfigured != nil || o.IsSecure != nil || o.IsRecovery != nil || o.IsDebug != nil ||
8490
o.IsReplayProtected != nil || o.IsIntegrityProtected != nil ||
85-
o.IsRuntimeMeasured != nil || o.IsImmutable != nil || o.IsTcb != nil {
91+
o.IsRuntimeMeasured != nil || o.IsImmutable != nil || o.IsTcb != nil ||
92+
o.IsConfidentialityProtected != nil {
8693
return true
8794
}
8895

@@ -110,6 +117,8 @@ func (o *FlagsMap) setFlag(value *bool, flags ...Flag) {
110117
o.IsImmutable = value
111118
case FlagIsTcb:
112119
o.IsTcb = value
120+
case FlagIsConfidentialityProtected:
121+
o.IsConfidentialityProtected = value
113122
default:
114123
if value == &True {
115124
o.setTrue(flag)
@@ -149,6 +158,8 @@ func (o *FlagsMap) Clear(flags ...Flag) {
149158
o.IsImmutable = nil
150159
case FlagIsTcb:
151160
o.IsTcb = nil
161+
case FlagIsConfidentialityProtected:
162+
o.IsConfidentialityProtected = nil
152163
default:
153164
o.clear(flag)
154165
}
@@ -175,6 +186,8 @@ func (o *FlagsMap) Get(flag Flag) *bool {
175186
return o.IsImmutable
176187
case FlagIsTcb:
177188
return o.IsTcb
189+
case FlagIsConfidentialityProtected:
190+
return o.IsConfidentialityProtected
178191
default:
179192
return o.get(flag)
180193
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2025 Contributors to the Veraison project.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package comid
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func Test_FlagsMap_IsConfidentialityProtected(t *testing.T) {
13+
fm := NewFlagsMap()
14+
15+
// Test initial state - should be nil (unset)
16+
assert.Nil(t, fm.Get(FlagIsConfidentialityProtected))
17+
assert.False(t, fm.AnySet())
18+
19+
// Test setting to true
20+
fm.SetTrue(FlagIsConfidentialityProtected)
21+
assert.True(t, fm.AnySet())
22+
assert.Equal(t, true, *fm.Get(FlagIsConfidentialityProtected))
23+
24+
// Test setting to false
25+
fm.SetFalse(FlagIsConfidentialityProtected)
26+
assert.True(t, fm.AnySet())
27+
assert.Equal(t, false, *fm.Get(FlagIsConfidentialityProtected))
28+
29+
// Test clearing
30+
fm.Clear(FlagIsConfidentialityProtected)
31+
assert.False(t, fm.AnySet())
32+
assert.Nil(t, fm.Get(FlagIsConfidentialityProtected))
33+
}
34+
35+
func Test_FlagsMap_IsConfidentialityProtected_Serialization(t *testing.T) {
36+
fm := NewFlagsMap()
37+
fm.SetTrue(FlagIsConfidentialityProtected)
38+
39+
// Test CBOR serialization
40+
cbor, err := fm.MarshalCBOR()
41+
assert.NoError(t, err)
42+
assert.NotNil(t, cbor)
43+
44+
var fm2 FlagsMap
45+
err = fm2.UnmarshalCBOR(cbor)
46+
assert.NoError(t, err)
47+
assert.Equal(t, true, *fm2.Get(FlagIsConfidentialityProtected))
48+
49+
// Test JSON serialization
50+
json, err := fm.MarshalJSON()
51+
assert.NoError(t, err)
52+
assert.NotNil(t, json)
53+
assert.Contains(t, string(json), "is-confidentiality-protected")
54+
55+
var fm3 FlagsMap
56+
err = fm3.UnmarshalJSON(json)
57+
assert.NoError(t, err)
58+
assert.Equal(t, true, *fm3.Get(FlagIsConfidentialityProtected))
59+
}

comid/flagsmap_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func Test_FlagsMap(t *testing.T) {
2222
FlagIsRuntimeMeasured,
2323
FlagIsImmutable,
2424
FlagIsTcb,
25+
FlagIsConfidentialityProtected,
2526
} {
2627
fm.SetTrue(flag)
2728
assert.True(t, fm.AnySet())

0 commit comments

Comments
 (0)