Skip to content

Commit

Permalink
Merge pull request #182 from yezhakov/master
Browse files Browse the repository at this point in the history
Fixed bug while add TSP in addSigners method
  • Loading branch information
malikzh authored Oct 11, 2023
2 parents 6cb55d6 + 359cd67 commit 7604dbb
Showing 1 changed file with 22 additions and 2 deletions.
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

0 comments on commit 7604dbb

Please sign in to comment.