Skip to content

Commit 49f8e26

Browse files
committed
More 7080 SSL cert tweaks
Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
1 parent fb39d81 commit 49f8e26

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
lines changed

src/TinyGsmClientSIM7000SSL.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ class TinyGsmSim7000SSL
284284
success &= waitResponse(5000L) == 1;
285285
if (!success) { return false; }
286286

287+
// NOTE: It just works much better if we wait a little bit before asking to
288+
// write the certificate
289+
delay(100);
290+
287291
// Write File to the Flash Buffer Allocated by CFSINIT
288292
// AT+CFSWFILE=<index>,<file name>,<mode>,<file size>,<input time>
289293
//<index> 3: "/customer/" (always use customer for certificates)
@@ -298,13 +302,21 @@ class TinyGsmSim7000SSL
298302
// <len_filename> Integer type. Maximum length of parameter <file name>.
299303
sendAT(GF("+CFSWFILE=3,\""), certificateName, GF("\",0,"), len,
300304
GF(",10000"));
301-
success &= waitResponse(5000L, GF("DOWNLOAD")) == 1;
305+
// The module sends back a 'DOWNLOAD' prompt - sometimes preceded by an 'OK'
306+
// NOTE: If we don't get the "DOWNLOAD" response or somehow miss hearing it,
307+
// we don't write the file. If we don't write something within 10 seconds
308+
// (the <input time>), the terminal will timeout and send back an 'OK' at
309+
// the 10s mark.
310+
success &= waitResponse(10500L, GF("DOWNLOAD"), GFP(GSM_OK),
311+
GFP(GSM_ERROR)) == 1;
302312

303313
if (success) {
304314
stream.write(cert, len);
305315
stream.flush();
316+
success &= waitResponse(5000L) == 1;
317+
} else {
318+
DBG(GF("### Failed to get download prompt!"));
306319
}
307-
success &= waitResponse(15000L) == 1;
308320

309321
// Verify the size of the uploaded file
310322
// AT+CFSGFIS=<index>,<filename>
@@ -317,6 +329,7 @@ class TinyGsmSim7000SSL
317329
streamSkipUntil('\n');
318330
success &= len_confirmed == len;
319331
}
332+
success &= waitResponse(5000L) == 1;
320333

321334
// Release AT relates to file system functions.
322335
// NOTE: We need to do this even if we didn't successfully write the file
@@ -832,6 +845,13 @@ class TinyGsmSim7000SSL
832845
const char* clientKeyName = thisClient->clientKeyName;
833846
const char* pskTableName = thisClient->pskTableName;
834847

848+
DBG("### SSL context index:", sslCtxIndex);
849+
DBG("### SSL auth mode:", (int)sslAuthMode);
850+
DBG("### CA cert name:", CAcertName);
851+
DBG("### Client cert name:", clientCertName);
852+
DBG("### Client key name:", clientKeyName);
853+
DBG("### PSK table name:", pskTableName);
854+
835855
// NOTE: We cannot link the SSL context or set the certificates until
836856
// AFTER setting the connection id (ie, AT+CACID=mux)
837857
linkSSLContext(mux,
@@ -844,6 +864,9 @@ class TinyGsmSim7000SSL
844864
}
845865
}
846866

867+
DBG("### host:", host);
868+
DBG("### port:", port);
869+
847870
// actually open the connection
848871
// AT+CAOPEN=<cid>[,<conn_type>],<server>,<port>
849872
// <cid> TCP/UDP identifier

src/TinyGsmClientSIM7080.h

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>,
326326
success &= waitResponse(5000L) == 1;
327327
if (!success) { return false; }
328328

329+
// NOTE: It just works much better if we wait a little bit before asking to
330+
// write the certificate
331+
delay(100);
332+
329333
// Write File to the Flash Buffer Allocated by CFSINIT
330334
// AT+CFSWFILE=<index>,<file name>,<mode>,<file size>,<input time>
331335
//<index> 3: "/customer/" (always use customer for certificates)
@@ -340,13 +344,21 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>,
340344
// <len_filename> Integer type. Maximum length of parameter <file name>.
341345
sendAT(GF("+CFSWFILE=3,\""), certificateName, GF("\",0,"), len,
342346
GF(",10000"));
343-
success &= waitResponse(5000L, GF("DOWNLOAD")) == 1;
347+
// The module sends back a 'DOWNLOAD' prompt - sometimes preceded by an 'OK'
348+
// NOTE: If we don't get the "DOWNLOAD" response or somehow miss hearing it,
349+
// we don't write the file. If we don't write something within 10 seconds
350+
// (the <input time>), the terminal will timeout and send back an 'OK' at
351+
// the 10s mark.
352+
success &= waitResponse(10500L, GF("DOWNLOAD"), GFP(GSM_OK),
353+
GFP(GSM_ERROR)) == 1;
344354

345355
if (success) {
346356
stream.write(cert, len);
347357
stream.flush();
358+
success &= waitResponse(5000L) == 1;
359+
} else {
360+
DBG(GF("### Failed to get download prompt!"));
348361
}
349-
success &= waitResponse(15000L) == 1;
350362

351363
// Verify the size of the uploaded file
352364
// AT+CFSGFIS=<index>,<filename>
@@ -359,6 +371,7 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>,
359371
streamSkipUntil('\n');
360372
success &= len_confirmed == len;
361373
}
374+
success &= waitResponse(5000L) == 1;
362375

363376
// Release AT relates to file system functions.
364377
// NOTE: We need to do this even if we didn't successfully write the file
@@ -949,11 +962,11 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>,
949962
const char* pskTableName = thisClient->pskTableName;
950963

951964
DBG("### SSL context index:", sslCtxIndex);
952-
DBG("SSL auth mode:", (int)sslAuthMode);
953-
DBG("CA cert name:", CAcertName);
954-
DBG("Client cert name:", clientCertName);
955-
DBG("Client key name:", clientKeyName);
956-
DBG("PSK table name:", pskTableName);
965+
DBG("### SSL auth mode:", (int)sslAuthMode);
966+
DBG("### CA cert name:", CAcertName);
967+
DBG("### Client cert name:", clientCertName);
968+
DBG("### Client key name:", clientKeyName);
969+
DBG("### PSK table name:", pskTableName);
957970

958971
// NOTE: We cannot link the SSL context or set the certificates until
959972
// AFTER setting the connection id (ie, AT+CACID=mux)
@@ -967,8 +980,8 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>,
967980
}
968981
}
969982

970-
DBG("host:", host);
971-
DBG("port:", port);
983+
DBG("### host:", host);
984+
DBG("### port:", port);
972985

973986
// actually open the connection
974987
// AT+CAOPEN=<cid>,<pdp_index>,<conn_type>,<server>,<port>[,<recv_mode>]

0 commit comments

Comments
 (0)