From 59822417ef9dd5a638aeee69c8b050e607d7c058 Mon Sep 17 00:00:00 2001
From: Michal Kostenec <kostenec@cesnet.cz>
Date: Wed, 13 May 2015 13:15:50 +0200
Subject: [PATCH] Option 'secret' overwrites client's configuration (hp-dio)

---
 warden3/contrib/connectors/hp-dio/README                | 3 +++
 warden3/contrib/connectors/hp-dio/warden3-dio-sender.py | 7 ++++++-
 warden3/contrib/connectors/hp-dio/warden_client-dio.cfg | 1 +
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/warden3/contrib/connectors/hp-dio/README b/warden3/contrib/connectors/hp-dio/README
index 2921f5c..d3f45a5 100644
--- a/warden3/contrib/connectors/hp-dio/README
+++ b/warden3/contrib/connectors/hp-dio/README
@@ -39,6 +39,9 @@ D. Configuration
    warden_client-dio.cfg
     warden - path to warden-client config, e.g. 'warden/warden_client.cfg'
     name - sensor's source id used as a source of events, e.g. 'cz.cesnet.server.dionaea'
+    secret - secret to authenticate client
+           - if 'secret' is non empty, is used instead of value in client's configuration
+           - useful while using more sensors with single client's configuration
 
     anonymised - no | yes | omit
                - no (default value)
diff --git a/warden3/contrib/connectors/hp-dio/warden3-dio-sender.py b/warden3/contrib/connectors/hp-dio/warden3-dio-sender.py
index 646ac29..32b917c 100644
--- a/warden3/contrib/connectors/hp-dio/warden3-dio-sender.py
+++ b/warden3/contrib/connectors/hp-dio/warden3-dio-sender.py
@@ -31,6 +31,7 @@ DEFAULT_CONTENT_TYPE = 'application/octet-stream'
 DEFAULT_CONTENT_ENCODING = 'base64'
 DEFAULT_ANONYMISED = 'no'
 DEFAULT_TARGET_NET = '0.0.0.0/0'
+DEFAULT_SECRET = ''
 
 
 def gen_attach_idea(logger, report_binaries, binaries_path, filename, hashtype, hashdigest, vtpermalink, avref):
@@ -143,9 +144,13 @@ def main():
   wconfig = read_cfg(aconfig.get('warden', DEFAULT_WCONFIG))
   
   aname = aconfig.get('name', DEFAULT_NAME)
+  wconfig['name'] = aname   
 
+  asecret = aconfig.get('secret', DEFAULT_SECRET)
+  if asecret:
+    wconfig['secret'] = asecret
+  
   wclient = Client(**wconfig)
-  wconfig['name'] = aname   
 
   awin = aconfig.get('awin', DEFAULT_AWIN) * 60
   abinpath = aconfig.get('binaries_path', DEFAULT_BINPATH)
diff --git a/warden3/contrib/connectors/hp-dio/warden_client-dio.cfg b/warden3/contrib/connectors/hp-dio/warden_client-dio.cfg
index 391c9cc..537d96a 100644
--- a/warden3/contrib/connectors/hp-dio/warden_client-dio.cfg
+++ b/warden3/contrib/connectors/hp-dio/warden_client-dio.cfg
@@ -1,6 +1,7 @@
 {
     "warden": "warden_client.cfg",
     "name": "cz.cesnet.server.dionaea",
+    "secret": "",
 
     "anonymised": "no",
     "target_net": "195.113.0.0/16",
-- 
GitLab