/** * @return string * Ciphertext. */ public function encode() { $secret = AesHelper::createSecret(); $rsaCiphertext = self::getRsa($this->appPubKey, 'public')->encrypt($secret); if (strlen($rsaCiphertext) !== Constants::RSA_MSG_BYTES) { throw new InvalidMessageException("RSA ciphertext has incorrect length"); } list($body, $signature) = AesHelper::encryptThenSign($secret, json_encode($this->data)); return self::NAME . Constants::PROTOCOL_DELIM . $this->appId . Constants::PROTOCOL_DELIM . base64_encode($rsaCiphertext) . Constants::PROTOCOL_DELIM . $signature . Constants::PROTOCOL_DELIM . $body; }
/** * @param array $appMeta * @return array * Array($cxnId, $isOk). */ public function register($appMeta) { AppMeta::validate($appMeta); if ($this->certValidator) { $this->certValidator->validateCert($appMeta['appCert']); } $cxn = $this->cxnStore->getByAppId($appMeta['appId']); if (!$cxn) { $cxn = array('cxnId' => Cxn::createId(), 'secret' => AesHelper::createSecret(), 'appId' => $appMeta['appId']); } $cxn['appUrl'] = $appMeta['appUrl']; $cxn['siteUrl'] = $this->siteUrl; $cxn['perm'] = $appMeta['perm']; Cxn::validate($cxn); $this->cxnStore->add($cxn); list($respCode, $respData) = $this->doCall($appMeta, 'Cxn', 'register', array(), $cxn); $success = $respCode == 200 && $respData['is_error'] == 0; $this->log->info($success ? 'Registered cxnId={cxnId} ({appId}, {appUrl})' : 'Failed to register cxnId={cxnId} ({appId}, {appUrl})', array('cxnId' => $cxn['cxnId'], 'appId' => $cxn['appId'], 'appUrl' => $cxn['appUrl'])); return array($cxn['cxnId'], $respData); }
public function invalidInputExamples() { $appKeyPair = KeyPair::create(); $otherKeyPair = KeyPair::create(); return array(array($appKeyPair, new InsecureMessage(array('sldjkfasdf'))), array($appKeyPair, new InsecureMessage(array('cxn' => array('abcd')))), array($appKeyPair, new StdMessage(Cxn::createId(), AesHelper::createSecret(), array('whatever'))), array($appKeyPair, new RegistrationMessage('app:org.civicrm.other', $appKeyPair['publickey'], array('whatever'))), array($appKeyPair, new RegistrationMessage(self::APP_ID, $otherKeyPair['publickey'], array('whatever')))); }