Skip to content

Latest commit

 

History

History
405 lines (343 loc) · 16.3 KB

0317-sdl-protocol-security-specification.md

File metadata and controls

405 lines (343 loc) · 16.3 KB

SDL Protocol Security Specification

Introduction

This proposal adds the documentation and specification around protected communication, encryption and handshake to the SDL protocol specification. It is a collaborated effort with Ford and Luxoft to protect the implemented SDL security from unexpected changes and to allow SDL Evolution proposals to improve it.

Motivation

SDL has used protected services since the start of mobile navigation apps. Unfortunately the protocol specification doesn't contain a section around establishing a protected service with handshake and encryption. This leads to contradictory implementations in SDL Core and the app libraries. Recently we have identified a number of bugs in SDL Core and the app libraries which break with protected communication. These issues are difficult to address with the SDLC as there is no specification around protected communication that Core and the app libraries should follow. In order to resolve the issues there must be a proper specification within SDLC around protected communication.

Proposed solution

The solution is to provide a new section into the protocol spec around security and protection. The baseline for this section is reverse engineered from SDL Core and the currently implemented behavior of the security manager but also existing documentation from SDL Core and the app libraries.

Change 1: Update Frame Header Fields description

Because SDL Core already has a defined behavior, Protocol Spec must be changed accordingly to reflect this behavior:

Field Size Description
E 1 bit Encryption Flag
0x0 This packet is not encrypted
0x1 This packet is encrypted
Note: Only available in Protocol Version 2 and higher. Must be always set to zero for a First Frame
Data Size 32 bit ...
Frame Type = 0x02 (First Frame)
0x08 The data size for a first frame is always 8 bytes.
In the payload, the first four bytes denote the Total Size of the data contained in all consecutive frames. This is always the size of whole non-encrypted payload (even if consecutive frames are encrypted).
The second four bytes denote the number of consecutive frames following this one
Frame Type = 0x01 or 0x03 (Single or Consecutive Frame)
The total bytes in this frame's payload. If frame is encrypted this is the size of encrypted payload, otherwise size of non-encrypted payload.
...

Change 2: Add New Section

The following section should be added to the protocol spec:

4.2.5 Start Service

The RPC service always needs to be started as unencrypted first, then it can be moved to an encrypted state by sending another StartService request containing an encryption flag set to 1 at a later point. Services of another type can be started as encrypted initially, i.e. it is not necessary to start them as unencrypted and then move to encrypted state using second StartService request (however such sequence of actions is also valid). See "7. Secured Communication" section for more details.

5.1.1 Security Query

The TLS Payload is sent in a binary query header. The size is 12 bytes which matches the size of the RPC Payload Binary Header.

5.1.1.1 Payload

The security query is able to contain JSON data as well as binary data. During the handshake the TLS handshake data is sent as binary data. In case of an error, a notification is sent with an error code and error message as JSON data. See "Error handling" section for details.

Binary Query Header
JSON Data
Binary Data

5.1.1.2 Binary Header

Byte 1 Byte 2 Byte 3 Byte 4
Query Type Query ID
Sequential Number
JSON Size

5.1.1.2.1 Binary Header Fields

Field Size Description
Query Type 8 bit 0x00 Request
0x01 - 0x0F Reserved
0x10 Response
0x11 - 0x1F Reserved
0x20 Notification
0x21 - 0xFE Reserved
0xFF Invalid Query Type
Query ID 24 bit 0x000001 Send Handshake Data
0x000002 Send Internal Error
0x000003 - 0xFFFFFE Reserved
0xFFFFFF Invalid Query ID
Sequential Number 32 bit Message ID can be set by the Mobile libraries to track security messages. The system uses the same Message ID when replying to the query allowing the mobile to correlate messages.
JSON Size 32 bit The size of the JSON data following the binary query header.

5.1.2 Error Frames

If an error occurs during the TLS handshake, a notification is sent with both JSON data and binary data describing the error. The JSON data contains the error code and an error text. The binary data is one single byte and only contains the error code.

The error code in JSON data and the binary data are the same value from the same code list.

5.1.2.1 Payload

The following query header is used by the system and the application to send error messages.

Binary Query Header
Query Type TLS Message Type Sequential Number JSON Size
Notification Send Internal Error Any number to be used to correlate query messages Size of the JSON data
0x20 0x000002 0xNNNNNNNN 0xNNNNNNNN
JSON Data
Binary Data: Single Byte Error Code

5.1.2.2 JSON structure

Key Description
id A decimal value representing an Error code.
text A string describing the error.

5.1.2.3 Error codes

Error code Byte Value Description
ERROR_SUCCESS 0x000 Internal Security Manager value
ERROR_INVALID_QUERY_SIZE 0x011 Wrong size of query data
ERROR_INVALID_QUERY_ID 0x022 Unknown Query ID
ERROR_NOT_SUPPORTED 0x033 SDL does not support encryption
ERROR_SERVICE_ALREADY_PROTECTED 0x044 Received request to protect a service that was protected before
ERROR_SERVICE_NOT_PROTECTED 0x055 Received handshake or encrypted data for not protected service
ERROR_DECRYPTION_FAILED 0x066 Decryption failed
ERROR_ENCRYPTION_FAILED 0x077 Encryption failed
ERROR_SSL_INVALID_DATA 0x088 SSL invalid data
ERROR_HANDSHAKE_FAILED 0x099 In case of all other handshake errors
INVALID_CERT 0x0A10 Handshake failed because certificate is invalid
EXPIRED_CERT 0x0B11 Handshake failed because certificate is expired
ERROR_INTERNAL 0xFF255 Internal error
ERROR_UNKNOWN_INTERNAL_ERROR 0xFE254 Error value for testing

