generated from pagopa/pagopa-functions-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SELC-5507] feat: namirial implementation in onboarding-crypto sdk (#500
- Loading branch information
1 parent
e5e6e2d
commit 06f4e97
Showing
22 changed files
with
341 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...sdk-crypto/src/main/java/it/pagopa/selfcare/onboarding/crypto/NamiralSignServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package it.pagopa.selfcare.onboarding.crypto; | ||
|
||
import it.pagopa.selfcare.onboarding.crypto.client.NamirialHttpClient; | ||
import it.pagopa.selfcare.onboarding.crypto.entity.Credentials; | ||
import it.pagopa.selfcare.onboarding.crypto.entity.Preferences; | ||
import it.pagopa.selfcare.onboarding.crypto.entity.SignRequest; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.StandardCopyOption; | ||
|
||
|
||
public class NamiralSignServiceImpl implements NamirialSignService { | ||
|
||
private final NamirialHttpClient namirialHttpClient; | ||
private final String username; | ||
private final String password; | ||
|
||
// Constructor for manual dependency injection | ||
public NamiralSignServiceImpl(String username, | ||
String password | ||
) { | ||
this.namirialHttpClient = new NamirialHttpClient(); | ||
this.username = username; | ||
this.password = password; | ||
} | ||
|
||
@Override | ||
public byte[] pkcs7Signhash(InputStream is) { | ||
try { | ||
|
||
Path tempFilePath = Files.createTempFile("tempfile", ".pdf"); | ||
File tempFile = tempFilePath.toFile(); | ||
|
||
// Copy InputStream data to the temporary file | ||
Files.copy(is, tempFilePath, StandardCopyOption.REPLACE_EXISTING); | ||
|
||
Credentials credentials = new Credentials(username, password); | ||
Preferences preferences = new Preferences("SHA256"); | ||
SignRequest request = new SignRequest(tempFile, credentials, preferences); | ||
|
||
return namirialHttpClient.signDocument(request); | ||
} catch (IOException e) { | ||
throw new IllegalStateException("Something gone wrong when invoking Namirial in order to calculate pkcs7 hash sign request", e); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
.../src/main/java/it/pagopa/selfcare/onboarding/crypto/NamirialPkcs7HashSignServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package it.pagopa.selfcare.onboarding.crypto; | ||
|
||
import java.io.InputStream; | ||
|
||
public class NamirialPkcs7HashSignServiceImpl implements Pkcs7HashSignService { | ||
|
||
private final NamirialSignService namirialSignService; | ||
|
||
public NamirialPkcs7HashSignServiceImpl(NamirialSignService namirialSignService) { | ||
this.namirialSignService = namirialSignService; | ||
} | ||
|
||
|
||
@Override | ||
public byte[] sign(InputStream is) { | ||
return namirialSignService.pkcs7Signhash(is); | ||
} | ||
|
||
|
||
@Override | ||
public boolean returnsFullPdf() { | ||
return true; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...ng-sdk-crypto/src/main/java/it/pagopa/selfcare/onboarding/crypto/NamirialSignService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package it.pagopa.selfcare.onboarding.crypto; | ||
|
||
|
||
import java.io.InputStream; | ||
|
||
public interface NamirialSignService { | ||
byte[] pkcs7Signhash(InputStream is); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.