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