Search in sources :

Example 1 with CreateSignedPKCS7

use of org.nhindirect.trustbundle.core.CreateSignedPKCS7 in project nhin-d by DirectProject.

the class ButtonSelector method actionPerformed.

public void actionPerformed(ActionEvent event) {
    //System.out.println("Event"+event.getActionCommand());
    if (event.getActionCommand().equalsIgnoreCase("Create Bundle")) {
        Component[] data = pane.getComponents();
        JTextField anchorDir = (JTextField) data[4];
        JTextField metaDataFile = (JTextField) data[7];
        JTextField destDir = (JTextField) data[10];
        JTextField bundleName = (JTextField) data[13];
        CreateUnSignedPKCS7 unCert = new CreateUnSignedPKCS7();
        error = unCert.getParameters(anchorDir.getText(), metaDataFile.getText(), destDir.getText(), bundleName.getText());
        JTextPane feedback = (JTextPane) data[16];
        feedback.setText(error);
    } else if (event.getActionCommand().equalsIgnoreCase("Create Signed Bundle")) {
        Component[] data = pane.getComponents();
        JTextField anchorDir = (JTextField) data[4];
        JTextField metaDataFile = (JTextField) data[7];
        JTextField certificateDir = (JTextField) data[10];
        JPasswordField passkey = (JPasswordField) data[13];
        //String passVal=new String();
        //System.out.println("The password:"+String.copyValueOf(passkey.getPassword()));
        JTextField destDir = (JTextField) data[15];
        JTextField bundleName = (JTextField) data[18];
        CreateSignedPKCS7 unCert = new CreateSignedPKCS7();
        error = unCert.getParameters(anchorDir.getText(), metaDataFile.getText(), certificateDir.getText(), String.copyValueOf(passkey.getPassword()), destDir.getText(), bundleName.getText());
        //System.out.println("The destination file path is:"+error);
        JTextPane feedback = (JTextPane) data[21];
        feedback.setText(error);
    } else {
        Component[] data = pane.getComponents();
        JTextField trustBundle = (JTextField) data[4];
        ViewTrustBundlePKCS7 unCert = new ViewTrustBundlePKCS7();
        error = unCert.getParameters(trustBundle.getText());
        new PreviewTrustBundle(error);
        PreviewTrustBundle.createAndShowGUI();
    //JTextPane feedback = (JTextPane) data[8];
    //feedback.setText(error);
    }
}
Also used : ViewTrustBundlePKCS7(org.nhindirect.trustbundle.core.ViewTrustBundlePKCS7) JTextPane(javax.swing.JTextPane) CreateUnSignedPKCS7(org.nhindirect.trustbundle.core.CreateUnSignedPKCS7) JPasswordField(javax.swing.JPasswordField) CreateSignedPKCS7(org.nhindirect.trustbundle.core.CreateSignedPKCS7) Component(java.awt.Component) JTextField(javax.swing.JTextField) PreviewTrustBundle(org.nhindirect.trustbundle.ui.PreviewTrustBundle)

Example 2 with CreateSignedPKCS7

use of org.nhindirect.trustbundle.core.CreateSignedPKCS7 in project nhin-d by DirectProject.

the class TestCreateSignedPKCS7 method testGetParameters.

@Test
public void testGetParameters() {
    CreateSignedPKCS7 cspk = new CreateSignedPKCS7();
    //CASE 1 : WRONG XML FILE
    actual = cspk.getParameters(anchorDir, "test", certificateDir, passkey, destDir, bundleName);
    assertEquals("Error: Kindly Provide A XML Meta data file", actual);
    //CASE 2 : NOT SELECTING TRUST ANCHOR DIRECTORY
    actual = cspk.getParameters("Select Trust Anchor Directory", metaDataFile, certificateDir, passkey, destDir, bundleName);
    assertEquals("Error: Kindly Provide A Trust Anchor Directory", actual);
    //CASE 3 : CANCEL WHILE SELECT TRUST ANCHOR DIRECTORY
    actual = cspk.getParameters("You pressed cancel", metaDataFile, certificateDir, passkey, destDir, bundleName);
    assertEquals("Error: Kindly Provide A Trust Anchor Directory", actual);
    //CASE 4 : TRUST BUNDLE DESTINATION DIRECTORY NOT PASSED
    actual = cspk.getParameters(anchorDir, metaDataFile, certificateDir, passkey, "Select Trust Bundle Destination Directory", bundleName);
    assertEquals("Error: Kindly Provide A Trust Bundle Destination Directory", actual);
    //CASE 5 : CANCEL WHILE TRUST BUNDLE DESTINATION DIRECTORY NOT PASSED
    actual = cspk.getParameters(anchorDir, metaDataFile, certificateDir, passkey, "You pressed cancel", bundleName);
    assertEquals("Error: Kindly Provide A Trust Bundle Destination Directory", actual);
    //CASE 6 : PASSING WRONG PASSWORD
    actual = cspk.getParameters(anchorDir, metaDataFile, certificateDir, "wrongpass", destDir, bundleName);
    assertEquals("Error: Creation ofsignednometadata.p7mfile failed!", actual);
    //CASE 7 : BUNDLE NAME WRONG FORMAT
    actual = cspk.getParameters(anchorDir, metaDataFile, certificateDir, passkey, destDir, "signedBundle.ppp");
    assertEquals("Error: Kindly Provide A Proper Trust Bundle Name with extension .p7m", actual);
    //CASE 8 : ALL PARAMETERS ARE CORRECT
    actual = cspk.getParameters(anchorDir, metaDataFile, certificateDir, passkey, destDir, bundleName);
    assertEquals("Message: signednometadata.p7m created successfully!", actual);
//fail("Not yet implemented"); // TODO
}
Also used : CreateSignedPKCS7(org.nhindirect.trustbundle.core.CreateSignedPKCS7) Test(org.junit.Test)

