/
profile.php
executable file
·133 lines (110 loc) · 4.46 KB
/
profile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/*
* RunThisApp allows sharing test builds of iOS apps with testers.
* Copyright (C) 2011 Ludovic Landry & Pascal Cans
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
use Entities\Device;
use Entities\Tester;
use Entities\Invitation;
require_once __DIR__ . '/lib/cfpropertylist/CFPropertyList.php';
require_once __DIR__ . '/lib/Swift/lib/swift_required.php';
require_once __DIR__ . '/credentials.php';
require_once __DIR__ . '/core/index.php';
require_once __DIR__ . '/tools.php';
require_once __DIR__ . '/mail.php';
require_once __DIR__ . '/asn.php';
$ciphertext_file = tempnam('', '__glancemyapp_');
file_put_contents($ciphertext_file, file_get_contents('php://input'));
/*
OpenSSL PHP implementation does'nt allow use to verify DER encoded CMS. :/
This works well in command line: openssl.exe smime -verify -noverify -in "payload.bin" -inform DER
but not using openssl_pkcs7_verify...
$certificates_file = tempnam('', '__glancemyapp_');
$deciphertext_file = tempnam('', '__glancemyapp_');
$result = openssl_pkcs7_verify(
$ciphertext_file,
PKCS7_BINARY | PKCS7_TEXT | PKCS7_NOVERIFY | PKCS7_NOCHAIN,
$certificates_file,
array(),
null,
$deciphertext_file
);
unlink($ciphertext_file);
unlink($certificates_file);
$plist = file_get_contents($deciphertext_file);
unlink($deciphertext_file);
while (($e = openssl_error_string()) !== false) {
$lf->write('openssl error='.$e.PHP_EOL);
}
*/
$plistValue = retreivePlistFromAsn($ciphertext_file);
/*
* TEST: $plistValue = '<?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>CHALLENGE</key><string>signed-auth-token</string><key>IMEI</key><string>00 000000 000000 0</string><key>PRODUCT</key><string>iPhone3,1</string><key>UDID</key><string>d2f22d586c333041d191c81e5bb80948732d6a68</string><key>VERSION</key><string>9A5248d</string></dict></plist>';
*/
if (empty($plistValue)) {
error_log('RTA::Unable to read plist from configuration profile challenge', 0);
die();
}
$plist = new CFPropertyList();
$plist->parse( $plistValue, CFPropertyList::FORMAT_AUTO);
$plistData = $plist->toArray();
$entityManager = initDoctrine();
date_default_timezone_set('Europe/Paris');
$invitation = $entityManager->getRepository('Entities\Invitation')->findOneBy(array('token' => $_GET['key']));
if ( $invitation == NULL ) {
error_log('RTA::This invitation is not valid!', 0);
die();
}
$tester = $invitation->getTester();
if ( $tester == NULL ) {
error_log('RTA::This user does not exist!', 0);
die();
}
//Verify if the device does not already exist (Update data for this device if it exists)
$device = $invitation->getDevice();
if ( $device == NULL ) {
$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->addInvitation($invitation);
$device->setTester($tester);
$invitation->setStatus(Invitation::STATUS_UDID);
$entityManager->persist($device);
$entityManager->persist($invitation);
$entityManager->flush();
//Send the confirmation email
$smtp = Swift_SmtpTransport::newInstance($CRED_SMTP, $CRED_SMTP_PORT, 'ssl')
->setUsername($CRED_SMTP_USR)
->setPassword($CRED_SMTP_PWD);
$mailer = Swift_Mailer::newInstance($smtp);
$url = Tools::rel2abs('runthisapp.php', Tools::current_url());
$msg = 'Click on following link to install your app: ';
$udid = $device->getUdid();
$mail = $device->getTester()->getEmail();
$token = $_GET['key'];
$app = $invitation->getVersion()->getName();
$ver = $invitation->getVersion()->getVersion();
$result = send_link_mail($mailer, $url, $app, $ver, $msg, $mail, $udid, $token);
// Error
if ( $result != 1 ) {
error_log('RTA::Error sending email', 0);
die();
}
?>