Skip to content

Commit ccac781

Browse files
authored
Merge pull request #572 from zigbee-alliance/improvements
improvements #566 #570
2 parents dd98906 + 034c07c commit ccac781

15 files changed

+330
-149
lines changed

docs/transactions.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ and DACs (leaf certificates) added to DCL if they are revoked in the CRL identif
10341034
- dataDigest: `optional(string)` - Digest of the entire contents of the associated file downloaded from the DataUrl. Must be omitted if RevocationType is 1. Must be provided if and only if the `DataFileSize` field is present.
10351035
- dataDigestType: `optional(uint32)` - The type of digest used in the DataDigest field from the list of [1, 7, 8, 10, 11, 12] (IANA Named Information Hash Algorithm Registry). Must be provided if and only if the `DataDigest` field is present.
10361036
- revocationType: `uint32` - The type of file found at the DataUrl for this entry. Supported types: 1 - RFC5280 Certificate Revocation List (CRL).
1037-
- schemaVersion: `optional(uint16)` - Schema version to support backward/forward compatability(default 0)
1037+
- schemaVersion: `optional(uint16)` - Schema version to support backward/forward compatibility (default is 1, the minimum value should be greater than or equal to 1)
10381038
- In State:
10391039
- `pki/RevocationDistributionPoint/value/<IssuerSubjectKeyID>` -> list of Revocation Distribution Points
10401040
- `pki/RevocationDistributionPoint/value/<IssuerSubjectKeyID>/<vid>/<label>`-> Revocation Distribution Point
@@ -1062,7 +1062,7 @@ Updates an existing PKI Revocation distribution endpoint (such as RFC5280 Certif
10621062
- dataFileSize: `optional(uint64)` - Total size in bytes of the file found at the DataUrl. Must be omitted if RevocationType is 1.
10631063
- dataDigest: `optional(string)` - Digest of the entire contents of the associated file downloaded from the DataUrl. Must be omitted if RevocationType is 1. Must be provided if and only if the `DataFileSize` field is present.
10641064
- dataDigestType: `optional(uint32)` - The type of digest used in the DataDigest field from the list of [1, 7, 8, 10, 11, 12] (IANA Named Information Hash Algorithm Registry). Must be provided if and only if the `DataDigest` field is present.
1065-
- schemaVersion: `optional(uint16)` - Schema version to support backward/forward compatability(default 0)
1065+
- schemaVersion: `optional(uint16)` - Schema version to support backward/forward compatibility (default is 1, the minimum value should be greater than or equal to 1)
10661066
- In State:
10671067
- `pki/RevocationDistributionPoint/value/<IssuerSubjectKeyID>` -> list of Revocation Distribution Points
10681068
- `pki/RevocationDistributionPoint/value/<IssuerSubjectKeyID>/<vid>/<label>` -> Revocation Distribution Point

integration_tests/cli/model-validation-cases.sh

+9-9
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ test_divider
312312
# Update the model version with few mutable fields and make sure all other fields are still the same
313313
echo "Update Device Model Version with few mutable fields and make sure all other fields are still the same for VID: $vid_1 PID: $pid_1 SV: $sv_1"
314314
result=$(echo "test1234" | dcld tx model update-model-version --vid=$vid_1 --pid=$pid_1 --softwareVersion=$sv_1 --softwareVersionValid=true \
315-
--releaseNotesURL="https://release.url.info" --otaURL="https://ota.url.com" --otaFileSize=123 --otaChecksum="123123123" --minApplicableSoftwareVersion=2 --maxApplicableSoftwareVersion=20 --from=$vendor_account_1 --yes)
315+
--releaseNotesURL="https://release.url.info" --otaURL="https://ota.url.com" --otaFileSize=123 --otaChecksum="SGVsbG8gbmV3IHdvcmxkIQ==" --minApplicableSoftwareVersion=2 --maxApplicableSoftwareVersion=20 --from=$vendor_account_1 --yes)
316316
result=$(get_txn_result "$result")
317317
check_response_and_report "$result" "\"code\": 0"
318318

