Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

tls.c File Reference

tls.c File Reference

TLS (Transport Layer Security) More...

Go to the source code of this file.

Functions

TlsContext * tlsInit (void)
 TLS context initialization.
error_t tlsSetIoCallbacks (TlsContext *context, TlsIoHandle handle, TlsIoSendCallback sendCallback, TlsIoReceiveCallback receiveCallback)
 Set send and receive callbacks (I/O abstraction layer)
error_t tlsSetConnectionEnd (TlsContext *context, TlsConnectionEnd entity)
 Set operation mode (client or server)
error_t tlsSetPrng (TlsContext *context, const PrngAlgo *prngAlgo, void *prngContext)
 Set the pseudo-random number generator to be used.
error_t tlsSetServerName (TlsContext *context, const char_t *serverName)
 Set the name of the remote server.
error_t tlsSetCache (TlsContext *context, TlsCache *cache)
 Set session cache.
error_t tlsSetClientAuthMode (TlsContext *context, TlsClientAuthMode mode)
 Set client authentication mode.
error_t tlsSetBufferSize (TlsContext *context, size_t txBufferSize, size_t rxBufferSize)
 Set TLS buffer size.
error_t tlsSetCipherSuites (TlsContext *context, const uint16_t *cipherSuites, uint_t length)
 Specify the list of allowed cipher suites.
error_t tlsSetDhParameters (TlsContext *context, const char_t *params, size_t length)
 Import Diffie-Hellman parameters.
error_t tlsSetAlpnProtocolList (TlsContext *context, const char_t *protocolList)
 Set the list of supported ALPN protocols.
const char_t * tlsGetAlpnProtocol (TlsContext *context)
 Get the name of the negotiated ALPN protocol.
error_t tlsSetPsk (TlsContext *context, const uint8_t *psk, size_t pskLength)
 Set the pre-shared key to be used.
error_t tlsSetPskIdentity (TlsContext *context, const char_t *pskIdentity)
 Set the PSK identity to be used by the client.
error_t tlsSetPskIdentityHint (TlsContext *context, const char_t *pskIdentityHint)
 Set the PSK identity hint to be used by the server.
error_t tlsSetPskCallback (TlsContext *context, TlsPskCallback pskCallback)
 Register the PSK callback function.
error_t tlsSetTrustedCaList (TlsContext *context, const char_t *trustedCaList, size_t length)
 Import a trusted CA list.
error_t tlsAddCertificate (TlsContext *context, const char_t *certChain, size_t certChainLength, const char_t *privateKey, size_t privateKeyLength)
 Import a certificate and the corresponding private key.
error_t tlsConnect (TlsContext *context)
 Initiate the TLS handshake.
error_t tlsWrite (TlsContext *context, const void *data, size_t length, size_t *written, uint_t flags)
 Send application data to the remote host using TLS.
error_t tlsRead (TlsContext *context, void *data, size_t size, size_t *received, uint_t flags)
 Receive application data from a the remote host using TLS.
error_t tlsShutdown (TlsContext *context)
 Gracefully close TLS session.
error_t tlsShutdownEx (TlsContext *context, bool_t waitForCloseNotify)
 Gracefully close TLS session.
void tlsFree (TlsContext *context)
 Release TLS context.
error_t tlsSaveSession (const TlsContext *context, TlsSession *session)
 Save TLS session.
error_t tlsRestoreSession (TlsContext *context, const TlsSession *session)
 Restore TLS session.

Detailed Description

TLS (Transport Layer Security)

License

Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneSSL Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Description

The TLS protocol provides communications security over the Internet. The protocol allows client/server applications to communicate in a way that is designed to prevent eavesdropping, tampering, or message forgery

Author:
Oryx Embedded SARL (www.oryx-embedded.com)
Version:
1.7.6

Definition in file tls.c.


Function Documentation

error_t tlsAddCertificate ( TlsContext *  context,
const char_t *  certChain,
size_t  certChainLength,
const char_t *  privateKey,
size_t  privateKeyLength 
)

Import a certificate and the corresponding private key.

