×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    16

    Security Exception in Socket creation

    Hi,

    I want to send a file from my mobile to a server.

    I tried creating a socket connection and sending the file. It worked fine in the WTK emulator. But when i tried it in my Nokia N70 mobile it threw a security exception.

    The code that i used:

    c = (SocketConnection) Connector.open("socket://" + uploadURL + ":80");

    I haven't signed my MIDlet. Could that be a problem? If so how can i get the required certificate?

    Thanks,
    veeyenkay

  2. #2
    Super Contributor
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,429

    Re: Security Exception in Socket creation

    Signing is not at all necessary. Signing will make your application trusted and avoid the permission messages. Are you getting any permission messages? If you dont allow those permission messages Security Exception will be thrown. Please try allowing those permission questions.

    Regards
    Gopal

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    16

    Re: Security Exception in Socket creation

    I gave Yes to all the permission questions. But i still i get the Security exception. Does Nokia N70 support operating on sockets?

    Thanks
    veeyenkay

  4. #4
    Regular Contributor
    Join Date
    Feb 2006
    Posts
    150

    Re: Security Exception in Socket creation

    Hi veeyenkay!

    I also have the N70 phone in the Spanish version and while I was developing MIDlets which wrote in files I noted that when you installed a MIDlet some permissions are not allowed by default! For example the "Edit User Data Permission" was always "not allowed"!

    This means that if you launch a MIDlet with one/several permission/s which aren't allowed by default then the MIDlet launches "Security Exceptions" automatically, without prompting for the user, when the application tries to use this permission!

    I would revise the MIDlet Permissions in Tools-->App Management-->Your MIDlet-->Options-->MIDlet Permissions and I would switch those Permissions on and then I would test the MIDlet again!

    I hope this post was useful for you! If you find the solution I would like you to keep me informed!

    Good Luck!

  5. #5
    Registered User
    Join Date
    Jul 2006
    Posts
    16

    Re: Security Exception in Socket creation

    I have already enabled these permissions. I am able to read and write files.

    Also i tried using a different port(9888) and i didn't get any exception. I think connecting to port 80 directly is restricted. How can i overcome this?

    Thanks,
    veeyenkay

  6. #6
    Regular Contributor
    Join Date
    Feb 2006
    Posts
    150

    Smile Re: Security Exception in Socket creation

    Hi again veeyenkay!

    Although you didn't write it, I think you are using to connections:

    1) The first connection to read the file that hosts in your mobile phone and which you want to send to the other end.

    2) The second connection to upload the file information to the other end.

    One of those connections is provoking your problem (I suppose... )!
    So if we suppose not to have problems with the reading/writing user permissions the other possibility is that the connection to the other end is failing!

    Some possible solutions:

    1) Change the port "80" as you did and use other port which isn't reseved for other standard service! You have to be sure that this new port doesn't match with other standard service port!

    2) Revise the connectivity permission and switch it on.

    3)Include the compulsory MIDlet-permissions (javax.microedition.io.Connector.file.read,javax.microedition.io.Connector.file.write, javax.microedition.io.Connector.socekt ...) in your .JAD file when you package your MIDlet.

    Although it isn't necessary when your MIDlet is not signed, it might resolve your problem!

    Best regards.

    Summerman.

  7. #7
    Registered User
    Join Date
    Jul 2006
    Posts
    16

    Re: Security Exception in Socket creation

    I need to send the file in my mobile to a HTTP server. If i use the HTTP connection then J2ME HTTP stack breaks down the data and sends them as chunks. But my HTTP server is not able to handle these chuked data send. So it replies to POST that chunked data send is not supported. So i created my own POST message and tried to send it to port 80 on which my HTTP server is listening.

    I think with other port numbers this would work fine. But i want to get it send the data to port 80. Is there any solution to it?

    Thanks
    veeyenkay

  8. #8
    Regular Contributor
    Join Date
    Feb 2006
    Posts
    150

    Arrow Re: Security Exception in Socket creation

    I don't understand you when you say that "your server is not able to reassembling the chunked data" because this is implementation depending not developer depending!

    I now this fact because I'm developing a 3rd-party application. The client is a J2ME mobile phone and the server is a "Java servlet" which is running in a server in a PC and some times the data sent from the mobile phone to the PC server are chunked and my colleague who is developing the server code didn't have to make the reassembling, he only had to read from an InputStream until the Stream is finished and there are no lost bytes!

    I want to tell you that he is programming his aplication with Java (J2EE) too and we are using the 8080 port because is recommended by the server for web applications!

    What language are you using for the server application?

    What server are you using: Tomcat...?

    Best regards.

    Summerman.

  9. #9
    Registered User
    Join Date
    Jul 2006
    Posts
    16

    Re: Security Exception in Socket creation

    I am using Apache server and using PHP to dump the sent file.
    It seems Apache server cannot handle chunked encoding. It is expecting Content Length in the HTTP POST method.
    But J2ME breaks the message and sends them in chunked encoding. Can i disable this chunked encoding in J2ME?

    Thanks
    veeyenkay

  10. #10
    Regular Contributor
    Join Date
    Feb 2006
    Posts
    150

    Thumbs up Re: Security Exception in Socket creation

    Hi veyeenkay!

    I've had a look to Apache website and it includes features to manage the "chunked" data! If you look up the word "chunked" in this url (http://tomcat.apache.org/tomcat-5.5-...nfig/http.html)
    you can read that!

    On the other hand, the HTTP implementation on your mobile phone MUST write the "Content-length" field automatically, if you didn't do it before sending the data via the HTTP connection! It might be that your Apache server doesn't manage the chuncked data because your implementation didn't include this field automatically, so you must to include by yourself. It is a good practice to indicate the "Transfer-encoding" field with the "chunked" value in your case too!

    Here, I've included a snippet of my HTTP code, it works

    //Create the HTTP connection
    httpc =(HttpConnection)Connector.open(url,Connector.READ_WRITE);

    //Set the request method and headers
    httpc.setRequestMethod(HttpConnection.POST); ////POST
    httpc.setRequestProperty("Content-Language","en-GB");
    httpc.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC1.1");

    //Indicate to Apache Server that it will receive Content-length bytes!
    httpc.setRequestMethod("Content-length",yourByteArray.length);

    //Indicate to Apache Server that it will receive chunked data!
    httpConnection.setRequestProperty("Transfer-Encoding","chunked");

    //Create the streams: DIS and DOS

    //WARNING: THE NEXT LINE WILL FLUSH THE ACTUAL HTTP PACKET WITHOUT ANY PAYLOAD (THE HTTP PACKET RECEIVED BY THE APACHE WILL BE EMPTY!)...
    //dis=httpc.openDataInputStream();//NOT INCLUDE IT!

    dos=httpc.openDataOutputStream();

    //Write the data an flush them
    dos.write(yourByteArray);
    dos.flush();
    Try to test this code! Good luck!

    Summerman.

  11. #11
    Registered User
    Join Date
    Jul 2006
    Posts
    16

    Re: Security Exception in Socket creation

    Thanks Summerman for taking so much effort in explaining the details.

    I added the "Content-Length" using setRequestProperty but J2ME did not add them in the message that was sent. Instead it added "Transfer-encoding" field with the "chunked" value. Only thing that i did not try from your code snippet is : i didn't add the "Transfer-encoding" field with the "chunked" value myself. J2ME added it by default.
    I will try this also and let you know

    Thanks
    veeyenkay

  12. #12
    Regular Contributor
    Join Date
    Feb 2006
    Posts
    150

    Wink Re: Security Exception in Socket creation

    My previous POST was very large so I didn't comment to you that it isn't really necessary because the HTTP implementation must do the segmentation and reassembling transparently to the user and it must include this HTTP field automatically ("Transfer-Encoding", "chunked").

    You can use a PROTOCOL MONITORING TOOL like "Ethereal" to CHECK all the HTTP packets that arrive to your server!
    http://www.ethereal.com/

    My regards.

    Summerman.

  13. #13
    Registered User
    Join Date
    Jul 2006
    Posts
    16

    Re: Security Exception in Socket creation

    i have seen the packets in ethereal. I added the Content-Length header but J2ME did not send that. As soon as the server receives the first chunk it replies with the message body:

    Content-Length needed. Chunked encoding is not supported for POST method.

    Thanks
    veeyenkay

  14. #14
    Regular Contributor
    Join Date
    Feb 2006
    Posts
    150

    Wink Re: Security Exception in Socket creation

    It is a very rare thing!

    I didn't write the "Content-Length" field and the HTTP implementation in my Nokia N93 and my Nokia 9500 phones wrote it! Your problem is due to this fact and, as you saw later, not due to your Apache server! If the Content-Length is not included your Apache Server can't interpret the HTTP payload!

    I would check two things:

    1) Have you got a Proxy that can be modified the HTTP fields!

    2) It might be an implementation error (consult with the Nokia Moderators and Nokia staff) and I recommend you to update your firmware in case of this issue has the fault of all your problems!

    If you resolve this problem, keep me informed please!

    Best regards.

    Summerman.

  15. #15
    Registered User
    Join Date
    Jul 2006
    Posts
    16

    Re: Security Exception in Socket creation

    The ethereal packets i saw were for the WTK emulator. Since it didn't work in the emulator, i didn't try it in the mobile.
    May be i will try the app once on mobile also.

    Thanks
    veeyenkay

Similar Threads

  1. VS.Net 2003 Carbide 2.01 and epoc32.exe
    By ValentinK in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 2
    Last Post: 2007-01-12, 12:31
  2. Security Exception while using socket Connection on 6682
    By aditya.binju in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2006-07-22, 22:43
  3. problem in persistant socket connection
    By poms4symbian in forum Browsing and Mark-ups
    Replies: 0
    Last Post: 2006-01-03, 13:23
  4. Socket usage throws a security exception on Nokia devices.
    By tamboss2 in forum Mobile Java Networking & Messaging & Security
    Replies: 4
    Last Post: 2005-09-01, 16:24
  5. can not successfully link any sample using .NET
    By lobotomat in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2002-08-20, 00:29

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×