mikroSDK Reference Manual
snmp_agent_usm.h
Go to the documentation of this file.
1
31#ifndef _SNMP_AGENT_USM_H
32#define _SNMP_AGENT_USM_H
33
34//Dependencies
35#include "core/net.h"
36#include "snmp/snmp_agent.h"
37#include "mibs/mib_common.h"
38#include "core/crypto.h"
39
40//Time window for replay protection
41#ifndef SNMP_TIME_WINDOW
42 #define SNMP_TIME_WINDOW 150
43#elif (SNMP_TIME_WINDOW < 1)
44 #error SNMP_TIME_WINDOW parameter is not valid
45#endif
46
47//MD5 authentication support
48#ifndef SNMP_MD5_SUPPORT
49 #define SNMP_MD5_SUPPORT ENABLED
50#elif (SNMP_MD5_SUPPORT != ENABLED && SNMP_MD5_SUPPORT != DISABLED)
51 #error SNMP_MD5_SUPPORT parameter is not valid
52#endif
53
54//SHA-1 authentication support
55#ifndef SNMP_SHA1_SUPPORT
56 #define SNMP_SHA1_SUPPORT ENABLED
57#elif (SNMP_SHA1_SUPPORT != ENABLED && SNMP_SHA1_SUPPORT != DISABLED)
58 #error SNMP_SHA1_SUPPORT parameter is not valid
59#endif
60
61//SHA-224 authentication support
62#ifndef SNMP_SHA224_SUPPORT
63 #define SNMP_SHA224_SUPPORT DISABLED
64#elif (SNMP_SHA224_SUPPORT != ENABLED && SNMP_SHA224_SUPPORT != DISABLED)
65 #error SNMP_SHA224_SUPPORT parameter is not valid
66#endif
67
68//SHA-256 authentication support
69#ifndef SNMP_SHA256_SUPPORT
70 #define SNMP_SHA256_SUPPORT DISABLED
71#elif (SNMP_SHA256_SUPPORT != ENABLED && SNMP_SHA256_SUPPORT != DISABLED)
72 #error SNMP_SHA256_SUPPORT parameter is not valid
73#endif
74
75//SHA-384 authentication support
76#ifndef SNMP_SHA384_SUPPORT
77 #define SNMP_SHA384_SUPPORT DISABLED
78#elif (SNMP_SHA384_SUPPORT != ENABLED && SNMP_SHA384_SUPPORT != DISABLED)
79 #error SNMP_SHA384_SUPPORT parameter is not valid
80#endif
81
82//SHA-512 authentication support
83#ifndef SNMP_SHA512_SUPPORT
84 #define SNMP_SHA512_SUPPORT DISABLED
85#elif (SNMP_SHA512_SUPPORT != ENABLED && SNMP_SHA512_SUPPORT != DISABLED)
86 #error SNMP_SHA512_SUPPORT parameter is not valid
87#endif
88
89//DES encryption support
90#ifndef SNMP_DES_SUPPORT
91 #define SNMP_DES_SUPPORT ENABLED
92#elif (SNMP_DES_SUPPORT != ENABLED && SNMP_DES_SUPPORT != DISABLED)
93 #error SNMP_DES_SUPPORT parameter is not valid
94#endif
95
96//AES encryption support
97#ifndef SNMP_AES_SUPPORT
98 #define SNMP_AES_SUPPORT ENABLED
99#elif (SNMP_AES_SUPPORT != ENABLED && SNMP_AES_SUPPORT != DISABLED)
100 #error SNMP_AES_SUPPORT parameter is not valid
101#endif
102
103//Support for MD5 authentication?
104#if (SNMP_MD5_SUPPORT == ENABLED)
105 #include "hash/md5.h"
106#endif
107
108//Support for SHA-1 authentication?
109#if (SNMP_SHA1_SUPPORT == ENABLED)
110 #include "hash/sha1.h"
111#endif
112
113//Support for SHA-224 authentication?
114#if (SNMP_SHA224_SUPPORT == ENABLED)
115 #include "hash/sha224.h"
116#endif
117
118//Support for SHA-256 authentication?
119#if (SNMP_SHA256_SUPPORT == ENABLED)
120 #include "hash/sha256.h"
121#endif
122
123//Support for SHA-384 authentication?
124#if (SNMP_SHA384_SUPPORT == ENABLED)
125 #include "hash/sha384.h"
126#endif
127
128//Support for SHA-512 authentication?
129#if (SNMP_SHA512_SUPPORT == ENABLED)
130 #include "hash/sha512.h"
131#endif
132
133//Support for DES encryption?
134#if (SNMP_DES_SUPPORT == ENABLED)
135 #include "cipher/des.h"
136 #include "cipher_modes/cbc.h"
137#endif
138
139//Support for AES encryption ?
140#if (SNMP_AES_SUPPORT == ENABLED)
141 #include "cipher/aes.h"
142 #include "cipher_modes/cfb.h"
143#endif
144
145//Maximum size for authentication and privacy keys
146#if (SNMP_SHA512_SUPPORT == ENABLED)
147 #define SNMP_MAX_KEY_SIZE 64
148#elif (SNMP_SHA384_SUPPORT == ENABLED)
149 #define SNMP_MAX_KEY_SIZE 48
150#elif (SNMP_SHA256_SUPPORT == ENABLED)
151 #define SNMP_MAX_KEY_SIZE 32
152#elif (SNMP_SHA224_SUPPORT == ENABLED)
153 #define SNMP_MAX_KEY_SIZE 28
154#elif (SNMP_SHA1_SUPPORT == ENABLED)
155 #define SNMP_MAX_KEY_SIZE 20
156#else
157 #define SNMP_MAX_KEY_SIZE 16
158#endif
159
160//Maximum size for truncated MACs
161#if (SNMP_SHA512_SUPPORT == ENABLED)
162 #define SNMP_MAX_TRUNCATED_MAC_SIZE 48
163#elif (SNMP_SHA384_SUPPORT == ENABLED)
164 #define SNMP_MAX_TRUNCATED_MAC_SIZE 32
165#elif (SNMP_SHA256_SUPPORT == ENABLED)
166 #define SNMP_MAX_TRUNCATED_MAC_SIZE 24
167#elif (SNMP_SHA224_SUPPORT == ENABLED)
168 #define SNMP_MAX_TRUNCATED_MAC_SIZE 16
169#elif (SNMP_SHA1_SUPPORT == ENABLED)
170 #define SNMP_MAX_TRUNCATED_MAC_SIZE 12
171#else
172 #define SNMP_MAX_TRUNCATED_MAC_SIZE 12
173#endif
174
175//SNMP message encryption overhead
176#if (SNMP_DES_SUPPORT == ENABLED)
177 #define SNMP_MSG_ENCRYPTION_OVERHEAD 8
178#else
179 #define SNMP_MSG_ENCRYPTION_OVERHEAD 0
180#endif
181
182//C++ guard
183#ifdef __cplusplus
184extern "C" {
185#endif
186
187
192typedef enum
193{
194 SNMP_MSG_FLAG_AUTH = 1,
195 SNMP_MSG_FLAG_PRIV = 2,
196 SNMP_MSG_FLAG_REPORTABLE = 4
198
199
212
213
218typedef enum
219{
220 SNMP_SECURITY_LEVEL_NO_AUTH_NO_PRIV = 1,
221 SNMP_SECURITY_LEVEL_AUTH_NO_PRIV = 2,
222 SNMP_SECURITY_LEVEL_AUTH_PRIV = 3
224
225
230typedef enum
231{
232 SNMP_ACCESS_NONE = 0,
233 SNMP_ACCESS_READ_ONLY = 1,
234 SNMP_ACCESS_WRITE_ONLY = 2,
235 SNMP_ACCESS_READ_WRITE = 3
236} SnmpAccess;
237
238
253
254
265
266
278
279
284typedef struct
285{
286 uint8_t b[SNMP_MAX_KEY_SIZE];
287} SnmpKey;
288
289
294typedef struct
295{
297 char_t name[SNMP_MAX_USER_NAME_LEN + 1];
299#if (SNMP_V3_SUPPORT == ENABLED)
306 uint8_t publicValue[SNMP_MAX_PUBLIC_VALUE_SIZE];
308#endif
310
311
312//USM related constants
313extern const uint8_t usmStatsUnsupportedSecLevelsObject[10];
314extern const uint8_t usmStatsNotInTimeWindowsObject[10];
315extern const uint8_t usmStatsUnknownUserNamesObject[10];
316extern const uint8_t usmStatsUnknownEngineIdsObject[10];
317extern const uint8_t usmStatsWrongDigestsObject[10];
318extern const uint8_t usmStatsDecryptionErrorsObject[10];
319
320//USM related functions
321SnmpUserEntry *snmpCreateUserEntry(SnmpAgentContext *context);
322
323SnmpUserEntry *snmpFindUserEntry(SnmpAgentContext *context,
324 const char_t *name, size_t length);
325
326error_t snmpGenerateKey(SnmpAuthProtocol authProtocol, const char_t *password,
327 SnmpKey *key);
328
329error_t snmpLocalizeKey(SnmpAuthProtocol authProtocol, const uint8_t *engineId,
330 size_t engineIdLen, SnmpKey *key, SnmpKey *localizedKey);
331
332void snmpChangeKey(const HashAlgo *hashAlgo, const uint8_t *random,
333 const uint8_t *delta, SnmpKey *key);
334
335void snmpCloneSecurityParameters(SnmpUserEntry *user,
336 const SnmpUserEntry *cloneFromUser);
337
338error_t snmpCheckSecurityParameters(const SnmpUserEntry *user,
339 SnmpMessage *message, const uint8_t *engineId, size_t engineIdLen);
340
341void snmpRefreshEngineTime(SnmpAgentContext *context);
342error_t snmpCheckEngineTime(SnmpAgentContext *context, SnmpMessage *message);
343
344error_t snmpAuthOutgoingMessage(const SnmpUserEntry *user, SnmpMessage *message);
345error_t snmpAuthIncomingMessage(const SnmpUserEntry *user, SnmpMessage *message);
346
347error_t snmpEncryptData(const SnmpUserEntry *user, SnmpMessage *message,
348 uint64_t *salt);
349
350error_t snmpDecryptData(const SnmpUserEntry *user, SnmpMessage *message);
351
352const HashAlgo *snmpGetHashAlgo(SnmpAuthProtocol authProtocol);
353size_t snmpGetMacLength(SnmpAuthProtocol authProtocol);
354
355
356//C++ guard
357#ifdef __cplusplus
358}
359#endif
360
361#endif
error_t
Error codes.
Definition error.h:43
Common definitions for MIB modules.
MibRowStatus
Row status.
Definition mib_common.h:101
TCP/IP stack core.
SNMP agent (Simple Network Management Protocol)
SnmpAuthProtocol
Definition snmp_agent_usm.h:244
@ SNMP_AUTH_PROTOCOL_SHA512
HMAC-SHA-512-384.
Definition snmp_agent_usm.h:251
@ SNMP_AUTH_PROTOCOL_NONE
No authentication.
Definition snmp_agent_usm.h:245
@ SNMP_AUTH_PROTOCOL_SHA224
HMAC-SHA-224-128.
Definition snmp_agent_usm.h:248
@ SNMP_AUTH_PROTOCOL_MD5
HMAC-MD5-96.
Definition snmp_agent_usm.h:246
@ SNMP_AUTH_PROTOCOL_SHA384
HMAC-SHA-384-256.
Definition snmp_agent_usm.h:250
@ SNMP_AUTH_PROTOCOL_SHA1
HMAC-SHA-1-96.
Definition snmp_agent_usm.h:247
@ SNMP_AUTH_PROTOCOL_SHA256
HMAC-SHA-256-192.
Definition snmp_agent_usm.h:249
SnmpKeyFormat
SNMP key format.
Definition snmp_agent_usm.h:272
@ SNMP_KEY_FORMAT_TEXT
ASCII password.
Definition snmp_agent_usm.h:274
@ SNMP_KEY_FORMAT_NONE
Unspecified key format.
Definition snmp_agent_usm.h:273
@ SNMP_KEY_FORMAT_LOCALIZED
Localized key.
Definition snmp_agent_usm.h:276
@ SNMP_KEY_FORMAT_RAW
Raw key.
Definition snmp_agent_usm.h:275
SnmpAccess
Access modes.
Definition snmp_agent_usm.h:231
SnmpSecurityLevel
Security levels.
Definition snmp_agent_usm.h:219
SnmpSecurityModel
Security models.
Definition snmp_agent_usm.h:205
@ SNMP_SECURITY_MODEL_USM
User-based security model.
Definition snmp_agent_usm.h:209
@ SNMP_SECURITY_MODEL_ANY
Any.
Definition snmp_agent_usm.h:206
@ SNMP_SECURITY_MODEL_TSM
Transport security model.
Definition snmp_agent_usm.h:210
@ SNMP_SECURITY_MODEL_V2C
SNMPv2c.
Definition snmp_agent_usm.h:208
@ SNMP_SECURITY_MODEL_V1
SNMPv1.
Definition snmp_agent_usm.h:207
SnmpPrivProtocol
Definition snmp_agent_usm.h:260
@ SNMP_PRIV_PROTOCOL_DES
DES-CBC.
Definition snmp_agent_usm.h:262
@ SNMP_PRIV_PROTOCOL_NONE
No privacy.
Definition snmp_agent_usm.h:261
@ SNMP_PRIV_PROTOCOL_AES
AES-128-CFB.
Definition snmp_agent_usm.h:263
SnmpMessageFlags
Message flags.
Definition snmp_agent_usm.h:193
SNMP secret key.
Definition snmp_agent_usm.h:285
SNMP message.
Definition snmp_agent_message.h:56
User table entry.
Definition snmp_agent_usm.h:295
SnmpKey rawAuthKey
Raw authentication key.
Definition snmp_agent_usm.h:301
SnmpAuthProtocol authProtocol
Authentication protocol.
Definition snmp_agent_usm.h:300
SnmpPrivProtocol privProtocol
Privacy protocol.
Definition snmp_agent_usm.h:303
size_t publicValueLen
Length of the public value.
Definition snmp_agent_usm.h:307
SnmpKey localizedAuthKey
Localized authentication key.
Definition snmp_agent_usm.h:302
SnmpKey rawPrivKey
Raw privacy key.
Definition snmp_agent_usm.h:304
MibRowStatus status
Status of the user.
Definition snmp_agent_usm.h:296
SnmpKey localizedPrivKey
Localized privacy key.
Definition snmp_agent_usm.h:305
SnmpAccess mode
Access mode.
Definition snmp_agent_usm.h:298