Skip to content

Commit

Permalink
Merge pull request #572 from zigbee-alliance/improvements
Browse files Browse the repository at this point in the history
improvements #566 #570
  • Loading branch information
akarabashov committed May 24, 2024
2 parents dd98906 + 034c07c commit ccac781
Show file tree
Hide file tree
Showing 15 changed files with 330 additions and 149 deletions.
4 changes: 2 additions & 2 deletions docs/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ and DACs (leaf certificates) added to DCL if they are revoked in the CRL identif
- 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.
- 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.
- revocationType: `uint32` - The type of file found at the DataUrl for this entry. Supported types: 1 - RFC5280 Certificate Revocation List (CRL).
- schemaVersion: `optional(uint16)` - Schema version to support backward/forward compatability(default 0)
- schemaVersion: `optional(uint16)` - Schema version to support backward/forward compatibility (default is 1, the minimum value should be greater than or equal to 1)
- In State:
- `pki/RevocationDistributionPoint/value/<IssuerSubjectKeyID>` -> list of Revocation Distribution Points
- `pki/RevocationDistributionPoint/value/<IssuerSubjectKeyID>/<vid>/<label>`-> Revocation Distribution Point
Expand Down Expand Up @@ -1062,7 +1062,7 @@ Updates an existing PKI Revocation distribution endpoint (such as RFC5280 Certif
- dataFileSize: `optional(uint64)` - Total size in bytes of the file found at the DataUrl. Must be omitted if RevocationType is 1.
- 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.
- 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.
- schemaVersion: `optional(uint16)` - Schema version to support backward/forward compatability(default 0)
- schemaVersion: `optional(uint16)` - Schema version to support backward/forward compatibility (default is 1, the minimum value should be greater than or equal to 1)
- In State:
- `pki/RevocationDistributionPoint/value/<IssuerSubjectKeyID>` -> list of Revocation Distribution Points
- `pki/RevocationDistributionPoint/value/<IssuerSubjectKeyID>/<vid>/<label>` -> Revocation Distribution Point
Expand Down
18 changes: 9 additions & 9 deletions integration_tests/cli/model-validation-cases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ test_divider
# Update the model version with few mutable fields and make sure all other fields are still the same
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"
result=$(echo "test1234" | dcld tx model update-model-version --vid=$vid_1 --pid=$pid_1 --softwareVersion=$sv_1 --softwareVersionValid=true \
--releaseNotesURL="https://release.url.info" --otaURL="https://ota.url.com" --otaFileSize=123 --otaChecksum="123123123" --minApplicableSoftwareVersion=2 --maxApplicableSoftwareVersion=20 --from=$vendor_account_1 --yes)
--releaseNotesURL="https://release.url.info" --otaURL="https://ota.url.com" --otaFileSize=123 --otaChecksum="SGVsbG8gbmV3IHdvcmxkIQ==" --minApplicableSoftwareVersion=2 --maxApplicableSoftwareVersion=20 --from=$vendor_account_1 --yes)
result=$(get_txn_result "$result")
check_response_and_report "$result" "\"code\": 0"

