@@ -90,15 +90,17 @@ private HttpSession currentSession() {
9090 * @return data to be signed
9191 */
9292 public DigestDTO prepareContainer (CertificateDTO certificateDTO , WebEidAuthentication authentication ) throws CertificateException , NoSuchAlgorithmException , IOException {
93- X509Certificate certificate = certificateDTO .toX509Certificate ();
94- if (!authentication .getIdCode ().equals (CertificateData .getSubjectIdCode (certificate ))) {
93+ final X509Certificate certificate = certificateDTO .toX509Certificate ();
94+ final String signingIdCode = CertificateData .getSubjectIdCode (certificate )
95+ .orElseThrow (() -> new RuntimeException ("Certificate does not contain subject ID code" ));
96+ if (!signingIdCode .equals (authentication .getIdCode ())) {
9597 throw new IllegalArgumentException ("Authenticated subject ID code differs from " +
9698 "signing certificate subject ID code" );
9799 }
98100
99- FileDTO fileDTO = FileDTO .getExampleForSigningFromResources ();
100- Container containerToSign = getContainerToSign (fileDTO );
101- String containerName = generateContainerName (fileDTO .getName ());
101+ final FileDTO fileDTO = FileDTO .getExampleForSigningFromResources ();
102+ final Container containerToSign = getContainerToSign (fileDTO );
103+ final String containerName = generateContainerName (fileDTO .getName ());
102104
103105 currentSession ().setAttribute (SESSION_ATTR_CONTAINER , containerToSign );
104106 currentSession ().setAttribute (SESSION_ATTR_FILE , fileDTO );
@@ -113,7 +115,7 @@ public DigestDTO prepareContainer(CertificateDTO certificateDTO, WebEidAuthentic
113115 "' is not supported. Supported algorithms are: " + String .join (", " , certificateDTO .getSupportedHashFunctionNames ()));
114116 }
115117
116- DataToSign dataToSign = SignatureBuilder
118+ final DataToSign dataToSign = SignatureBuilder
117119 .aSignature (containerToSign )
118120 .withSignatureProfile (SignatureProfile .LT ) // AIA OCSP is supported for signatures with LT or LTA profile.
119121 .withSigningCertificate (certificate )
@@ -127,7 +129,7 @@ public DigestDTO prepareContainer(CertificateDTO certificateDTO, WebEidAuthentic
127129 final byte [] digest = signatureDigestAlgorithm .getDssDigestAlgorithm ().getMessageDigest ()
128130 .digest (dataToSign .getDataToSign ());
129131
130- DigestDTO digestDTO = new DigestDTO ();
132+ final DigestDTO digestDTO = new DigestDTO ();
131133 digestDTO .setHash (DatatypeConverter .printBase64Binary (digest ));
132134 digestDTO .setHashFunction (digestAlgorithmName );
133135
0 commit comments