Example 3 with CreateSignedPKCS7

use of org.nhindirect.trustbundle.core.CreateSignedPKCS7 in project nhin-d by DirectProject.

the class TestCreateSignedPKCS7 method testCreate.

@Test
public void testCreate() {
    CreateSignedPKCS7 cspk = new CreateSignedPKCS7();
    //CASE 1: ALL PARAMETER CORRECT
    createFile = new File(projectPath + "src\\test\\resources\\testdataoutput\\signedmetadata1.p7m");
    expectedfile = new File(projectPath + "src\\test\\resources\\testdataoutput\\signedmetadata1.p7m");
    actualfile = cspk.create(anchorDir, createFile, metaFile, metaExists, p12certiFile, passkey);
    assertEquals(expectedfile, actualfile);
    //CASE 2: ANCHOR DIRECTORY WRONG
    createFile = new File(projectPath + "src\\test\\resources\\testdataoutput\\signedmetadata2.p7m");
    actualfile = cspk.create("src\\test\\resources\\wrong directory", createFile, metaFile, metaExists, p12certiFile, passkey);
    assertEquals(null, actualfile);
    //CASE 3: WRONG META FILE WITH METAFILEEXISTS TRUE
    actualfile = cspk.create(anchorDir, createFile, new File(projectPath + "src\\test\\resources\\testdatainput\\wrong meta file.xml"), metaExists, p12certiFile, passkey);
    assertEquals(null, actualfile);
    //CASE 4: CORRECT META FILE WITH METAFILEEXISTS FALSE
    createFile = new File(projectPath + "src\\test\\resources\\testdataoutput\\signednometadata1.p7m");
    expectedfile = new File(projectPath + "src\\test\\resources\\testdataoutput\\signednometadata1.p7m");
    actualfile = cspk.create(anchorDir, createFile, metaFile, false, p12certiFile, passkey);
    assertEquals(expectedfile, actualfile);
    //CASE 5: WRONG META FILE WITH METAFILEEXISTS FALSE
    createFile = new File(projectPath + "src\\test\\resources\\testdataoutput\\signednometadata2.p7m");
    expectedfile = new File(projectPath + "src\\test\\resources\\testdataoutput\\signednometadata2.p7m");
    actualfile = cspk.create(anchorDir, createFile, new File(projectPath + "src\\test\\resources\\testdatainput\\wrong meta file.xml"), false, p12certiFile, passkey);
    assertEquals(expectedfile, actualfile);
    //CASE 6: WRONG p12certiFile
    actualfile = cspk.create(anchorDir, createFile, metaFile, true, new File(projectPath + "src\\test\\resources\\testdatainput\\wrongfile.p12"), passkey);
    assertEquals(null, actualfile);
    //CASE 7: PASS KEY NULL
    createFile = new File(projectPath + "src\\test\\resources\\testdataoutput\\signedmetadata2nopass.p7m");
    expectedfile = new File(projectPath + "src\\test\\resources\\testdataoutput\\signedmetadata2nopass.p7m");
    actualfile = cspk.create(anchorDir, createFile, metaFile, true, p12certiFile, null);
    assertEquals(expectedfile, actualfile);
}
Also used : CreateSignedPKCS7(org.nhindirect.trustbundle.core.CreateSignedPKCS7) File(java.io.File) Test(org.junit.Test)

Aggregations

CreateSignedPKCS7 (org.nhindirect.trustbundle.core.CreateSignedPKCS7)3 Test (org.junit.Test)2 Component (java.awt.Component)1 File (java.io.File)1 JPasswordField (javax.swing.JPasswordField)1 JTextField (javax.swing.JTextField)1 JTextPane (javax.swing.JTextPane)1 CreateUnSignedPKCS7 (org.nhindirect.trustbundle.core.CreateUnSignedPKCS7)1 ViewTrustBundlePKCS7 (org.nhindirect.trustbundle.core.ViewTrustBundlePKCS7)1 PreviewTrustBundle (org.nhindirect.trustbundle.ui.PreviewTrustBundle)1