Expand All @@ -330,7 +330,7 @@ check_response_and_report "$result" "\"cdVersionNumber\": 1"
check_response_and_report "$result" "\"softwareVersionValid\": true"
check_response_and_report "$result" "\"otaUrl\": \"https://ota.url.com\""
check_response_and_report "$result" "\"otaFileSize\": \"123\""
check_response_and_report "$result" "\"otaChecksum\": \"123123123\""
check_response_and_report "$result" "\"otaChecksum\": \"SGVsbG8gbmV3IHdvcmxkIQ==\""
check_response_and_report "$result" "\"minApplicableSoftwareVersion\": 2"
check_response_and_report "$result" "\"maxApplicableSoftwareVersion\": 20"
check_response_and_report "$result" "\"releaseNotesUrl\": \"https://release.url.info\""
Expand All @@ -343,7 +343,7 @@ result=$(echo 'test1234' | dcld tx model add-model-version --vid=$vid_1 --pid=$p
--softwareVersionString="1.0" --cdVersionNumber=21334 \
--firmwareInformation="123456789012345678901234567890123456789012345678901234567890123" \
--softwareVersionValid=true --otaURL="https://ota.url.info" --otaFileSize=123456789 \
--otaChecksum="123456789012345678901234567890123456789012345678901234567890123" --releaseNotesURL="https://release.notes.url.info" \
--otaChecksum="SGVsbG8gd29ybGQh" --releaseNotesURL="https://release.notes.url.info" \
--otaChecksumType=1 --maxApplicableSoftwareVersion=32 --minApplicableSoftwareVersion=5 --from=$vendor_account_1 --yes)
result=$(get_txn_result "$result")
echo "$result"
Expand All @@ -364,7 +364,7 @@ check_response_and_report "$result" "\"firmwareInformation\": \"1234567890123456
check_response_and_report "$result" "\"softwareVersionValid\": true"
check_response_and_report "$result" "\"otaUrl\": \"https://ota.url.info\""
check_response_and_report "$result" "\"otaFileSize\": \"123456789\""
check_response_and_report "$result" "\"otaChecksum\": \"123456789012345678901234567890123456789012345678901234567890123\""
check_response_and_report "$result" "\"otaChecksum\": \"SGVsbG8gd29ybGQh\""
check_response_and_report "$result" "\"otaChecksumType\": 1"
check_response_and_report "$result" "\"releaseNotesUrl\": \"https://release.notes.url.info\""
check_response_and_report "$result" "\"maxApplicableSoftwareVersion\": 32"
Expand Down Expand Up @@ -393,7 +393,7 @@ check_response_and_report "$result" "\"firmwareInformation\": \"1234567890123456
check_response_and_report "$result" "\"softwareVersionValid\": true"
check_response_and_report "$result" "\"otaUrl\": \"https://ota.url.info\""
check_response_and_report "$result" "\"otaFileSize\": \"123456789\""
check_response_and_report "$result" "\"otaChecksum\": \"123456789012345678901234567890123456789012345678901234567890123\""
check_response_and_report "$result" "\"otaChecksum\": \"SGVsbG8gd29ybGQh\""
check_response_and_report "$result" "\"otaChecksumType\": 1"
check_response_and_report "$result" "\"releaseNotesUrl\": \"https://release.notes.url.info\""
check_response_and_report "$result" "\"maxApplicableSoftwareVersion\": 32"
Expand Down Expand Up @@ -422,7 +422,7 @@ check_response_and_report "$result" "\"firmwareInformation\": \"1234567890123456
check_response_and_report "$result" "\"softwareVersionValid\": false"
check_response_and_report "$result" "\"otaUrl\": \"https://ota.url.info\""
check_response_and_report "$result" "\"otaFileSize\": \"123456789\""
check_response_and_report "$result" "\"otaChecksum\": \"123456789012345678901234567890123456789012345678901234567890123\""
check_response_and_report "$result" "\"otaChecksum\": \"SGVsbG8gd29ybGQh\""
check_response_and_report "$result" "\"otaChecksumType\": 1"
check_response_and_report "$result" "\"releaseNotesUrl\": \"https://release.notes.url.info\""
check_response_and_report "$result" "\"maxApplicableSoftwareVersion\": 32"
Expand Down Expand Up @@ -453,7 +453,7 @@ check_response_and_report "$result" "\"firmwareInformation\": \"1234567890123456
check_response_and_report "$result" "\"softwareVersionValid\": true"
check_response_and_report "$result" "\"otaUrl\": \"https://updated.ota.url.info\""
check_response_and_report "$result" "\"otaFileSize\": \"123456789\""
check_response_and_report "$result" "\"otaChecksum\": \"123456789012345678901234567890123456789012345678901234567890123\""
check_response_and_report "$result" "\"otaChecksum\": \"SGVsbG8gd29ybGQh\""
check_response_and_report "$result" "\"otaChecksumType\": 1"
check_response_and_report "$result" "\"releaseNotesUrl\": \"https://updated.release.notes.url.info\""
check_response_and_report "$result" "\"maxApplicableSoftwareVersion\": 25"
Expand All @@ -465,7 +465,7 @@ result=$(echo 'test1234' | dcld tx model add-model-version --vid=$vid_1 --pid=$p
--softwareVersionString="1.0" --cdVersionNumber=21334 \
--firmwareInformation="123456789012345678901234567890123456789012345678901234567890123" \
--softwareVersionValid=true --otaURL="https://ota.url.info" --otaFileSize=123456789 \
--otaChecksum="123456789012345678901234567890123456789012345678901234567890123" \
--otaChecksum="SGVsbG8gd29ybGQh" \
--otaChecksumType=1 --maxApplicableSoftwareVersion=32 --minApplicableSoftwareVersion=5 --from=$vendor_account_1 --yes)
result=$(get_txn_result "$result")
echo "$result"
Expand All @@ -486,7 +486,7 @@ check_response_and_report "$result" "\"firmwareInformation\": \"1234567890123456
check_response_and_report "$result" "\"softwareVersionValid\": true"
check_response_and_report "$result" "\"otaUrl\": \"https://ota.url.info\""
check_response_and_report "$result" "\"otaFileSize\": \"123456789\""
check_response_and_report "$result" "\"otaChecksum\": \"123456789012345678901234567890123456789012345678901234567890123\""
check_response_and_report "$result" "\"otaChecksum\": \"SGVsbG8gd29ybGQh\""
check_response_and_report "$result" "\"otaChecksumType\": 1"
check_response_and_report "$result" "\"maxApplicableSoftwareVersion\": 32"
check_response_and_report "$result" "\"minApplicableSoftwareVersion\": 5"
Expand Down
4 changes: 4 additions & 0 deletions integration_tests/grpc_rest/pki/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,7 @@ func Demo(suite *utils.TestSuite) {
Label: "label",
DataURL: testconstants.DataURL,
RevocationType: 1,
SchemaVersion: 1,
}
_, err = suite.BuildAndBroadcastTx([]sdk.Msg{&msgAddPkiRevDistPoints}, vendorAdminName, vendorAdminAccount)
require.Error(suite.T, err)
Expand All @@ -1555,6 +1556,7 @@ func Demo(suite *utils.TestSuite) {
Label: "label",
DataURL: testconstants.DataURL,
RevocationType: 1,
SchemaVersion: 1,
}
_, err = suite.BuildAndBroadcastTx([]sdk.Msg{&msgAddPkiRevDistPoints}, vendorName, vendorAccount)
require.NoError(suite.T, err)
Expand Down Expand Up @@ -1622,6 +1624,7 @@ func Demo(suite *utils.TestSuite) {
Label: "label_PAI",
DataURL: testconstants.DataURL,
RevocationType: 1,
SchemaVersion: 1,
}
_, err = suite.BuildAndBroadcastTx([]sdk.Msg{&msgAddPkiRevDistPoints}, venName65522, venAcc65522)
require.NoError(suite.T, err)
Expand Down Expand Up @@ -1650,6 +1653,7 @@ func Demo(suite *utils.TestSuite) {
CrlSignerCertificate: testconstants.PAACertWithNumericVid,
Label: "label",
DataURL: "https://url2.data.dclmodel",
SchemaVersion: 2,
}

