use of com.helger.phase4.crypto.AS4CryptoProperties in project phase4 by phax.
the class MainPhase4PeppolSenderExplicitCryptoProperties method main.
public static void main(final String[] args) {
WebScopeManager.onGlobalBegin(MockServletContext.create());
try {
final byte[] aPayloadBytes = SimpleFileIO.getAllFileBytes(new File("src/test/resources/examples/base-example.xml"));
if (aPayloadBytes == null)
throw new IllegalStateException("Failed to read XML file to be send");
// Manual information - don't use crypto.properties
final AS4CryptoProperties aCP = new AS4CryptoProperties().setKeyStoreType(EKeyStoreType.PKCS12).setKeyStorePath("test-ap.p12").setKeyStorePassword("peppol").setKeyAlias("openpeppol aisbl id von pop000306").setKeyPassword("peppol").setTrustStoreType(EKeyStoreType.JKS).setTrustStorePath("complete-truststore.jks").setTrustStorePassword("peppol");
// Start configuring here
final IParticipantIdentifier aReceiverID = Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("9958:peppol-development-governikus-01");
final ESimpleUserMessageSendResult eResult;
eResult = Phase4PeppolSender.builder().cryptoFactory(new AS4CryptoFactoryProperties(aCP)).documentTypeID(Phase4PeppolSender.IF.createDocumentTypeIdentifierWithDefaultScheme("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0::2.1")).processID(Phase4PeppolSender.IF.createProcessIdentifierWithDefaultScheme("urn:fdc:peppol.eu:2017:poacc:billing:01:1.0")).senderParticipantID(Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("9915:phase4-test-sender")).receiverParticipantID(aReceiverID).senderPartyID("POP000306").payload(aPayloadBytes).smpClient(new SMPClientReadOnly(Phase4PeppolSender.URL_PROVIDER, aReceiverID, ESML.DIGIT_TEST)).validationConfiguration(PeppolValidation3_13_0.VID_OPENPEPPOL_INVOICE_V3, new Phase4PeppolValidatonResultHandler()).sendMessageAndCheckForReceipt();
LOGGER.info("Peppol send result: " + eResult);
} catch (final Exception ex) {
LOGGER.error("Error sending Peppol message via AS4", ex);
} finally {
WebScopeManager.onGlobalEnd();
}
}
use of com.helger.phase4.crypto.AS4CryptoProperties in project phase4 by phax.
the class MainDecipherAS4In method main.
public static void main(final String[] args) throws Exception {
final File folder = new File("src/test/resources/incoming/");
if (!folder.isDirectory())
throw new IllegalStateException();
final File f = new File(folder, "165445-9-8a813f8d-3dda-4ef9-868e-f6d829972d4e.as4in");
if (!f.exists())
throw new IllegalStateException();
final AS4CryptoProperties aCP = new AS4CryptoProperties(new FileSystemResource(folder, "crypto.properties"));
aCP.setKeyStorePath(folder.getAbsolutePath() + "/" + aCP.getKeyStorePath());
aCP.setTrustStorePath(folder.getAbsolutePath() + "/" + aCP.getTrustStorePath());
LOGGER.info("Reading " + f.getName());
final byte[] aBytes = SimpleFileIO.getAllFileBytes(f);
AS4DumpReader.decryptAS4In(aBytes, new AS4CryptoFactoryProperties(aCP), null, aDecryptedBytes -> SimpleFileIO.writeFile(new File(folder, "payload.decrypted"), aDecryptedBytes));
}
use of com.helger.phase4.crypto.AS4CryptoProperties in project phase4 by phax.
the class AS4ClientReceiptMessageTest method testBuildMessageSignedChecks.
@Test
public void testBuildMessageSignedChecks() throws Exception {
final AS4ClientReceiptMessage aClient = new AS4ClientReceiptMessage(s_aResMgr);
aClient.setSoapVersion(ESoapVersion.AS4_DEFAULT);
// Parse EBMS3 Messaging object
final Node aPayload = DOMReader.readXMLDOM(new ClassPathResource(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML));
aClient.setSoapDocument(MockMessages.createUserMessageSigned(aClient.getSoapVersion(), aPayload, null, s_aResMgr));
aClient.setNonRepudiation(true);
aClient.setReceiptShouldBeSigned(true);
final AS4CryptoProperties aCP = new AS4CryptoProperties().setKeyStoreType(EKeyStoreType.JKS).setKeyStorePath("keys/dummy-pw-test.jks").setKeyStorePassword("test").setKeyAlias("ph-as4").setKeyPassword("test");
aClient.setAS4CryptoFactory(new AS4CryptoFactoryProperties(aCP));
aClient.signingParams().setAlgorithmSign(ECryptoAlgorithmSign.SIGN_ALGORITHM_DEFAULT).setAlgorithmSignDigest(ECryptoAlgorithmSignDigest.SIGN_DIGEST_ALGORITHM_DEFAULT);
_ensureValidState(aClient);
}
use of com.helger.phase4.crypto.AS4CryptoProperties in project phase4 by phax.
the class AS4ClientUserMessageTest method _setKeyStoreTestData.
/**
* Sets the keystore attributes, it uses the dummy keystore
* keys/dummy-pw-test.jks
*
* @param aClient
* the client on which these attributes should be set
* @return the client to continue working with it
*/
@Nonnull
private static AS4ClientUserMessage _setKeyStoreTestData(@Nonnull final AS4ClientUserMessage aClient) {
final AS4CryptoProperties aCP = new AS4CryptoProperties().setKeyStoreType(EKeyStoreType.JKS).setKeyStorePath("keys/dummy-pw-test.jks").setKeyStorePassword("test").setKeyAlias("ph-as4").setKeyPassword("test");
aClient.setAS4CryptoFactory(new AS4CryptoFactoryProperties(aCP));
aClient.cryptParams().setAlias(aCP.getKeyAlias());
return aClient;
}
use of com.helger.phase4.crypto.AS4CryptoProperties in project phase4 by phax.
the class AS4ClientUserMessageTest method testBuildMessageKeyStoreCheckFailure.
@Test
public void testBuildMessageKeyStoreCheckFailure() throws Exception {
final AS4ClientUserMessage aClient = _createMandatoryAttributesSuccessMessage();
// Set sign attributes, to get to the check, the check only gets called if
// sign or encrypt needs to be done for the usermessage
aClient.signingParams().setAlgorithmSign(ECryptoAlgorithmSign.RSA_SHA_256).setAlgorithmSignDigest(ECryptoAlgorithmSignDigest.DIGEST_SHA_256);
// No Keystore attributes set
_ensureInvalidState(aClient);
final AS4CryptoProperties aCP = new AS4CryptoProperties().setKeyStorePath("keys/dummy-pw-test.jks");
final AS4CryptoFactoryProperties aCF = new AS4CryptoFactoryProperties(aCP);
aClient.setAS4CryptoFactory(aCF);
_ensureInvalidState(aClient);
aCF.cryptoProperties().setKeyStorePassword("test");
_ensureInvalidState(aClient);
aCF.cryptoProperties().setKeyStoreType(EKeyStoreType.JKS);
_ensureInvalidState(aClient);
aCF.cryptoProperties().setKeyAlias("ph-as4");
_ensureInvalidState(aClient);
aCF.cryptoProperties().setKeyPassword("test");
_ensureValidState(aClient);
}
Aggregations