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