Skip to content

Commit 98379d5

Browse files
committedNov 18, 2024
Logic corrections
1 parent 7268e3c commit 98379d5

13 files changed

+27
-17
lines changed
 

‎x/pki/genesis_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,5 @@ func TestGenesis(t *testing.T) {
264264
require.ElementsMatch(t, genesisState.RevokedNocIcaCertificatesList, got.RevokedNocIcaCertificatesList)
265265
require.ElementsMatch(t, genesisState.AllCertificatesBySubjectList, got.AllCertificatesBySubjectList)
266266
require.ElementsMatch(t, genesisState.AllCertificatesBySubjectKeyIdList, got.AllCertificatesBySubjectKeyIdList)
267-
require.ElementsMatch(t, genesisState.AllCertificatesBySubjectKeyIdList, got.AllCertificatesBySubjectKeyIdList)
268267
// this line is used by starport scaffolding # genesis/test/assert
269268
}

‎x/pki/keeper/all_certificates_by_subject_key_id.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ func (k Keeper) SetAllCertificatesBySubjectKeyID(ctx sdk.Context, allCertificate
1919

2020
// Add an All certificate to the list of All certificates with the subjectKeyId map.
2121
func (k Keeper) AddAllCertificateBySubjectKeyID(ctx sdk.Context, certificate types.Certificate) {
22-
k.addAllCertificates(ctx, certificate.SubjectKeyId, []*types.Certificate{&certificate})
22+
k.addAllCertificatesBySubjectKeyID(ctx, certificate.SubjectKeyId, []*types.Certificate{&certificate})
2323
}
2424

2525
// Add an All certificates list to All certificates with the subjectKeyId map.
2626
func (k Keeper) AddAllCertificatesBySubjectKeyID(ctx sdk.Context, allCertificate types.AllCertificates) {
27-
k.addAllCertificates(ctx, allCertificate.SubjectKeyId, allCertificate.Certs)
27+
k.addAllCertificatesBySubjectKeyID(ctx, allCertificate.SubjectKeyId, allCertificate.Certs)
2828
}
2929

30-
func (k Keeper) addAllCertificates(ctx sdk.Context, subjectKeyID string, certs []*types.Certificate) {
30+
func (k Keeper) addAllCertificatesBySubjectKeyID(ctx sdk.Context, subjectKeyID string, certs []*types.Certificate) {
3131
store := prefix.NewStore(ctx.KVStore(k.storeKey), pkitypes.KeyPrefix(types.AllCertificatesBySubjectKeyIDKeyPrefix))
3232

33-
AllCertificatesBytes := store.Get(types.AllCertificatesBySubjectKey(
33+
AllCertificatesBytes := store.Get(types.AllCertificatesBySubjectKeyIDKey(
3434
subjectKeyID,
3535
))
3636
var AllCertificates types.AllCertificatesBySubjectKeyId

‎x/pki/keeper/grpc_query_all_certificates.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ func (k Keeper) CertificatesAll(c context.Context, req *types.QueryAllCertificat
4141
pageRes = &query.PageResponse{Total: 1}
4242
} else {
4343
store := ctx.KVStore(k.storeKey)
44-
approvedCertificatesStore := prefix.NewStore(store, pkitypes.KeyPrefix(types.ApprovedCertificatesKeyPrefix))
44+
allCertificatesStore := prefix.NewStore(store, pkitypes.KeyPrefix(types.AllCertificatesBySubjectKeyIDKeyPrefix))
4545

46-
pageRes, err = query.Paginate(approvedCertificatesStore, req.Pagination, func(key []byte, value []byte) error {
46+
pageRes, err = query.Paginate(allCertificatesStore, req.Pagination, func(key []byte, value []byte) error {
4747
var certificates types.AllCertificates
4848
if err := k.cdc.Unmarshal(value, &certificates); err != nil {
4949
return err

‎x/pki/keeper/migrations.go

-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ func (m Migrator) Migrate3to4(ctx sdk.Context) error {
3333
approvedCertificates := m.keeper.GetAllApprovedCertificates(ctx)
3434
for _, cert := range approvedCertificates {
3535
m.keeper.AddAllCertificates(ctx, cert.Subject, cert.SubjectKeyId, cert.SchemaVersion, cert.Certs)
36-
}
37-
for _, cert := range approvedCertificates {
3836
m.keeper.AddAllCertificatesBySubjectKeyID(ctx, pkitypes.AllCertificates(cert))
3937
}
4038
approvedCertificatesBySubject := m.keeper.GetAllApprovedCertificatesBySubject(ctx)

‎x/pki/keeper/msg_server_add_noc_x_509_ica_cert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (k msgServer) AddNocX509IcaCert(goCtx context.Context, msg *types.MsgAddNoc
109109
// append to global list of certificates indexed by subject
110110
k.AddAllCertificateBySubject(ctx, certificate.Subject, certificate.SubjectKeyId)
111111

112-
// add to global list of certificates indexed by subject
112+
// add to global list of certificates indexed by skid
113113
k.AddAllCertificateBySubjectKeyID(ctx, certificate)
114114

115115
// Add to the list of all NOC certificates

‎x/pki/keeper/msg_server_add_noc_x_509_root_cert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (k msgServer) AddNocX509RootCert(goCtx context.Context, msg *types.MsgAddNo
9090
// append to global list of certificates indexed by subject
9191
k.AddAllCertificateBySubject(ctx, certificate.Subject, certificate.SubjectKeyId)
9292

93-
// add to global list of certificates indexed by subject
93+
// add to global list of certificates indexed by skid
9494
k.AddAllCertificateBySubjectKeyID(ctx, certificate)
9595

9696
// Add to the list of all NOC certificates

‎x/pki/keeper/msg_server_add_x_509_cert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (k msgServer) AddX509Cert(goCtx context.Context, msg *types.MsgAddX509Cert)
113113
// append to global list of certificates indexed by subject
114114
k.AddAllCertificateBySubject(ctx, certificate.Subject, certificate.SubjectKeyId)
115115

116-
// add to global list of certificates indexed by subject
116+
// add to global list of certificates indexed by skid
117117
k.AddAllCertificateBySubjectKeyID(ctx, certificate)
118118

119119
// append new certificate to list of certificates with the same Subject/SubjectKeyID combination and store updated list

‎x/pki/keeper/msg_server_approve_add_x_509_root_cert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (k msgServer) ApproveAddX509RootCert(goCtx context.Context, msg *types.MsgA
8585
// append to global list of certificates indexed by subject
8686
k.AddAllCertificateBySubject(ctx, rootCertificate.Subject, rootCertificate.SubjectKeyId)
8787

88-
// add to global list of certificates indexed by subject
88+
// add to global list of certificates indexed by skid
8989
k.AddAllCertificateBySubjectKeyID(ctx, rootCertificate)
9090

9191
// add approved certificate to stored list of certificates with the same Subject/SubjectKeyID combination

‎x/pki/keeper/msg_server_assign_vid.go

+9
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ func (k msgServer) AssignVid(goCtx context.Context, msg *types.MsgAssignVid) (*t
6868
return nil, pkitypes.NewErrNotEmptyVid("Vendor ID (VID) already present in certificates")
6969
}
7070

71+
// assign VID to certificates in global list indexed by subject key id
72+
allCertificatesBySubjectKeyID, found := k.GetAllCertificatesBySubjectKeyID(ctx, msg.SubjectKeyId)
73+
if !found {
74+
return nil, pkitypes.NewErrCertificateDoesNotExist(msg.Subject, msg.SubjectKeyId)
75+
}
76+
k.assignVid(&allCertificatesBySubjectKeyID.Certs, msg.Vid)
77+
7178
// assign VID to certificates in approved list
7279
approvedCertificates, found := k.GetApprovedCertificates(ctx, msg.Subject, msg.SubjectKeyId)
7380
if !found {
@@ -84,6 +91,8 @@ func (k msgServer) AssignVid(goCtx context.Context, msg *types.MsgAssignVid) (*t
8491

8592
// update global certificates list
8693
k.SetAllCertificates(ctx, certificates)
94+
// update global certificates list indexed by subject key id
95+
k.SetAllCertificatesBySubjectKeyID(ctx, allCertificatesBySubjectKeyID)
8796
// update approved certificates list
8897
k.SetApprovedCertificates(ctx, approvedCertificates)
8998
// update certificates list indexed by subject key id

‎x/pki/keeper/msg_server_remove_x_509_cert.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ func (k msgServer) RemoveX509Cert(goCtx context.Context, msg *types.MsgRemoveX50
6969
} else {
7070
// remove from global certificates map
7171
k.RemoveAllCertificates(ctx, certID.Subject, certID.SubjectKeyId)
72-
// remove from global subject -> subject key ID map
72+
// remove from global subject -> subject map
7373
k.RemoveAllCertificateBySubject(ctx, certID.Subject, certID.SubjectKeyId)
74+
// remove from global subject -> subject key ID map
7475
k.RemoveAllCertificatesBySubjectKeyID(ctx, certID.Subject, certID.SubjectKeyId)
7576
// remove from approved certificates map
7677
k.RemoveApprovedCertificates(ctx, certID.Subject, certID.SubjectKeyId)

‎x/pki/keeper/msg_server_revoke_noc_x_509_ica_cert.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ func (k msgServer) _revokeNocIcaCertificates(ctx sdk.Context, certificates types
112112
})
113113
// remove cert from global certs list
114114
k.RemoveAllCertificates(ctx, certificates.Subject, certificates.SubjectKeyId)
115-
// remove cert from global certs list -> subject key ID map
115+
// remove cert from global certs list -> subject map
116116
k.RemoveAllCertificateBySubject(ctx, certificates.Subject, certificates.SubjectKeyId)
117+
// remove cert from global certs list -> subject key ID map
117118
k.RemoveAllCertificatesBySubjectKeyID(ctx, certificates.Subject, certificates.SubjectKeyId)
118119
// remove cert from NOC certs list
119120
k.RemoveNocCertificates(ctx, certificates.Subject, certificates.SubjectKeyId)

‎x/pki/keeper/msg_server_revoke_noc_x_509_root_cert.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ func (k msgServer) _revokeNocRootCertificates(ctx sdk.Context, certificates type
118118

119119
// remove cert from global certs list
120120
k.RemoveAllCertificates(ctx, certificates.Subject, certificates.SubjectKeyId)
121-
// remove cert from global certs list -> subject key ID map
121+
// remove cert from global certs list -> subject map
122122
k.RemoveAllCertificateBySubject(ctx, certificates.Subject, certificates.SubjectKeyId)
123+
// remove cert from global certs list -> subject key ID map
123124
k.RemoveAllCertificatesBySubjectKeyID(ctx, certificates.Subject, certificates.SubjectKeyId)
124125
// remove cert from NOC certs list
125126
k.RemoveNocCertificates(ctx, certificates.Subject, certificates.SubjectKeyId)

‎x/pki/keeper/msg_server_revoke_x_509_cert.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ func (k msgServer) _revokeX509Certificates(ctx sdk.Context, certID types.Certifi
6565

6666
// Remove certificate from global list
6767
k.RemoveAllCertificates(ctx, certID.Subject, certID.SubjectKeyId)
68-
// Remove certificate from global list -> subject key ID map
68+
// Remove certificate from global list -> subject map
6969
k.RemoveAllCertificateBySubject(ctx, certID.Subject, certID.SubjectKeyId)
70+
// Remove certificate from global list -> subject key ID map
7071
k.RemoveAllCertificatesBySubjectKeyID(ctx, certID.Subject, certID.SubjectKeyId)
7172
// Remove certificate from approved list
7273
k.RemoveApprovedCertificates(ctx, certID.Subject, certID.SubjectKeyId)

0 commit comments

Comments
 (0)