[CalendarServer-changes] [14348] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Tue Jan 27 10:39:08 PST 2015
Revision: 14348
http://trac.calendarserver.org//changeset/14348
Author: cdaboo at apple.com
Date: 2015-01-27 10:39:08 -0800 (Tue, 27 Jan 2015)
Log Message:
-----------
DKIM fixes.
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/dkimtool.py
CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/dkim.py
CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/test/test_dkim.py
Modified: CalendarServer/trunk/calendarserver/tools/dkimtool.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/dkimtool.py 2015-01-27 18:38:09 UTC (rev 14347)
+++ CalendarServer/trunk/calendarserver/tools/dkimtool.py 2015-01-27 18:39:08 UTC (rev 14348)
@@ -15,6 +15,7 @@
# limitations under the License.
##
+import os
import sys
from Crypto.PublicKey import RSA
from StringIO import StringIO
@@ -24,9 +25,7 @@
from twisted.python.usage import Options
from twext.python.log import Logger, LogLevel, StandardIOObserver
-from txweb2.client.http import ClientRequest
from txweb2.http_headers import Headers
-from txweb2.stream import MemoryStream
from txdav.caldav.datastore.scheduling.ischedule.dkim import RSA256, DKIMRequest, \
PublicKeyLookup, DKIMVerifier, DKIMVerificationError
@@ -114,19 +113,17 @@
@inlineCallbacks
def _doVerify(options):
# Parse the HTTP file
- verify = open(options["verify"]).read()
- method, uri, headers, stream = _parseRequest(verify)
+ verify = open(os.path.expanduser(options["verify"])).read()
+ _method, _uri, headers, body = _parseRequest(verify)
- request = ClientRequest(method, uri, headers, stream)
-
# Check for local public key
if options["pub-key"]:
- PublicKeyLookup_File.pubkeyfile = options["pub-key"]
+ PublicKeyLookup_File.pubkeyfile = os.path.expanduser(options["pub-key"])
lookup = (PublicKeyLookup_File,)
else:
lookup = None
- dkim = DKIMVerifier(request, lookup)
+ dkim = DKIMVerifier(headers, body, lookup)
if options["fake-time"]:
dkim.time = 0
@@ -162,7 +159,7 @@
name, value = hdr.split(':', 1)
headers.addRawHeader(name, value.strip())
- stream = MemoryStream("".join(body))
+ stream = "".join(body)
return method, uri, headers, stream
Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/dkim.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/dkim.py 2015-01-27 18:38:09 UTC (rev 14347)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/dkim.py 2015-01-27 18:39:08 UTC (rev 14348)
@@ -294,8 +294,16 @@
@staticmethod
def canonicalizeBody(data):
- if not data.endswith("\r\n"):
- data += "\r\n"
+ """
+ DKIM simple body canonicalization: remove empty lines at the end
+ and ensure it ends with one \r\n.
+
+ @param data: data to canonicalize
+ @type data: L{str}
+ """
+ while data.endswith("\r\n"):
+ data = data[:-2]
+ data += "\r\n"
return data
Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/test/test_dkim.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/test/test_dkim.py 2015-01-27 18:38:09 UTC (rev 14347)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/ischedule/test/test_dkim.py 2015-01-27 18:39:08 UTC (rev 14348)
@@ -389,6 +389,33 @@
self.assertEqual(extracted, result.replace("\n", "\r\n"))
+ def test_canonicalize_body(self):
+ """
+ L{DKIMUtils.canonicalizeBody} correctly canonicalizes bodies.
+ """
+
+ data = (
+ (
+ """Simple""",
+ """Simple\n""",
+ ),
+ (
+ """Simple\n""",
+ """Simple\n""",
+ ),
+ (
+ """Simple\n\n""",
+ """Simple\n""",
+ ),
+ )
+
+ for text, result in data:
+ self.assertEqual(
+ DKIMUtils.canonicalizeBody(text.replace("\n", "\r\n")),
+ result.replace("\n", "\r\n"),
+ )
+
+
@inlineCallbacks
def test_locate_public_key(self):
"""
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150127/1c51d8c0/attachment.html>
More information about the calendarserver-changes
mailing list