Parameters:
[in]contextPointer to the TLS context
[in]certChainCertificate chain (PEM format)
[in]certChainLengthTotal length of the certificate chain
[in]privateKeyPrivate key (PEM format)
[in]privateKeyLengthTotal length of the private key
Returns:
Error code

Definition at line 674 of file tls.c.

error_t tlsConnect ( TlsContext *  context )

Initiate the TLS handshake.

Parameters:
[in]contextPointer to the TLS context
Returns:
Error code

Definition at line 778 of file tls.c.

void tlsFree ( TlsContext *  context )

Release TLS context.

Parameters:
[in]contextPointer to the TLS context

Definition at line 1230 of file tls.c.

const char_t* tlsGetAlpnProtocol ( TlsContext *  context )

Get the name of the negotiated ALPN protocol.

Parameters:
[in]contextPointer to the TLS context
Returns:
Pointer to the protocol name

Definition at line 450 of file tls.c.

TlsContext* tlsInit ( void   )

TLS context initialization.

Returns:
Handle referencing the fully initialized TLS context

Definition at line 60 of file tls.c.

error_t tlsRead ( TlsContext *  context,
void *  data,
size_t  size,
size_t *  received,
uint_t  flags 
)

Receive application data from a the remote host using TLS.

Parameters:
[in]contextPointer to the TLS context
[out]dataBuffer into which received data will be placed
[in]sizeMaximum number of bytes that can be received
[out]receivedNumber of bytes that have been received
[in]flagsSet of flags that influences the behavior of this function
Returns:
Error code

Definition at line 932 of file tls.c.

error_t tlsRestoreSession ( TlsContext *  context,
const TlsSession session 
)

Restore TLS session.

Parameters:
[in]contextPointer to the TLS context
[in]sessionPointer to the session to be restored
Returns:
Error code

Definition at line 1408 of file tls.c.

error_t tlsSaveSession ( const TlsContext *  context,
TlsSession session 
)

Save TLS session.

Parameters:
[in]contextPointer to the TLS context
[out]sessionBuffer where to store the current session parameters
Returns:
Error code

Definition at line 1372 of file tls.c.

error_t tlsSetAlpnProtocolList ( TlsContext *  context,
const char_t *  protocolList 
)

Set the list of supported ALPN protocols.

Parameters:
[in]contextPointer to the TLS context
[in]protocolListComma-delimited list of supported protocols
Returns:
Error code

Definition at line 402 of file tls.c.

error_t tlsSetBufferSize ( TlsContext *  context,
size_t  txBufferSize,
size_t  rxBufferSize 
)

Set TLS buffer size.

Parameters:
[in]contextPointer to the TLS context
[in]txBufferSizeTX buffer size
[in]rxBufferSizeRX buffer size
Returns:
Error code

Definition at line 310 of file tls.c.

error_t tlsSetCache ( TlsContext *  context,
TlsCache cache 
)

Set session cache.

Parameters:
[in]contextPointer to the TLS context
[in]cacheSession cache that will be used to save/resume TLS sessions
Returns:
Error code

Definition at line 267 of file tls.c.

error_t tlsSetCipherSuites ( TlsContext *  context,
const uint16_t *  cipherSuites,
uint_t  length 
)

Specify the list of allowed cipher suites.

Parameters:
[in]contextPointer to the TLS context
[in]cipherSuitesPointer to the cipher suite list
[in]lengthNumber of cipher suites in the list
Returns:
Error code

Definition at line 347 of file tls.c.

error_t tlsSetClientAuthMode ( TlsContext *  context,
TlsClientAuthMode  mode 
)

Set client authentication mode.

Parameters:
[in]contextPointer to the TLS context
[in]modeClient authentication mode
Returns:
Error code

Definition at line 288 of file tls.c.

error_t tlsSetConnectionEnd ( TlsContext *  context,
TlsConnectionEnd  entity 
)

Set operation mode (client or server)

Parameters:
[in]contextPointer to the TLS context
[in]entitySpecifies whether this entity is considered a client or a server
Returns:
Error code

Definition at line 167 of file tls.c.

error_t tlsSetDhParameters ( TlsContext *  context,
const char_t *  params,
size_t  length 
)

