[CalendarServer-changes] [15232] CalendarServer/trunk/bin
source_changes at macosforge.org
source_changes at macosforge.org
Mon Oct 26 10:26:14 PDT 2015
Revision: 15232
http://trac.calendarserver.org//changeset/15232
Author: cdaboo at apple.com
Date: 2015-10-26 10:26:14 -0700 (Mon, 26 Oct 2015)
Log Message:
-----------
Setup keychain items for testing during bin/develop on OS X.
Modified Paths:
--------------
CalendarServer/trunk/bin/_build.sh
CalendarServer/trunk/bin/develop
Added Paths:
-----------
CalendarServer/trunk/bin/keychain_init.py
Modified: CalendarServer/trunk/bin/_build.sh
===================================================================
--- CalendarServer/trunk/bin/_build.sh 2015-10-26 15:21:15 UTC (rev 15231)
+++ CalendarServer/trunk/bin/_build.sh 2015-10-26 17:26:14 UTC (rev 15232)
@@ -165,7 +165,7 @@
case "$(uname -s)" in
Darwin)
default_requirements="${wd}/requirements-osx.txt";
- use_openssl="false"
+ use_openssl="false"
;;
esac;
fi;
@@ -706,8 +706,8 @@
ruler "Patching Python requirements";
echo "";
if [ ! -e "${dev_patches}/Twisted" ]; then
- apply_patches "Twisted" "${py_virtualenv}/lib/python2.7/site-packages"
- touch "${dev_patches}/Twisted";
+ apply_patches "Twisted" "${py_virtualenv}/lib/python2.7/site-packages"
+ touch "${dev_patches}/Twisted";
fi;
echo "";
Modified: CalendarServer/trunk/bin/develop
===================================================================
--- CalendarServer/trunk/bin/develop 2015-10-26 15:21:15 UTC (rev 15231)
+++ CalendarServer/trunk/bin/develop 2015-10-26 17:26:14 UTC (rev 15232)
@@ -70,10 +70,22 @@
ln -s "../${source}" "${target}";
- # NO! This causes bin/develop to hang the second time it is run
+ # NO! This causes bin/develop to hang the second time it is run
#rm -f "${target}/.develop";
#ln -s "${wd}/.develop" "${target}/.develop";
done;
}
+#
+# Do keychain init on OS X
+#
+if [ -z "${USE_OPENSSL-}" ]; then
+ case "$(uname -s)" in
+ Darwin)
+ echo "Keychain init."
+ bin/python bin/keychain_init.py
+ ;;
+ esac;
+fi;
+
echo "Dependency setup complete."
Added: CalendarServer/trunk/bin/keychain_init.py
===================================================================
--- CalendarServer/trunk/bin/keychain_init.py (rev 0)
+++ CalendarServer/trunk/bin/keychain_init.py 2015-10-26 17:26:14 UTC (rev 15232)
@@ -0,0 +1,125 @@
+#!/usr/bin/env python
+##
+# Copyright (c) 2015 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 subprocess import Popen, PIPE, STDOUT
+import os
+import re
+import sys
+
+identity_preference = "org.calendarserver.test"
+certname_regex = re.compile(r'"alis"<blob>="(.*)"')
+
+certificate_name = "localhost"
+certificate_file = "./twistedcaldav/test/data/server.pem"
+
+def identityExists():
+ child = Popen(
+ args=[
+ "/usr/bin/security", "get-identity-preference",
+ "-s", identity_preference,
+ "login.keychain",
+ ],
+ stdout=PIPE, stderr=STDOUT,
+ )
+ output, _ignore_error = child.communicate()
+
+ if child.returncode:
+ print("Could not find identity '{}'".format(identity_preference))
+ return False
+ else:
+ match = certname_regex.search(output)
+ if not match:
+ raise RuntimeError("No certificate found for identity '{}'".format(identity_preference))
+ else:
+ print("Found certificate '{}' for identity '{}'".format(match.group(1), identity_preference))
+ return True
+
+
+
+def identityCreate():
+ child = Popen(
+ args=[
+ "/usr/bin/security", "set-identity-preference",
+ "-s", identity_preference,
+ "-c", certificate_name,
+ ],
+ stdout=PIPE, stderr=STDOUT,
+ )
+ output, error = child.communicate()
+
+ if child.returncode:
+ raise RuntimeError(error if error else output)
+ else:
+ print("Created identity '{}' for certificate '{}'".format(identity_preference, certificate_name))
+ return True
+
+
+
+def certificateExists():
+ child = Popen(
+ args=[
+ "/usr/bin/security", "find-certificate",
+ "-c", certificate_name,
+ "login.keychain",
+ ],
+ stdout=PIPE, stderr=STDOUT,
+ )
+ _ignore_output, _ignore_error = child.communicate()
+
+ if child.returncode:
+ print("No certificate '{}' found for identity '{}'".format(certificate_name, identity_preference))
+ return False
+ else:
+ print("Found certificate '{}'".format(certificate_name))
+ return True
+
+
+
+def certificateImport():
+ child = Popen(
+ args=[
+ "/usr/bin/security", "import",
+ certificate_file,
+ "-k", "login.keychain",
+ "-A",
+ ],
+ stdout=PIPE, stderr=STDOUT,
+ )
+ output, error = child.communicate()
+
+ if child.returncode:
+ raise RuntimeError(error if error else output)
+ else:
+ print("Imported certificate '{}'".format(certificate_name))
+ return True
+
+if __name__ == '__main__':
+
+ if os.path.isfile("/usr/bin/security"):
+ # If the identity exists we are done
+ if identityExists():
+ sys.exit(0)
+
+ # Check for certificate and import if not present
+ if not certificateExists():
+ certificateImport()
+
+ # Create the identity
+ identityCreate()
+
+ else:
+ raise RuntimeError("Keychain access utility ('security') not found")
Property changes on: CalendarServer/trunk/bin/keychain_init.py
___________________________________________________________________
Added: svn:executable
+ *
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20151026/343325ed/attachment-0001.html>
More information about the calendarserver-changes
mailing list