Skip to content

Commit 01f4501

Browse files
committed
Fix typo and naming
1 parent e91830f commit 01f4501

11 files changed

+23
-31
lines changed

integration_tests/cli/pki-demo.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ test_divider
658658
echo "6. REVOKE INTERMEDIATE (AND HENCE LEAF) CERTS - No Approvals needed"
659659
test_divider
660660

661-
echo "Try to revoke the intermediate certificate using an account that does not have vendor role"
661+
echo "Try to revoke the intermediate certificate when sender is not Vendor account"
662662
result=$(echo "$passphrase" | dcld tx pki revoke-x509-cert --subject="$intermediate_cert_subject" --subject-key-id="$intermediate_cert_subject_key_id" --from=$user_account --yes)
663663
check_response "$result" "\"code\": 4"
664664

integration_tests/cli/pki-remove-x509-certificates.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ echo "Remove intermediate certificate with invalid serialNumber"
7979
result=$(echo "$passphrase" | dcld tx pki remove-x509-cert --subject="$intermediate_cert_subject" --subject-key-id="$intermediate_cert_subject_key_id" --serial-number="invalid" --from=$vendor_account_65521 --yes)
8080
check_response "$result" "\"code\": 404"
8181

82-
echo "Try to remove the intermediate certificate using an account that does not have vendor role"
82+
echo "Try to remove the intermediate certificate when sender is not Vendor account"
8383
result=$(echo "$passphrase" | dcld tx pki remove-x509-cert --subject="$intermediate_cert_subject" --subject-key-id="$intermediate_cert_subject_key_id" --serial-number="$intermediate_cert_1_serial_number" --from=$trustee_account --yes)
8484
check_response "$result" "\"code\": 4"
8585

types/pki/errors.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ func NewErrUnauthorizedCertOwner(subject string, subjectKeyID string) error {
188188
subject, subjectKeyID)
189189
}
190190

191-
func NewErrUnauthorizedCertVendor(subject string, subjectKeyID string, ownerVid int32) error {
191+
func NewErrUnauthorizedCertVendor(ownerVid int32) error {
192192
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized,
193193
"Only the vendor accounts with vid=%d, has the authority "+
194-
"to add, remove, or revoke a certificate with subject=%v and subjectKeyID=%v",
195-
ownerVid, subject, subjectKeyID)
194+
"to add, remove, or revoke a certificate with provided subject and subjectKeyID",
195+
ownerVid)
196196
}
197197

