;; MacOSX Sandbox profile for bundled tor
;;
;; Copyright 2010 Robert Malmgren AB. All rights reserved.
;;
;; Redistribution and use in source and binary forms, with or without modification, are
;; permitted provided that the following conditions are met:
;;
;;   1. Redistributions of source code must retain the above copyright notice, this list of
;;      conditions and the following disclaimer.
;;
;;   2. Redistributions in binary form must reproduce the above copyright notice, this list
;;      of conditions and the following disclaimer in the documentation and/or other materials
;;      provided with the distribution.
;;
;; THIS SOFTWARE IS PROVIDED BY Robert Malmgren AB ``AS IS'' AND ANY EXPRESS OR IMPLIED
;; WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
;; FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
;; ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
;; ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;; 
;; The views and conclusions contained in the software and documentation are those of the
;; authors and should not be interpreted as representing official policies, either expressed
;; or implied, of Robert Malmgren AB.
;;
;; Written by andreas@romab.com 
(version 1)

(deny default)

(allow file-ioctl
       (literal "/dev/dtracehelper"))

(allow file-read-data file-read-metadata
       (literal "TORAPPDIR/Contents/Frameworks/libcrypto.0.9.8.dylib")
       (literal "TORAPPDIR/Contents/Frameworks/libssl.0.9.8.dylib")
       (literal "TORAPPDIR/Contents/Frameworks/libz.1.dylib")
       (literal "TORAPPDIR/TorBrowser_en-US.app/.tor/state")
       (literal "TORAPPDIR/Contents/MacOS/torrc")
       (literal "TORAPPDIR/.tor/state")
       (literal "TORAPPDIR/.tor/cached-descriptors.new"))

(allow file-read-data
       (literal "TORAPPDIR/.tor/cached-certs")
       (literal "TORAPPDIR/.tor/cached-consensus")
       (literal "TORAPPDIR/.tor/cached-descriptors")
       (literal "TORAPPDIR/.tor/cached-descriptors.new")
       (literal "TORAPPDIR/.tor/lock")
       (literal "/dev/dtracehelper")
       (literal "/dev/null")
       (literal "/dev/urandom")
       (subpath "/usr/share"))

(allow file-read-metadata
       (literal "TORAPPDIR/.tor")
       (literal "/etc")
       (literal "/private/etc/localtime")
       (subpath "/usr/lib"))

(allow file-write*
       (literal "TORAPPDIR/.tor/cached-descriptors")
       (literal "TORAPPDIR/.tor/cached-descriptors.new")
       (literal "TORAPPDIR/.tor/cached-descriptors.new.tmp")
       (literal "TORAPPDIR/.tor/cached-descriptors.tmp")
       (literal "TORAPPDIR/.tor/cached-descriptors.tmp.tmp")
       (literal "TORAPPDIR/.tor/cached-consensus")
       (literal "TORAPPDIR/.tor/cached-consensus.tmp")
       (literal "TORAPPDIR/.tor/state")
       (literal "TORAPPDIR/.tor/state.tmp"))

(allow file-write-data
       (literal "TORAPPDIR/.tor/lock")
       (literal "/dev/dtracehelper"))

(allow ipc-posix-shm)

(allow mach-lookup
       (global-name "com.apple.system.notification_center"))

(allow network-inbound
       (local tcp "localhost:9150")
       (local tcp "localhost:9151"))

(allow network-outbound)
;       (remote tcp "*:*")) 
; we need to allow any port (but as tor in relay mode might need udp)


(allow process-exec
       (literal "TORAPPDIR/Contents/MacOS/tor-bin"))

(allow sysctl-read)
