Esempio n. 1
0
 /**
  * Initializes EntityAuthData with the auth data of a user or a platform. While the parameters $socialRecord and
  * $accountKeyPair are mandatory, the $personalKeyPair is optional and may be omitted.
  * 
  * @param $socialRecord SocialRecord The SocialRecord of the entity
  * @param $accountKeyPair KeyPair The accountKeyPair for the entity
  * @param $personalKeyPair KeyPair The personalKeyPair for the entity. OPTIONAL!
  */
 public function __construct(SocialRecord $socialRecord, KeyPair $accountKeyPair, KeyPair $personalKeyPair = NULL)
 {
     $this->globalID = $socialRecord->getGlobalID();
     $this->socialRecord = $socialRecord;
     $this->personalKeyPair = $personalKeyPair;
     $this->accountKeyPair = $accountKeyPair;
 }
Esempio n. 2
0
 /**
  * Exports a SocialRecord object to a serialized JSONObject
  * 
  * @param SocialRecord The SocialRecord to export
  * @param KeyPair account key pair to export
  * @param KeyPair personal key pair to export
  * @return string The exported SocialRecord
  */
 public static function exportSocialRecord(SocialRecord $socialRecord, KeyPair $accountKeyPair = NULL, KeyPair $personalKeyPair = NULL)
 {
     $json = new JSONObject();
     $json->put('socialRecord', $socialRecord->getJSONObject());
     if ($accountKeyPair != NULL) {
         $json->put('accountPrivateKey', PrivateKey::exportKey($accountKeyPair->getPrivateKey()));
     }
     if ($personalKeyPair != NULL) {
         $json->put('personalPrivateKey', PrivateKey::exportKey($personalKeyPair->getPrivateKey()));
     }
     return $json->write();
 }
Esempio n. 3
0
 /**
  * Pushes an update for a SocialRecord to the GSLS. The SocialRecord will be transformed into a signed JWT, which is then stored in the GSLS
  * 
  * @param $sr The SocialRecord
  * @param $personalPrivateKey The private key to sign the JWT
  * 
  * @throws Exception
  * 
  * @return result json string
  */
 public static function putSocialRecord(SocialRecord $sr, $personalPrivateKey)
 {
     if (!$sr->verify()) {
         throw new \Excetion("Error: Invalid Social Record");
     }
     // create and sign JWT
     $signer = new Sha512();
     $personalPrivateKey = PrivateKey::formatPEM($personalPrivateKey);
     $token = (new Builder())->set('socialRecord', base64_encode($sr->getJSONString()))->sign($signer, $personalPrivateKey)->getToken();
     $ch = curl_init(Configuration::getPrimaryGSLSNode());
     if (Configuration::getCurlVerbose() >= 2) {
         curl_setopt($ch, CURLOPT_VERBOSE, 1);
     }
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_TIMEOUT, Configuration::getGSLSTimeout());
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json', 'Content-Length: ' . strlen((string) $token)));
     curl_setopt($ch, CURLOPT_POSTFIELDS, (string) $token);
     $result = curl_exec($ch);
     if (curl_errno($ch) != CURLE_OK) {
         $ch = curl_init(Configuration::getSecondaryGSLSNode());
         if (Configuration::getCurlVerbose() >= 2) {
             curl_setopt($ch, CURLOPT_VERBOSE, 1);
         }
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_HTTPGET, 1);
         $result = curl_exec($ch);
         if (curl_errno($ch) != CURLE_OK) {
             throw new \Exception('Connection error: ' . curl_error($ch));
         }
     }
     $result = json_decode($result);
     curl_close($ch);
     if ($result->responseCode != 200) {
         throw new \Exception("Error: " . $result->message);
     } else {
         return $result;
     }
 }