198198
func NewErrProvidedNocCertButExistingNotNoc(subject string, subjectKeyID string) error {
@@ -226,7 +226,7 @@ func NewErrRootCertVidNotEqualToCertVid(rootVID int32, certVID int32) error {
226226

227227
func NewErrRootCertVidNotEqualToAccountVid(rootVID int32, accountVID int32) error {
228228
return sdkerrors.Wrapf(ErrCertVidNotEqualAccountVid,
229-
"Only a Vendor associated with root certificate VID can add a child certificate: "+
229+
"Only a Vendor associated with VID of root certificate can add a child certificate: "+
230230
"Root certificate's VID = %v, Account VID = %v",
231231
rootVID, accountVID)
232232
}

x/pki/handler_add_non_root_cert_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func TestHandler_AddX509Cert_ForExistingNocCertificate(t *testing.T) {
134134
nocCertificate.IsNoc = true
135135

136136
setup.Keeper.AddApprovedCertificate(setup.Ctx, nocCertificate)
137-
// TODO: add the certificate to the ICA store after the store is implemented
137+
setup.Keeper.AddNocCertificate(setup.Ctx, nocCertificate)
138138
uniqueCertificate := types.UniqueCertificate{
139139
Issuer: nocCertificate.Issuer,
140140
SerialNumber: nocCertificate.SerialNumber,

x/pki/handler_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ func TestHandler_ProposeRevokeX509RootCert_ByTrusteeNotOwner(t *testing.T) {
752752
rootCertOptions := createTestRootCertOptions()
753753
proposeAndApproveRootCertificate(setup, setup.Trustee1, rootCertOptions)
754754

755-
// store another trustee
755+
// add another trustee
756756
anotherTrustee := GenerateAccAddress()
757757
setup.AddAccount(anotherTrustee, []dclauthtypes.AccountRole{dclauthtypes.Trustee}, 1)
758758

@@ -1211,7 +1211,7 @@ func TestHandler_ApproveRevokeX509RootCert_ForTree(t *testing.T) {
12111211
require.Equal(t, 1, len(allRevokedCertificates[2].Certs))
12121212
require.Equal(t, testconstants.IntermediateCertPem, allRevokedCertificates[2].Certs[0].PemCert)
12131213

1214-
// check that no certificates stays approved
1214+
// check that approved certs list is empty
12151215
allApprovedCertificates, err := queryAllApprovedCertificates(setup)
12161216
require.NoError(t, err)
12171217
require.Equal(t, 0, len(allApprovedCertificates))

x/pki/keeper/keeper.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (k Keeper) CertificateRejectApprovalsCount(ctx sdk.Context, authKeeper type
5151
return authKeeper.CountAccountsWithRole(ctx, authTypes.Trustee) - k.CertificateApprovalsCount(ctx, authKeeper) + 1
5252
}
5353

54-
func (k Keeper) EnsureSenderAndOwnerVidMatch(ctx sdk.Context, certificate *types.Certificate, signer string) error {
54+
func (k Keeper) EnsureVidMatches(ctx sdk.Context, owner string, signer string) error {
5555
// get signer VID
5656
signerAddr, err := sdk.AccAddressFromBech32(signer)
5757
if err != nil {
@@ -62,7 +62,7 @@ func (k Keeper) EnsureSenderAndOwnerVidMatch(ctx sdk.Context, certificate *types
6262
signerVid := signerAccount.VendorID
6363

6464
// get owner VID
65-
ownerAddr, err := sdk.AccAddressFromBech32(certificate.Owner)
65+
ownerAddr, err := sdk.AccAddressFromBech32(owner)
6666
if err != nil {
6767
return pkitypes.NewErrInvalidAddress(err)
6868
}
@@ -71,7 +71,7 @@ func (k Keeper) EnsureSenderAndOwnerVidMatch(ctx sdk.Context, certificate *types
7171
ownerVid := ownerAccount.VendorID
7272

7373
if signerVid != ownerVid {
74-
return pkitypes.NewErrUnauthorizedCertVendor(certificate.Subject, certificate.SubjectKeyId, ownerVid)
74+
return pkitypes.NewErrUnauthorizedCertVendor(ownerVid)
7575
}
7676

7777
return nil

x/pki/keeper/msg_server_add_noc_x_509_cert.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ func (k msgServer) AddNocX509Cert(goCtx context.Context, msg *types.MsgAddNocX50
6262

6363
// signer VID must be same as VID of existing certificates
6464
if accountVid != existingCertificate.Vid {
65-
return nil, pkitypes.NewErrUnauthorizedCertVendor(
66-
x509Certificate.Subject,
67-
x509Certificate.SubjectKeyID,
68-
existingCertificate.Vid,
69-
)
65+
return nil, pkitypes.NewErrUnauthorizedCertVendor(existingCertificate.Vid)
7066
}
7167
}
7268
// Valid certificate chain must be built for new certificate

x/pki/keeper/msg_server_add_noc_x_509_root_cert.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@ func (k msgServer) AddNocX509RootCert(goCtx context.Context, msg *types.MsgAddNo
6868

6969
// signer VID must be same as VID of existing certificates
7070
if signerVid != existingCertificate.Vid {
71-
return nil, pkitypes.NewErrUnauthorizedCertVendor(
72-
x509Certificate.Subject,
73-
x509Certificate.SubjectKeyID,
74-
existingCertificate.Vid,
75-
)
71+
return nil, pkitypes.NewErrUnauthorizedCertVendor(existingCertificate.Vid)
7672
}
7773
}
7874

x/pki/keeper/msg_server_add_x_509_cert.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (k msgServer) AddX509Cert(goCtx context.Context, msg *types.MsgAddX509Cert)
2121

2222
// check if signer has vendor role
2323
if !k.dclauthKeeper.HasRole(ctx, signerAddr, dclauthtypes.Vendor) {
24-
return nil, pkitypes.NewErrUnauthorizedRole("MsgAddNocX509RootCert", dclauthtypes.Vendor)
24+
return nil, pkitypes.NewErrUnauthorizedRole("MsgAddX509Cert", dclauthtypes.Vendor)
2525
}
2626

2727
// decode pem certificate
@@ -58,7 +58,7 @@ func (k msgServer) AddX509Cert(goCtx context.Context, msg *types.MsgAddX509Cert)
5858
return nil, pkitypes.NewErrProvidedNotNocCertButExistingNoc(x509Certificate.Subject, x509Certificate.SubjectKeyID)
5959
}
6060

61-
if err = k.EnsureSenderAndOwnerVidMatch(ctx, existingCertificate, msg.Signer); err != nil {
61+
if err = k.EnsureVidMatches(ctx, existingCertificate.Owner, msg.Signer); err != nil {
6262
return nil, err
6363
}
6464
}
@@ -81,8 +81,8 @@ func (k msgServer) AddX509Cert(goCtx context.Context, msg *types.MsgAddX509Cert)
8181
return nil, pkitypes.NewErrProvidedNotNocCertButRootIsNoc()
8282
}
8383

84-
// Provided certificate, root certificate and account VID must match
85-
if err = k.ensureCertsAndSenderVidMatch(ctx, rootCert, x509Certificate, signerAddr); err != nil {
84+
// VID of account must match to VID of root and provided child certificates
85+
if err = k.ensureVidMatches(ctx, rootCert, x509Certificate, signerAddr); err != nil {
8686
return nil, err
8787
}
8888

@@ -127,7 +127,7 @@ func (k msgServer) AddX509Cert(goCtx context.Context, msg *types.MsgAddX509Cert)
127127
return &types.MsgAddX509CertResponse{}, nil
128128
}
129129

130-
func (k msgServer) ensureCertsAndSenderVidMatch(
130+
func (k msgServer) ensureVidMatches(
131131
ctx sdk.Context,
132132
rootCert *types.Certificate,
133133
childCert *x509.Certificate,

x/pki/keeper/msg_server_remove_x_509_cert.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func (k msgServer) RemoveX509Cert(goCtx context.Context, msg *types.MsgRemoveX50
2020

2121
// check if signer has vendor role
2222
if !k.dclauthKeeper.HasRole(ctx, signerAddr, dclauthtypes.Vendor) {
23-
return nil, pkitypes.NewErrUnauthorizedRole("MsgAddNocX509RootCert", dclauthtypes.Vendor)
23+
return nil, pkitypes.NewErrUnauthorizedRole("MsgRemoveX509Cert", dclauthtypes.Vendor)
2424
}
2525

2626
aprCerts, foundApproved := k.GetApprovedCertificates(ctx, msg.Subject, msg.SubjectKeyId)
@@ -35,7 +35,7 @@ func (k msgServer) RemoveX509Cert(goCtx context.Context, msg *types.MsgRemoveX50
3535
return nil, pkitypes.NewErrMessageRemoveRoot(msg.Subject, msg.SubjectKeyId)
3636
}
3737

38-
if err := k.EnsureSenderAndOwnerVidMatch(ctx, certificates[0], msg.Signer); err != nil {
38+
if err := k.EnsureVidMatches(ctx, certificates[0].Owner, msg.Signer); err != nil {
3939
return nil, err
4040
}
4141

x/pki/keeper/msg_server_revoke_x_509_cert.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (k msgServer) RevokeX509Cert(goCtx context.Context, msg *types.MsgRevokeX50
1919

2020
// check if signer has vendor role
2121
if !k.dclauthKeeper.HasRole(ctx, signerAddr, dclauthtypes.Vendor) {
22-
return nil, pkitypes.NewErrUnauthorizedRole("MsgAddNocX509RootCert", dclauthtypes.Vendor)
22+
return nil, pkitypes.NewErrUnauthorizedRole("MsgRevokeX509Cert", dclauthtypes.Vendor)
2323
}
2424

2525
certificates, _ := k.GetApprovedCertificates(ctx, msg.Subject, msg.SubjectKeyId)
@@ -31,7 +31,7 @@ func (k msgServer) RevokeX509Cert(goCtx context.Context, msg *types.MsgRevokeX50
3131
return nil, pkitypes.NewErrMessageRemoveRoot(msg.Subject, msg.SubjectKeyId)
3232
}
3333

34-
if err := k.EnsureSenderAndOwnerVidMatch(ctx, certificates.Certs[0], msg.Signer); err != nil {
34+
if err := k.EnsureVidMatches(ctx, certificates.Certs[0].Owner, msg.Signer); err != nil {
3535
return nil, err
3636
}
3737

0 commit comments

Comments
 (0)