mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-19 21:13:12 -07:00
Merge RegistKey and Auth
This commit is contained in:
parent
1a4634f3c2
commit
73ccfb6f22
7 changed files with 62 additions and 51 deletions
|
@ -46,9 +46,7 @@ struct StreamSessionConnectInfo
|
|||
uint32_t log_level_mask;
|
||||
QString log_file;
|
||||
QString host;
|
||||
QString registkey;
|
||||
QString ostype;
|
||||
QString auth;
|
||||
QString regist_key;
|
||||
QString morning;
|
||||
QString did;
|
||||
ChiakiConnectVideoProfile video_profile;
|
||||
|
|
|
@ -72,12 +72,6 @@ int main(int argc, char *argv[])
|
|||
QCommandLineOption regist_key_option("registkey", "", "registkey");
|
||||
parser.addOption(regist_key_option);
|
||||
|
||||
QCommandLineOption ostype_option("ostype", "", "ostype", "Win10.0.0");
|
||||
parser.addOption(ostype_option);
|
||||
|
||||
QCommandLineOption auth_option("auth", "", "auth");
|
||||
parser.addOption(auth_option);
|
||||
|
||||
QCommandLineOption morning_option("morning", "", "morning");
|
||||
parser.addOption(morning_option);
|
||||
|
||||
|
@ -104,9 +98,7 @@ int main(int argc, char *argv[])
|
|||
connect_info.log_file = CreateLogFilename();
|
||||
|
||||
connect_info.host = host;
|
||||
connect_info.registkey = parser.value(regist_key_option);
|
||||
connect_info.ostype = parser.value(ostype_option);
|
||||
connect_info.auth = parser.value(auth_option);
|
||||
connect_info.regist_key = parser.value(regist_key_option);
|
||||
connect_info.morning = parser.value(morning_option);
|
||||
connect_info.did = parser.value(did_option);
|
||||
|
||||
|
@ -114,7 +106,7 @@ int main(int argc, char *argv[])
|
|||
CHIAKI_VIDEO_RESOLUTION_PRESET_720p,
|
||||
CHIAKI_VIDEO_FPS_PRESET_30);
|
||||
|
||||
if(connect_info.registkey.isEmpty() || connect_info.ostype.isEmpty() || connect_info.auth.isEmpty() || connect_info.morning.isEmpty() || connect_info.did.isEmpty())
|
||||
if(connect_info.regist_key.isEmpty() || connect_info.morning.isEmpty() || connect_info.did.isEmpty())
|
||||
parser.showHelp(1);
|
||||
|
||||
return RunStream(app, connect_info);
|
||||
|
|
|
@ -45,22 +45,18 @@ StreamSession::StreamSession(const StreamSessionConnectInfo &connect_info, QObje
|
|||
audio_io(nullptr)
|
||||
{
|
||||
QByteArray host_str = connect_info.host.toUtf8();
|
||||
QByteArray registkey_str = connect_info.registkey.toUtf8();
|
||||
QByteArray ostype_str = connect_info.ostype.toUtf8();
|
||||
|
||||
ChiakiConnectInfo chiaki_connect_info;
|
||||
chiaki_connect_info.host = host_str.constData();
|
||||
chiaki_connect_info.regist_key = registkey_str.constData();
|
||||
chiaki_connect_info.ostype = ostype_str.constData();
|
||||
chiaki_connect_info.video_profile = connect_info.video_profile;
|
||||
|
||||
QByteArray auth_str = connect_info.auth.toUtf8();
|
||||
QByteArray auth_str = connect_info.regist_key.toUtf8();
|
||||
size_t auth_len = auth_str.length();
|
||||
if(auth_len > sizeof(chiaki_connect_info.auth))
|
||||
auth_len = sizeof(chiaki_connect_info.auth);
|
||||
memcpy(chiaki_connect_info.auth, auth_str.constData(), auth_len);
|
||||
if(auth_len < sizeof(chiaki_connect_info.auth))
|
||||
memset(chiaki_connect_info.auth + auth_len, 0, sizeof(chiaki_connect_info.auth) - auth_len);
|
||||
if(auth_len > sizeof(chiaki_connect_info.regist_key))
|
||||
auth_len = sizeof(chiaki_connect_info.regist_key);
|
||||
memcpy(chiaki_connect_info.regist_key, auth_str.constData(), auth_len);
|
||||
if(auth_len < sizeof(chiaki_connect_info.regist_key))
|
||||
memset(chiaki_connect_info.regist_key + auth_len, 0, sizeof(chiaki_connect_info.regist_key) - auth_len);
|
||||
|
||||
size_t morning_size = sizeof(chiaki_connect_info.morning);
|
||||
QByteArray morning_str = connect_info.morning.toUtf8();
|
||||
|
|
|
@ -70,9 +70,7 @@ CHIAKI_EXPORT void chiaki_connect_video_profile_preset(ChiakiConnectVideoProfile
|
|||
typedef struct chiaki_connect_info_t
|
||||
{
|
||||
const char *host; // null terminated
|
||||
const char *regist_key; // null terminated
|
||||
const char *ostype; // null terminated
|
||||
char auth[CHIAKI_SESSION_AUTH_SIZE]; // must be completely filled (pad with \0)
|
||||
char regist_key[CHIAKI_SESSION_AUTH_SIZE]; // must be completely filled (pad with \0)
|
||||
uint8_t morning[0x10];
|
||||
uint8_t did[CHIAKI_RP_DID_SIZE];
|
||||
ChiakiConnectVideoProfile video_profile;
|
||||
|
@ -137,9 +135,7 @@ typedef struct chiaki_session_t
|
|||
struct addrinfo *host_addrinfos;
|
||||
struct addrinfo *host_addrinfo_selected;
|
||||
char hostname[128];
|
||||
char *regist_key;
|
||||
char *ostype;
|
||||
char auth[CHIAKI_RPCRYPT_KEY_SIZE];
|
||||
char regist_key[CHIAKI_RPCRYPT_KEY_SIZE];
|
||||
uint8_t morning[CHIAKI_RPCRYPT_KEY_SIZE];
|
||||
uint8_t did[CHIAKI_RP_DID_SIZE];
|
||||
ChiakiConnectVideoProfile video_profile;
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include <assert.h>
|
||||
|
||||
|
||||
#define SESSION_OSTYPE "Win10.0.0"
|
||||
|
||||
#define SESSION_CTRL_PORT 9295
|
||||
|
||||
#define CTRL_EXPECT_TIMEOUT 5000
|
||||
|
@ -342,7 +344,7 @@ static ChiakiErrorCode ctrl_connect(ChiakiCtrl *ctrl)
|
|||
|
||||
|
||||
uint8_t auth_enc[CHIAKI_RPCRYPT_KEY_SIZE];
|
||||
ChiakiErrorCode err = chiaki_rpcrypt_encrypt(&session->rpcrypt, 0, (uint8_t *)session->connect_info.auth, auth_enc, CHIAKI_RPCRYPT_KEY_SIZE);
|
||||
ChiakiErrorCode err = chiaki_rpcrypt_encrypt(&session->rpcrypt, 0, (uint8_t *)session->connect_info.regist_key, auth_enc, CHIAKI_RPCRYPT_KEY_SIZE);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
goto error;
|
||||
char auth_b64[CHIAKI_RPCRYPT_KEY_SIZE*2];
|
||||
|
@ -360,10 +362,10 @@ static ChiakiErrorCode ctrl_connect(ChiakiCtrl *ctrl)
|
|||
goto error;
|
||||
|
||||
uint8_t ostype_enc[128];
|
||||
size_t ostype_len = strlen(session->connect_info.ostype) + 1;
|
||||
size_t ostype_len = strlen(SESSION_OSTYPE) + 1;
|
||||
if(ostype_len > sizeof(ostype_enc))
|
||||
goto error;
|
||||
err = chiaki_rpcrypt_encrypt(&session->rpcrypt, 2, (uint8_t *)session->connect_info.ostype, ostype_enc, ostype_len);
|
||||
err = chiaki_rpcrypt_encrypt(&session->rpcrypt, 2, (uint8_t *)SESSION_OSTYPE, ostype_enc, ostype_len);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
goto error;
|
||||
char ostype_b64[256];
|
||||
|
|
|
@ -151,23 +151,9 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_session_init(ChiakiSession *session, Chiaki
|
|||
return CHIAKI_ERR_PARSE_ADDR;
|
||||
}
|
||||
|
||||
session->connect_info.regist_key = strdup(connect_info->regist_key);
|
||||
if(!session->connect_info.regist_key)
|
||||
{
|
||||
chiaki_session_fini(session);
|
||||
return CHIAKI_ERR_MEMORY;
|
||||
}
|
||||
|
||||
session->connect_info.ostype = strdup(connect_info->ostype);
|
||||
if(!session->connect_info.regist_key)
|
||||
{
|
||||
chiaki_session_fini(session);
|
||||
return CHIAKI_ERR_MEMORY;
|
||||
}
|
||||
|
||||
chiaki_controller_state_set_idle(&session->controller_state);
|
||||
|
||||
memcpy(session->connect_info.auth, connect_info->auth, sizeof(session->connect_info.auth));
|
||||
memcpy(session->connect_info.regist_key, connect_info->regist_key, sizeof(session->connect_info.regist_key));
|
||||
memcpy(session->connect_info.morning, connect_info->morning, sizeof(session->connect_info.morning));
|
||||
memcpy(session->connect_info.did, connect_info->did, sizeof(session->connect_info.did));
|
||||
|
||||
|
@ -193,8 +179,6 @@ CHIAKI_EXPORT void chiaki_session_fini(ChiakiSession *session)
|
|||
chiaki_stop_pipe_fini(&session->stop_pipe);
|
||||
chiaki_cond_fini(&session->state_cond);
|
||||
chiaki_mutex_fini(&session->state_mutex);
|
||||
free(session->connect_info.regist_key);
|
||||
free(session->connect_info.ostype);
|
||||
freeaddrinfo(session->connect_info.host_addrinfos);
|
||||
}
|
||||
|
||||
|
@ -527,9 +511,27 @@ static bool session_thread_request_session(ChiakiSession *session)
|
|||
"Rp-Version: 8.0\r\n"
|
||||
"\r\n";
|
||||
|
||||
size_t regist_key_len = sizeof(session->connect_info.regist_key);
|
||||
for(size_t i=0; i<regist_key_len; i++)
|
||||
{
|
||||
if(!session->connect_info.regist_key[i])
|
||||
{
|
||||
regist_key_len = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
char regist_key_hex[sizeof(session->connect_info.regist_key) * 2 + 1];
|
||||
ChiakiErrorCode err = format_hex(regist_key_hex, sizeof(regist_key_hex), (uint8_t *)session->connect_info.regist_key, regist_key_len);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
close(session_sock);
|
||||
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_UNKNOWN;
|
||||
return false;
|
||||
}
|
||||
|
||||
char buf[512];
|
||||
int request_len = snprintf(buf, sizeof(buf), session_request_fmt,
|
||||
session->connect_info.hostname, SESSION_PORT, session->connect_info.regist_key);
|
||||
session->connect_info.hostname, SESSION_PORT, regist_key_hex);
|
||||
if(request_len < 0 || request_len >= sizeof(buf))
|
||||
{
|
||||
close(session_sock);
|
||||
|
@ -551,7 +553,7 @@ static bool session_thread_request_session(ChiakiSession *session)
|
|||
size_t header_size;
|
||||
size_t received_size;
|
||||
chiaki_mutex_unlock(&session->state_mutex);
|
||||
ChiakiErrorCode err = chiaki_recv_http_header(session_sock, buf, sizeof(buf), &header_size, &received_size, &session->stop_pipe, SESSION_EXPECT_TIMEOUT_MS);
|
||||
err = chiaki_recv_http_header(session_sock, buf, sizeof(buf), &header_size, &received_size, &session->stop_pipe, SESSION_EXPECT_TIMEOUT_MS);
|
||||
ChiakiErrorCode mutex_err = chiaki_mutex_lock(&session->state_mutex);
|
||||
assert(mutex_err == CHIAKI_ERR_SUCCESS);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
|
|
|
@ -76,4 +76,29 @@ static inline ChiakiErrorCode parse_hex(uint8_t *buf, size_t *buf_size, const ch
|
|||
return CHIAKI_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
static inline char nibble_char(uint8_t v)
|
||||
{
|
||||
if(v > 0xf)
|
||||
return '0';
|
||||
if(v < 0xa)
|
||||
return '0' + v;
|
||||
return 'a' + v;
|
||||
}
|
||||
|
||||
static inline ChiakiErrorCode format_hex(char *hex_buf, size_t hex_buf_size, const uint8_t *buf, size_t buf_size)
|
||||
{
|
||||
if(hex_buf_size < buf_size * 2 + 1)
|
||||
return CHIAKI_ERR_BUF_TOO_SMALL;
|
||||
|
||||
for(size_t i=0; i<buf_size; i++)
|
||||
{
|
||||
uint8_t v = buf[i];
|
||||
hex_buf[i*2+0] = nibble_char(v >> 4);
|
||||
hex_buf[i*2+1] = nibble_char(v & 0xf);
|
||||
}
|
||||
hex_buf[buf_size*2] = '\0';
|
||||
|
||||
return CHIAKI_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
#endif // CHIAKI_UTILS_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue