[CalendarServer-changes] [8187] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Tue Oct 11 17:20:02 PDT 2011
Revision: 8187
http://trac.macosforge.org/projects/calendarserver/changeset/8187
Author: sagen at apple.com
Date: 2011-10-11 17:20:01 -0700 (Tue, 11 Oct 2011)
Log Message:
-----------
Pull the APN topics out of the certificates themselves rather than having to specify them in caldavd.plist.
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/stdconfig.py
Added Paths:
-----------
CalendarServer/trunk/calendarserver/push/util.py
Added: CalendarServer/trunk/calendarserver/push/util.py
===================================================================
--- CalendarServer/trunk/calendarserver/push/util.py (rev 0)
+++ CalendarServer/trunk/calendarserver/push/util.py 2011-10-12 00:20:01 UTC (rev 8187)
@@ -0,0 +1,36 @@
+##
+# Copyright (c) 2011 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+from OpenSSL import crypto
+
+def getAPNTopicFromCertificate(certPath):
+ """
+ Given the path to a certificate, extract the UID value portion of the
+ subject, which in this context is used for the associated APN topic.
+
+ @param certPath: file path of the certificate
+ @type certPath: C{str}
+
+ @return: C{str} topic, or empty string if value is not found
+ """
+ certData = open(certPath).read()
+ x509 = crypto.load_certificate(crypto.FILETYPE_PEM, certData)
+ subject = x509.get_subject()
+ components = subject.get_components()
+ for name, value in components:
+ if name == "UID":
+ return value
+ return ""
Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/stdconfig.py 2011-10-11 21:32:18 UTC (rev 8186)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py 2011-10-12 00:20:01 UTC (rev 8187)
@@ -34,6 +34,8 @@
from twistedcaldav.util import getPasswordFromKeychain
from twistedcaldav.util import KeychainAccessError, KeychainPasswordNotFound
+from calendarserver.push.util import getAPNTopicFromCertificate
+
log = Logger()
@@ -1208,13 +1210,22 @@
for key, service in configDict.Notifications["Services"].iteritems():
- # The default for apple push DataHost is ServerHostName
if (
service["Service"] == "calendarserver.push.applepush.ApplePushNotifierService" and
- service["DataHost"] == ""
+ service["Enabled"]
):
- service["DataHost"] = configDict.ServerHostName
+ # The default for apple push DataHost is ServerHostName
+ if service["DataHost"] == "":
+ service["DataHost"] = configDict.ServerHostName
+ # Retrieve APN topics from certificates if not explicitly set
+ for protocol in ("CalDAV", "CardDAV"):
+ if not service[protocol]["Topic"]:
+ certPath = service[protocol]["CertificatePath"]
+ if certPath and os.path.exists(certPath):
+ topic = getAPNTopicFromCertificate(certPath)
+ service[protocol]["Topic"] = topic
+
if (
service["Service"] == "twistedcaldav.notify.XMPPNotifierService" and
service["Enabled"]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20111011/729a3ed5/attachment.html>
More information about the calendarserver-changes
mailing list