@@ -330,7 +330,7 @@ check_response_and_report "$result" "\"cdVersionNumber\": 1"
330330
check_response_and_report "$result" "\"softwareVersionValid\": true"
331331
check_response_and_report "$result" "\"otaUrl\": \"https://ota.url.com\""
332332
check_response_and_report "$result" "\"otaFileSize\": \"123\""
333-
check_response_and_report "$result" "\"otaChecksum\": \"123123123\""
333+
check_response_and_report "$result" "\"otaChecksum\": \"SGVsbG8gbmV3IHdvcmxkIQ==\""
334334
check_response_and_report "$result" "\"minApplicableSoftwareVersion\": 2"
335335
check_response_and_report "$result" "\"maxApplicableSoftwareVersion\": 20"
336336
check_response_and_report "$result" "\"releaseNotesUrl\": \"https://release.url.info\""
@@ -343,7 +343,7 @@ result=$(echo 'test1234' | dcld tx model add-model-version --vid=$vid_1 --pid=$p
343343
--softwareVersionString="1.0" --cdVersionNumber=21334 \
344344
--firmwareInformation="123456789012345678901234567890123456789012345678901234567890123" \
345345
--softwareVersionValid=true --otaURL="https://ota.url.info" --otaFileSize=123456789 \
346-
--otaChecksum="123456789012345678901234567890123456789012345678901234567890123" --releaseNotesURL="https://release.notes.url.info" \
346+
--otaChecksum="SGVsbG8gd29ybGQh" --releaseNotesURL="https://release.notes.url.info" \
347347
--otaChecksumType=1 --maxApplicableSoftwareVersion=32 --minApplicableSoftwareVersion=5 --from=$vendor_account_1 --yes)
348348
result=$(get_txn_result "$result")
349349
echo "$result"
@@ -364,7 +364,7 @@ check_response_and_report "$result" "\"firmwareInformation\": \"1234567890123456
364364
check_response_and_report "$result" "\"softwareVersionValid\": true"
365365
check_response_and_report "$result" "\"otaUrl\": \"https://ota.url.info\""
366366
check_response_and_report "$result" "\"otaFileSize\": \"123456789\""
367-
check_response_and_report "$result" "\"otaChecksum\": \"123456789012345678901234567890123456789012345678901234567890123\""
367+
check_response_and_report "$result" "\"otaChecksum\": \"SGVsbG8gd29ybGQh\""
368368
check_response_and_report "$result" "\"otaChecksumType\": 1"
369369
check_response_and_report "$result" "\"releaseNotesUrl\": \"https://release.notes.url.info\""
370370
check_response_and_report "$result" "\"maxApplicableSoftwareVersion\": 32"
@@ -393,7 +393,7 @@ check_response_and_report "$result" "\"firmwareInformation\": \"1234567890123456
393393
check_response_and_report "$result" "\"softwareVersionValid\": true"
394394
check_response_and_report "$result" "\"otaUrl\": \"https://ota.url.info\""
395395
check_response_and_report "$result" "\"otaFileSize\": \"123456789\""
396-
check_response_and_report "$result" "\"otaChecksum\": \"123456789012345678901234567890123456789012345678901234567890123\""
396+
check_response_and_report "$result" "\"otaChecksum\": \"SGVsbG8gd29ybGQh\""
397397
check_response_and_report "$result" "\"otaChecksumType\": 1"
398398
check_response_and_report "$result" "\"releaseNotesUrl\": \"https://release.notes.url.info\""
399399
check_response_and_report "$result" "\"maxApplicableSoftwareVersion\": 32"
@@ -422,7 +422,7 @@ check_response_and_report "$result" "\"firmwareInformation\": \"1234567890123456
422422
check_response_and_report "$result" "\"softwareVersionValid\": false"
423423
check_response_and_report "$result" "\"otaUrl\": \"https://ota.url.info\""
424424
check_response_and_report "$result" "\"otaFileSize\": \"123456789\""
425-
check_response_and_report "$result" "\"otaChecksum\": \"123456789012345678901234567890123456789012345678901234567890123\""
425+
check_response_and_report "$result" "\"otaChecksum\": \"SGVsbG8gd29ybGQh\""
426426
check_response_and_report "$result" "\"otaChecksumType\": 1"
427427
check_response_and_report "$result" "\"releaseNotesUrl\": \"https://release.notes.url.info\""
428428
check_response_and_report "$result" "\"maxApplicableSoftwareVersion\": 32"
@@ -453,7 +453,7 @@ check_response_and_report "$result" "\"firmwareInformation\": \"1234567890123456
453453
check_response_and_report "$result" "\"softwareVersionValid\": true"
454454
check_response_and_report "$result" "\"otaUrl\": \"https://updated.ota.url.info\""
455455
check_response_and_report "$result" "\"otaFileSize\": \"123456789\""
456-
check_response_and_report "$result" "\"otaChecksum\": \"123456789012345678901234567890123456789012345678901234567890123\""
456+
check_response_and_report "$result" "\"otaChecksum\": \"SGVsbG8gd29ybGQh\""
457457
check_response_and_report "$result" "\"otaChecksumType\": 1"
458458
check_response_and_report "$result" "\"releaseNotesUrl\": \"https://updated.release.notes.url.info\""
459459
check_response_and_report "$result" "\"maxApplicableSoftwareVersion\": 25"
@@ -465,7 +465,7 @@ result=$(echo 'test1234' | dcld tx model add-model-version --vid=$vid_1 --pid=$p
465465
--softwareVersionString="1.0" --cdVersionNumber=21334 \
466466
--firmwareInformation="123456789012345678901234567890123456789012345678901234567890123" \
467467
--softwareVersionValid=true --otaURL="https://ota.url.info" --otaFileSize=123456789 \
468-
--otaChecksum="123456789012345678901234567890123456789012345678901234567890123" \
468+
--otaChecksum="SGVsbG8gd29ybGQh" \
469469
--otaChecksumType=1 --maxApplicableSoftwareVersion=32 --minApplicableSoftwareVersion=5 --from=$vendor_account_1 --yes)
470470
result=$(get_txn_result "$result")
471471
echo "$result"
@@ -486,7 +486,7 @@ check_response_and_report "$result" "\"firmwareInformation\": \"1234567890123456
486486
check_response_and_report "$result" "\"softwareVersionValid\": true"
487487
check_response_and_report "$result" "\"otaUrl\": \"https://ota.url.info\""
488488
check_response_and_report "$result" "\"otaFileSize\": \"123456789\""
489-
check_response_and_report "$result" "\"otaChecksum\": \"123456789012345678901234567890123456789012345678901234567890123\""
489+
check_response_and_report "$result" "\"otaChecksum\": \"SGVsbG8gd29ybGQh\""
490490
check_response_and_report "$result" "\"otaChecksumType\": 1"
491491
check_response_and_report "$result" "\"maxApplicableSoftwareVersion\": 32"
492492
check_response_and_report "$result" "\"minApplicableSoftwareVersion\": 5"

