Skip to content
This repository has been archived by the owner on Dec 16, 2020. It is now read-only.

Commit

Permalink
update getAttestation
Browse files Browse the repository at this point in the history
  • Loading branch information
mgp25 committed Jun 21, 2015
1 parent 91a9a27 commit f830a9c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
57 changes: 34 additions & 23 deletions src/snapchat.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ class Snapchat extends SnapchatAgent {
public function __construct($username, $gEmail, $gPasswd, $debug = FALSE)
{
$this->username = $username;
$this->debug = $debug;
$this->gEmail = $gEmail;
$this->gPasswd = $gPasswd;
$this->debug = $debug;
$this->gEmail = $gEmail;
$this->gPasswd = $gPasswd;

if(file_exists(__DIR__ . DIRECTORY_SEPARATOR . self::DATA_FOLDER . DIRECTORY_SEPARATOR . "auth-$this->username.dat")){
$this->totArray = unserialize(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . self::DATA_FOLDER . DIRECTORY_SEPARATOR . "auth-$this->username.dat"));
Expand Down Expand Up @@ -131,25 +131,34 @@ public function device()

return $result;
}
private function getAttestation(){
$binaryRequest = base64_decode("ClMKABIUY29tLnNuYXBjaGF0LmFuZHJvaWQaIC8cqvyh7TDQtOOIY+76vqDoFXEfpM95uCJRmoJZ2VpYIgAojKq/AzIECgASADoECAEQAUD4kP+pBRIA");
$ch = curl_init("https://www.googleapis.com/androidcheck/v1/attestations/attest?alt=JSON&key=AIzaSyDqVnJBjE5ymo--oBJt3On7HQx9xNm1RHA");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $binaryRequest);
curl_setopt($ch, CURLOPT_USERAGENT, "SafetyNet/7329000 (A116 _Quad KOT49H); gzip");
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("content-type: application/x-protobuf", "Accept:", "Expect:"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
if(curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200) {
$d = json_decode($data,true);
return $d['signedAttestation'];//the json response, json_decode and grab the signedAttestation value.
} else {
return curl_error($ch);
}
}
private function getAttestation($password, $timestamp)
{
$nonce = base64_encode(hash('sha256', "$this->username|$password|$timestamp|loq/login", true));
$authentication = 'cp4craTcEr82Pdf5j8mwFKyb8FNZbcel';
$apkDigest = 'JJShKOLH4YYjWZlJQ71A2dPTcmxbaMboyfo0nsKYayE';

$url = 'http://attest.casper.io/attestation';
$data = array(
'nonce' => $nonce,
'authentication' => $authentication,
'apk_digest' => $apkDigest,
'timestamp' => $timestamp
);

$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
),
);

$context = stream_context_create($options);
$result = json_decode(file_get_contents($url, false, $context));

return $result->signedAttestation;
}

public function getAuthToken()
{
if(($this->gEmail != null) && ($this->gPasswd != null))
Expand Down Expand Up @@ -331,7 +340,8 @@ public function login($password, $force = FALSE)
return $auth;
}
parent::setGAuth($auth);
$attestation = $this->getAttestation();
$attestation = $this->getAttestation($password, $timestamp);

$result = parent::post(
'/loq/login',
array(
Expand All @@ -346,6 +356,7 @@ public function login($password, $force = FALSE)
'ptoken' => "ie",
'timestamp' => $timestamp,
'attestation' => $attestation,
'sflag' => '1',
'application_id' => 'com.snapchat.android',
'req_token' => $req_token,
),
Expand Down
4 changes: 3 additions & 1 deletion src/snapchat_agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract class SnapchatAgent {
* Before updating this value, confirm
* that the library requests everything in the same way as the app.
*/
const USER_AGENT = 'Snapchat/9.9.0.0 (HTC One; Android 4.4.2#302626.7#19; gzip)';
const USER_AGENT = 'Snapchat/9.10.0.0 (HTC One; Android 4.4.2#302626.7#19; gzip)';

/*
* The API URL. We're using the /bq endpoint, the one that the iPhone
Expand Down Expand Up @@ -427,6 +427,8 @@ public function post($endpoint, $data, $params, $multipart = FALSE, $debug = FAL
{
$jsonResult = json_decode($result);
echo 'RESULT: ' . print_r($jsonResult) . "\n";
if ($jsonResult->status == '-103')
exit();
}
else
{
Expand Down

0 comments on commit f830a9c

Please sign in to comment.