_, err = suite.BuildAndBroadcastTx([]sdk.Msg{&msgUpdPkiRevDistPoint}, vendorName, vendorAccount)
Expand Down
4 changes: 2 additions & 2 deletions proto/zigbeealliance/distributedcomplianceledger/pki/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ message MsgAddPkiRevocationDistributionPoint {
string dataDigest = 10;
uint32 dataDigestType = 11;
uint32 revocationType = 12 [(gogoproto.moretags) = "validate:\"required\""];
uint32 schemaVersion = 13 [(gogoproto.moretags) = "validate:\"gte=0,lte=65535\""];
uint32 schemaVersion = 13 [(gogoproto.moretags) = "validate:\"gte=1,lte=65535\""];
string crlSignerDelegator = 14 [(gogoproto.moretags) = "validate:\"max=10485760\""];
}

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

Expand Down
6 changes: 6 additions & 0 deletions x/model/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var (
ErrLsfRevisionIsNotAllowed = errors.Register(ModuleName, 523, "LsfRevision is not allowed if LsfURL is not present")
ErrModelVersionDeletionCertified = errors.Register(ModuleName, 524, "model version has a compliance record and can not be deleted")
ErrModelDeletionCertified = errors.Register(ModuleName, 525, "model has a model version that has a compliance record and correcponding model can not be deleted")
ErrOtaChecksumIsNotValid = errors.Register(ModuleName, 526, "OTA Checksum is not base64 encoded")
)

func NewErrModelAlreadyExists(vid interface{}, pid interface{}) error {
Expand Down Expand Up @@ -131,3 +132,8 @@ func NewErrModelVersionDeletionCertified(vid interface{}, pid interface{}, softw
"Model version associated with vid=%v, pid=%v and softwareVersion=%v has a compliance record and can't be deleted",
vid, pid, softwareVersion)
}

func NewErrOtaChecksumIsNotBase64Encoded(otaChecksum string) error {
return errors.Wrapf(ErrOtaChecksumIsNotValid,
"OtaChecksum %v is not base64 encoded", otaChecksum)
}
12 changes: 12 additions & 0 deletions x/model/types/messages_model_version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import (
"encoding/base64"

"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -82,6 +84,11 @@ func (msg *MsgCreateModelVersion) ValidateBasic() error {
return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}

_, err = base64.StdEncoding.DecodeString(msg.OtaChecksum)
if err != nil {
return NewErrOtaChecksumIsNotBase64Encoded(msg.OtaChecksum)
}