integration_tests/grpc_rest/pki/helpers.go

+4
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,7 @@ func Demo(suite *utils.TestSuite) {
15411541
Label: "label",
15421542
DataURL: testconstants.DataURL,
15431543
RevocationType: 1,
1544+
SchemaVersion: 1,
15441545
}
15451546
_, err = suite.BuildAndBroadcastTx([]sdk.Msg{&msgAddPkiRevDistPoints}, vendorAdminName, vendorAdminAccount)
15461547
require.Error(suite.T, err)
@@ -1555,6 +1556,7 @@ func Demo(suite *utils.TestSuite) {
15551556
Label: "label",
15561557
DataURL: testconstants.DataURL,
15571558
RevocationType: 1,
1559+
SchemaVersion: 1,
15581560
}
15591561
_, err = suite.BuildAndBroadcastTx([]sdk.Msg{&msgAddPkiRevDistPoints}, vendorName, vendorAccount)
15601562
require.NoError(suite.T, err)
@@ -1622,6 +1624,7 @@ func Demo(suite *utils.TestSuite) {
16221624
Label: "label_PAI",
16231625
DataURL: testconstants.DataURL,
16241626
RevocationType: 1,
1627+
SchemaVersion: 1,
16251628
}
16261629
_, err = suite.BuildAndBroadcastTx([]sdk.Msg{&msgAddPkiRevDistPoints}, venName65522, venAcc65522)
16271630
require.NoError(suite.T, err)
@@ -1650,6 +1653,7 @@ func Demo(suite *utils.TestSuite) {
16501653
CrlSignerCertificate: testconstants.PAACertWithNumericVid,
16511654
Label: "label",
16521655
DataURL: "https://url2.data.dclmodel",
1656+
SchemaVersion: 2,
16531657
}
16541658

16551659
_, err = suite.BuildAndBroadcastTx([]sdk.Msg{&msgUpdPkiRevDistPoint}, vendorName, vendorAccount)

proto/zigbeealliance/distributedcomplianceledger/pki/tx.proto

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ message MsgAddPkiRevocationDistributionPoint {
132132
string dataDigest = 10;
133133
uint32 dataDigestType = 11;
134134
uint32 revocationType = 12 [(gogoproto.moretags) = "validate:\"required\""];
135-
uint32 schemaVersion = 13 [(gogoproto.moretags) = "validate:\"gte=0,lte=65535\""];
135+
uint32 schemaVersion = 13 [(gogoproto.moretags) = "validate:\"gte=1,lte=65535\""];
136136
string crlSignerDelegator = 14 [(gogoproto.moretags) = "validate:\"max=10485760\""];
137137
}
138138

