Prasanth S
Prasanth S

Reputation: 3830

Getting an iPhone UDID and IMEI from Mobile Safari Using java servlet

I want to get iPhone UDID through Mobile Safari. Iam using .mobileconifg as

<plist version="1.0">
    <dict>
        <key>PayloadContent</key>
        <dict>
            <key>URL</key>
            <string>http://192.168.12.45:8080/enroll/retrieve</string>
            <key>DeviceAttributes</key>
            <array>
                <string>UDID</string>
                <string>SERIAL</string>
                <string>CHALLENGE</string>
                <string>IMEI</string>
                <string>ICCID</string>
                <string>VERSION</string>
                <string>PRODUCT</string>
                <string>DEVICE_NAME</string>
                <string>MAC_ADDRESS_EN0</string>
            </array>
        </dict>
        <key>PayloadOrganization</key>
        <string>Org</string>
        <key>PayloadDisplayName</key>
        <string>Profile Service</string>
        <key>PayloadVersion</key>
        <integer>1</integer>
        <key>PayloadUUID</key>
        <string>D6F1B2A3-0039-48B5-915B-8E2B35663816</string>
        <key>PayloadIdentifier</key>
        <string>Identifer</string>
        <key>PayloadDescription</key>
        <string>This temporary profile will be used to find and display your current device's UDID.</string>
        <key>PayloadType</key>
        <string>Profile Service</string>
    </dict>
</plist>

retrieve.php

<?php
  $data = file_get_contents('php://input');
  header('Location: http://192.168.12.45/enroll/info?'.$data, true, 301);
?>

info is a directory and not a page, I have created index.php in this directory I get data in $_GET.

But i am able to get from php.

But i want to use java servlet, i changed url in mobileconfig file on servlet url but i am not able to get any values in java.

retrieve Java Code

    Enumeration headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String paramName = (String) headerNames.nextElement();
        String paramValue = request.getHeader(paramName);
        System.out.println("paramValue :" + paramValue);
    }

Output :

paramValue :192.168.12.45:8080
paramValue :keep-alive
paramValue :gzip, deflate
paramValue :Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D201 Safari/9537.53
paramValue :en-us
paramValue :text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

it shows error like this

enter image description here

But i want java servlet for getting IMEI. I want to change the above php code to java servlet. How to solve this and install Profile to get UDID and IMEI

Upvotes: 5

Views: 1882

Answers (2)

janos
janos

Reputation: 124804

So it seems you want to use a Java servlet instead of PHP. According to this article, this might not work, as it seems the receiving URL specified in your .mobileconfig file must be a PHP file:

QUIRK WARNING: For whatever reason, the process is EXTREMELY particulary about how your server responds when it sends the user to your preset URL. After many tries, I believe that your receiving url MUST be a .php file. This sounds nuts but I'm serious.

But you could try anyway. According to this post, this Java code should be roughly equivalent to PHP's php://input, this this in your servlet:

    InputStream stream = request.getInputStream();
    byte[] buffer = new byte[512];
    StringBuilder builder = new StringBuilder();
    while (stream.read(buffer) != -1) {
        builder.append(new String(buffer));
    }
    System.out.println(builder);

If that still doesn't work, I suppose you have no choice but to do what the author of the article did, and use PHP just to redirect to the servlet. In that case, it will be better if in retrieve.php, you need to pass $data as a named query parameter, by changing '/info?'.$data to '/info?data='.$data, like this:

<?php
  $data = file_get_contents('php://input');
  header('Location: http://192.168.12.45/enroll/info?data='.rawurlencode($data));
?>

I also wrapped $data in rawurlencode($data), and removed the extra parameters that don't seem to be necessary.

Then in your servlet, you can access the data parameter like this:

protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String data = request.getParameter("data");
    System.out.println(data);
}

Upvotes: 0

Andrei Shender
Andrei Shender

Reputation: 2497

This is might be due to encryption enabled on your database file or directory containing it. Use:

NSFileManager's setAttributes:ofItemAtPath:error: with NSFileProtectionNone

Upvotes: 3

Related Questions