Import Diffie-Hellman parameters.

Parameters:
[in]contextPointer to the TLS context
[in]paramsPEM structure that holds Diffie-Hellman parameters
[in]lengthTotal length of the DER structure
Returns:
Error code

Definition at line 374 of file tls.c.

error_t tlsSetIoCallbacks ( TlsContext *  context,
TlsIoHandle  handle,
TlsIoSendCallback  sendCallback,
TlsIoReceiveCallback  receiveCallback 
)

Set send and receive callbacks (I/O abstraction layer)

Parameters:
[in]contextPointer to the TLS context
[in]handleHandle for I/O operations
[in]sendCallbackSend callback function
[in]receiveCallbackReceive callback function
Returns:
Error code

Definition at line 141 of file tls.c.

error_t tlsSetPrng ( TlsContext *  context,
const PrngAlgo prngAlgo,
void *  prngContext 
)

Set the pseudo-random number generator to be used.

Parameters:
[in]contextPointer to the TLS context
[in]prngAlgoPRNG algorithm
[in]prngContextPointer to the PRNG context
Returns:
Error code

Definition at line 192 of file tls.c.

error_t tlsSetPsk ( TlsContext *  context,
const uint8_t *  psk,
size_t  pskLength 
)

Set the pre-shared key to be used.

Parameters:
[in]contextPointer to the TLS context
[in]pskPointer to the pre-shared key
[in]pskLengthLength of the pre-shared key, in bytes
Returns:
Error code

Definition at line 465 of file tls.c.

error_t tlsSetPskCallback ( TlsContext *  context,
TlsPskCallback  pskCallback 
)

Register the PSK callback function.

Parameters:
[in]contextPointer to the TLS context
[in]pskCallbackPSK callback function
Returns:
Error code

Definition at line 617 of file tls.c.

error_t tlsSetPskIdentity ( TlsContext *  context,
const char_t *  pskIdentity 
)

Set the PSK identity to be used by the client.

Parameters:
[in]contextPointer to the TLS context
[in]pskIdentityNULL-terminated string that contains the PSK identity
Returns:
Error code

Definition at line 517 of file tls.c.

error_t tlsSetPskIdentityHint ( TlsContext *  context,
const char_t *  pskIdentityHint 
)

Set the PSK identity hint to be used by the server.

Parameters:
[in]contextPointer to the TLS context
[in]pskIdentityHintNULL-terminated string that contains the PSK identity hint
Returns:
Error code

Definition at line 567 of file tls.c.

error_t tlsSetServerName ( TlsContext *  context,
const char_t *  serverName 
)

Set the name of the remote server.

Parameters:
[in]contextPointer to the TLS context
[in]serverNameFully qualified domain name of the server
Returns:
Error code

Definition at line 218 of file tls.c.

error_t tlsSetTrustedCaList ( TlsContext *  context,
const char_t *  trustedCaList,
size_t  length 
)

Import a trusted CA list.

Parameters:
[in]contextPointer to the TLS context
[in]trustedCaListList of trusted CA (PEM format)
[in]lengthTotal length of the list
Returns:
Error code

Definition at line 645 of file tls.c.

error_t tlsShutdown ( TlsContext *  context )

Gracefully close TLS session.

Parameters:
[in]contextPointer to the TLS context

Definition at line 1097 of file tls.c.

error_t tlsShutdownEx ( TlsContext *  context,
bool_t  waitForCloseNotify 
)

Gracefully close TLS session.

Parameters:
[in]contextPointer to the TLS context
[in]waitForCloseNotifyWait for the close notify alert from the peer

Definition at line 1110 of file tls.c.

error_t tlsWrite ( TlsContext *  context,
const void *  data,
size_t  length,
size_t *  written,
uint_t  flags 
)

Send application data to the remote host using TLS.

Parameters:
[in]contextPointer to the TLS context
[in]dataPointer to a buffer containing the data to be transmitted
[in]lengthNumber of bytes to be transmitted
[out]writtenActual number of bytes written (optional parameter)
[in]flagsSet of flags that influences the behavior of this function
Returns:
Error code

Definition at line 849 of file tls.c.