Skip to content

Commit

Permalink
Fixed bug while add TSP in addSigners method
Browse files Browse the repository at this point in the history
При добавлении новой подписи в существующий CMS перезаписывались TSP в предыдущих подписях.
  • Loading branch information
yezhakov committed Oct 11, 2023
1 parent 546133b commit bbb0377
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 bbb0377

Please sign in to comment.