Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug while add TSP in addSigners method #182

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/main/java/kz/ncanode/service/CmsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,19 @@ public CmsResponse addSigners(CmsCreateRequest cmsCreateRequest) {
List<SignerInformation> signers = new ArrayList<>();

int i = 0;

for (Object signer : signerStore.getSigners()) {
X509Certificate cert = certificates.get(i++);
signers.add(tspService.addTspToSigner((SignerInformation) signer, cert, useTsaPolicy));

//Нельзя перезатирать TSP у предыдущих подписантов
boolean isCurrentSignerSameAsPrevious = isSignerSameAsPrevious((SignerInformation) signer, cms);
if(isCurrentSignerSameAsPrevious) {
//Старых подписантов оставляем без изменений
signers.add((SignerInformation)signer);
}
else {
//Новым подписантам устанавливаем TSP
signers.add(tspService.addTspToSigner((SignerInformation) signer, cert, useTsaPolicy));
}
}

signed = CMSSignedData.replaceSigners(signed, new SignerInformationStore(signers));
Expand All @@ -177,6 +186,17 @@ public CmsResponse addSigners(CmsCreateRequest cmsCreateRequest) {
}
}

private static boolean isSignerSameAsPrevious(SignerInformation signer, CMSSignedData cms) {
boolean isCurrentSignerSameAsPrevious = false;
for(Object obj : cms.getSignerInfos().getSigners()) {
SignerInformation prevSignerInfo = (SignerInformation)obj;
if (prevSignerInfo.getSID().equals(signer.getSID())) {
isCurrentSignerSameAsPrevious = true;
}
}
return isCurrentSignerSameAsPrevious;
}

/**
* Проверяет подписанный CMS
*
Expand Down