dia 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ ## "Dia"
2
+
3
+ "Dia" allows you to sandbox applications on the OSX platform by restricting what access to Operating System resources they can have.
4
+
5
+ ## What restrictions can you apply?
6
+
7
+ * No internet access.
8
+ * No network access of any kind.
9
+ * No file system writes.
10
+ * No file system writes, exlcuding writing to /tmp.
11
+ * A complete lockdown of Operating System resources.
12
+
13
+ ## How?
14
+ FFI, and the C header "sandbox.h" (found on OSX).
15
+
16
+ ## Example?
17
+
18
+ require 'rubygems'
19
+ require 'dia'
20
+
21
+ sandbox = Dia::SandBox.new("/Applications/Firefox.app/Contents/MacOS/firefox-bin", Dia::Profiles::NO_INTERNET)
22
+ sandbox.run
23
+ puts "Launched #{sandbox.app_path} with a pid of #{sandbox.pid} using the profile #{sandbox.profile}"
24
+
25
+ ## Install?
26
+
27
+ Right now, the github repository is where you can install "Dia" from.
28
+ There is a "gemspec" in the root of the project.
29
+ gem build *.gemspec;
30
+ gem install *.gem
31
+ ... after cloning the repository.
32
+
33
+ ## License(MIT)
34
+
35
+ Copyright (c) 2010 Robert Gleeson
36
+
37
+ Permission is hereby granted, free of charge, to any person
38
+ obtaining a copy of this software and associated documentation
39
+ files (the "Software"), to deal in the Software without
40
+ restriction, including without limitation the rights to use,
41
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
42
+ copies of the Software, and to permit persons to whom the
43
+ Software is furnished to do so, subject to the following
44
+ conditions:
45
+
46
+ The above copyright notice and this permission notice shall be
47
+ included in all copies or substantial portions of the Software.
48
+
49
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
50
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
51
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
52
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
53
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
54
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
55
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
56
+ OTHER DEALINGS IN THE SOFTWARE.
data/lib/dia.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'ffi'
2
+ require File.join(File.dirname(__FILE__), 'dia/profiles.rb')
3
+ require File.join(File.dirname(__FILE__), 'dia/commonapi.rb')
4
+ require File.join(File.dirname(__FILE__), 'dia/sandbox.rb')
5
+
6
+ module Dia
7
+ class SandBoxException < StandardError; end
8
+ end
9
+
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'ffi'
3
+
4
+ module Dia
5
+ module CommonAPI
6
+ extend FFI::Library
7
+ attach_function :sandbox_init, [ :string, :int, :pointer ], :int
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module Dia
2
+
3
+ module Profiles
4
+ extend FFI::Library
5
+
6
+ NO_INTERNET = attach_variable(:kSBXProfileNoInternet, :string).read_string
7
+ NO_NETWORKING = attach_variable(:kSBXProfileNoNetwork, :string).read_string
8
+ NO_FILESYSTEM_WRITE = attach_variable(:kSBXProfileNoWrite, :string).read_string
9
+ NO_FILESYSTEM_WRITE_EXCEPT_TMP = attach_variable(:kSBXProfileNoWriteExceptTemporary, :string).read_string
10
+ NO_OS_SERVICES = attach_variable(:kSBXProfilePureComputation, :string).read_string
11
+
12
+ end
13
+
14
+ end
15
+
@@ -0,0 +1,27 @@
1
+ module Dia
2
+
3
+ class SandBox
4
+
5
+ include Dia::CommonAPI
6
+
7
+ attr_accessor :app_path
8
+ attr_accessor :profile
9
+ attr_accessor :pid
10
+
11
+ def initialize app_path, profile
12
+ @app_path = app_path
13
+ @profile = profile
14
+ end
15
+
16
+ def run
17
+ @pid = fork do
18
+ unless ( ret = sandbox_init(@profile, 0x0001, error = FFI::MemoryPointer.new(:pointer)) ) == 0
19
+ raise Dia::SandBoxException, "Couldn't sandbox #{@app_path}, sandbox_init returned #{ret} with error message: '#{error.get_pointer(0).read_string}'"
20
+ end
21
+ exec(@app_path)
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dia
3
+ version: !ruby/object:Gem::Version
4
+ version: "1.0"
5
+ platform: ruby
6
+ authors:
7
+ - Robert
8
+ - Gleeson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2010-01-31 00:00:00 +00:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: ffi
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ version:
26
+ description: Dia allows you to sandbox applications on the OSX platform
27
+ email: rob@flowof.info
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files: []
33
+
34
+ files:
35
+ - README.md
36
+ - lib/dia/commonapi.rb
37
+ - lib/dia/profiles.rb
38
+ - lib/dia/sandbox.rb
39
+ - lib/dia.rb
40
+ has_rdoc: true
41
+ homepage:
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options: []
46
+
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.3.5
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Dia allows you to sandbox applications on the OSX platform
68
+ test_files: []
69
+