Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Create an AppleServices class to manage web services

  • Loading branch information...
commit 5e4acee9c2e310115b77f6c19ebb74923d133699 1 parent 4f5bfdc
Ludovic Landry authored
View
4 .gitignore
@@ -1,4 +1,4 @@
.DS_Store
-/gma.esproj
+/*.esproj
+/nbproject
/credentials.php
-
View
371 core/apple-services.php
@@ -0,0 +1,371 @@
+<?php
+
+require_once __DIR__ . '/../lib/cfpropertylist/CFPropertyList.php';
+require_once __DIR__ . '/../credentials.php';
+require_once __DIR__ . '/tools.php';
+
+/**
+ * AppleServices provides mothodes to access developer rovisioning portal
+ */
+class AppleServices {
+
+ /**
+ * Apple web services base URL
+ * @var string $base_url_services
+ */
+ private static $base_url_services = 'https://connect1.apple.com/services/GL9N1P/';
+
+ /**
+ * Apple client id
+ * @var string $client_id
+ */
+ private static $client_id = 'XABBG36SBA';
+
+ /**
+ * Coookie used for authentication
+ * @var string $cookie
+ */
+ private static $cookie;
+
+ /**
+ * Connect the developer with its user name/password and store the connection cookie
+ * @param string $user
+ * @param string $pwd
+ *
+ * if $result['resultCode'] equal 0 you are connected
+ * user info are acessible via $result['firstName'] and $result['lastName']
+ *
+ * else you can print the error $result['resultString']
+ *
+ * @return array $result
+ */
+ public static function connect($user, $pwd) {
+
+ $url = 'https://daw2.apple.com/cgi-bin/WebObjects/DSAuthWeb.woa/wa/' .
+ 'clientDAW?format=plist&appIdKey=D136F3CA19FC87ADBC8514E10325B1000184218304C8DB66713C0CB40291F620' .
+ '&appleId=' . urlencode($user) . '&password=' . urlencode($pwd) . '&userLocale=en_US&protocolVersion=A1234';
+
+ // create a new cURL resource
+ $ch = curl_init();
+
+ // set URL and other appropriate options
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
+ 'User-Agent: Xcode',
+ 'Accept: text/x-xml-plist',
+ 'Accept-Language: en-us',
+ 'Connection: keep-alive'));
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
+
+ //TODO do not use a file
+ //curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
+ //curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
+ curl_setopt($ch, CURLOPT_HEADER, true);
+ preg_match('/^set-cookie: (.*?)$/m', curl_exec($ch), $m);
+ self::$cookie = $m[1];
+
+ $data = curl_exec($ch);
+
+ // close cURL resource
+ curl_close($ch);
+
+ //TODO: we cant read this because we have CURLOPT_HEADER for the cookie
+ //$plist = new CFPropertyList();
+ //$plist->parse($data, CFPropertyList::FORMAT_AUTO);
+ //$plistData = $plist->toArray();
+
+ return $data; //$plistData;
+ }
+
+ /**
+ * Get developer detail informations
+ *
+ * If $result['resultCode'] equals 0 everything is good
+ * info returned are $result['developer.email'], $result['developer.firstName'] and $result['developer.lastName']
+ *
+ * else you can print the error $result['resultString']
+ *
+ * @return array $result
+ */
+ public static function viewDeveloper() {
+
+ // Create Web Service URL
+ $url = self::$base_url_services . 'viewDeveloper.action?clientId=' . self::$client_id;
+
+ // Generating content
+ $payload = array();
+
+ $payload['clientId'] = self::$client_id;
+ $payload['protocolVersion'] = 'GL9N1P';
+ $payload['requestId'] = Tools::randomAppleRequestId();
+
+ $user_locale = array();
+ $user_locale[0] = 'en_US';
+ $payload['userLocale'] = $user_locale;
+
+ $plist = new CFPropertyList();
+ $type_detector = new CFTypeDetector();
+ $plist->add($type_detector->toCFType($payload));
+ $contents = $plist->toXML(true);
+
+ // create a new cURL resource
+ $ch = curl_init();
+
+ // set URL and other appropriate options
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $contents);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
+ 'User-Agent: Xcode',
+ 'Content-Type: text/x-xml-plist',
+ 'Accept: text/x-xml-plist',
+ 'Accept-Language: en-us',
+ 'Connection: keep-alive'));
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ curl_setopt($ch, CURLOPT_POST, true);
+ curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
+
+ //TODO do not use a file
+ curl_setopt($ch, CURLOPT_HEADER, true);
+ curl_setopt($ch, CURLOPT_COOKIE, self::$cookie);
+ preg_match('/^Set-Cookie: (.*?)$/m', curl_exec($ch), $m);
+ self:$cookie = $m[1];
+ //curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
+ //curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
+
+ //TODO secure the connection
+ //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
+ //curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . '/certs/VeriSignCA.pem');
+
+ $data = curl_exec($ch);
+
+ // close cURL resource
+ curl_close($ch);
+
+ //TODO: we cant read this because we have CURLOPT_HEADER for the cookie
+ //$plist = new CFPropertyList();
+ //$plist->parse($data, CFPropertyList::FORMAT_AUTO);
+ //$plistData = $plist->toArray();
+
+ return $data;//$plistData;
+ }
+
+ /**
+ * Get all developer teams
+ *
+ * If $result['resultCode'] equals 0 everything is good
+ * info returned is $result['teamId'] and $result['name']
+ *
+ * else you can print the error $result['resultString']
+ *
+ * @return array $result
+ */
+ public static function listTeams() {
+
+ // Create Web Service URL
+ $url = self::$base_url_services . 'listTeams.action?clientId=' . self::$client_id;
+
+ // Generating content
+ $payload = array();
+
+ $payload['clientId'] = self::$client_id;
+ $payload['protocolVersion'] = 'GL9N1P';
+ $payload['requestId'] = Tools::randomAppleRequestId();
+
+ $user_locale = array();
+ $user_locale[0] = 'en_US';
+ $payload['userLocale'] = $user_locale;
+
+ $plist = new CFPropertyList();
+ $type_detector = new CFTypeDetector();
+ $plist->add($type_detector->toCFType($payload));
+ $contents = $plist->toXML(true);
+
+ // create a new cURL resource
+ $ch = curl_init();
+
+ // set URL and other appropriate options
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $contents);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
+ 'User-Agent: Xcode',
+ 'Content-Type: text/x-xml-plist',
+ 'Accept: text/x-xml-plist',
+ 'Accept-Language: en-us',
+ 'Connection: keep-alive'));
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ curl_setopt($ch, CURLOPT_POST, true);
+ curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
+ curl_setopt($ch, CURLOPT_COOKIE, self::$cookie);
+
+ //TODO secure the connection
+ //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
+ //curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . '/certs/VeriSignCA.pem');
+
+ $data = curl_exec($ch);
+
+ // close cURL resource
+ curl_close($ch);
+
+ $plist = new CFPropertyList();
+ $plist->parse($data, CFPropertyList::FORMAT_AUTO);
+ $plistData = $plist->toArray();
+
+ return $plistData;
+ }
+
+ /**
+ * Get all developer devices for the team
+ *
+ * if $result['resultCode'] equal 0 have your result
+ * else you can print the error $result['resultString']
+ *
+ * @param string $team_id
+ * @return array $result
+ */
+ public static function listDevices($team_id) {
+
+ // Create Web Service URL
+ $url = self::$base_url_services . 'listDevices.action?clientId=' . self::$client_id;
+
+ // Generating content
+ $payload = array();
+
+ $payload['clientId'] = self::$client_id;
+ $payload['protocolVersion'] = 'GL9N1P';
+ $payload['requestId'] = Tools::randomAppleRequestId();
+ $payload['teamId'] = $team_id;
+
+ $user_locale = array();
+ $user_locale[0] = 'en_US';
+ $payload['userLocale'] = $user_locale;
+
+ $plist = new CFPropertyList();
+ $type_detector = new CFTypeDetector();
+ $plist->add($type_detector->toCFType($payload));
+ $contents = $plist->toXML(true);
+
+ // create a new cURL resource
+ $ch = curl_init();
+
+ // set URL and other appropriate options
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $contents);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
+ 'User-Agent: Xcode',
+ 'Content-Type: text/x-xml-plist',
+ 'Accept: text/x-xml-plist',
+ 'Accept-Language: en-us',
+ 'Connection: keep-alive'));
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ curl_setopt($ch, CURLOPT_POST, true);
+ curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
+ curl_setopt($ch, CURLOPT_COOKIE, self::$cookie);
+
+ //TODO secure the connection
+ //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
+ //curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . '/certs/VeriSignCA.pem');
+
+ $data = curl_exec($ch);
+
+ // close cURL resource
+ curl_close($ch);
+
+ $plist = new CFPropertyList();
+ $plist->parse($data, CFPropertyList::FORMAT_AUTO);
+ $plistData = $plist->toArray();
+
+ return $plistData;
+ }
+
+ public static function addDevice() {
+
+ //TODO: xxx
+ }
+
+ public static function updateDevice($deviceId) {
+
+ //TODO: xxx
+ }
+
+ public static function listAppIds() {
+
+ //TODO: xxx
+ }
+
+ public static function viewAppId() {
+
+ //TODO: xxx
+ }
+
+ public static function addAppId() {
+
+ //TODO: xxx
+ }
+
+ public static function deleteAppId() {
+
+ //TODO: xxx
+ }
+
+ public static function listMyDevelopmentCertRequests() {
+
+ //TODO: xxx
+ }
+
+ public static function downloadDevelopmentCert() {
+
+ //TODO: xxx
+ }
+
+ public static function revokeDevelopmentCert() {
+
+ //TODO: xxx
+ }
+
+ public static function submitDevelopmentCSR() {
+
+ //TODO: xxx
+ }
+
+ public static function downloadTeamProvisioningProfile() {
+
+ //TODO: xxx
+ }
+
+ public static function listProvisioningProfiles() {
+
+ //TODO: xxx
+ }
+
+ public static function downloadProvisioningProfile() {
+
+ //TODO: xxx
+ }
+
+ public static function listDistributionCertRequests() {
+
+ //TODO: xxx
+ }
+
+ public static function downloadDistributionCert() {
+
+ //TODO: xxx
+ }
+
+ public static function revokeDistributionCert() {
+
+ //TODO: xxx
+ }
+
+ public static function submitDistributionCSR() {
+
+ //TODO: xxx
+ }
+}
+
+?>
View
41 core/tools.php
@@ -0,0 +1,41 @@
+<?php
+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ * Description of tools
+ *
+ * @author Ludovic Landry
+ */
+class Tools {
+
+ /**
+ * Generate a random Apple request id used for web services
+ * The format returned is XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
+ * @return string request_id
+ */
+ static function randomAppleRequestId() {
+
+ $request_id = md5(rand());
+ $request_id = substr_replace($request_id, '-', 20, 0);
+ $request_id = substr_replace($request_id, '-', 16, 0);
+ $request_id = substr_replace($request_id, '-', 12, 0);
+ $request_id = substr_replace($request_id, '-', 8, 0);
+
+ return strtoupper($request_id);
+ }
+
+ /**
+ * Return an hexa hash generated randomly with the given length
+ * @param int $length
+ * @return string hash
+ */
+ static function randomHashWithSize($length) {
+ return substr(md5(rand()), 0, $length);
+ }
+}
+
+?>
View
13 documentation/Install_guide.txt
@@ -1,4 +1,8 @@
+git submodule init
+git submodule update
+
+
These folders needs to be writable: (chmod ugo+rwx __file__)
for the database SQLite:
@@ -12,5 +16,12 @@ for app upload:
- /app/
+Authentication: create a credentials.php file and add this:
+
+<?php
+ $CRED_USR = '__your_user__';
+ $CRED_PWD = '__your_passwd__';
+?>
+
-PHP 5 required
+PHP 5 required
View
51 profile.php
@@ -1,11 +1,11 @@
<?php
-
-use Entities\Device;
+
+use Entities\Device;
require_once __DIR__ . '/lib/cfpropertylist/CFPropertyList.php';
require_once __DIR__ . '/lib/log.php';
require_once __DIR__ . '/core/index.php';
-require_once __DIR__ . '/asn.php';
+require_once __DIR__ . '/asn.php';
$lf = new logfile();
@@ -41,7 +41,7 @@
}
$plist = new CFPropertyList();
-$plist->parse( $plistValue, CFPropertyList::FORMAT_XML);
+$plist->parse( $plistValue, CFPropertyList::FORMAT_AUTO);
//echo '<pre>';
//var_dump( $plist->toArray() );
@@ -51,30 +51,27 @@
//$lf->writeln('mail='.$_GET['mail']);
//$lf->writeln('app='.$_GET['app']);
//$lf->writeln('key='.$_GET['key']);
-//echo '</pre>';
-
-$entityManager = initDoctrine();
-date_default_timezone_set('Europe/Paris');
-
-// Retrieve the tester with his mail (unique)
-$tester = $entityManager->getRepository('Entities\Tester')->findOneBy(array('email' => $_GET['mail']));
-
-//TODO: use $_GET['app'] and $_GET['key'] to verify response integrity
-//TODO: verify if the device does not already exist (Update data for the same udid if it exists)
-
-$device = new Device;
-$device->setName($plistData['DEVICE_NAME']);
-$device->setDateCreation(new \DateTime("now"));
-$device->setSystemVersion($plistData['VERSION']);
-$device->setModel($plistData['PRODUCT']);
-$device->setUdid($plistData['UDID']);
-//$device->setInvitation($invitation);
-$device->setTester($tester);
-
-$entityManager->persist($device);
-$entityManager->flush();
+//echo '</pre>';
+
+$entityManager = initDoctrine();
+date_default_timezone_set('Europe/Paris');
-//
+// Retrieve the tester with his mail (unique)
+$tester = $entityManager->getRepository('Entities\Tester')->findOneBy(array('email' => $_GET['mail']));
+//TODO: use $_GET['app'] and $_GET['key'] to verify response integrity
+//TODO: verify if the device does not already exist (Update data for the same udid if it exists)
+
+$device = new Device;
+$device->setName($plistData['DEVICE_NAME']);
+$device->setDateCreation(new \DateTime("now"));
+$device->setSystemVersion($plistData['VERSION']);
+$device->setModel($plistData['PRODUCT']);
+$device->setUdid($plistData['UDID']);
+//$device->setInvitation($invitation);
+$device->setTester($tester);
+
+$entityManager->persist($device);
+$entityManager->flush();
?>
View
161 sign.php
@@ -3,134 +3,61 @@
require_once __DIR__ . '/lib/cfpropertylist/CFPropertyList.php';
require_once __DIR__ . '/asn.php';
require_once __DIR__ . '/credentials.php';
+require_once __DIR__ . '/core/apple-services.php';
//Step 1 check needed params:
-if (!isset($_GET['udid'], $_GET['app'], $_GET['ver']))
-{
- die('parameters udid, app and ver are needed');
+if ( !isset($_GET['udid'], $_GET['app'], $_GET['ver']) ) {
+ die ('parameters udid, app and ver are needed');
}
-function connect($user, $pwd){
- /*
- HTTP/1.1
- Host: daw2.apple.com
- User-Agent: Xcode
- Accept-Encoding: gzip, deflate
- Content-Type: text/x-xml-plist
- Accept: text/x-xml-plist
- AcceptGLanguage: en-us
- Cookie: ""
- Connection: keep-alive
- */
- $url= 'https://daw2.apple.com/cgi-bin/WebObjects/DSAuthWeb.woa/wa/clientDAW?format=plist&appIdKey=D136F3CA19FC87ADBC8514E10325B1000184218304C8DB66713C0CB40291F620&appleId='.urlencode($user).'&password='.urlencode($pwd).'&userLocale=en_US&protocolVersion=A1234';
-
- // create a new cURL resource
- $ch = curl_init();
+$result = AppleServices::connect($CRED_USR, $CRED_PWD);
+//echo var_dump($result);
+if ( $result['resultCode'] != 0 ) {
+ //die ($result['userString']);
+}
+
- // set URL and other appropriate options
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'User-Agent: Xcode',
-
- 'Accept: text/x-xml-plist',
- 'Accept-Language: en-us',
- 'Connection: keep-alive'));
- //'Content-Type: text/x-xml-plist',
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- //curl_setopt($ch, CURLOPT_POST, true);
- //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
- curl_setopt($ch, CURLOPT_ENCODING , 'gzip, deflate');
- //TODO do not use a file
- curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
- curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
-
- curl_setopt($ch, CURLOPT_HEADER, true);
- //curl_setopt($ch, CURLOPT_POSTFIELDS, $contents);
-
- //TODO secure the connection
- //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
- //curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . '/certs/VeriSignCA.pem');
-
- // grab URL and pass it to the browser
- $head = curl_exec($ch);
- $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- echo "url= $url</br>";
- echo "httpCode= $httpCode</br>";
- echo "head= $head</br>";
-
- // close cURL resource, and free up system resources
- curl_close($ch);
-
-
-
- }
-
- function viewDeveloper(){
+$result = AppleServices::viewDeveloper();
+//echo var_dump($result);
+if ( $result['resultCode'] != 0 ) {
+ //die ($result['userString']);
+}
+
-
-
- $url= 'https://connect1.apple.com/services/GL9N1P/viewDeveloper.action?clientId=XABBG36SBA?clientId=XABBG36SBA';
-
- $contents = '<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
-"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
- <key>clientId</key>
- <string>XABBG36SBA</string>
- <key>protocolVersion</key>
- <string>GL9N1P</string>
- <key>requestId</key>
- <string>FFE3A771-193F-4311-88BD-566797548E11</string>
- <key>userLocale</key>
- <array>
- <string>en_US</string>
- </array>
-</dict>
-</plist>';
+$result = AppleServices::listTeams();
+//echo var_dump($result);
+if ( $result['resultCode'] != 0 ) {
+ die ($result['userString']);
+}
- // create a new cURL resource
- $ch = curl_init();
+// TODO: For now we only take care about the one team case
+$team_id = $result['teams'][0]['teamId'];
- // set URL and other appropriate options
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'User-Agent: Xcode',
- 'Content-Type: text/x-xml-plist',
- 'Accept: text/x-xml-plist',
- 'Accept-Language: en-us',
- 'Connection: keep-alive'));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_ENCODING , 'gzip, deflate');
- //TODO do not use a file
- curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
- curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
-
- curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $contents);
-
- //TODO secure the connection
- //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
- //curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . '/certs/VeriSignCA.pem');
-
- // grab URL and pass it to the browser
- $head = curl_exec($ch);
- $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- echo "url= $url</br>";
- echo "httpCode= $httpCode</br>";
- echo "head= $head</br>";
-
- // close cURL resource, and free up system resources
- curl_close($ch);
+$result = AppleServices::listDevices($team_id);
+//echo var_dump($result);
+if ( $result['resultCode'] != 0 ) {
+ die ($result['userString']);
}
+$device_found = false;
+foreach ($result['devices'] as $device) {
+ if ($_GET['udid'] == $device['deviceNumber']) {
+ $device_found = true;
+ break;
+ }
+}
-connect($CRED_USR, $CRED_PWD);
-viewDeveloper();
+if ( $device_found ) {
+ echo 'The device is already registered.<br/>' . PHP_EOL;
+ echo 'UDID: ' . $device['deviceNumber'] . '<br/>' . PHP_EOL;
+ echo 'deviceId: ' . $device['deviceId'] . '<br/>' . PHP_EOL;
+ echo 'name: ' . $device['name'] . '<br/>' . PHP_EOL;
+ //$result = AppleServices::updateDevice($deviceId);
+} else {
+ echo 'This device is not registered';
+ //$result = AppleServices::addDevice();
+}
-?>
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.