@@ -149,7 +149,7 @@ message MsgUpdatePkiRevocationDistributionPoint {
149149
uint64 dataFileSize = 7;
150150
string dataDigest = 8;
151151
uint32 dataDigestType = 9;
152-
uint32 schemaVersion = 10 [(gogoproto.moretags) = "validate:\"gte=0,lte=65535\""];
152+
uint32 schemaVersion = 10 [(gogoproto.moretags) = "validate:\"gte=1,lte=65535\""];
153153
string crlSignerDelegator = 11 [(gogoproto.moretags) = "validate:\"max=10485760\""];
154154
}
155155

x/model/types/errors.go

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var (
2626
ErrLsfRevisionIsNotAllowed = errors.Register(ModuleName, 523, "LsfRevision is not allowed if LsfURL is not present")
2727
ErrModelVersionDeletionCertified = errors.Register(ModuleName, 524, "model version has a compliance record and can not be deleted")
2828
ErrModelDeletionCertified = errors.Register(ModuleName, 525, "model has a model version that has a compliance record and correcponding model can not be deleted")
29+
ErrOtaChecksumIsNotValid = errors.Register(ModuleName, 526, "OTA Checksum is not base64 encoded")
2930
)
3031

3132
func NewErrModelAlreadyExists(vid interface{}, pid interface{}) error {
@@ -131,3 +132,8 @@ func NewErrModelVersionDeletionCertified(vid interface{}, pid interface{}, softw
131132
"Model version associated with vid=%v, pid=%v and softwareVersion=%v has a compliance record and can't be deleted",
132133
vid, pid, softwareVersion)
133134
}
135+
136+
func NewErrOtaChecksumIsNotBase64Encoded(otaChecksum string) error {
137+
return errors.Wrapf(ErrOtaChecksumIsNotValid,
138+
"OtaChecksum %v is not base64 encoded", otaChecksum)
139+
}

x/model/types/messages_model_version.go

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package types
22