7. Secured Communication

It is possible to establish a secured and encrypted communication with the system by setting the frame header encryption flag to 1 when starting a new service or by sending another StartService with the encryption flag set to 1 when the service is already established (this the required flow for the RPC service). If the authentication is successful, the system will reply with a StartService ACK frame with the encryption flag also set to 1 indicating that encrypted data is now accepted. If the authentication fails for some reason, the system will reset the TLS connection and return a StartService NAK frame.

Before the encryption of RPC service is enabled (encryption is not available), SDL Core rejects any RPC request with result code ENCRYPTION_NEEDED if the RPC needs protection (please see policy updates for which RPCs need protection). SDL Core continues processing an RPC request if the RPC does not need protection. SDL Core sends a notification only if the notification RPC does not need protection.

After the encryption of RPC service is enabled (encryption is available), SDL Core rejects any unencrypted RPC requests with result code ENCRYPTION_NEEDED with the unencrypted response if the RPC needs protection. SDL Core continues processing an unencrypted RPC request if the RPC does not need protection and responds with an unencrypted response. SDL Core continues processing an encrypted RPC request if the RPC needs protection and responds with an encrypted response. SDL Core sends an unencrypted notification if the RPC does not need protection. SDL Core sends an encrypted notification if the RPC needs protection. In addition, SDL Core shall continue processing an encrypted RPC request if the RPC does not need protection and responds with an encrypted response.

7.1 Authentication

The below diagram shows the sequence of how the TLS handshake exchanges certificates to compute the master secret.

TLS Handshake activity diagram

The authentication is done using TLS handshake. The TLS handshake process is defined by TLS and is not part of the SDL protocol. The handshake is designed as a client server communication which is configurable in the system settings. An application must take the role of a server where the system is the client. The client entity will initiate a TLS handshake with the corresponding security manager of the server. The client will do this only if the server was not authenticated before in the current transport connection. According to the TLS handshake process the peer certificate can be omitted for the server but it's required for the client. Certificate peer verification can be enabled/disabled on the Core side by changing VerifyPeer parameter in the configuration file. On the other hand, the SDL app library does not require the certificate from Core for the TLS handshake. However, Core performs its internal certificate validation before starting the actual TLS handshake. During internal validation, Core checks if the certificate is missing (or outdated/invalid) and if so, it initiates a PTU to obtain a new certificate from the Policy Server. If a valid certificate can't be obtained, Core does not start the TLS handshake and it notifies the app library that the protected service start has failed.

The system can be configured to support one encryption method. The following methods are supported:

  • SSLv3
  • TLSv1
  • TLSv1.1
  • TLSv1.2
  • DTLSv1

The system has to initiate with the corresponding client method. For instance, if the system is configured to use DTLSv1, it has to use the method DTLSv1_client. The application role has to be server and must use DTLSv1_server.

The system also supports configurable SSL Security level introduced in OpenSSL 1.1.0. This parameter can be changed by SecurityLevel parameter in the Core configuration file. By default, system uses security level 1 for TLS handshakes. At this time setting the security level higher than 1 for general internet use is likely to cause considerable interoperability issues and is not recommended. This is because the SHA1 algorithm is very widely used in certificates and will be rejected at levels higher than 1 because it only offers 80 bits of security.

7.2 Handshake Frames

The system will initiate a TLS handshake to authenticate the application where the system's role will be the client while the application's role will be the server. The system will do this only once if the application was not authenticated before in the current transport connection. The TLS handshake data is always sent in single frames. The service type for TLS handshake is the control service.

7.2.1 SDL Protocol Frame Header

The following SDL frame header is used for every frame related to TLS handshake.

SDL Protocol Frame Header
Version E Frame Type Service Type Frame Info Session ID Data Size Message ID
Max major version supported
by module and application
no Single Frame Control Service Single Frame Info Assigned Session ID Query Binary Header +
JSON Data size +
Binary Handshake Data size
Enumerated number
0xN 0b0 0b001 0x00 0x00 0xNN 0xC + 0xNNNNNNNN + 0xNNNNNNNN 0xNNNNNNNN

7.2.2 Security Query Binary Header

The following query header is used by the system and the application to send TLS handshake data.

Binary Query Header
Query Type TLS Message Type Sequential Number JSON Size
Request Send Handshake Data Any number to be used to correlate query messages Zero
0x00 0x000001 0xNNNNNNNN 0x00000000
Binary TLS Handshake Data

7.3 Error handling

In case of an error, the system and the application should reset the active SSL connection of the current transport connection. This impacts already established secured service sessions as all of them will be closed. The application will need to restart all services which require protection.

Potential downsides

Identifying potential downsides is difficult as this proposal adds specifications and documentation to the existing implementation. The downside of accepting this proposal is the effort that's required to review and audit the implementations of every SDL platform.

Impact on existing code

The proposed updates would only require changes in SDL protocol specification. Code of SDL Core, Mobile libraries or any other project wouldn't be impacted.

Alternatives considered

The author couldn't think of other alternatives to add a security specification to SDL. There are security enabled vehicles on the road which limit the abilities to design a new specification. However with the protocol specification version and this security section it is possible to improve the security with a future version.