mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-19 21:13:12 -07:00
Add Regist with Np-AccountId (Fix #51)
This commit is contained in:
parent
4361ba4583
commit
b5ce69cb43
6 changed files with 101 additions and 23 deletions
|
@ -642,13 +642,13 @@ JNIEXPORT void JNICALL JNI_FCN(registStart)(JNIEnv *env, jobject obj, jobject re
|
||||||
ChiakiRegistInfo regist_info;
|
ChiakiRegistInfo regist_info;
|
||||||
regist_info.host = E->GetStringUTFChars(env, host_string, NULL);
|
regist_info.host = E->GetStringUTFChars(env, host_string, NULL);
|
||||||
regist_info.broadcast = broadcast;
|
regist_info.broadcast = broadcast;
|
||||||
regist_info.psn_id = E->GetStringUTFChars(env, psn_id_string, NULL);
|
// TODO regist_info.psn_id = E->GetStringUTFChars(env, psn_id_string, NULL);
|
||||||
regist_info.pin = (uint32_t)pin;
|
regist_info.pin = (uint32_t)pin;
|
||||||
|
|
||||||
err = chiaki_regist_start(®ist->regist, ®ist->log.log, ®ist_info, android_chiaki_regist_cb, regist);
|
err = chiaki_regist_start(®ist->regist, ®ist->log.log, ®ist_info, android_chiaki_regist_cb, regist);
|
||||||
|
|
||||||
E->ReleaseStringUTFChars(env, host_string, regist_info.host);
|
E->ReleaseStringUTFChars(env, host_string, regist_info.host);
|
||||||
E->ReleaseStringUTFChars(env, psn_id_string, regist_info.psn_id);
|
// TODO E->ReleaseStringUTFChars(env, psn_id_string, regist_info.psn_id);
|
||||||
|
|
||||||
if(err != CHIAKI_ERR_SUCCESS)
|
if(err != CHIAKI_ERR_SUCCESS)
|
||||||
{
|
{
|
||||||
|
|
|
@ -268,7 +268,7 @@ class DiscoveryService(
|
||||||
data class RegistInfo(
|
data class RegistInfo(
|
||||||
val host: String,
|
val host: String,
|
||||||
val broadcast: Boolean,
|
val broadcast: Boolean,
|
||||||
val psnId: String,
|
val psnId: String, // TODO: this is outdated now
|
||||||
val pin: UInt
|
val pin: UInt
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ class QLineEdit;
|
||||||
class QPlainTextEdit;
|
class QPlainTextEdit;
|
||||||
class QDialogButtonBox;
|
class QDialogButtonBox;
|
||||||
class QCheckBox;
|
class QCheckBox;
|
||||||
|
class QRadioButton;
|
||||||
|
|
||||||
class RegistDialog : public QDialog
|
class RegistDialog : public QDialog
|
||||||
{
|
{
|
||||||
|
@ -40,7 +41,10 @@ class RegistDialog : public QDialog
|
||||||
|
|
||||||
QLineEdit *host_edit;
|
QLineEdit *host_edit;
|
||||||
QCheckBox *broadcast_check_box;
|
QCheckBox *broadcast_check_box;
|
||||||
QLineEdit *psn_id_edit;
|
QRadioButton *psn_online_id_radio_button;
|
||||||
|
QLineEdit *psn_online_id_edit;
|
||||||
|
QRadioButton *psn_account_id_radio_button;
|
||||||
|
QLineEdit *psn_account_id_edit;
|
||||||
QLineEdit *pin_edit;
|
QLineEdit *pin_edit;
|
||||||
QDialogButtonBox *button_box;
|
QDialogButtonBox *button_box;
|
||||||
QPushButton *register_button;
|
QPushButton *register_button;
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
|
#include <QRadioButton>
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(ChiakiLogLevel)
|
Q_DECLARE_METATYPE(ChiakiLogLevel)
|
||||||
|
|
||||||
|
@ -57,8 +58,23 @@ RegistDialog::RegistDialog(Settings *settings, const QString &host, QWidget *par
|
||||||
form_layout->addRow(tr("Broadcast:"), broadcast_check_box);
|
form_layout->addRow(tr("Broadcast:"), broadcast_check_box);
|
||||||
broadcast_check_box->setChecked(host.isEmpty());
|
broadcast_check_box->setChecked(host.isEmpty());
|
||||||
|
|
||||||
psn_id_edit = new QLineEdit(this);
|
auto UpdatePSNIDEdits = [this]() {
|
||||||
form_layout->addRow(tr("PSN ID (username, case-sensitive):"), psn_id_edit);
|
psn_online_id_edit->setEnabled(psn_online_id_radio_button->isChecked());
|
||||||
|
psn_account_id_edit->setEnabled(psn_account_id_radio_button->isChecked());
|
||||||
|
};
|
||||||
|
|
||||||
|
psn_online_id_radio_button = new QRadioButton(tr("PSN Online-ID (username, case-sensitive) for PS4 < 7.0:"), this);
|
||||||
|
psn_online_id_edit = new QLineEdit(this);
|
||||||
|
form_layout->addRow(psn_online_id_radio_button, psn_online_id_edit);
|
||||||
|
connect(psn_online_id_radio_button, &QRadioButton::toggled, this, UpdatePSNIDEdits);
|
||||||
|
|
||||||
|
psn_account_id_radio_button = new QRadioButton(tr("PSN Account-ID (base64) for PS4 >= 7.0:"), this);
|
||||||
|
psn_account_id_edit = new QLineEdit(this);
|
||||||
|
form_layout->addRow(psn_account_id_radio_button, psn_account_id_edit);
|
||||||
|
psn_account_id_radio_button->setChecked(true);
|
||||||
|
connect(psn_account_id_radio_button, &QRadioButton::toggled, this, UpdatePSNIDEdits);
|
||||||
|
|
||||||
|
UpdatePSNIDEdits();
|
||||||
|
|
||||||
pin_edit = new QLineEdit(this);
|
pin_edit = new QLineEdit(this);
|
||||||
pin_edit->setValidator(new QRegularExpressionValidator(pin_re, pin_edit));
|
pin_edit->setValidator(new QRegularExpressionValidator(pin_re, pin_edit));
|
||||||
|
@ -71,7 +87,7 @@ RegistDialog::RegistDialog(Settings *settings, const QString &host, QWidget *par
|
||||||
connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||||
|
|
||||||
connect(host_edit, &QLineEdit::textChanged, this, &RegistDialog::ValidateInput);
|
connect(host_edit, &QLineEdit::textChanged, this, &RegistDialog::ValidateInput);
|
||||||
connect(psn_id_edit, &QLineEdit::textChanged, this, &RegistDialog::ValidateInput);
|
connect(psn_online_id_edit, &QLineEdit::textChanged, this, &RegistDialog::ValidateInput);
|
||||||
connect(pin_edit, &QLineEdit::textChanged, this, &RegistDialog::ValidateInput);
|
connect(pin_edit, &QLineEdit::textChanged, this, &RegistDialog::ValidateInput);
|
||||||
ValidateInput();
|
ValidateInput();
|
||||||
}
|
}
|
||||||
|
@ -83,7 +99,8 @@ RegistDialog::~RegistDialog()
|
||||||
void RegistDialog::ValidateInput()
|
void RegistDialog::ValidateInput()
|
||||||
{
|
{
|
||||||
bool valid = !host_edit->text().trimmed().isEmpty()
|
bool valid = !host_edit->text().trimmed().isEmpty()
|
||||||
&& !psn_id_edit->text().trimmed().isEmpty()
|
&& (!psn_online_id_radio_button->isChecked() || !psn_online_id_edit->text().trimmed().isEmpty())
|
||||||
|
&& (!psn_account_id_radio_button->isChecked() || !psn_account_id_radio_button->text().trimmed().isEmpty())
|
||||||
&& pin_edit->text().length() == PIN_LENGTH;
|
&& pin_edit->text().length() == PIN_LENGTH;
|
||||||
register_button->setEnabled(valid);
|
register_button->setEnabled(valid);
|
||||||
}
|
}
|
||||||
|
@ -91,10 +108,28 @@ void RegistDialog::ValidateInput()
|
||||||
void RegistDialog::accept()
|
void RegistDialog::accept()
|
||||||
{
|
{
|
||||||
ChiakiRegistInfo info = {};
|
ChiakiRegistInfo info = {};
|
||||||
QByteArray psn_id = psn_id_edit->text().trimmed().toUtf8();
|
|
||||||
QByteArray host = host_edit->text().trimmed().toUtf8();
|
QByteArray host = host_edit->text().trimmed().toUtf8();
|
||||||
info.psn_id = psn_id.data();
|
info.host = host.constData();
|
||||||
info.host = host.data();
|
|
||||||
|
QByteArray psn_id; // keep this out of the if scope
|
||||||
|
if(psn_online_id_radio_button->isChecked())
|
||||||
|
{
|
||||||
|
psn_id = psn_online_id_edit->text().trimmed().toUtf8();
|
||||||
|
info.psn_online_id = psn_id.constData();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QString account_id_b64 = psn_account_id_edit->text().trimmed();
|
||||||
|
QByteArray account_id = QByteArray::fromBase64(account_id_b64.toUtf8());
|
||||||
|
if(account_id.size() != CHIAKI_PSN_ACCOUNT_ID_SIZE)
|
||||||
|
{
|
||||||
|
QMessageBox::critical(this, tr("Invalid Account-ID"), tr("The PSN Account-ID must be exactly %1 bytes encoded as base64.").arg(CHIAKI_PSN_ACCOUNT_ID_SIZE));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
info.psn_online_id = nullptr;
|
||||||
|
memcpy(info.psn_account_id, account_id.constData(), CHIAKI_PSN_ACCOUNT_ID_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
info.broadcast = broadcast_check_box->isChecked();
|
info.broadcast = broadcast_check_box->isChecked();
|
||||||
info.pin = (uint32_t)pin_edit->text().toULong();
|
info.pin = (uint32_t)pin_edit->text().toULong();
|
||||||
|
|
||||||
|
|
|
@ -29,11 +29,23 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define CHIAKI_PSN_ACCOUNT_ID_SIZE 8
|
||||||
|
|
||||||
typedef struct chiaki_regist_info_t
|
typedef struct chiaki_regist_info_t
|
||||||
{
|
{
|
||||||
const char *host;
|
const char *host;
|
||||||
bool broadcast;
|
bool broadcast;
|
||||||
const char *psn_id;
|
|
||||||
|
/**
|
||||||
|
* may be null, in which case psn_account_id will be used
|
||||||
|
*/
|
||||||
|
const char *psn_online_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* will be used if psn_online_id is null, for PS4 >= 7.0
|
||||||
|
*/
|
||||||
|
uint8_t psn_account_id[CHIAKI_PSN_ACCOUNT_ID_SIZE];
|
||||||
|
|
||||||
uint32_t pin;
|
uint32_t pin;
|
||||||
} ChiakiRegistInfo;
|
} ChiakiRegistInfo;
|
||||||
|
|
||||||
|
@ -79,7 +91,10 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_regist_start(ChiakiRegist *regist, ChiakiLo
|
||||||
CHIAKI_EXPORT void chiaki_regist_fini(ChiakiRegist *regist);
|
CHIAKI_EXPORT void chiaki_regist_fini(ChiakiRegist *regist);
|
||||||
CHIAKI_EXPORT void chiaki_regist_stop(ChiakiRegist *regist);
|
CHIAKI_EXPORT void chiaki_regist_stop(ChiakiRegist *regist);
|
||||||
|
|
||||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_regist_request_payload_format(uint8_t *buf, size_t *buf_size, ChiakiRPCrypt *crypt, const char *psn_id);
|
/**
|
||||||
|
* @param psn_account_id must be exactly of size CHIAKI_PSN_ACCOUNT_ID_SIZE
|
||||||
|
*/
|
||||||
|
CHIAKI_EXPORT ChiakiErrorCode chiaki_regist_request_payload_format(uint8_t *buf, size_t *buf_size, ChiakiRPCrypt *crypt, const char *psn_online_id, const uint8_t *psn_account_id);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <chiaki/http.h>
|
#include <chiaki/http.h>
|
||||||
#include <chiaki/random.h>
|
#include <chiaki/random.h>
|
||||||
#include <chiaki/time.h>
|
#include <chiaki/time.h>
|
||||||
|
#include <chiaki/base64.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -55,9 +56,13 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_regist_start(ChiakiRegist *regist, ChiakiLo
|
||||||
regist->info.host = strdup(regist->info.host);
|
regist->info.host = strdup(regist->info.host);
|
||||||
if(!regist->info.host)
|
if(!regist->info.host)
|
||||||
return CHIAKI_ERR_MEMORY;
|
return CHIAKI_ERR_MEMORY;
|
||||||
regist->info.psn_id = strdup(regist->info.psn_id);
|
|
||||||
if(!regist->info.psn_id)
|
if(regist->info.psn_online_id)
|
||||||
goto error_host;
|
{
|
||||||
|
regist->info.psn_online_id = strdup(regist->info.psn_online_id);
|
||||||
|
if(!regist->info.psn_online_id)
|
||||||
|
goto error_host;
|
||||||
|
}
|
||||||
|
|
||||||
regist->cb = cb;
|
regist->cb = cb;
|
||||||
regist->cb_user = cb_user;
|
regist->cb_user = cb_user;
|
||||||
|
@ -75,7 +80,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_regist_start(ChiakiRegist *regist, ChiakiLo
|
||||||
error_stop_pipe:
|
error_stop_pipe:
|
||||||
chiaki_stop_pipe_fini(®ist->stop_pipe);
|
chiaki_stop_pipe_fini(®ist->stop_pipe);
|
||||||
error_psn_id:
|
error_psn_id:
|
||||||
free((char *)regist->info.psn_id);
|
free((char *)regist->info.psn_online_id);
|
||||||
error_host:
|
error_host:
|
||||||
free((char *)regist->info.host);
|
free((char *)regist->info.host);
|
||||||
return err;
|
return err;
|
||||||
|
@ -85,7 +90,7 @@ CHIAKI_EXPORT void chiaki_regist_fini(ChiakiRegist *regist)
|
||||||
{
|
{
|
||||||
chiaki_thread_join(®ist->thread, NULL);
|
chiaki_thread_join(®ist->thread, NULL);
|
||||||
chiaki_stop_pipe_fini(®ist->stop_pipe);
|
chiaki_stop_pipe_fini(®ist->stop_pipe);
|
||||||
free((char *)regist->info.psn_id);
|
free((char *)regist->info.psn_online_id);
|
||||||
free((char *)regist->info.host);
|
free((char *)regist->info.host);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,13 +111,20 @@ static const char * const request_fmt =
|
||||||
"HOST: 10.0.2.15\r\n" // random lol
|
"HOST: 10.0.2.15\r\n" // random lol
|
||||||
"User-Agent: remoteplay Windows\r\n"
|
"User-Agent: remoteplay Windows\r\n"
|
||||||
"Connection: close\r\n"
|
"Connection: close\r\n"
|
||||||
"Content-Length: %llu\r\n\r\n";
|
"Content-Length: %llu\r\n"
|
||||||
|
"RP-Version: " CHIAKI_RP_CLIENT_VERSION "\r\n\r\n";
|
||||||
|
|
||||||
static const char * const request_inner_fmt =
|
static const char * const request_inner_account_id_fmt =
|
||||||
|
"Client-Type: Windows\r\n"
|
||||||
|
"Np-AccountId: %s\r\n";
|
||||||
|
|
||||||
|
static const char * const request_inner_online_id_fmt =
|
||||||
"Client-Type: Windows\r\n"
|
"Client-Type: Windows\r\n"
|
||||||
"Np-Online-Id: %s\r\n";
|
"Np-Online-Id: %s\r\n";
|
||||||
|
|
||||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_regist_request_payload_format(uint8_t *buf, size_t *buf_size, ChiakiRPCrypt *crypt, const char *psn_id)
|
|
||||||
|
|
||||||
|
CHIAKI_EXPORT ChiakiErrorCode chiaki_regist_request_payload_format(uint8_t *buf, size_t *buf_size, ChiakiRPCrypt *crypt, const char *psn_online_id, const uint8_t *psn_account_id)
|
||||||
{
|
{
|
||||||
size_t buf_size_val = *buf_size;
|
size_t buf_size_val = *buf_size;
|
||||||
static const size_t inner_header_off = 0x1e0;
|
static const size_t inner_header_off = 0x1e0;
|
||||||
|
@ -120,7 +132,19 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_regist_request_payload_format(uint8_t *buf,
|
||||||
return CHIAKI_ERR_BUF_TOO_SMALL;
|
return CHIAKI_ERR_BUF_TOO_SMALL;
|
||||||
memset(buf, 'A', inner_header_off);
|
memset(buf, 'A', inner_header_off);
|
||||||
chiaki_rpcrypt_aeropause(buf + 0x11c, crypt->ambassador);
|
chiaki_rpcrypt_aeropause(buf + 0x11c, crypt->ambassador);
|
||||||
int inner_header_size = snprintf((char *)buf + inner_header_off, buf_size_val - inner_header_off, request_inner_fmt, psn_id);
|
int inner_header_size;
|
||||||
|
if(psn_online_id)
|
||||||
|
inner_header_size = snprintf((char *)buf + inner_header_off, buf_size_val - inner_header_off, request_inner_online_id_fmt, psn_online_id);
|
||||||
|
else if(psn_account_id)
|
||||||
|
{
|
||||||
|
char account_id_b64[CHIAKI_PSN_ACCOUNT_ID_SIZE * 2];
|
||||||
|
ChiakiErrorCode err = chiaki_base64_encode(psn_account_id, CHIAKI_PSN_ACCOUNT_ID_SIZE, account_id_b64, sizeof(account_id_b64));
|
||||||
|
if(err != CHIAKI_ERR_SUCCESS)
|
||||||
|
return err;
|
||||||
|
inner_header_size = snprintf((char *)buf + inner_header_off, buf_size_val - inner_header_off, request_inner_account_id_fmt, account_id_b64);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return CHIAKI_ERR_INVALID_DATA;
|
||||||
if(inner_header_size < 0 || inner_header_size >= buf_size_val - inner_header_off)
|
if(inner_header_size < 0 || inner_header_size >= buf_size_val - inner_header_off)
|
||||||
return CHIAKI_ERR_BUF_TOO_SMALL;
|
return CHIAKI_ERR_BUF_TOO_SMALL;
|
||||||
ChiakiErrorCode err = chiaki_rpcrypt_encrypt(crypt, 0, buf + inner_header_off, buf + inner_header_off, inner_header_size);
|
ChiakiErrorCode err = chiaki_rpcrypt_encrypt(crypt, 0, buf + inner_header_off, buf + inner_header_off, inner_header_size);
|
||||||
|
@ -148,7 +172,7 @@ static void *regist_thread_func(void *user)
|
||||||
|
|
||||||
uint8_t payload[0x400];
|
uint8_t payload[0x400];
|
||||||
size_t payload_size = sizeof(payload);
|
size_t payload_size = sizeof(payload);
|
||||||
err = chiaki_regist_request_payload_format(payload, &payload_size, &crypt, regist->info.psn_id);
|
err = chiaki_regist_request_payload_format(payload, &payload_size, &crypt, regist->info.psn_online_id, regist->info.psn_account_id);
|
||||||
if(err != CHIAKI_ERR_SUCCESS)
|
if(err != CHIAKI_ERR_SUCCESS)
|
||||||
{
|
{
|
||||||
CHIAKI_LOGE(regist->log, "Regist failed to format payload");
|
CHIAKI_LOGE(regist->log, "Regist failed to format payload");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue