Skip to content

Commit

Permalink
stratum password
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-wilson committed Jan 13, 2024
1 parent ef344f2 commit 794af8d
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion components/stratum/include/stratum_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void STRATUM_V1_parse(StratumApiV1Message *message, const char *stratum_json);

void STRATUM_V1_free_mining_notify(mining_notify *params);

int STRATUM_V1_authenticate(int socket, const char *username);
int STRATUM_V1_authenticate(int socket, const char *username, const char *pass);

void STRATUM_V1_configure_version_rolling(int socket, uint32_t * version_mask);

Expand Down
22 changes: 14 additions & 8 deletions components/stratum/stratum_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ int STRATUM_V1_suggest_difficulty(int socket, uint32_t difficulty)
return 1;
}

int STRATUM_V1_authenticate(int socket, const char *username)
int STRATUM_V1_authenticate(int socket, const char *username, const char *pass)
{
char authorize_msg[BUFFER_SIZE];
sprintf(authorize_msg, "{\"id\": %d, \"method\": \"mining.authorize\", \"params\": [\"%s\", \"x\"]}\n",
send_uid++, username);
sprintf(authorize_msg, "{\"id\": %d, \"method\": \"mining.authorize\", \"params\": [\"%s\", \"%s\"]}\n",
send_uid++, username, pass);
debug_stratum_tx(authorize_msg);

write(socket, authorize_msg, strlen(authorize_msg));
Expand Down Expand Up @@ -344,11 +344,17 @@ void STRATUM_V1_configure_version_rolling(int socket, uint32_t * version_mask)
line = STRATUM_V1_receive_jsonrpc_line(socket);

ESP_LOGI(TAG, "Received result %s", line);
StratumApiV1Message stratum_api_v1_message;
STRATUM_V1_parse(&stratum_api_v1_message, line);
if (stratum_api_v1_message.method == MINING_SET_VERSION_MASK || stratum_api_v1_message.method == STRATUM_RESULT_VERSION_MASK) {
*version_mask = stratum_api_v1_message.version_mask;
ESP_LOGI(TAG, "Set version mask: %08lx", *version_mask);

cJSON * result = cJSON_GetObjectItem(line, "result");
if (result != NULL)
{
cJSON * version_rolling_enabled = cJSON_GetObjectItem(result, "version-rolling");
if (cJSON_IsBool(version_rolling_enabled) && cJSON_IsTrue(version_rolling_enabled)){
cJSON * mask = cJSON_GetObjectItem(result, "version-rolling.mask");
uint32_t version_mask = strtoul(mask->valuestring, NULL, 16);
ESP_LOGI(TAG, "Set version mask: %08lx", version_mask);
}

}

free(line);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<label>Stratum User: </label>
<input formControlName="stratumUser" type="text">
</div>
<div class="form-group">
<label>Stratum Password: </label>
<input formControlName="stratumPassword" type="password">
</div>

<ng-container *ngIf="!devToolsOpen && ASICModel == eASICModel.BM1366">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class EditComponent implements OnInit {
Validators.max(65353)
]],
stratumUser: [info.stratumUser, [Validators.required]],
stratumPassword: ['password', [Validators.required]],
ssid: [info.ssid, [Validators.required]],
wifiPass: ['password'],
coreVoltage: [info.coreVoltage, [Validators.required]],
Expand Down Expand Up @@ -107,6 +108,9 @@ export class EditComponent implements OnInit {
if (form.wifiPass === 'password') {
delete form.wifiPass;
}
if (form.stratumPassword === 'password') {
delete form.stratumPassword;
}

this.systemService.updateSystem(this.uri, form)
.pipe(this.loadingService.lockUIUntilComplete())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class SettingsComponent {
Validators.max(65353)
]],
stratumUser: [info.stratumUser, [Validators.required]],
stratumPassword: ['password', [Validators.required]],
ssid: [info.ssid, [Validators.required]],
wifiPass: ['password'],
coreVoltage: [info.coreVoltage, [Validators.required]],
Expand Down Expand Up @@ -112,6 +113,9 @@ export class SettingsComponent {
if (form.wifiPass === 'password') {
delete form.wifiPass;
}
if (form.stratumPassword === 'password') {
delete form.stratumPassword;
}

this.systemService.updateSystem(undefined, form)
.pipe(this.loadingService.lockUIUntilComplete())
Expand Down
3 changes: 3 additions & 0 deletions main/http_server/http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ static esp_err_t PATCH_update_settings(httpd_req_t * req)
if ((item = cJSON_GetObjectItem(root, "stratumUser")) != NULL) {
nvs_config_set_string(NVS_CONFIG_STRATUM_USER, item->valuestring);
}
if ((item = cJSON_GetObjectItem(root, "stratumPassword")) != NULL) {
nvs_config_set_string(NVS_CONFIG_STRATUM_PASS, item->valuestring);
}
if ((item = cJSON_GetObjectItem(root, "stratumPort")) != NULL) {
nvs_config_set_u16(NVS_CONFIG_STRATUM_PORT, item->valueint);
}
Expand Down
4 changes: 3 additions & 1 deletion main/tasks/stratum_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ void stratum_task(void * pvParameters)
STRATUM_V1_suggest_difficulty(GLOBAL_STATE->sock, STRATUM_DIFFICULTY);

char * username = nvs_config_get_string(NVS_CONFIG_STRATUM_USER, STRATUM_USER);
STRATUM_V1_authenticate(GLOBAL_STATE->sock, username);
char * password = nvs_config_get_string(NVS_CONFIG_STRATUM_PASS, STRATUM_PW);
STRATUM_V1_authenticate(GLOBAL_STATE->sock, username, password);
free(password);
free(username);

ESP_LOGI(TAG, "Extranonce: %s", GLOBAL_STATE->extranonce_str);
Expand Down

0 comments on commit 794af8d

Please sign in to comment.