What i want to do is :
1) Install digital signed testing certificate in my mobile device (using S60).
2) Create a SMS sending form in midlet.
3) Digitally signed the information using installed certificate before sending via SMS sending form.
How would do this??
What i've done till:
1) I've installed a certificate from this link http://www.aloaha.com/wi-software-en/aloaha-pki.php.
2) I used following midlet as example:
3) While running this midlet. I'm unable to create .dat file. Even, file connection code is not executing.. as it is not showing any security exception regading file connection.Code:import javax.microedition.lcdui.*; import javax.microedition.midlet.MIDlet; import javax.microedition.securityservice.CMSMessageSignatureService; import javax.microedition.securityservice.CMSMessageSignatureServiceException; import javax.microedition.io.file.FileConnection; import javax.microedition.io.file.FileSystemRegistry; import java.io.OutputStream; import java.util.Enumeration; import javax.microedition.io.Connector; public class PaymentAuthorization extends MIDlet implements CommandListener { Display display = null; List employeeList = null; String[] employeeArray = {"Derrick Johnson, 40 hrs", "James Williams, 44 hrs", "Tirrell Payton, 42 hrs", "William Bean, 20 hrs"}; Form progressForm = null; Command authCommand = null; Command denyCommand = null; Command exitCommand = null; String originalMessage = null; byte[] signedMessage = null; String signedMessageFile = "paymentAuthorization.dat"; public PaymentAuthorization(){ employeeList = new List("Payment Authorization", List.IMPLICIT, employeeArray, null); employeeList.setCommandListener(this); authCommand = new Command("Authorize", Command.OK, 0); denyCommand = new Command("Deny", Command.OK, 0); exitCommand = new Command("Exit", Command.EXIT, 1); employeeList.addCommand(authCommand); employeeList.addCommand(denyCommand); progressForm = new Form("Signing Progress"); progressForm.addCommand(exitCommand); progressForm.setCommandListener(this); } public void startApp() { display = Display.getDisplay(this); display.setCurrent(employeeList); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command command, Displayable d) { if (command == exitCommand) { destroyApp(true); notifyDestroyed(); } else { display.setCurrent(progressForm); originalMessage = employeeArray[employeeList.getSelectedIndex()] + ", " + command.getLabel(); new Thread() { public void run() { progressForm.append("Sign test started ...\n"); System.out.println("Sign test started..."); signMessage(); progressForm.append("Sign test finished.\n"); System.out.println("Sign test finished."); } }.start(); } } private void signMessage() { String caName = "c=US,o=Aloaha Certification Authority,cn=Aloaha Certification Authority"; String[] caNames = new String[1]; String userPrompt = "Please insert the proper security element "; caNames[0] = caName; try { signedMessage = CMSMessageSignatureService.sign(originalMessage,CMSMessageSignatureService.SIG_INCLUDE_CERTIFICATE | CMSMessageSignatureService.SIG_INCLUDE_CONTENT, caNames, userPrompt); FileConnection fileConnection = null; OutputStream outputStream = null; try{ Enumeration e = FileSystemRegistry.listRoots(); String rootName = (String) e.nextElement (); String galleryPath = System.getProperty("fileconn.dir.photos"); fileConnection = (FileConnection)Connector.open(galleryPath + signedMessageFile); if (fileConnection.exists() == false){ fileConnection.create(); } outputStream = fileConnection.openOutputStream(); outputStream.write(signedMessage); outputStream.flush(); outputStream.close(); fileConnection.close(); } catch (Exception e){ System.out.println("Error creating file"); e.printStackTrace(); } } catch (IllegalArgumentException iae) { // Perform error handling iae.printStackTrace(); } catch (CMSMessageSignatureServiceException ce) { if (ce.getReason() == CMSMessageSignatureServiceException.CRYPTO_FORMAT_ERROR) { System.out.println("Error formatting signature."); } else { System.out.println(ce.getMessage()); } } catch (Exception e) { System.out.println("Other exception: " + e); } } }
Thanks!!!

Reply With Quote

