Skip to content

Commit

Permalink
#535 Enable providing serial number while revoking x509 certs
Browse files Browse the repository at this point in the history
Resolve MR comments

Signed-off-by: Abdulbois <[email protected]>
Signed-off-by: Abdulbois <[email protected]>
  • Loading branch information
Abdulbois committed Feb 16, 2024
1 parent ca02c54 commit fd3f363
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
8 changes: 2 additions & 6 deletions x/pki/keeper/approved_certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,9 @@ func (k Keeper) GetApprovedCertificateBySerialNumber(
return val, false
}

for _, cert := range certs.Certs {
if cert.SerialNumber == serialNumber {
return *cert, true
}
}
cert, found := findCertificate(serialNumber, &certs.Certs)

return val, false
return *cert, found
}

// RemoveApprovedCertificates removes a approvedCertificates from the store.
Expand Down
13 changes: 7 additions & 6 deletions x/pki/keeper/msg_server_approve_revoke_x_509_root_cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@ func (k msgServer) ApproveRevokeX509RootCert(goCtx context.Context, msg *types.M
}
k.AddRevokedRootCertificate(ctx, certID)
k.RemoveProposedCertificateRevocation(ctx, msg.Subject, msg.SubjectKeyId, msg.SerialNumber)

certBySerialNumber, _ := findCertificate(msg.SerialNumber, &certificates.Certs)
if certBySerialNumber != nil {
certBySerialNumber.Approvals = revocation.Approvals
k._removeAndRevokeBySerialNumber(ctx, certBySerialNumber, certificates)
if msg.SerialNumber != "" {
k._removeAndRevokeBySerialNumber(ctx, revocation.Approvals, msg.SerialNumber, certificates)
} else {
k._removeAndRevoke(ctx, revocation.Approvals, certificates)
}
Expand Down Expand Up @@ -96,14 +93,18 @@ func (k msgServer) _removeAndRevoke(ctx sdk.Context, approvals []*types.Grant, c
// remove from subject key ID -> certificates map
k.RemoveApprovedCertificatesBySubjectKeyID(ctx, certificates.Subject, certificates.SubjectKeyId)
}
func (k msgServer) _removeAndRevokeBySerialNumber(ctx sdk.Context, cert *types.Certificate, certificates types.ApprovedCertificates) {
func (k msgServer) _removeAndRevokeBySerialNumber(ctx sdk.Context, approvals []*types.Grant, serialNumber string, certificates types.ApprovedCertificates) {
cert, _ := findCertificate(serialNumber, &certificates.Certs)
cert.Approvals = approvals

k.AddRevokedCertificates(ctx,
types.ApprovedCertificates{
Subject: cert.Subject,
SubjectKeyId: cert.SubjectKeyId,
Certs: []*types.Certificate{cert},
})
k.removeCertFromList(cert.Issuer, cert.SerialNumber, &certificates)

if len(certificates.Certs) == 0 {
k.RemoveApprovedCertificates(ctx, cert.Subject, cert.SubjectKeyId)
k.RevokeChildCertificates(ctx, cert.Subject, cert.SubjectKeyId)
Expand Down

0 comments on commit fd3f363

Please sign in to comment.