err = validator.Validate(msg)
if err != nil {
return err
Expand Down Expand Up @@ -151,6 +158,11 @@ func (msg *MsgUpdateModelVersion) ValidateBasic() error {
return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}

_, err = base64.StdEncoding.DecodeString(msg.OtaChecksum)
if err != nil {
return NewErrOtaChecksumIsNotBase64Encoded(msg.OtaChecksum)
}

err = validator.Validate(msg)
if err != nil {
return err
Expand Down
33 changes: 31 additions & 2 deletions x/model/types/messages_model_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,22 @@ func TestMsgCreateModelVersion_ValidateBasic(t *testing.T) {
{
name: "OtaChecksum length > 64",
msg: func(msg *MsgCreateModelVersion) *MsgCreateModelVersion {
msg.OtaChecksum = tmrand.Str(65)
msg.OtaChecksum = "SGVsbG8gd29ybGQhSGVsbG8gd29ybGQhSGVsbG8gd29ybGQhSGVsbG8gd29ybGQhSGVsbG8gd29ybGQhSGVsbG8gd29ybGQhSGVsbG8gd29ybGQh"

return msg
}(validMsgCreateModelVersion()),
err: validator.ErrFieldMaxLengthExceeded,
},
{
name: "OtaChecksum is not base64 encoded",
msg: func(msg *MsgCreateModelVersion) *MsgCreateModelVersion {
msg.OtaUrl = "https://sampleflowurl.dclmodel"
msg.OtaChecksum = "not_base64_encoded"

return msg
}(validMsgCreateModelVersion()),
err: ErrOtaChecksumIsNotValid,
},
{
name: "OtaChecksumType == 0 when OtaUrl is set",
msg: func(msg *MsgCreateModelVersion) *MsgCreateModelVersion {
Expand Down Expand Up @@ -430,7 +440,7 @@ func TestMsgCreateModelVersion_ValidateBasic(t *testing.T) {
name: "OtaChecksum is set when OtaUrl is set",
msg: func(msg *MsgCreateModelVersion) *MsgCreateModelVersion {
msg.OtaUrl = "https://sampleflowurl.dclmodel"
msg.OtaChecksum = tmrand.Str(32)
msg.OtaChecksum = "SGVsbG8gd29ybGQh"

return msg
}(validMsgCreateModelVersion()),
Expand Down Expand Up @@ -654,6 +664,16 @@ func TestMsgUpdateModelVersion_ValidateBasic(t *testing.T) {
}(validMsgUpdateModelVersion()),
err: validator.ErrFieldMaxLengthExceeded,
},
{
name: "OtaChecksum is not base64 encoded",
msg: func(msg *MsgUpdateModelVersion) *MsgUpdateModelVersion {
msg.OtaUrl = "https://sampleflowurl.dclmodel"
msg.OtaChecksum = "not_base64_encoded"

return msg
}(validMsgUpdateModelVersion()),
err: ErrOtaChecksumIsNotValid,
},
{
name: "MinApplicableSoftwareVersion and MaxApplicableSoftwareVersion are set " +
"and MinApplicableSoftwareVersion > MaxApplicableSoftwareVersion",
Expand Down Expand Up @@ -776,6 +796,15 @@ func TestMsgUpdateModelVersion_ValidateBasic(t *testing.T) {
return msg
}(validMsgUpdateModelVersion()),
},
{
name: "OtaChecksum is base64 encoded",
msg: func(msg *MsgUpdateModelVersion) *MsgUpdateModelVersion {
msg.OtaUrl = "https://sampleflowurl.dclmodel"
msg.OtaChecksum = "SGVsbG8gd29ybGQh"

return msg
}(validMsgUpdateModelVersion()),
},
{
name: "OtaUrl length == 256",
msg: func(msg *MsgUpdateModelVersion) *MsgUpdateModelVersion {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func CmdAddPkiRevocationDistributionPoint() *cobra.Command {
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")
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
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)")
cmd.Flags().Uint32Var(&schemaVersion, common.FlagSchemaVersion, 0, "Schema version")
cmd.Flags().Uint32Var(&schemaVersion, common.FlagSchemaVersion, 1, "Schema version - default is 1, the minimum value should be greater than or equal to 1")

flags.AddTxFlagsToCmd(cmd)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func CmdUpdatePkiRevocationDistributionPoint() *cobra.Command {
cmd.Flags().Uint64Var(&dataFileSize, FlagDataFileSize, 0, "Total size in bytes of the file found at the DataURL. Must be omitted if RevocationType is 1")
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")
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
cmd.Flags().Uint32Var(&schemaVersion, common.FlagSchemaVersion, 0, "Schema version")
cmd.Flags().Uint32Var(&schemaVersion, common.FlagSchemaVersion, 1, "Schema version - default is 1, the minimum value should be greater than or equal to 1")

flags.AddTxFlagsToCmd(cmd)

Expand Down

0 comments on commit ccac781

Please sign in to comment.