aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/epan/opcua/opcua_keyset.h
blob: 0492427b4c8bbc2b2ca462aac0feaf925d16890e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/******************************************************************************
** Copyright (C) 2006-2023 ascolab GmbH. All Rights Reserved.
** Web: http://www.ascolab.com
**
** SPDX-License-Identifier: GPL-2.0-or-later
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** Project: OpcUa Wireshark Plugin
**
** Description: OpcUa Protocol Decoder.
**
** Author: Gerhard Gappmeier <gerhard.gappmeier@ascolab.com>
******************************************************************************/

#ifndef __OPCUA_KEYSET_H__
#define __OPCUA_KEYSET_H__

#include <stdint.h>

/** symmetric encryption keyset */
struct ua_keyset {
    uint64_t id; /** keyset identifier: combination of securechannel_id and token_id */
    unsigned char client_iv[16]; /**< Client side IV. Always 128 bit. */
    unsigned char server_iv[16]; /**< Server side IV. Always 128 bit. */
    unsigned char client_key[32]; /**< client encryption key */
    unsigned char server_key[32]; /**< server encryption key */
    unsigned int client_key_len; /**< AES key length: 16 (AES-128) or 32 (AES-256) */
    unsigned int server_key_len; /**< AES key length: 16 (AES-128) or 32 (AES-256) */
    unsigned int client_sig_len; /**< Client side symmetric signture length. */
    unsigned int server_sig_len; /**< Server side symmetric signture length. */
};

int ua_keysets_init(void);
int ua_keysets_clear(void);

/**
 * Creates a unique keyset id from securechannel_id and token_id.
 *
 * @param securechannel_id Identifies the secure channel to be able to distinguish
 *   different connections. This is a randomly generated id.
 * @param token_id Identifies the keyset of a channel. This number normally starts with
 *   1 and gets incremented with every secure channel renew.
 *
 * @return 64bit Id.
 */
static inline uint64_t ua_keyset_id(uint32_t securechannel_id, uint32_t token_id)
{
    return ((uint64_t)securechannel_id << 32) | token_id;
}

struct ua_keyset *ua_keysets_add(void);
void ua_keysets_sort(void);
struct ua_keyset *ua_keysets_lookup(uint64_t id);
void ua_keysets_dump(void);

#endif /* __OPCUA_KEYSET_H__ */