open62541 1.4.15
Open source implementation of OPC UA
Loading...
Searching...
No Matches
ua_pubsub_keystorage.h
Go to the documentation of this file.
1/** This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 *
5 * Copyright (c) 2019 ifak e.V. Magdeburg (Holger Zipper)
6 * Copyright (c) 2022 Linutronix GmbH (Author: Muddasir Shakil)
7 */
8
9#ifndef UA_PUBSUB_KEYSTORAGE
10#define UA_PUBSUB_KEYSTORAGE
11
15#include <open62541/server.h>
16#include <open62541/client.h>
17
18#include "open62541_queue.h"
19
21
22#ifdef UA_ENABLE_PUBSUB_SKS
23
24
25
26
27typedef struct UA_PubSubKeyListItem {
28 /* The SecurityTokenId associated with Key*/
29 UA_UInt32 keyID;
30
31 /* This key is not used directly since the protocol associated with the PubSubGroup(s)
32 * specifies an algorithm to generate distinct keys for different types of
33 * cryptography operations*/
34 UA_ByteString key;
35
36 /* Pointers to the key list entries*/
37 TAILQ_ENTRY(UA_PubSubKeyListItem) keyListEntry;
38} UA_PubSubKeyListItem;
39
40/** Queue Definition*/
41typedef TAILQ_HEAD(keyListItems, UA_PubSubKeyListItem) keyListItems;
42
43
44typedef struct UA_PubSubSKSConfig {
45 UA_ClientConfig clientConfig;
46 const char *endpointUrl;
47 UA_Server_sksPullRequestCallback userNotifyCallback;
48 void *context;
49 UA_UInt32 reqId;
50} UA_PubSubSKSConfig;
51
52
53typedef struct UA_PubSubKeyStorage {
54
55
56 UA_String securityGroupID;
57
58
59 UA_PubSubSecurityPolicy *policy;
60
61
62 UA_UInt32 referenceCount;
63
64
65 keyListItems keyList;
66
67
68 size_t keyListSize;
69
70
71 UA_UInt32 maxPastKeyCount;
72
73
74 UA_UInt32 maxFutureKeyCount;
75
76 /*
77 * The maximum keylist size, calculated from maxPastKeyCount and maxFutureKeyCount
78 */
79 UA_UInt32 maxKeyListSize;
80
81
82 UA_UInt32 currentTokenId;
83
84
85 UA_PubSubKeyListItem *currentItem;
86
87
88 UA_Duration keyLifeTime;
89
90
91 UA_UInt64 callBackId;
92
93
94 UA_PubSubSKSConfig sksConfig;
95
96
97 LIST_ENTRY(UA_PubSubKeyStorage) keyStorageList;
98
99} UA_PubSubKeyStorage;
100
101
102UA_PubSubKeyStorage *
103UA_PubSubKeyStorage_findKeyStorage(UA_Server *server, UA_String securityGroupId);
104
105
106UA_PubSubSecurityPolicy *
107findPubSubSecurityPolicy(UA_Server *server, const UA_String *securityPolicyUri);
108
109
110void
111UA_PubSubKeyStorage_delete(UA_Server *server, UA_PubSubKeyStorage *keyStorage);
112
113
115UA_PubSubKeyStorage_init(UA_Server *server, UA_PubSubKeyStorage *keyStorage,
116 const UA_String *securityGroupId,
117 UA_PubSubSecurityPolicy *policy,
118 UA_UInt32 maxPastKeyCount, UA_UInt32 maxFutureKeyCount);
119
120
122UA_PubSubKeyStorage_storeSecurityKeys(UA_Server *server, UA_PubSubKeyStorage *keyStorage,
123 UA_UInt32 currentTokenId, const UA_ByteString *currentKey,
124 UA_ByteString *futureKeys, size_t futureKeyCount,
125 UA_Duration msKeyLifeTime);
126
127
129UA_PubSubKeyStorage_getKeyByKeyID(const UA_UInt32 keyId, UA_PubSubKeyStorage *keyStorage,
130 UA_PubSubKeyListItem **keyItem);
131
132
133UA_PubSubKeyListItem *
134UA_PubSubKeyStorage_push(UA_PubSubKeyStorage *keyStorage, const UA_ByteString *key,
135 UA_UInt32 keyID);
136
137
139UA_PubSubKeyStorage_addKeyRolloverCallback(UA_Server *server,
140 UA_PubSubKeyStorage *keyStorage,
141 UA_ServerCallback callback,
142 UA_Duration timeToNextMs,
143 UA_UInt64 *callbackID);
144
145
147UA_PubSubKeyStorage_activateKeyToChannelContext(UA_Server *server, const UA_NodeId pubSubGroupId,
148 const UA_String securityGroupId);
149
150
151void
152UA_PubSubKeyStorage_keyRolloverCallback(UA_Server *server, UA_PubSubKeyStorage *keyStorage);
153
154
156UA_PubSubKeyStorage_update(UA_Server *server, UA_PubSubKeyStorage *keyStorage,
157 const UA_ByteString *currentKey, UA_UInt32 currentKeyID,
158 const size_t futureKeySize, UA_ByteString *futureKeys,
159 UA_Duration msKeyLifeTime);
160
161/** KeyStorage must be referenced by atleast one PubSubGroup. This method reduces
162 * the reference count by one. If no PubSubGroup uses the key storage, then it
163 * is deleted. */
164void
165UA_PubSubKeyStorage_detachKeyStorage(UA_Server *server, UA_PubSubKeyStorage *keyStorage);
166
167/*Calls get SecurityKeys Method and Store the returned keys into KeyStorage*/
169getSecurityKeysAndStoreFetchedKeys(UA_Server *server, UA_PubSubKeyStorage *keyStorage);
170
171#endif
172
174
175#endif /* UA_ENABLE_PUBSUB */
void(* UA_ServerCallback)(UA_Server *server, void *data)
Definition common.h:203
struct UA_Server UA_Server
Definition common.h:198
#define _UA_BEGIN_DECLS
#undef UA_DEBUG_DUMP_PKGS
Definition config.h:100
#define _UA_END_DECLS
Definition config.h:107
#define TAILQ_HEAD(name, type)
#define LIST_ENTRY(type)
#define TAILQ_ENTRY(type)
uint32_t UA_UInt32
Definition types.h:57
uint32_t UA_StatusCode
Definition types.h:82
uint64_t UA_UInt64
Definition types.h:67
UA_Double UA_Duration
Duration.