summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--custodia.conf1
-rwxr-xr-xcustodia/custodia3
-rw-r--r--custodia/httpd/server.py17
-rw-r--r--custodia/log.py31
-rw-r--r--custodia/message/common.py14
-rw-r--r--custodia/message/kem.py5
-rw-r--r--custodia/store/interface.py10
7 files changed, 63 insertions, 18 deletions
diff --git a/custodia.conf b/custodia.conf
index 1f9dff9..c3c56a5 100644
--- a/custodia.conf
+++ b/custodia.conf
@@ -1,5 +1,6 @@
[global]
server_version = "Secret/0.0.7"
+debug = True
#[auth:simple]
#handler = custodia.httpd.authenticators.SimpleCredsAuth
diff --git a/custodia/custodia b/custodia/custodia
index 0fd621b..0aa7986 100755
--- a/custodia/custodia
+++ b/custodia/custodia
@@ -7,6 +7,7 @@ try:
except ImportError:
from configparser import RawConfigParser
from custodia.httpd.server import LocalHTTPServer
+from custodia import log
import importlib
import os
import six
@@ -103,6 +104,8 @@ def parse_config(cfgfile):
if __name__ == '__main__':
cfgfile = source_config()
config = parse_config(cfgfile)
+ if config.get('debug') == 'True':
+ log.DEBUG = True
if 'server_socket' in config:
address = config['server_socket']
diff --git a/custodia/httpd/server.py b/custodia/httpd/server.py
index dc88aef..240e3b6 100644
--- a/custodia/httpd/server.py
+++ b/custodia/httpd/server.py
@@ -10,14 +10,13 @@ except ImportError:
from http.server import BaseHTTPRequestHandler
from socketserver import ForkingMixIn, UnixStreamServer
from urllib.parse import urlparse, parse_qs
-import io
+from custodia.log import stacktrace
+from custodia.log import debug as log_debug
import os
import shutil
import six
import socket
import struct
-import sys
-import traceback
SO_PEERCRED = 17
MAX_REQUEST_SIZE = 10*1024*1024 # For now limit body to 10MiB
@@ -28,15 +27,9 @@ class HTTPError(Exception):
def __init__(self, code=None, message=None):
self.code = code if code is not None else 500
self.mesg = message
- super(HTTPError, self).__init__('%d: %s' % (self.code, self.mesg))
-
-
-def stacktrace():
- with io.BytesIO() as f:
- _, _, tb = sys.exc_info()
- traceback.print_tb(tb, None, file=f)
- del tb
- return f.getvalue()
+ errstring = '%d: %s' % (self.code, self.mesg)
+ log_debug(errstring)
+ super(HTTPError, self).__init__(errstring)
class ForkingLocalHTTPServer(ForkingMixIn, UnixStreamServer):
diff --git a/custodia/log.py b/custodia/log.py
new file mode 100644
index 0000000..12a6ba7
--- /dev/null
+++ b/custodia/log.py
@@ -0,0 +1,31 @@
+# Copyright (C) 2015 Custodia Project Contributors - see LICENSE file
+
+import io
+import sys
+import traceback
+import time
+
+
+DEBUG = False
+
+
+def stacktrace():
+ with io.BytesIO() as f:
+ _, _, tb = sys.exc_info()
+ traceback.print_tb(tb, None, file=f)
+ del tb
+ return f.getvalue()
+
+
+def error(msg, head=None):
+ if head is not None:
+ t = time.gmtime(time.time())
+ head = '%04d/%02d/%02d %02d:%02d:%02d' % (
+ t[0], t[1], t[2], t[3], t[4], t[5])
+ sys.stderr.write('[%s] %s\n' % (head, msg))
+
+
+def debug(msg):
+ if DEBUG:
+ error(msg, 'DEBUG')
+ sys.stderr.write(stacktrace())
diff --git a/custodia/message/common.py b/custodia/message/common.py
index 25ce4e7..c538a57 100644
--- a/custodia/message/common.py
+++ b/custodia/message/common.py
@@ -1,5 +1,7 @@
# Copyright (C) 2015 Custodia Project Contributors - see LICENSE file
+from custodia import log
+
class InvalidMessage(Exception):
"""Invalid Message.
@@ -7,7 +9,9 @@ class InvalidMessage(Exception):
This exception is raised when a message cannot be parsed
or validated.
"""
- pass
+ def __init__(self, message=None):
+ log.debug(message)
+ super(InvalidMessage, self).__init__(message)
class UnknownMessageType(Exception):
@@ -16,7 +20,9 @@ class UnknownMessageType(Exception):
This exception is raised when a message is of an unknown
type.
"""
- pass
+ def __init__(self, message=None):
+ log.debug(message)
+ super(UnknownMessageType, self).__init__(message)
class UnallowedMessage(Exception):
@@ -25,7 +31,9 @@ class UnallowedMessage(Exception):
This exception is raise when the message type is know but
is not allowed.
"""
- pass
+ def __init__(self, message=None):
+ log.debug(message)
+ super(UnallowedMessage, self).__init__(message)
class MessageHandler(object):
diff --git a/custodia/message/kem.py b/custodia/message/kem.py
index 3d15e2f..343cb90 100644
--- a/custodia/message/kem.py
+++ b/custodia/message/kem.py
@@ -3,6 +3,7 @@
from custodia.httpd.authorizers import SimplePathAuthz
from custodia.message.common import InvalidMessage
from custodia.message.common import MessageHandler
+from custodia import log
from jwcrypto.common import json_decode
from jwcrypto.common import json_encode
from jwcrypto.jwe import JWE
@@ -19,7 +20,9 @@ KEY_USAGE_MAP = {KEY_USAGE_SIG: 'sig', KEY_USAGE_ENC: 'enc'}
class UnknownPublicKey(Exception):
- pass
+ def __init__(self, message=None):
+ log.debug(message)
+ super(UnknownPublicKey, self).__init__(message)
class KEMKeysStore(SimplePathAuthz):
diff --git a/custodia/store/interface.py b/custodia/store/interface.py
index 5a7db93..11c2e36 100644
--- a/custodia/store/interface.py
+++ b/custodia/store/interface.py
@@ -1,12 +1,18 @@
# Copyright (C) 2015 Custodia Project Contributors - see LICENSE file
+from custodia import log
+
class CSStoreError(Exception):
- pass
+ def __init__(self, message=None):
+ log.debug(message)
+ super(CSStoreError, self).__init__(message)
class CSStoreExists(Exception):
- pass
+ def __init__(self, message=None):
+ log.debug(message)
+ super(CSStoreExists, self).__init__(message)
class CSStore(object):