S2OPC OPCUA Toolkit
Loading...
Searching...
No Matches
sopc_secure_channels_internal_ctx.h
Go to the documentation of this file.
1/*
2 * Licensed to Systerel under one or more contributor license
3 * agreements. See the NOTICE file distributed with this work
4 * for additional information regarding copyright ownership.
5 * Systerel licenses this file to you under the Apache
6 * License, Version 2.0 (the "License"); you may not use this
7 * file except in compliance with the License. You may obtain
8 * a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#ifndef SOPC_SECURE_CHANNELS_INTERNAL_CTX_H_
21#define SOPC_SECURE_CHANNELS_INTERNAL_CTX_H_
22
23#include <stdbool.h>
24#include <stdint.h>
25
26#include "sopc_builtintypes.h"
27#include "sopc_crypto_decl.h"
28#include "sopc_event_handler.h"
29#include "sopc_key_sets.h"
30#include "sopc_secret_buffer.h"
32#include "sopc_time_reference.h"
34#include "sopc_types.h"
35
36typedef enum
37{
41 SECURE_LISTENER_STATE_INACTIVE /*<< This state is used when only reverse connections are managed but no listener is
42 active. Listener is still used to keep SC associated to this EP. */
44
59
74
78typedef struct
79{
80 bool timeoutExpired; // set to true if the response shall now be ignored
82 uint32_t requestHandle;
84 uint32_t timerId;
86
97
98// Chunk manager context
100{
101 SOPC_Buffer* currentChunkInputBuffer; // The current chunk bytes accumulation
106 bool hasCurrentMsgRequestId; // Set to true if currentRequetId is set (set when first chunk received)
107 uint32_t currentMsgRequestId; // The valid requestId of the current message in reception
108 // (shall be the same for all chunks)
109 SOPC_Buffer* currentMessageInputBuffer; // The message (from one or several chunks) received:
110 // only set when message is complete
112
113// Set on HEL/ACK exchange (see OPC UA specification Part 6 table 36/37)
115{
117 uint32_t receiveBufferSize; // Maximum size of connection for reception (static by configuration)
118 uint32_t sendBufferSize; // Maximum size of connection for sending (dynamic on HEL/ACK exchange)
119 uint32_t
120 receiveMaxMessageSize; // Max size of received OPC UA message BODY (see also part 4 §5.3 last § for more detail)
121 uint32_t sendMaxMessageSize; // Max size of OPC UA message BODY that could be used to send a message
122 uint32_t receiveMaxChunkCount; // Maximum number of chunks accepted for a message received
123 uint32_t sendMaxChunkCount; // Maximum number of chunks that could be used to send a message
125
126// Set on OPN request reception (see OPC UA specification Part 6 table 27): necessary to check coherence with body OPN
127// message content
129{
130 const char* securityPolicyUri;
131 uint16_t validSecurityModes; // accepted security mode for the valid security policy requested
132 bool isSecureModeActive; // a secure mode is active (sign or signAndEncrypt) choice based on certificates presence
133 // in OPN
134 SOPC_CertificateList* clientCertificate; /* temporary record of the client certificate */
136
137// See Part 6 table 29
139{
140 uint32_t lastSNsent; // Last sequence number sent on connection
141 uint32_t lastSNreceived; // Last sequence number received on connection
142 SOPC_SLinkedList* sentRequestIds; // Request ids sent for which a response can be received
144
146{
147 uint32_t secureChannelId; // TODO: move secure channel Id outside (it shall not be changed with the token)
148 uint32_t tokenId;
149 SOPC_DateTime createdAt; // OpcUa date format
150 SOPC_TimeReference lifetimeEndTimeRef; // target time reference (monotonic)
153
155{
156 /* Set and accessed only by Chunks manager */
158 /* Set by Chunks manager */
163
164 // (Client side specific)
165 uint32_t clientSecureChannelId; // Temporary recorded information from the OPN response TCP message
166 // (Client side specific)
167 uint32_t clientNextReqId; // client last request Id used
168 // (Server side specific)
170 serverAsymmSecuInfo; // Temporary recorded information form the OPN request asymmetric security header
171
172 /* Set by SC connection state manager */
175 // SC reverse connection info
176 bool isReverseConnection; // use ReverseHello mechanism for this connection
177 uint16_t serverReverseConnIdx; // reverse connection index in endpoint configuration
178 // (set only on server side if isReverseConnection is true)
179 uint32_t clientReverseEpConfigIdx; // reverse endpoint configuration index
180 // (set only on client side if isReverseConnection is true)
181
182 uint32_t socketIndex; // associated TCP socket index (defined when state != TCP_INIT or SC_CLOSED)
183
184 // SC connection timeout management
186
187 // Message body content dependent properties
189 SOPC_CryptoProvider* cryptoProvider; // defined once security policy id define (OPN req)
194 // (Server side specific)
195 SOPC_SecretBuffer* clientNonce; // client nonce used to create symmetric key
196
197 // (Client side specific)
199
200 // (Server side specific)
201 // flag indicating if the new (current) security token shall be used to send MSG otherwise use precedent until
202 // new one activated by client (reception of MSG with new token)
204
205 /* Server or Client side connection */
207 // (Server side specific)
208 uint32_t serverEndpointConfigIdx; // (reverse) endpoint description configuration association
209
214
216{
218 bool reverseEnpoint; // true if it is a client reverse endpoint
220 uint32_t socketIndex; // associated TCP socket index (in OPENED state only)
221 // Management of the active connections on the listener
222 uint32_t connectionIdxArray[SOPC_MAX_SOCKETS_CONNECTIONS]; // index of connected connections on the listener
225 // Management of retry timeouts for reverse connection to clients
228
231
234extern uint32_t lastSecureConnectionArrayIdx; // last secure connection index used for a new secure connection
235
241
244
247
249
252
253typedef void SC_ApplyToConnection(SOPC_SecureConnection* conn, uint32_t connIdx, uintptr_t param, uintptr_t auxParam);
254
255void SC_ApplyToAllSCs(SC_ApplyToConnection* applyToConnection, uintptr_t param, uintptr_t auxParam);
256
262 SOPC_Buffer* intermediateChunk);
266
269
272
274 int32_t event,
275 uint32_t id,
276 uintptr_t params,
277 uintptr_t auxParam);
279 int32_t event,
280 uint32_t id,
281 uintptr_t params,
282 uintptr_t auxParam);
284 int32_t event,
285 uint32_t id,
286 uintptr_t params,
287 uintptr_t auxParam);
289 int32_t event,
290 uint32_t id,
291 uintptr_t params,
292 uintptr_t auxParam);
293
294#endif /* SOPC_SECURE_CHANNELS_INTERNAL_CTX_H_ */
int64_t SOPC_DateTime
OPC UA timestamp format which is 100 nanoseconds from 1601/01/01 00:00:00 UTC.
Definition sopc_builtintypes.h:160
Defines the common declarations for the cryptographic objects. The structures and macros defined in t...
struct _SOPC_EventHandler SOPC_EventHandler
Processes messages from a queue.
Definition sopc_event_handler.h:35
void SOPC_SetListenerFunc(SOPC_EventHandler *handler)
Function prototype for connecting an event emitter to a listener.
Definition sopc_event_handler.h:59
struct _SOPC_Looper SOPC_Looper
Manages the processing of events on a given thread.
Definition sopc_event_handler.h:43
SecretBuffer (mangled key) and ExposedBuffer (contiguous deciphered buffered) APIs.
struct SOPC_SecretBuffer SOPC_SecretBuffer
Definition sopc_secret_buffer.h:35
void SOPC_SecureChannels_OnTimerEvent(SOPC_EventHandler *handler, int32_t event, uint32_t id, uintptr_t params, uintptr_t auxParam)
void SC_ApplyToAllSCs(SC_ApplyToConnection *applyToConnection, uintptr_t param, uintptr_t auxParam)
void SOPC_SecureChannelsInternalContext_Initialize(SOPC_SetListenerFunc *setSocketsListener)
Initialize the array of secure listeners/connections.
bool SOPC_ScInternalContext_AddIntermediateInputChunk(SOPC_SecureConnection_TcpProperties *tcpProperties, SOPC_SecureConnection_ChunkMgrCtx *chunkCtx, SOPC_Buffer *intermediateChunk)
Add an intermediate chunk received into message chunks.
uint32_t lastSecureConnectionArrayIdx
struct SOPC_SecureConnection_TcpProperties SOPC_SecureConnection_TcpProperties
void SOPC_SecureChannels_OnInputEvent(SOPC_EventHandler *handler, int32_t event, uint32_t id, uintptr_t params, uintptr_t auxParam)
void SOPC_SecureChannels_OnSocketsEvent(SOPC_EventHandler *handler, int32_t event, uint32_t id, uintptr_t params, uintptr_t auxParam)
struct SOPC_SecureConnection_ChunkMgrCtx SOPC_SecureConnection_ChunkMgrCtx
SOPC_EventHandler * secureChannelsInternalEventHandler
uint32_t SOPC_ScInternalContext_GetNbIntermediateInputChunks(SOPC_SecureConnection_ChunkMgrCtx *chunkCtx)
Retrieve the number of intermediate chunks already received.
SOPC_EventHandler * secureChannelsEventHandler
void SOPC_ScInternalContext_ClearIntermediateInputChunks(SOPC_SecureConnection_ChunkMgrCtx *chunkCtx)
Clear the list of intermediate chunks received (should be called directly only in case of abort chunk...
SOPC_EventHandler * secureChannelsTimerEventHandler
SOPC_EventHandler * secureChannelsInputEventHandler
SOPC_SecureListener secureListenersArray[SOPC_MAX_ENDPOINT_DESCRIPTION_CONFIGURATIONS *2+1]
Array containing all listeners that can be used for server endpoints and client reverse endpoints.
SOPC_SecureConnection secureConnectionsArray[SOPC_MAX_SECURE_CONNECTIONS_PLUS_BUFFERED+1]
Array containing all connections that can be used.
void SOPC_SecureChannelsInternalContext_Clear(void)
Clear the array of secure listeners/connections.
struct SOPC_SecureConnection_TcpOpnReqAsymmSecu SOPC_SecureConnection_TcpAsymmSecu
void SOPC_ScInternalContext_ClearInputChunksContext(SOPC_SecureConnection_ChunkMgrCtx *chunkCtx)
Clear the current chunk and intermediate chunks context.
SOPC_Msg_IsFinal
UA Message Chunk IsFinal type.
Definition sopc_secure_channels_internal_ctx.h:91
@ SOPC_MSG_ISFINAL_FINAL
Definition sopc_secure_channels_internal_ctx.h:94
@ SOPC_MSG_ISFINAL_INTERMEDIATE
Definition sopc_secure_channels_internal_ctx.h:93
@ SOPC_MSG_ISFINAL_ABORT
Definition sopc_secure_channels_internal_ctx.h:95
@ SOPC_MSG_ISFINAL_INVALID
Definition sopc_secure_channels_internal_ctx.h:92
struct SOPC_SecureConnection_TcpSequenceProperties SOPC_SecureConnection_TcpSequenceProperties
const SOPC_CertificateList * SC_OwnCertificate(SOPC_SecureConnection *conn)
SOPC_SecureConnection_State
Definition sopc_secure_channels_internal_ctx.h:46
@ SECURE_CONNECTION_STATE_SC_CONNECTED_RENEW
Definition sopc_secure_channels_internal_ctx.h:57
@ SECURE_CONNECTION_STATE_TCP_INIT
Definition sopc_secure_channels_internal_ctx.h:52
@ SECURE_CONNECTION_STATE_SC_CONNECTED
Definition sopc_secure_channels_internal_ctx.h:56
@ SECURE_CONNECTION_STATE_TCP_REVERSE_TOKEN
Definition sopc_secure_channels_internal_ctx.h:49
@ SECURE_CONNECTION_STATE_TCP_REVERSE_INIT
Definition sopc_secure_channels_internal_ctx.h:51
@ SECURE_CONNECTION_STATE_SC_CONNECTING
Definition sopc_secure_channels_internal_ctx.h:55
@ SECURE_CONNECTION_STATE_SC_INIT
Definition sopc_secure_channels_internal_ctx.h:54
@ SECURE_CONNECTION_STATE_TCP_NEGOTIATE
Definition sopc_secure_channels_internal_ctx.h:53
@ SECURE_CONNECTION_STATE_SC_CLOSED
Definition sopc_secure_channels_internal_ctx.h:47
@ SECURE_CONNECTION_STATE_SC_CLOSING
Definition sopc_secure_channels_internal_ctx.h:48
SOPC_SecureListener_State
Definition sopc_secure_channels_internal_ctx.h:37
@ SECURE_LISTENER_STATE_INACTIVE
Definition sopc_secure_channels_internal_ctx.h:41
@ SECURE_LISTENER_STATE_OPENED
Definition sopc_secure_channels_internal_ctx.h:40
@ SECURE_LISTENER_STATE_CLOSED
Definition sopc_secure_channels_internal_ctx.h:38
@ SECURE_LISTENER_STATE_OPENING
Definition sopc_secure_channels_internal_ctx.h:39
SOPC_Msg_Type
TCP UA Message types.
Definition sopc_secure_channels_internal_ctx.h:64
@ SOPC_MSG_TYPE_ERR
Definition sopc_secure_channels_internal_ctx.h:68
@ SOPC_MSG_TYPE_SC_OPN
Definition sopc_secure_channels_internal_ctx.h:70
@ SOPC_MSG_TYPE_INVALID
Definition sopc_secure_channels_internal_ctx.h:65
@ SOPC_MSG_TYPE_SC_CLO
Definition sopc_secure_channels_internal_ctx.h:71
@ SOPC_MSG_TYPE_HEL
Definition sopc_secure_channels_internal_ctx.h:66
@ SOPC_MSG_TYPE_RHE
Definition sopc_secure_channels_internal_ctx.h:69
@ SOPC_MSG_TYPE_SC_MSG
Definition sopc_secure_channels_internal_ctx.h:72
@ SOPC_MSG_TYPE_ACK
Definition sopc_secure_channels_internal_ctx.h:67
void SOPC_ScInternalContext_ClearCurrentInputChunkContext(SOPC_SecureConnection_ChunkMgrCtx *chunkCtx)
Clear the current chunk context but not the intermediate chunks context.
void SC_ApplyToConnection(SOPC_SecureConnection *conn, uint32_t connIdx, uintptr_t param, uintptr_t auxParam)
Definition sopc_secure_channels_internal_ctx.h:253
SOPC_SecureConnection * SC_GetConnection(uint32_t connectionIdx)
void SOPC_SecureChannels_OnInternalEvent(SOPC_EventHandler *handler, int32_t event, uint32_t id, uintptr_t params, uintptr_t auxParam)
struct SOPC_SecureListener SOPC_SecureListener
SOPC_Looper * secureChannelsLooper
struct SOPC_SecureConnection SOPC_SecureConnection
const SOPC_CertificateList * SC_PeerCertificate(SOPC_SecureConnection *conn)
struct SOPC_SecureConnection_SecurityToken SOPC_SecureConnection_SecurityToken
A singly linked list based on elements with unique identifiers and dynamically allocated.
struct SOPC_SLinkedList SOPC_SLinkedList
Singly linked list structure.
Definition sopc_singly_linked_list.h:36
A platform independent API to handle time reference management.
uint64_t SOPC_TimeReference
Definition sopc_time_reference.h:52
Contains the configuration constants used by the Tookit. Those constants could be modified for specif...
#define SOPC_MAX_SECURE_CONNECTIONS_PLUS_BUFFERED
SOPC_MAX_SECURE_CONNECTIONS defines the simultaneous stable SC, More slots are used (+25%) to check i...
Definition sopc_toolkit_config_constants.h:85
#define SOPC_MAX_REVERSE_CLIENT_CONNECTIONS
Maximum number of configured reverse connection from a server endpoint to clients.
Definition sopc_toolkit_config_constants.h:113
#define SOPC_MAX_ENDPOINT_DESCRIPTION_CONFIGURATIONS
Maximum number of classic endpoint descriptions configured (same as number of connection listeners)....
Definition sopc_toolkit_config_constants.h:68
#define SOPC_MAX_SOCKETS_CONNECTIONS
Maximum number of TCP sockets connections on a socket listener.
Definition sopc_toolkit_config_constants.h:54
The asymmetric key representation.
Definition key_manager_cyclone.h:42
Bytes buffer structure.
Definition sopc_buffer.h:38
The signed public key representation.
Definition key_manager_cyclone.h:60
The SOPC_CryptoProvider context.
Definition sopc_crypto_provider.h:43
Definition sopc_key_sets.h:33
Definition sopc_secure_channels_internal_ctx.h:100
uint32_t currentMsgSize
Definition sopc_secure_channels_internal_ctx.h:102
bool hasCurrentMsgRequestId
Definition sopc_secure_channels_internal_ctx.h:106
SOPC_Msg_Type currentMsgType
Definition sopc_secure_channels_internal_ctx.h:103
SOPC_Buffer * currentChunkInputBuffer
Definition sopc_secure_channels_internal_ctx.h:101
SOPC_Buffer * currentMessageInputBuffer
Definition sopc_secure_channels_internal_ctx.h:109
uint32_t currentMsgRequestId
Definition sopc_secure_channels_internal_ctx.h:107
SOPC_Msg_IsFinal currentMsgIsFinal
Definition sopc_secure_channels_internal_ctx.h:104
SOPC_SLinkedList * intermediateChunksInputBuffers
Definition sopc_secure_channels_internal_ctx.h:105
Definition sopc_secure_channels_internal_ctx.h:146
uint32_t tokenId
Definition sopc_secure_channels_internal_ctx.h:148
uint32_t revisedLifetime
Definition sopc_secure_channels_internal_ctx.h:151
SOPC_TimeReference lifetimeEndTimeRef
Definition sopc_secure_channels_internal_ctx.h:150
SOPC_DateTime createdAt
Definition sopc_secure_channels_internal_ctx.h:149
uint32_t secureChannelId
Definition sopc_secure_channels_internal_ctx.h:147
Definition sopc_secure_channels_internal_ctx.h:129
const char * securityPolicyUri
Definition sopc_secure_channels_internal_ctx.h:130
uint16_t validSecurityModes
Definition sopc_secure_channels_internal_ctx.h:131
SOPC_CertificateList * clientCertificate
Definition sopc_secure_channels_internal_ctx.h:134
bool isSecureModeActive
Definition sopc_secure_channels_internal_ctx.h:132
Definition sopc_secure_channels_internal_ctx.h:115
uint32_t sendMaxChunkCount
Definition sopc_secure_channels_internal_ctx.h:123
uint32_t protocolVersion
Definition sopc_secure_channels_internal_ctx.h:116
uint32_t receiveMaxChunkCount
Definition sopc_secure_channels_internal_ctx.h:122
uint32_t receiveMaxMessageSize
Definition sopc_secure_channels_internal_ctx.h:120
uint32_t receiveBufferSize
Definition sopc_secure_channels_internal_ctx.h:117
uint32_t sendMaxMessageSize
Definition sopc_secure_channels_internal_ctx.h:121
uint32_t sendBufferSize
Definition sopc_secure_channels_internal_ctx.h:118
Definition sopc_secure_channels_internal_ctx.h:139
SOPC_SLinkedList * sentRequestIds
Definition sopc_secure_channels_internal_ctx.h:142
uint32_t lastSNreceived
Definition sopc_secure_channels_internal_ctx.h:141
uint32_t lastSNsent
Definition sopc_secure_channels_internal_ctx.h:140
Definition sopc_secure_channels_internal_ctx.h:155
uint32_t connectionTimeoutTimerId
Definition sopc_secure_channels_internal_ctx.h:185
SOPC_SecretBuffer * clientNonce
Definition sopc_secure_channels_internal_ctx.h:195
uint32_t symmSecuMaxBodySize
Definition sopc_secure_channels_internal_ctx.h:161
uint16_t serverReverseConnIdx
Definition sopc_secure_channels_internal_ctx.h:177
bool isServerConnection
Definition sopc_secure_channels_internal_ctx.h:206
SOPC_CryptoProvider * cryptoProvider
Definition sopc_secure_channels_internal_ctx.h:189
uint32_t socketIndex
Definition sopc_secure_channels_internal_ctx.h:182
SOPC_CertificateList * serverCertificate
Definition sopc_secure_channels_internal_ctx.h:211
SOPC_CertificateList * clientCertificate
Definition sopc_secure_channels_internal_ctx.h:212
SOPC_SecureConnection_SecurityToken precedentSecurityToken
Definition sopc_secure_channels_internal_ctx.h:190
SOPC_SC_SecurityKeySets precedentSecuKeySets
Definition sopc_secure_channels_internal_ctx.h:191
SOPC_SecureConnection_TcpProperties tcpMsgProperties
Definition sopc_secure_channels_internal_ctx.h:188
uint32_t clientSecureChannelId
Definition sopc_secure_channels_internal_ctx.h:165
SOPC_SecureConnection_TcpAsymmSecu serverAsymmSecuInfo
Definition sopc_secure_channels_internal_ctx.h:170
uint32_t clientReverseEpConfigIdx
Definition sopc_secure_channels_internal_ctx.h:179
uint32_t secuTokenRenewTimerId
Definition sopc_secure_channels_internal_ctx.h:198
SOPC_SecureConnection_State state
Definition sopc_secure_channels_internal_ctx.h:173
SOPC_AsymmetricKey * privateKey
Definition sopc_secure_channels_internal_ctx.h:210
bool hasExtraPaddingSize
Definition sopc_secure_channels_internal_ctx.h:162
SOPC_SecureConnection_SecurityToken currentSecurityToken
Definition sopc_secure_channels_internal_ctx.h:192
SOPC_SecureConnection_ChunkMgrCtx chunksCtx
Definition sopc_secure_channels_internal_ctx.h:157
bool isReverseConnection
Definition sopc_secure_channels_internal_ctx.h:176
bool serverNewSecuTokenActive
Definition sopc_secure_channels_internal_ctx.h:203
uint32_t asymmSecuMaxBodySize
Definition sopc_secure_channels_internal_ctx.h:160
SOPC_SC_SecurityKeySets currentSecuKeySets
Definition sopc_secure_channels_internal_ctx.h:193
uint32_t secureChannelConfigIdx
Definition sopc_secure_channels_internal_ctx.h:174
uint32_t serverEndpointConfigIdx
Definition sopc_secure_channels_internal_ctx.h:208
uint32_t clientNextReqId
Definition sopc_secure_channels_internal_ctx.h:167
SOPC_SecureConnection_TcpSequenceProperties tcpSeqProperties
Definition sopc_secure_channels_internal_ctx.h:159
Definition sopc_secure_channels_internal_ctx.h:216
uint32_t socketIndex
Definition sopc_secure_channels_internal_ctx.h:220
uint32_t reverseConnRetryTimerIds[SOPC_MAX_REVERSE_CLIENT_CONNECTIONS]
Definition sopc_secure_channels_internal_ctx.h:226
uint32_t connectionIdxArray[SOPC_MAX_SOCKETS_CONNECTIONS]
Definition sopc_secure_channels_internal_ctx.h:222
bool isUsedConnectionIdxArray[SOPC_MAX_SOCKETS_CONNECTIONS]
Definition sopc_secure_channels_internal_ctx.h:223
uint32_t lastConnectionIdxArrayIdx
Definition sopc_secure_channels_internal_ctx.h:224
SOPC_SecureListener_State state
Definition sopc_secure_channels_internal_ctx.h:217
uint32_t serverEndpointConfigIdx
Definition sopc_secure_channels_internal_ctx.h:219
bool reverseEnpoint
Definition sopc_secure_channels_internal_ctx.h:218
Structure containing the context of a sent request message at SC layer level.
Definition sopc_secure_channels_internal_ctx.h:79
uint32_t scConnectionIdx
Definition sopc_secure_channels_internal_ctx.h:81
bool timeoutExpired
Definition sopc_secure_channels_internal_ctx.h:80
uint32_t requestHandle
Definition sopc_secure_channels_internal_ctx.h:82
uint32_t timerId
Definition sopc_secure_channels_internal_ctx.h:84
SOPC_Msg_Type msgType
Definition sopc_secure_channels_internal_ctx.h:83