1 7 8 package org.enhydra.oyster.test; 9 10 import org.enhydra.oyster.smime.SignedSMIME; 11 import org.enhydra.oyster.exception.SMIMEException; 12 import java.io.File ; 13 import java.io.ByteArrayInputStream ; 14 import java.io.InputStream ; 15 16 17 44 public class TestSignedGeneratedHtml 45 { 46 47 public static void main(String [] args) 48 { 49 50 String subject = "S/MIME signed message - Subject test: ÜüÄäÖöÜüß"; 51 String from = "sender@together.at"; 52 String password = "together"; 53 54 if (args.length < 7) 55 { 56 System.err.println( 57 System.getProperty("line.separator") + 58 "Usage of TestSignedGeneratedHtml: " + 59 System.getProperty("line.separator") + 60 "java TestSignedGeneratedHtml <mailHost> <mailAddress> <digestAlgorithm> " + 61 "<includingCert> <includingSignAttrib> <pfxFileName> <externalSigning>" + 62 "[<attachment>]" + 63 System.getProperty("line.separator") + 64 System.getProperty("line.separator") + 65 "Examples:" + 66 System.getProperty("line.separator") + 67 "java TestSignedGeneratedHtml together.at recipient@together.at SHA1_WITH_RSA true " + 68 "true sender512.pfx true"+ 69 System.getProperty("line.separator") + 70 "java TestSignedGeneratedHtml together.at recipient@together.at SHA1_WITH_DSA true " + 71 "true senderDSA512.pfx false .\\test\\Zip8Test.zip"); 72 System.exit(-1); 73 } 74 75 String smtpHost = args[0]; 76 String addressTO = args[1]; 77 String digestAlgorithm = args[2]; 78 79 boolean includingCert = true; 80 if (args[3].equalsIgnoreCase("true")) 81 includingCert = true; 82 else 83 includingCert = false; 84 85 boolean includingSignAttrib = true; 86 if (args[4].equalsIgnoreCase("true")) 87 includingSignAttrib = true; 88 else 89 includingSignAttrib = false; 90 91 String pfxfileName = args[5]; 92 93 boolean externalSigning = true; 94 if (args[6].equalsIgnoreCase("true")) 95 externalSigning = true; 96 else 97 externalSigning = false; 98 99 String fileName = null; 100 if (args.length > 7) 101 fileName = args[7]; 102 103 String addressCC = "recipient@together.at"; 104 String addressBCC = "recipient@together.at"; 105 106 subject = digestAlgorithm + " " + args[3] + " " + args[4] + " " + 107 pfxfileName + " " + args[6] + " " + subject; 108 109 SignedSMIME ss = null; 110 111 try { 112 ExampleGenerator generator = new ExampleGenerator(); 113 114 String green = "*****000generated.gif"; 119 120 File redFile = new File ("./test/pictures/red.gif"); 123 String red = redFile.getAbsoluteFile().getCanonicalPath(); 124 125 File blueFile = new File ("./test/pictures/blue.gif"); 128 String blue = "file:///" + blueFile.getAbsoluteFile().getCanonicalPath(); 129 blue = blue.replace('\\','/'); 130 131 String commonPath = new File ("./test/HtmlTest.html").getParent(); 138 139 generator.setResourceInExampleHtml("GREEN", green); 140 generator.setResourceInExampleHtml("RED", red); 141 generator.setResourceInExampleHtml("BLUE", blue); 142 143 InputStream [] in = {generator.getGifImage()}; 145 146 ss = new SignedSMIME(smtpHost, from, subject, "ISO-8859-1"); 148 149 ss.setContent( generator.getHtmlString(), "text/html", commonPath, in ); 151 155 ss.addAttachment(generator.getZipStream(), "test.zip"); 159 160 File attachment2 = new File ("./test/AdobeAcrobatTest.pdf"); 162 ss.addAttachment(attachment2); 163 File attachment3 = new File ("./test/Word2000Test.doc"); 164 ss.addAttachment(attachment3); 165 166 if (fileName!=null) { 167 ss.addAttachment(fileName); } 169 170 ss.setReply(from); 172 ss.addRecipient(addressTO, "TO"); 176 ss.setCapabilities("SYMMETRIC", 5, 3, 1, 4, 2); ss.setCapabilities("ENCIPHER", 1, 0, 0, 0, 0); ss.setCapabilities("SIGNATURE", 1, 2, 3, 4, 0); 180 ss.addSigner(pfxfileName, password, digestAlgorithm, 181 includingCert, includingSignAttrib); 183 System.out.println("Creating signed message with " + digestAlgorithm + " algorithm ... "); 184 ss.signing(externalSigning); 185 System.out.print("Sending signed message ... "); 186 ss.send(); System.out.println("done."); 189 } 190 catch (Exception e) { 191 SMIMEException.setErrorFilePath("Log"); if(e instanceof SMIMEException) { 193 SMIMEException eTmp = (SMIMEException)e; 194 eTmp.displayErrors(null); 196 e = eTmp.getNonSMIMEException(); 197 if(e != null) 198 e.printStackTrace(); 199 } 200 else { 201 e.printStackTrace(); 202 } 203 } 204 } 205 206 207 } | Popular Tags |