Skip to content

Commit e35ece4

Browse files
authored
Set custom server URL, fingerprint, and connection security
Added methods to support a custom server URL, a host fingerprint for SSL, or option to set the connection client to insecure.
1 parent b95506a commit e35ece4

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

Diff for: src/internal/esp8266/ParseClient.cpp

+29-2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ static void sendAndEchoToSerial(WiFiClientSecure& client, const char *line) {
8181
ParseClient::ParseClient() {
8282
memset(applicationId, 0, sizeof(applicationId));
8383
memset(clientKey, 0, sizeof(clientKey));
84+
memset(serverURL, 0, sizeof(serverURL));
85+
memset(hostFingerprint, 0, sizeof(hostFingerprint));
8486
memset(installationId, 0, sizeof(installationId));
8587
memset(sessionToken, 0, sizeof(sessionToken));
8688
memset(lastPushTime, 0, sizeof(lastPushTime));
@@ -110,6 +112,29 @@ void ParseClient::begin(const char *applicationId, const char *clientKey) {
110112
restoreKeys();
111113
}
112114

115+
void ParseClient::setServerURL(const char *serverURL) {
116+
Serial.print("setting serverURL(");
117+
Serial.print(serverURL ? serverURL : "NULL");
118+
Serial.println(")");
119+
if(serverURL) {
120+
strncpy(this->serverURL, serverURL, sizeof(this->serverURL));
121+
}
122+
}
123+
124+
void ParseClient::setHostFingerprint(const char *hostFingerprint) {
125+
Serial.print("setting hostFingerprint(");
126+
Serial.print(hostFingerprint ? hostFingerprint : "NULL");
127+
Serial.println(")");
128+
if(hostFingerprint) {
129+
strncpy(this->hostFingerprint, hostFingerprint, sizeof(this->hostFingerprint));
130+
}
131+
}
132+
133+
void ParseClient::setClientInsecure() {
134+
Serial.println("setting connection client insecure");
135+
client.setInsecure();
136+
}
137+
113138
void ParseClient::setInstallationId(const char *installationId) {
114139
if (installationId) {
115140
if (strcmp(this->installationId, installationId))
@@ -201,8 +226,10 @@ ParseResponse ParseClient::sendRequest(const String& httpVerb, const String& htt
201226

202227
int retry = 3;
203228
bool connected;
229+
230+
client.setFingerprint(hostFingerprint);
204231

205-
while(!(connected = client.connect(PARSE_API, SSL_PORT)) && retry--) {
232+
while(!(connected = client.connect(serverURL, SSL_PORT)) && retry--) {
206233
Serial.printf("connecting...%d\n", retry);
207234
yield();
208235
}
@@ -220,7 +247,7 @@ ParseResponse ParseClient::sendRequest(const String& httpVerb, const String& htt
220247
snprintf(buff, sizeof(buff) - 1, "%s %s HTTP/1.1\r\n", httpVerb.c_str(), httpPath.c_str());
221248
}
222249
sendAndEchoToSerial(client, buff);
223-
snprintf(buff, sizeof(buff) - 1, "Host: %s\r\n", PARSE_API);
250+
snprintf(buff, sizeof(buff) - 1, "Host: %s\r\n", serverURL);
224251
sendAndEchoToSerial(client, buff);
225252
snprintf(buff, sizeof(buff) - 1, "X-Parse-Client-Version: %s\r\n", CLIENT_VERSION);
226253
sendAndEchoToSerial(client, buff);

0 commit comments

Comments
 (0)