From bc07f0c7dbd3f1392074865c23a72c8cc99e247c Mon Sep 17 00:00:00 2001 From: Denis Klygov Date: Tue, 12 Dec 2023 13:24:28 +0600 Subject: [PATCH] =?UTF-8?q?CORE-2380=20=D0=92=20=D0=BD=D0=BE=D0=B2=D0=BE?= =?UTF-8?q?=D0=BC=20NCAnode=20=D0=BD=D0=B5=20=D1=84=D0=B8=D0=BD=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B7=D0=B8=D1=80=D1=83=D0=B5=D1=82=D1=81=D1=8F=20?= =?UTF-8?q?=D1=82=D0=B8=D0=BA=D0=B5=D1=82,=20=D0=B5=D1=81=D0=BB=D0=B8=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=BA=D1=83=D0=BC=D0=B5=D0=BD=D1=82=20=D0=B1=D1=8B?= =?UTF-8?q?=D0=BB=20=D0=BF=D0=BE=D0=B4=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=20?= =?UTF-8?q?=D0=B4=D0=B0=D0=B2=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - При проверке TSP метки, при получении аттрибутов (фиг знает, че за аттрибуты), мог вернуться как вектор, так и 1 аттрибут. Добавил обработку и вектора, и одного объекта. --- .../java/kz/ncanode/service/CmsService.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/kz/ncanode/service/CmsService.java b/src/main/java/kz/ncanode/service/CmsService.java index 22165181..a4dcbd11 100644 --- a/src/main/java/kz/ncanode/service/CmsService.java +++ b/src/main/java/kz/ncanode/service/CmsService.java @@ -228,16 +228,23 @@ public CmsVerificationResponse verify(String signedCms, String detachedData, boo // TSP Checking if (signer.getUnsignedAttributes() != null) { var attrs = signer.getUnsignedAttributes().toHashtable(); - if (attrs.containsKey(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken)) { - Attribute attr = (Attribute) attrs.get(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken); - - - if (attr.getAttrValues().size() != 1) { + Object maybeVectorOrAttr = attrs.get(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken); + + Optional attr = maybeVectorOrAttr instanceof Vector + ? Optional.of(((List) maybeVectorOrAttr) + .stream() + .filter(Objects::nonNull) + .map(Attribute.class::cast) + .findFirst() + .orElseThrow(() -> new Exception("No attributes found"))) + : Optional.of((Attribute) maybeVectorOrAttr); + + if (attr.get().getAttrValues().size() != 1) { throw new Exception("Too many TSP tokens"); } - CMSSignedData tspCms = new CMSSignedData(attr.getAttrValues().getObjectAt(0).getDERObject().getEncoded()); + CMSSignedData tspCms = new CMSSignedData(attr.get().getAttrValues().getObjectAt(0).getDERObject().getEncoded()); TimeStampTokenInfo tspi = tspService.info(tspCms).orElseThrow(); try {