Skip to content

Commit 0753e5f

Browse files
committed
Error messages improvements
Signed-off-by: Abdulbois <abdulbois.tursunov@dsr-corporation.com> Signed-off-by: Abdulbois <abdulbois123@gmail.com>
1 parent 35a48cd commit 0753e5f

8 files changed

+29
-13
lines changed

types/pki/errors.go

+22-4
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func NewErrProposedCertificateDoesNotExist(subject string, subjectKeyID string)
7575
return errors.Wrapf(ErrProposedCertificateDoesNotExist,
7676
"No proposed X509 root certificate associated "+
7777
"with the combination of subject=%v and subjectKeyID=%v on the ledger. "+
78-
"The cerificate either does not exists or already approved.",
78+
"The certificate either does not exists, already approved or rejected",
7979
subject, subjectKeyID)
8080
}
8181

@@ -115,11 +115,15 @@ func NewErrProposedCertificateRevocationAlreadyExists(subject string, subjectKey
115115
subject, subjectKeyID)
116116
}
117117

118-
func NewErrProposedCertificateRevocationDoesNotExist(subject string, subjectKeyID string) error {
118+
func NewErrProposedCertificateRevocationDoesNotExist(subject string, subjectKeyID string, serialNumber string) error {
119+
if serialNumber != "" {
120+
serialNumber = " and serialNumber=" + serialNumber
121+
}
122+
119123
return errors.Wrapf(ErrProposedCertificateRevocationDoesNotExist,
120124
"No proposed X509 root certificate revocation associated "+
121-
"with the combination of subject=%v and subjectKeyID=%v on the ledger.",
122-
subject, subjectKeyID)
125+
"with the combination of subject=%v, subjectKeyID=%v%v on the ledger.",
126+
subject, subjectKeyID, serialNumber)
123127
}
124128

125129
func NewErrRevokedCertificateDoesNotExist(subject string, subjectKeyID string) error {
@@ -235,6 +239,20 @@ func NewErrRootCertVidNotEqualToAccountVid(rootVID int32, accountVID int32) erro
235239
rootVID, accountVID)
236240
}
237241

