new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / headers / sec.h
1 /* Copyright (C) 2009 Trend Micro Inc.
2  * All right reserved.
3  *
4  * This program is a free software; you can redistribute it
5  * and/or modify it under the terms of the GNU General Public
6  * License (version 2) as published by the FSF - Free Software
7  * Foundation
8  */
9
10 #ifndef __SEC_H
11 #define __SEC_H
12
13 #include <time.h>
14
15 /* Unique key for each agent */
16 typedef struct _keyentry {
17     time_t rcvd;
18     unsigned int local;
19     unsigned int keyid;
20     unsigned int global;
21
22     char *id;
23     char *key;
24     char *name;
25
26     os_ip *ip;
27     struct sockaddr_storage peer_info;
28     FILE *fp;
29 } keyentry;
30
31 /* Key storage */
32 typedef struct _keystore {
33     /* Array with all the keys */
34     keyentry **keyentries;
35
36     /* Hashes, based on the ID/IP to look up the keys */
37     OSHash *keyhash_id;
38     OSHash *keyhash_ip;
39
40     /* Total key size */
41     unsigned int keysize;
42
43     /* Key file stat */
44     time_t file_change;
45 } keystore;
46
47 /** Function prototypes -- key management **/
48
49 /* Check if the authentication keys are present */
50 int OS_CheckKeys(void);
51
52 void OS_PassEmptyKeyfile(void);
53
54 /* Read the keys */
55 void OS_ReadKeys(keystore *keys) __attribute((nonnull));
56
57 /* Free the auth keys */
58 void OS_FreeKeys(keystore *keys) __attribute((nonnull));
59
60 /* Check if key changed */
61 int OS_CheckUpdateKeys(const keystore *keys) __attribute((nonnull));
62
63 /* Update the keys if they changed on the system */
64 int OS_UpdateKeys(keystore *keys) __attribute((nonnull));
65
66 /* Start counter for all agents */
67 void OS_StartCounter(keystore *keys) __attribute((nonnull));
68
69 /* Remove counter for id */
70 void OS_RemoveCounter(const char *id) __attribute((nonnull));
71
72 /* Configure to pass if keys file is empty */
73 void OS_PassEmptyKeyfile();
74
75 /** Function prototypes -- agent authorization **/
76
77 /* Check if the IP is allowed */
78 int OS_IsAllowedIP(keystore *keys, const char *srcip) __attribute((nonnull(1)));
79
80 /* Check if the ID is allowed */
81 int OS_IsAllowedID(keystore *keys, const char *id) __attribute((nonnull(1)));
82
83 /* Check if the name is valid */
84 int OS_IsAllowedName(const keystore *keys, const char *name) __attribute((nonnull));
85
86 /* Check if the id is valid and dynamic */
87 int OS_IsAllowedDynamicID(keystore *keys, const char *id, const char *srcip) __attribute((nonnull(1)));
88
89
90 /** Function prototypes -- send/recv messages **/
91
92 /* Decrypt and decompress a remote message */
93 char *ReadSecMSG(keystore *keys, char *buffer, char *cleartext,
94                  int id, unsigned int buffer_size) __attribute((nonnull));
95
96 /* Create an OSSEC message (encrypt and compress) */
97 size_t CreateSecMSG(const keystore *keys, const char *msg, char *msg_encrypted, unsigned int id) __attribute((nonnull));
98
99
100 /** Remote IDs directories and internal definitions */
101 #ifndef WIN32
102 #define RIDS_DIR        "/queue/rids"
103 #else
104 #define RIDS_DIR        "rids"
105 #endif
106
107 #define SENDER_COUNTER  "sender_counter"
108 #define KEYSIZE         128
109
110 #endif /* __SEC_H */
111