Quectel BG95BG77 SSL Application Note V1.0
Quectel BG95BG77 SSL Application Note V1.0
Application Note
Rev. BG95&BG77_SSL_Application_Note_V1.0
Date: 2019-10-12
Status: Released
www.quectel.com
LPWA Module Series
BG95&BG77 SSL Application Note
Our aim is to provide customers with timely and comprehensive service. For any
assistance, please contact our company headquarters:
GENERAL NOTES
QUECTEL OFFERS THE INFORMATION AS A SERVICE TO ITS CUSTOMERS. THE INFORMATION
PROVIDED IS BASED UPON CUSTOMERS’ REQUIREMENTS. QUECTEL MAKES EVERY EFFORT
TO ENSURE THE QUALITY OF THE INFORMATION IT MAKES AVAILABLE. QUECTEL DOES NOT
MAKE ANY WARRANTY AS TO THE INFORMATION CONTAINED HEREIN, AND DOES NOT ACCEPT
ANY LIABILITY FOR ANY INJURY, LOSS OR DAMAGE OF ANY KIND INCURRED BY USE OF OR
RELIANCE UPON THE INFORMATION. ALL INFORMATION SUPPLIED HEREIN IS SUBJECT TO
CHANGE WITHOUT PRIOR NOTICE.
COPYRIGHT
THE INFORMATION CONTAINED HERE IS PROPRIETARY TECHNICAL INFORMATION OF
QUECTEL WIRELESS SOLUTIONS CO., LTD. TRANSMITTING, REPRODUCTION, DISSEMINATION
AND EDITING OF THIS DOCUMENT AS WELL AS UTILIZATION OF THE CONTENT ARE
FORBIDDEN WITHOUT PERMISSION. OFFENDERS WILL BE HELD LIABLE FOR PAYMENT OF
DAMAGES. ALL RIGHTS ARE RESERVED IN THE EVENT OF A PATENT GRANT OR
REGISTRATION OF A UTILITY MODEL OR DESIGN.
Copyright © Quectel Wireless Solutions Co., Ltd. 2019. All rights reserved.
BG95&BG77_SSL_Application_Note 1 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
History
Revision Date Author Description
BG95&BG77_SSL_Application_Note 2 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
Contents
1 Introduction .......................................................................................................................................... 6
1.1. SSL Versions and Cipher Suites ................................................................................................. 6
1.2. The Process of Using SSL Function ........................................................................................... 8
1.3. Description of Data Access Modes ............................................................................................. 8
1.4. Certificate Validity Check ............................................................................................................ 9
3 Examples ............................................................................................................................................ 23
3.1. Configure and Activate a PDP Context ..................................................................................... 23
3.1.1. Configure a PDP Context ............................................................................................... 23
3.1.2. Activate a PDP Context.................................................................................................. 23
3.1.3. Deactivate a PDP Context ............................................................................................. 23
3.2. Configure an SSL Context ........................................................................................................ 23
3.3. SSL Client Works in Buffer Access Mode ................................................................................. 24
3.3.1. Set up an SSL Connection and Enter Buffer Access Mode........................................... 24
3.3.2. Send Data in Buffer Access Mode ................................................................................. 24
3.3.3. Retrieve Data in Buffer Access Mode ............................................................................ 24
3.3.4. Close an SSL Connection .............................................................................................. 25
3.4. SSL Client Works in Direct Push Mode .................................................................................... 25
3.4.1. Set up an SSL Connection and Enter Direct Push Mode .............................................. 25
3.4.2. Send Data in Direct Push Mode..................................................................................... 25
3.4.3. Retrieve Data in Direct Push Mode................................................................................ 26
3.4.4. Close an SSL Connection .............................................................................................. 26
3.5. SSL Client Works in Transparent Access Mode ....................................................................... 26
3.5.1. Set up an SSL Connection and Send Data in Transparent Access Mode..................... 26
3.5.2. Set up an SSL Connection and Retrieve Data in Transparent Access Mode ............... 26
3.5.3. Close an SSL Connection .............................................................................................. 26
BG95&BG77_SSL_Application_Note 3 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
6 Appendix A References..................................................................................................................... 30
BG95&BG77_SSL_Application_Note 4 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
Table Index
BG95&BG77_SSL_Application_Note 5 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
1 Introduction
This document describes how to use the SSL functionality of Quectel BG95 and BG77 modules. In some
cases, in order to ensure communication privacy, the communication between the server and the client
should be in an encrypted way to prevent data from eavesdropping, tampering or forging during the
communication process. The SSL function meets these demands.
The following are SSL versions supported by BG95 and BG77 modules.
SSL Version
SSL3.0
TLS1.0
TLS1.1
TLS1.2
The following table shows SSL cipher suites supported by BG95 and BG77 modules. For detailed
description of cipher suites, please refer to RFC 2246-The TLS Protocol Version 1.0.
0X0035 TLS_RSA_WITH_AES_256_CBC_SHA
0X002F TLS_RSA_WITH_AES_128_CBC_SHA
0X0005 TLS_RSA_WITH_RC4_128_SHA
BG95&BG77_SSL_Application_Note 6 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
0X0004 TLS_RSA_WITH_RC4_128_MD5
0X000A TLS_RSA_WITH_3DES_EDE_CBC_SHA
0X003D TLS_RSA_WITH_AES_256_CBC_SHA256
0XC002 TLS_ECDH_ECDSA_WITH_RC4_128_SHA
0XC003 TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA
0XC004 TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
0XC005 TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
0XC007 TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
0XC008 TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA
0XC009 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
0XC00A TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
0XC011 TLS_ECDHE_RSA_WITH_RC4_128_SHA
0XC012 TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
0XC013 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
0XC014 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
0XC00C TLS_ECDH_RSA_WITH_RC4_128_SHA
0XC00D TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
0XC00E TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
0XC00F TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
0XC023 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
0XC024 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
0XC025 TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
0XC026 TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
0XC027 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
BG95&BG77_SSL_Application_Note 7 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
0XC028 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
0XC029 TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
0XC02A TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
0XC02F TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
Step 1: Configure <APN>, <username>, <password> and other parameters of a PDP context by
AT+QICSGP command. Please refer to document [3] for details of the command.
Step 2: Activate the PDP context by AT+QIACT command, then the assigned IP address can be queried
by AT+QIACT? command. Please refer to document [3] for details of the command.
Step 3: Configure the SSL version, cipher suite, path of trusted CA certificate and the security level for a
specified SSL context by AT+QSSLCFG command.
Step 4: Open SSL client connection by AT+QSSLOPEN command. <sslctxID> is used to specify the
SSL context, and <access_mode> is used to specify the data access mode.
Step 5: After the SSL connection has been established, data will be sent or received via the connection.
For details about how to send and receive data under different data access modes, please refer
to Chapter 1.3.
The SSL connection supports the following three kinds of data access modes:
BG95&BG77_SSL_Application_Note 8 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
When opening an SSL connection via AT+QSSLOPEN command, the data access mode can be
specified by the parameter <access_mode>. After the SSL connection has been established,
AT+QISWTMD command can be used to switch the data access mode.
1. In buffer access mode, data are sent via AT+QSSLSEND command, and if the module has received
data from the Internet, it will report a URC as +QSSLURC: "recv",<clientID>. In such a case, the
data can be retrieved via AT+QSSLRECV command.
2. In direct push mode, data are sent via AT+QSSLSEND command, and if the module has received
data from the Internet, the data will be outputted directly via UART1/USB modem/USB AT port in the
following format: +QSSLURC: "recv",<clientID>,<currentrecvlength><CR><LF><data>.
3. In transparent access mode, the corresponding port enters exclusive mode. The data received from
COM port will be sent to the Internet directly, and the received data from the Internet will be outputted
to COM port directly. +++ or DTR (AT&D1 should be set first) can be used to switch the data access
mode to buffer access mode. In transparent access mode, if any abnormal SSL disconnection
happens, the module will report NO CARRIER.
4. To exit from transparent access mode, +++ or DTR (AT&D1 should be set first) can be used. To
prevent the +++ from being misinterpreted as data, the following sequence should be followed:
1) Do not input any character within 1s (at least or longer) before inputting +++.
2) Input +++ within 1s, and no other characters can be inputted during the time.
3) Do not input any character within 1s after +++ has been inputted.
4) Use +++ or DTR (AT&D1 should be set first) to make the module exit from transparent access
mode, and wait until OK is returned.
To check whether a certificate is in the validity period, the certificate must be parsed. Compare the local
time with the "Not before" and "Not after" of the certificate. If the local time is earlier than the time of "Not
before" or later than the time of "Not after", the certificate will be considered expired.
BG95&BG77_SSL_Application_Note 9 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
BG95&BG77_SSL_Application_Note 10 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
The command can be used to configure the SSL version, cipher suites, security level, CA certificate, client
certificate and client key. These parameters will be used in the handshake procedure.
<sslctxID> is the index of the SSL context. The module supports 6 SSL contexts at most. On the basis of
one SSL context, several SSL connections can be established. The settings such as the SSL version and
the cipher suite are stored in the SSL context, and they will be applied to the new SSL connections
associated with the SSL context.
BG95&BG77_SSL_Application_Note 11 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
BG95&BG77_SSL_Application_Note 12 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
Or
ERROR
Write Command Response
Configure the path of client private key for a If <clientkeypath> is omitted, query the path of client private
specified SSL context: key for the specified SSL context:
AT+QSSLCFG="clientkey",<sslctxID>[,< +QSSLCFG: "clientkey",<sslctxID>,<clientkeypath>
clientkeypath>]
OK
OK
BG95&BG77_SSL_Application_Note 13 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
OK
BG95&BG77_SSL_Application_Note 14 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
ERROR
Write Command Response
Enable/disable DTLS feature for a specified If <dtls_enable> is omitted, query the DTLS feature for the
SSL context: specified SSL context:
AT+QSSLCFG="dtls",<sslctxID>[,<dtls_e +QSSLCFG: "dtls",<sslctxID>,<dtls_enable>
nable>]
OK
Parameter
BG95&BG77_SSL_Application_Note 15 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
0XC003 TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA
0XC004 TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
0XC005 TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
0XC007 TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
0XC008 TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA
0XC009 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
0XC00A TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
0XC011 TLS_ECDHE_RSA_WITH_RC4_128_SHA
0XC012 TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
0XC013 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
0XC014 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
0XC00C TLS_ECDH_RSA_WITH_RC4_128_SHA
0XC00D TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
0XC00E TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
0XC00F TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
0XC023 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
0XC024 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
0XC025 TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
0XC026 TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
0XC027 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
0XC028 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
0XC029 TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
0XC02A TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
0XC02F TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
0XFFFF Support all
<ignore_localtime> Numeric format. How to deal with certificate validity check.
0 Does not ignore validity check for certificate
1 Ignore validity check for certificate
<cacertpath> String format. The path of the trusted CA certificate.
<clientcertpath> String format. The path of the client certificate.
<clientkeypath> String format. The path of the client private key.
<seclevel> Numeric format. The authentication mode.
0 No authentication
1 Manage server authentication
2 Manage server and client authentication if requested by the remote
server
<session> Numeric format. Whether to enable SSL Resumption feature.
0 Disable SSL Resumption
1 Enable SSL Resumption
<sni> Numeric format. Whether to enable Server Name Indication feature, currently, the
only server names supported are DNS hostnames.
0 Disable Server Name Indication
1 Enable Server Name Indication
<checkhost> Numeric format. Whether to enable hostname validation feature (Subject
BG95&BG77_SSL_Application_Note 16 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
The command is used to set up an SSL connection. During the negotiation between the module and the
Internet, parameters configured by AT+QSSLCFG command will be used in the handshake procedure.
After shaking hands with the Internet successfully, the module can send or receive data via this SSL
connection. Also the module can set up several SSL connections based on one SSL context.
It is suggested to wait for a specific period of time (refer to the Maximum Response Time below) for
+QSSLOPEN: <connectID>,<err> URC to be outputted. If the URC response cannot be received during
the time, AT+QSSLCLOSE command can be used to close the SSL connection.
OK
Write Command Response
AT+QSSLOPEN=<pdpctxID>,<sslctxI If the <access_mode> is transparent access mode and the
D>,<clientID>,<serveraddr>,<server_ SSL connection is successfully set up:
port>[,<access_mode>] CONNECT
If the <access_mode> is buffer access mode or direct push
mode:
OK
+QSSLOPEN: <clientID>,<err>
BG95&BG77_SSL_Application_Note 17 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
Parameter
After the connection is established, the module can send data through the SSL connection.
OK
Write Command Response
Send variable-length data >
AT+QSSLSEND=<clientID> After the above response, input the data to be sent. Tap
CTRL+Z to send, and tap ESC to cancel the operation.
If the connection has been established and sending is
successful:
SEND OK
BG95&BG77_SSL_Application_Note 18 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
Parameter
When an SSL connection is opened with <access_mode> specified as 0 (buffer access mode), the
module will report URC +QSSLURC: "recv",<clientID> when it receives data from the Internet. The
received data can be read from buffer with AT+QSSLRECV command.
OK
Write Command Response
AT+QSSLRECV=<clientID>[,<readlen If the specified connection has received data:
>] +QSSLRECV: <havereadlen><CR><LF><data>
OK
BG95&BG77_SSL_Application_Note 19 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
+QSSLRECV: 0
OK
Parameter
The command is used to close an SSL connection. If all the SSL connections based on the same SSL
context are closed, the module will release the SSL context.
OK
Write Command Response
AT+QSSLCLOSE=<clientID>[,<close_ If the SSL connection is successfully closed:
timeout>] OK
Parameter
BG95&BG77_SSL_Application_Note 20 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
OK
Execution Command Response
AT+QSSLSTATE List of
(+QSSLSTATE: <clientID>,"SSLClient",<IP_address>,<re
mote_port>,<local_port>,<socket_state>,<pdpctxID>,<ser
verID>,<access_mode>,<AT_port>,<sslctxID>)s
OK
Parameter
BG95&BG77_SSL_Application_Note 21 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
+QSSLURC: "recv" URC is used to indicate incoming data in buffer access mode and direct push mode.
Parameter
+QSSLURC: "closed" URC is used to indicate that the SSL connection has been disconnected. Lots of
reasons can cause this phenomenon, such as the Internet closes the connection or the state of GPRS
PDP is deactivated. The SSL connection state based on the specified socket will be "closing". In such
case, AT+QSSLCLOSE=<connectID> must be executed to change the SSL connection state to "initial".
+QSSLURC: "closed",<clientID> The SSL connection based on the specified socket is closed.
Parameter
BG95&BG77_SSL_Application_Note 22 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
3 Examples
OK
AT+QSSLCFG="sslversion",1,1
OK
AT+QSSLCFG="ciphersuite",1,0X0035
OK
AT+QSSLCFG="seclevel",1,1
BG95&BG77_SSL_Application_Note 23 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
OK
AT+QSSLCFG="cacert",1,"cacert.pem"
OK
AT+QSSLOPEN=1,1,4,"220.180.239.212",8010,0
OK
OK
AT+QSSLRECV=4,1500 //Retrieve the data. The length of data to be retrieved is 1500 bytes.
+QSSLRECV: 18 //The retrieved data length is 18 bytes.
Test data from SSL
OK
BG95&BG77_SSL_Application_Note 24 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
AT+QSSLRECV=4,1500
+QSSLRECV: 0 //No data in the buffer.
OK
AT+QSSLOPEN= 1,1,4,"220.180.239.212",8011,1
OK
OK
BG95&BG77_SSL_Application_Note 25 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
+QSSLURC: "recv",4,18
Test data from SSL
3.5.1. Set up an SSL Connection and Send Data in Transparent Access Mode
3.5.2. Set up an SSL Connection and Retrieve Data in Transparent Access Mode
BG95&BG77_SSL_Application_Note 26 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
4 Error Handling
1. Query the status of the specified PDP context by AT+QIACT? command to check whether the
specified PDP context has been activated.
2. If the address of server is a domain name, please check whether the address of DNS server is valid
by AT+QIDNSCFG=<contextID>. Because an invalid DNS server address cannot convert domain
name to IP address.
3. Please check the SSL configuration by AT+QSSLCFG command, especially the SSL version and
cipher suite, so as to make sure they are supported on server side. If <seclevel> has been configured
as 1 or 2, then the trusted CA certificate must be uploaded to the module by AT+QFUPL command. If
the server has configured "SSLVerifyClient required", then the client certificate and client private key
must be uploaded to the module by AT+QFUPL command. For details about certificate validity check,
please refer to Chapter 1.4. And for more details about related FILE AT commands, please refer to
document [4].
BG95&BG77_SSL_Application_Note 27 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
<err> Meaning
0 Operation successful
BG95&BG77_SSL_Application_Note 28 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
BG95&BG77_SSL_Application_Note 29 / 30
LPWA Module Series
BG95&BG77 SSL Application Note
6 Appendix A References
Abbreviation Description
BG95&BG77_SSL_Application_Note 30 / 30