/** * Execute the login command * * @param array $args - CLI arguments * @echo * @return null */ public function fire(array $args = []) { $username = \count($args) > 0 ? $args[0] : $this->prompt("Please enter your username: "******"Password:"******"\n"; exit(255); } // Let's store the result in our local config if (!\array_key_exists('suppliers', $this->config)) { $this->config['suppliers'] = []; } if (\array_key_exists($username, $this->config['suppliers'])) { $this->config['suppliers'][$username]['token'] = $result['token']; foreach ($result['signing_keys'] as $res_key) { $found = false; foreach ($this->config['suppliers'][$username]['signing_keys'] as $key) { if ($key['public_key'] === $res_key['public_key']) { $found = true; break; } } // If we loaded our salt into the skyport, import it: if (!$found && isset($res_key['salt'])) { $this->config['suppliers'][$username]['signing_keys'][] = $res_key; } } echo 'Authentication successful', "\n"; } else { $this->config['suppliers'][$username] = $result; } }
/** * Check that we've updated our version string since the last push. * * @param array $manifest * @return boolean */ protected function versionCheck(array $manifest = [], string $type = '') { list($skyport, $publicKey) = $this->getSkyport(); $result = Base\HTTP::postSignedJSON($skyport . 'package/' . $manifest['supplier'] . '/' . $manifest['name'] . '/version', $publicKey, ['type' => $type, 'token' => $this->getToken($manifest['supplier'])]); if (isset($result['latest'])) { if ($result['latest'] !== $manifest['version']) { return true; } while (true) { echo 'The current version you are trying to push, ', $this->c['yellow'], $manifest['version'], $this->c[''], ",\n"; echo 'is already in the system. (The latest version pushed is ', $this->c['yellow'], $result['latest'], $this->c[''], ".\n\n"; echo 'A forced push is not likely to succeed.', "\n"; // Get and process the user's response $choice = $this->prompt('Push a new release anyway? (y/N)'); switch ($choice) { case 'YES': case 'yes': case 'Y': case 'y': return true; case 'N': case 'NO': case 'n': case 'no': case '': // Just pressing enter means "don't push it"! return false; default: echo "\n", $this->c['yellow'], 'Invalid response. Please enter yes or no.', $this->c[''], "\n"; } } } // No latest version to be found? Just let it go through. return true; }
/** * Send the upstream revocation notice * * @param string $supplier * @param array $data * @param string $masterSignature * @param string $masterPublicKey * @return array * @throws \Exception */ protected function sendRevocation(string $supplier, array $data = [], string $masterSignature, string $masterPublicKey) : array { list($skyport, $publicKey) = $this->getSkyport(); $postData = ['token' => $this->getToken($supplier), 'message' => $data, 'master' => ['public_key' => $masterPublicKey, 'signature' => $masterSignature]]; // The user must opt in for this to be invoked: if ($data['store_in_cloud']) { $postData['stored_salt'] = $data['salt']; } return Base\HTTP::postSignedJSON($skyport . 'key/revoke', $publicKey, $postData); }
/** * Send information about the new key to our Skyport * * @param string $supplier * @param array $data * @param string $message * @param string $masterSignature * @param string $masterPublicKey * @return array */ protected function sendToSkyport(string $supplier, array $data = [], string $message, string $masterSignature, string $masterPublicKey) : array { list($skyport, $publicKey) = $this->getSkyport(); $postData = ['token' => $this->getToken($supplier), 'date_generated' => $data['date_generated'], 'message' => $message, 'publickey' => $data['public_key'], 'type' => $data['type']]; // The user must opt in for this to be invoked: if ($data['store_in_cloud']) { $postData['stored_salt'] = $data['salt']; } // If this isn't our first key, we should be signing it with our master key. if ($masterPublicKey && $masterSignature) { // The skyport MUST make validate the master public key before checking // the signature. $postData['master'] = ['public_key' => $masterPublicKey, 'signature' => $masterSignature]; } return Base\HTTP::postSignedJSON($skyport . 'key/add', $publicKey, $postData); }