Library v3.1 supports only Smart-ID v3 API. All the previous v2 related code has been removed and all the code necessary for Smart-ID API v3 is under package smartid. Some classes could also be used in v3 and for those classes the package did not change.
For signing flows are restored legacy RSASSA-PKCS#1 v1.5 algorithms (SHA256_WITH_RSA_ENCRYPTION, SHA384_WITH_RSA_ENCRYPTION, SHA512_WITH_RSA_ENCRYPTION) which are compatible with DigiDoc4j's signing support.
For that reason:
SignatureAlgorithmclass is split intoAuthenticationSignatureAlgorithmandSigningSignatureAlgorithm.SignatureValueValidator.validatelast parameter changed fromRsaSsaPssParameterstoSignatureFactory
Changes needed in authentication flows:
- change
SignatureAlgorithmtoAuthenticationSignatureAlgorithm - change
SignatureValueValidator.validatelast parameter fromRsaSsaPssParameterstonew RsaSsaPssSignatureFactory(RsaSsaPssParameters)
Changes needed in signing flows:
- change
SignatureAlgorithmtoSigningSignatureAlgorithm - suggestion for
SignatureValueValidator.validatelast parameter changes:- when using only signature algorithm RSASSA_PSS then use
new RsaSsaPssSignatureFactory(RsaSsaPssParameters) - when using only legacy signature algorithms (
SHA256_WITH_RSA_ENCRYPTION,SHA384_WITH_RSA_ENCRYPTION,SHA512_WITH_RSA_ENCRYPTION) then usenew RsaSsaPkcs1SignatureFactory(SigningSignatureAlgorithm) - when both RSASSA_PSS and legacy RSA algorithms are used then possible solution is:
SignatureFactory signatureFactory = signatureResponse.getSignatureAlgorithm().isLegacyRsa() ? new RsaSsaPkcs1SignatureFactory(signatureResponse.getSignatureAlgorithm()) : new RsaSsaPssSignatureFactory(signatureResponse.getRsaSsaPssParameters());
- when using only signature algorithm RSASSA_PSS then use
The following classes are moved from ee.sk.smartid to ee.sk.smartid.signature so when used then imports need to be adjusted:
AuthenticationSignatureAlgorithmDigestInputMaskGenAlgorithmRsaSsaPssParametersSignableDataSignableHashSignatureValueValidatorSignatureValueValidatorImplSigningSignatureAlgorithmTrailerField
For legacy RSA with DigiDoc4j there is new chapter in README.md: Legacy algorithms for signing with DigiDoc4j
Smart-ID v3 authentication offers new methods to construct builders createDeviceLinkAuthentication() and createNotificationAuthentication() to create authentication session request builders.
It is recommended to start using device-link authentication flows from Smart-ID API v3 as these are more secure.
- Create authentication hash
- Generate verification code from authentication hash
- Verification code can be shown to the user
- Create builder and set values.
- Call build method (
authenticate()) to create authentication session and to start polling for session status. - After session status is
COMPLETEresponse will be checked in the build method. - Use
AuthenticationResponseValidatorto validate the certificate and the signature in the response.
- Replace generating authentication hash with generating RP challenge using
RpChallengeGenerator.generate() - Create device-link authentication builder and set values and start authentication session by calling build-method
initAuthenticationSession() - Replace showing verification code with showing device link or QR-code. Recommended to use device link for same device and QR-code for cross-device authentication.
- Create device link or QR-code from values in session response and display it to the user. QR-code should be recreated after every second.
- Querying session status can be done in parallel while displaying device content. Check out session status poller.
ee.sk.smartid.SmartIdClientprovides methodgetSessionsStatusPoller()to get version specific session status poller. - When session status state is
COMPLETEpolling will be stopped and response should be checked withDeviceLinkAuthenticationResponseValidatororNotificationAuthenticationResponseValidator(depending on the flow). They will validate required fields, certificate and signature value in sessions status, and they will also handle errors. - If everything is ok
AuthenticationIdentitywill be returned. AuthenticationIdentity is same as used for V2.
Signing migration will be focusing on moving to signature flow when device link authentication has been completed before.
- Set values for certificate choice builder and call build method. Should return certificate as a response.
- Use queried certificate to create DataToSign object. Requires DigiDoc4j library.
- Create SignableData from DataToSign.
- Create verification code from SignableData
- Create signature builder and set values.
- Call build method (
sign()) to create signing session and to start polling for session status. - After session status is
COMPLETEresponse will be checked in the build method. And signed document will be returned.
DigiDoc4j library does not currently support signing with signature algorithm RSASSA-PSS. Support will be added in the future. There is a possible workaround to use DigiDoc4j library and DSS library together to create ASICS container and sign it with Smart-ID v3 API. Steps below include examples how to set up DataToSign for signing with RSASSA-PSS and how validate returned signature value.
- Replace certificate choice builder with
CertificateByDocumentNumberRequestBuilder. SmartID clientee.sk.smartid.SmartIdClientprovides methodcreateCertificateByDocumentNumber()for easier access. Call build method.getCertificateByDocumentNumber()to get the certificate. Checkout example here. - Use
SignableDatato create digested value for signing. Example for setting up DataToSign with DSS: https://github.com/SK-EID/smart-id-java-demo/blob/81880330822f7d86a9205e597f24bca42c72d87b/src/main/java/ee/sk/siddemo/services/SmartIdDeviceLinkSignatureService.java#L181 - Use
ee.sk.smartid.SmartIdClientto create session request buildercreateDeviceLinkSignature()and call build methodinitSignatureSession()to start the signing session. - Replace showing verification code with showing device link or QR-code. Create device link or QR-code from values in session response and display it to the user. QR-code should be recreated after every second.
- Poll for session status until its complete.
- Validate session response with
SignatureResponseValidator.SignatureSessionResponsewill be returned when everything is ok. - Validate signature value. Example for validating signature value: https://github.com/SK-EID/smart-id-java-demo/blob/81880330822f7d86a9205e597f24bca42c72d87b/src/main/java/ee/sk/siddemo/services/SmartIdSignatureService.java#L65
NB! Without DigiDoc4j library integrator has to provide implementation for creating signed container. Smart-id-java-client only provides means to validate that signature response has required fields and returned signature value is valid.
- Replace certificate choice builder with
CertificateByDocumentNumberRequestBuilder. SmartID clientee.sk.smartid.SmartIdClientprovides methodcreateCertificateByDocumentNumber()for easier access. Call build method.getCertificateByDocumentNumber()to get the certificate. Checkout example here. - Use
SignableDatato create digested value for signing. - Use
ee.sk.smartid.SmartIdClientto create session request buildercreateDeviceLinkSignature()and call build methodinitSignatureSession()to start the signing session. - Replace showing verification code with showing device link or QR-code. Create device link or QR-code from values in session response and display it to the user. QR-code should be recreated after every second.
- Poll for session status until its complete.
- Validate session status response with
SignatureResponseValidator.SignatureSessionResponsewill be returned when everything is ok. - Validate signature value with
SignatureValueValidator