33
import (
4+
"encoding/base64"
5+
46
"cosmossdk.io/errors"
57
sdk "github.com/cosmos/cosmos-sdk/types"
68
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@@ -82,6 +84,11 @@ func (msg *MsgCreateModelVersion) ValidateBasic() error {
8284
return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
8385
}
8486

87+
_, err = base64.StdEncoding.DecodeString(msg.OtaChecksum)
88+
if err != nil {
89+
return NewErrOtaChecksumIsNotBase64Encoded(msg.OtaChecksum)
90+
}
91+
8592
err = validator.Validate(msg)
8693
if err != nil {
8794
return err
@@ -151,6 +158,11 @@ func (msg *MsgUpdateModelVersion) ValidateBasic() error {
151158
return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
152159
}
153160

161+
_, err = base64.StdEncoding.DecodeString(msg.OtaChecksum)
162+
if err != nil {
163+
return NewErrOtaChecksumIsNotBase64Encoded(msg.OtaChecksum)
164+
}
165+
154166
err = validator.Validate(msg)
155167
if err != nil {
156168
return err

x/model/types/messages_model_version_test.go

+31-2
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,22 @@ func TestMsgCreateModelVersion_ValidateBasic(t *testing.T) {
184184
{
185185
name: "OtaChecksum length > 64",
186186
msg: func(msg *MsgCreateModelVersion) *MsgCreateModelVersion {
187-
msg.OtaChecksum = tmrand.Str(65)
187+
msg.OtaChecksum = "SGVsbG8gd29ybGQhSGVsbG8gd29ybGQhSGVsbG8gd29ybGQhSGVsbG8gd29ybGQhSGVsbG8gd29ybGQhSGVsbG8gd29ybGQhSGVsbG8gd29ybGQh"
188188

189189
return msg
190190
}(validMsgCreateModelVersion()),
191191
err: validator.ErrFieldMaxLengthExceeded,
192192
},
193+
{
194+
name: "OtaChecksum is not base64 encoded",
195+
msg: func(msg *MsgCreateModelVersion) *MsgCreateModelVersion {
196+
msg.OtaUrl = "https://sampleflowurl.dclmodel"
197+
msg.OtaChecksum = "not_base64_encoded"
198+
199+
return msg
200+
}(validMsgCreateModelVersion()),
201+
err: ErrOtaChecksumIsNotValid,
202+
},
193203
{
194204
name: "OtaChecksumType == 0 when OtaUrl is set",
195205
msg: func(msg *MsgCreateModelVersion) *MsgCreateModelVersion {
@@ -430,7 +440,7 @@ func TestMsgCreateModelVersion_ValidateBasic(t *testing.T) {
430440
name: "OtaChecksum is set when OtaUrl is set",
431441
msg: func(msg *MsgCreateModelVersion) *MsgCreateModelVersion {
432442
msg.OtaUrl = "https://sampleflowurl.dclmodel"
433-
msg.OtaChecksum = tmrand.Str(32)
443+
msg.OtaChecksum = "SGVsbG8gd29ybGQh"
434444

435445
return msg
436446
}(validMsgCreateModelVersion()),
@@ -654,6 +664,16 @@ func TestMsgUpdateModelVersion_ValidateBasic(t *testing.T) {
654664
}(validMsgUpdateModelVersion()),
655665
err: validator.ErrFieldMaxLengthExceeded,
656666
},
667+
{
668+
name: "OtaChecksum is not base64 encoded",
669+
msg: func(msg *MsgUpdateModelVersion) *MsgUpdateModelVersion {
670+
msg.OtaUrl = "https://sampleflowurl.dclmodel"
671+
msg.OtaChecksum = "not_base64_encoded"
672+
673+
return msg
674+
}(validMsgUpdateModelVersion()),
675+
err: ErrOtaChecksumIsNotValid,
676+
},
657677
{
658678
name: "MinApplicableSoftwareVersion and MaxApplicableSoftwareVersion are set " +
659679
"and MinApplicableSoftwareVersion > MaxApplicableSoftwareVersion",
@@ -776,6 +796,15 @@ func TestMsgUpdateModelVersion_ValidateBasic(t *testing.T) {
776796
return msg
777797
}(validMsgUpdateModelVersion()),
778798
},
799+
{
800+
name: "OtaChecksum is base64 encoded",
801+
msg: func(msg *MsgUpdateModelVersion) *MsgUpdateModelVersion {
802+
msg.OtaUrl = "https://sampleflowurl.dclmodel"
803+
msg.OtaChecksum = "SGVsbG8gd29ybGQh"
804+
805+
return msg
806+
}(validMsgUpdateModelVersion()),
807+
},
779808
{
780809
name: "OtaUrl length == 256",
781810
msg: func(msg *MsgUpdateModelVersion) *MsgUpdateModelVersion {

x/pki/client/cli/tx_add_pki_revocation_distribution_point.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func CmdAddPkiRevocationDistributionPoint() *cobra.Command {
9393
cmd.Flags().StringVar(&dataDigest, FlagDataDigest, "", "Digest of the entire contents of the associated file downloaded from the DataURL. Must be omitted if RevocationType is 1. Must be provided if and only if the DataFileSize field is present")
9494
cmd.Flags().Uint32Var(&dataDigestType, FlagDataDigestType, 0, "The type of digest used in the DataDigest field from the list of [1, 7, 8, 10, 11, 12] (IANA Named Information Hash Algorithm Registry). Must be provided if and only if the DataDigest field is present") //TODO: will give error if omitted
9595
cmd.Flags().Uint32Var(&revocationType, FlagRevocationType, 1, "The type of file found at the DataURL for this entry. Supported types: 1 - RFC5280 Certificate Revocation List (CRL)")
96-
cmd.Flags().Uint32Var(&schemaVersion, common.FlagSchemaVersion, 0, "Schema version")
96+
cmd.Flags().Uint32Var(&schemaVersion, common.FlagSchemaVersion, 1, "Schema version - default is 1, the minimum value should be greater than or equal to 1")
9797

9898
flags.AddTxFlagsToCmd(cmd)
9999

x/pki/client/cli/tx_update_pki_revocation_distribution_point.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func CmdUpdatePkiRevocationDistributionPoint() *cobra.Command {
8383
cmd.Flags().Uint64Var(&dataFileSize, FlagDataFileSize, 0, "Total size in bytes of the file found at the DataURL. Must be omitted if RevocationType is 1")
8484
cmd.Flags().StringVar(&dataDigest, FlagDataDigest, "", "Digest of the entire contents of the associated file downloaded from the DataURL. Must be omitted if RevocationType is 1. Must be provided if and only if the DataFileSize field is present")
8585
cmd.Flags().Uint32Var(&dataDigestType, FlagDataDigestType, 0, "The type of digest used in the DataDigest field from the list of [1, 7, 8, 10, 11, 12] (IANA Named Information Hash Algorithm Registry). Must be provided if and only if the DataDigest field is present") //TODO: will give error if omitted
86-
cmd.Flags().Uint32Var(&schemaVersion, common.FlagSchemaVersion, 0, "Schema version")
86+
cmd.Flags().Uint32Var(&schemaVersion, common.FlagSchemaVersion, 1, "Schema version - default is 1, the minimum value should be greater than or equal to 1")
8787

8888
flags.AddTxFlagsToCmd(cmd)
8989

0 commit comments

Comments
 (0)