242+
func NewErrRevokeRootCertVidNotEqualToAccountVid(rootVID int32, accountVID int32) error {
243+
return errors.Wrapf(ErrCertVidNotEqualAccountVid,
244+
"Only a Vendor associated with VID of root certificate can revoke certificate: "+
245+
"Root certificate's VID = %v, Account VID = %v",
246+
rootVID, accountVID)
247+
}
248+
249+
func NewErrRevokeCertVidNotEqualToAccountVid(rootVID int32, accountVID int32) error {
250+
return errors.Wrapf(ErrCertVidNotEqualAccountVid,
251+
"Only a Vendor associated with VID of certificate can revoke certificate: "+
252+
"Certificate's VID = %v, Account VID = %v",
253+
rootVID, accountVID)
254+
}
255+
238256
func NewErrCRLSignerCertificateInvalidFormat(description string) error {
239257
return errors.Wrapf(
240258
ErrCRLSignerCertificateInvalidFormat, "Invalid CRL Signer Certificate format: %v",

x/pki/handler_add_noc_cert_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func TestHandler_AddXNoc509Cert_WhenNocRootCertIsAbsent(t *testing.T) {
224224
addNocX509Cert := types.NewMsgAddNocX509IcaCert(accAddress.String(), testconstants.NocCert1, testconstants.CertSchemaVersion, testconstants.SchemaVersion)
225225
_, err := setup.Handler(setup.Ctx, addNocX509Cert)
226226

227-
require.ErrorIs(t, err, pkitypes.ErrInvalidCertificate)
227+
require.ErrorIs(t, err, pkitypes.ErrCertificateDoesNotExist)
228228
}
229229

230230
func TestHandler_AddNocX509Cert_CertificateExist(t *testing.T) {

x/pki/handler_add_non_root_cert_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func TestHandler_AddX509Cert_ForAbsentDirectParentCert(t *testing.T) {
235235
// add intermediate x509 certificate
236236
addX509Cert := types.NewMsgAddX509Cert(vendorAccAddress.String(), testconstants.IntermediateCertPem, testconstants.CertSchemaVersion, testconstants.SchemaVersion)
237237
_, err := setup.Handler(setup.Ctx, addX509Cert)
238-
require.ErrorIs(t, err, pkitypes.ErrInvalidCertificate)
238+
require.ErrorIs(t, err, pkitypes.ErrCertificateDoesNotExist)
239239
}
240240

241241
func TestHandler_AddX509Cert_ForFailedCertificateVerification(t *testing.T) {

x/pki/keeper/approved_certificates.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ func (k Keeper) verifyCertificate(ctx sdk.Context,
129129
} else {
130130
parentCertificates, found := k.GetApprovedCertificates(ctx, x509Certificate.Issuer, x509Certificate.AuthorityKeyID)
131131
if !found {
132-
return nil, pkitypes.NewErrInvalidCertificate(
133-
fmt.Sprintf("Certificate verification failed for certificate with subject=%v and subjectKeyID=%v",
134-
x509Certificate.Subject, x509Certificate.SubjectKeyID))
132+
return nil, pkitypes.NewErrRootCertificateDoesNotExist(x509Certificate.Issuer, x509Certificate.AuthorityKeyID)
135133
}
136134

137135
for _, cert := range parentCertificates.Certs {

x/pki/keeper/msg_server_add_noc_x_509_ica_cert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (k msgServer) AddNocX509IcaCert(goCtx context.Context, msg *types.MsgAddNoc
8282
}
8383
// Check VID scoping
8484
if nocRootCert.Vid != accountVid {
85-
return nil, pkitypes.NewErrRootCertVidNotEqualToAccountVid(accountVid, nocRootCert.Vid)
85+
return nil, pkitypes.NewErrRootCertVidNotEqualToAccountVid(nocRootCert.Vid, accountVid)
8686
}
8787

8888
// create new certificate

x/pki/keeper/msg_server_approve_revoke_x_509_root_cert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (k msgServer) ApproveRevokeX509RootCert(goCtx context.Context, msg *types.M
2929
// get proposed certificate revocation
3030
revocation, found := k.GetProposedCertificateRevocation(ctx, msg.Subject, msg.SubjectKeyId, msg.SerialNumber)
3131
if !found {
32-
return nil, pkitypes.NewErrProposedCertificateRevocationDoesNotExist(msg.Subject, msg.SubjectKeyId)
32+
return nil, pkitypes.NewErrProposedCertificateRevocationDoesNotExist(msg.Subject, msg.SubjectKeyId, msg.SerialNumber)
3333
}
3434

3535
// check if proposed certificate revocation already has approval form signer

x/pki/keeper/msg_server_revoke_noc_x_509_ica_cert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (k msgServer) RevokeNocX509IcaCert(goCtx context.Context, msg *types.MsgRev
4040
signerVid := signerAccount.VendorID
4141
// signer VID must be same as VID of existing certificates
4242
if signerVid != cert.Vid {
43-
return nil, pkitypes.NewErrRootCertVidNotEqualToAccountVid(cert.Vid, signerVid)
43+
return nil, pkitypes.NewErrRevokeCertVidNotEqualToAccountVid(cert.Vid, signerVid)
4444
}
4545

4646
if msg.SerialNumber != "" {

x/pki/keeper/msg_server_revoke_noc_x_509_root_cert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (k msgServer) RevokeNocX509RootCert(goCtx context.Context, msg *types.MsgRe
4141
signerVid := signerAccount.VendorID
4242
// signer VID must be same as VID of existing certificates
4343
if signerVid != cert.Vid {
44-
return nil, pkitypes.NewErrRootCertVidNotEqualToAccountVid(cert.Vid, signerVid)
44+
return nil, pkitypes.NewErrRevokeRootCertVidNotEqualToAccountVid(cert.Vid, signerVid)
4545
}
4646

4747
if msg.SerialNumber != "" {

0 commit comments

Comments
 (0)