├── .rvmrc ├── plugins └── siriproxy-example │ ├── Rakefile │ ├── .gitignore │ ├── Gemfile │ ├── siriproxy-example.gemspec │ └── lib │ └── siriproxy-example.rb ├── lib ├── siriproxy │ ├── version.rb │ ├── connection │ │ ├── guzzoni.rb │ │ └── iphone.rb │ ├── plugin.rb │ ├── dns.rb │ ├── interpret_siri.rb │ ├── plugin_manager.rb │ ├── command_line.rb │ └── connection.rb ├── siriproxy.rb └── siri_objects.rb ├── bin └── siriproxy ├── .gitignore ├── Rakefile ├── siriproxy.gemspec ├── Gemfile ├── config.example.yml ├── scripts ├── gen_certs.sh └── openssl.cnf ├── README.md └── COPYING /.rvmrc: -------------------------------------------------------------------------------- 1 | rvm 1.9.3@SiriProxy --create 2 | -------------------------------------------------------------------------------- /plugins/siriproxy-example/Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | -------------------------------------------------------------------------------- /lib/siriproxy/version.rb: -------------------------------------------------------------------------------- 1 | class SiriProxy 2 | VERSION = "0.5.4" 3 | end 4 | -------------------------------------------------------------------------------- /plugins/siriproxy-example/.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | .bundle 3 | Gemfile.lock 4 | pkg/* 5 | -------------------------------------------------------------------------------- /plugins/siriproxy-example/Gemfile: -------------------------------------------------------------------------------- 1 | source "http://rubygems.org" 2 | 3 | # Specify your gem's dependencies in siriproxy-example.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /bin/siriproxy: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib') 3 | 4 | require 'siriproxy/command_line' 5 | 6 | SiriProxy::CommandLine.new 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | server.passless.crt 2 | server.passless.key 3 | .DS_Store 4 | demoCA/ 5 | newkey.pem 6 | newreq.pem 7 | config.yml 8 | Gemfile.lock 9 | *.gem 10 | .bundle 11 | pkg/* 12 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rake' 2 | require 'rake/testtask' 3 | require "bundler/gem_tasks" 4 | 5 | Rake::TestTask.new do |t| 6 | t.libs << "test" 7 | t.test_files = FileList['test/*.rb'] 8 | t.verbose = true 9 | end 10 | -------------------------------------------------------------------------------- /lib/siriproxy/connection/guzzoni.rb: -------------------------------------------------------------------------------- 1 | ##### 2 | # This is the connection to the Guzzoni (the Siri server backend) 3 | ##### 4 | class SiriProxy::Connection::Guzzoni < SiriProxy::Connection 5 | def initialize 6 | super 7 | self.name = "Guzzoni" 8 | end 9 | 10 | def connection_completed 11 | super 12 | start_tls(:verify_peer => false) 13 | end 14 | 15 | def received_object(object) 16 | return plugin_manager.process_filters(object, :from_guzzoni) 17 | 18 | #plugin_manager.object_from_guzzoni(object, self) 19 | end 20 | 21 | def block_rest_of_session 22 | @block_rest_of_session = true 23 | end 24 | end -------------------------------------------------------------------------------- /plugins/siriproxy-example/siriproxy-example.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | $:.push File.expand_path("../lib", __FILE__) 3 | 4 | Gem::Specification.new do |s| 5 | s.name = "siriproxy-example" 6 | s.version = "0.0.1" 7 | s.authors = ["plamoni"] 8 | s.email = [""] 9 | s.homepage = "" 10 | s.summary = %q{An Example Siri Proxy Plugin} 11 | s.description = %q{This is a "hello world" style plugin. It simply intercepts the phrase "text siri proxy" and responds with a message about the proxy being up and running. This is good base code for other plugins. } 12 | 13 | s.rubyforge_project = "siriproxy-example" 14 | 15 | s.files = `git ls-files 2> /dev/null`.split("\n") 16 | s.test_files = `git ls-files -- {test,spec,features}/* 2> /dev/null`.split("\n") 17 | s.executables = `git ls-files -- bin/* 2> /dev/null`.split("\n").map{ |f| File.basename(f) } 18 | s.require_paths = ["lib"] 19 | 20 | # specify any dependencies here; for example: 21 | # s.add_development_dependency "rspec" 22 | # s.add_runtime_dependency "rest-client" 23 | end 24 | -------------------------------------------------------------------------------- /siriproxy.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | $:.push File.expand_path("../lib", __FILE__) 3 | require "siriproxy/version" 4 | 5 | Gem::Specification.new do |s| 6 | s.name = "siriproxy" 7 | s.version = SiriProxy::VERSION 8 | s.authors = ["plamoni", "chendo", "netpro2k"] 9 | s.email = ["plamoni@siriproxy.info"] 10 | s.homepage = "http://www.siriproxy.info/" 11 | s.summary = %q{A (tampering) proxy server for Apple's Siri} 12 | s.description = %q{Siri Proxy is a proxy server for Apple's Siri "assistant." The idea is to allow for the creation of custom handlers for different actions. This can allow developers to easily add functionality to Siri.} 13 | 14 | s.rubyforge_project = "siriproxy" 15 | 16 | s.files = `git ls-files 2> /dev/null`.split("\n") 17 | s.test_files = `git ls-files -- {test,spec,features}/* 2> /dev/null`.split("\n") 18 | s.executables = `git ls-files -- bin/* 2> /dev/null`.split("\n").map{ |f| File.basename(f) } 19 | s.require_paths = ["lib"] 20 | 21 | s.required_ruby_version = Gem::Requirement.new(">= 1.9.2") 22 | 23 | s.add_runtime_dependency "CFPropertyList", "=2.1.2" 24 | s.add_runtime_dependency "eventmachine" 25 | s.add_runtime_dependency "uuidtools" 26 | s.add_runtime_dependency "cora", "=0.0.4" 27 | s.add_runtime_dependency "bundler" 28 | s.add_runtime_dependency "rake" 29 | s.add_runtime_dependency "rubydns", "~> 0.6.0" 30 | end 31 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | 5 | # load plugins 6 | require 'yaml' 7 | require 'ostruct' 8 | config_file = File.expand_path(File.join('~', '.siriproxy', 'config.yml')); 9 | 10 | unless File.exists?(config_file) 11 | default_config = config_file 12 | config_file = File.expand_path(File.join(File.dirname(__FILE__), 'config.example.yml')) 13 | puts "[Notice - Configuration] ==================== Important Configuration Notice ==========================" 14 | puts "[Notice - Configuration] '#{default_config}' not found. Using '#{config_file}'" 15 | puts "[Notice - Configuration] " 16 | puts "[Notice - Configuration] Remove this message by copying '#{config_file}' into '~/.siriproxy/'" 17 | puts "[Notice - Configuration] ==============================================================================" 18 | end 19 | 20 | gem 'cora', '0.0.4' 21 | 22 | config = OpenStruct.new(YAML.load_file(File.expand_path(config_file))) 23 | if config.plugins 24 | puts "[Info - Configuration] Loading plugins -- If any fail to load, run `siriproxy bundle` (not `bundle install`) to resolve." 25 | config.plugins.each do |plugin| 26 | if plugin.is_a? String 27 | gem "siriproxy-#{plugin.downcase}" 28 | else 29 | gem "siriproxy-#{plugin['gem'] || plugin['name'].downcase}", :path => plugin['path'], :git => plugin['git'], :branch => plugin['branch'], :require => plugin['require'] 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /config.example.yml: -------------------------------------------------------------------------------- 1 | listen: 0.0.0.0 2 | port: 443 3 | log_level: 1 4 | 5 | #Create an array of DNS servers for use by internal DNS server and resolving guzzoni.apple.com 6 | upstream_dns: [8.8.8.8, 8.8.4.4] 7 | 8 | #Set your computer's IP for use by the internal DNS server 9 | # server_ip: 192.168.1.100 10 | 11 | #Set effective user when running as root. Supply a non-privileged user (such as 'nobody') 12 | # user: nobody 13 | 14 | 15 | plugins: 16 | # NOTE: run bundle after changing plugin configurations to update required gems 17 | 18 | - name: 'Example' 19 | path: './plugins/siriproxy-example' 20 | 21 | # - name: 'Thermostat' 22 | # git: 'git://github.com/plamoni/SiriProxy-Thermostat.git' 23 | # host: '192.168.2.71' 24 | 25 | # - name: 'Twitter' 26 | # path: './plugins/siriproxy-twitter' # path works just like specifing in gemfile 27 | # consumer_key: "YOUR_KEY" 28 | # consumer_secret: "YOUR_SECRET" 29 | # oauth_token: "YOUR_TOKEN" 30 | # oauth_token_secret: "YOUR_TOKEN_SECRET" 31 | 32 | # Note: Eliza should not be run with other plugins 33 | # - name: 'Eliza' 34 | # path: './plugins/siriproxy-eliza' # path works just like specifing in gemfile 35 | 36 | # Below are not actual plugins, just further example of config options 37 | 38 | # - SimplePlugin # simple syntax for plugins that are in rubygems and have no config 39 | 40 | # - name: 'AnotherPlugin' 41 | # git: 'git://github.com/netpro2k/SiriProxy-AnotherPlugin.git' # git works just like specifying in Gemfile 42 | -------------------------------------------------------------------------------- /lib/siriproxy/connection/iphone.rb: -------------------------------------------------------------------------------- 1 | require 'resolv' 2 | 3 | ##### 4 | # This is the connection to the iPhone 5 | ##### 6 | class SiriProxy::Connection::Iphone < SiriProxy::Connection 7 | def initialize upstream_dns 8 | super() 9 | self.name = "iPhone" 10 | @upstream_dns = upstream_dns 11 | end 12 | 13 | def post_init 14 | super 15 | start_tls(:cert_chain_file => File.expand_path("~/.siriproxy/server.passless.crt"), 16 | :private_key_file => File.expand_path("~/.siriproxy/server.passless.key"), 17 | :verify_peer => false) 18 | end 19 | 20 | # Resolves guzzoni.apple.com using the Google DNS servers. This allows the 21 | # machine running siriproxy to use the DNS server returning fake records for 22 | # guzzoni.apple.com. 23 | 24 | def resolve_guzzoni 25 | addresses = Resolv::DNS.open(nameserver: @upstream_dns) do |dns| 26 | res = dns.getresources('guzzoni.apple.com', Resolv::DNS::Resource::IN::A) 27 | 28 | res.map { |r| r.address } 29 | end 30 | 31 | addresses.map do |address| 32 | address.address.unpack('C*').join('.') 33 | end.sample 34 | end 35 | 36 | def ssl_handshake_completed 37 | super 38 | self.other_connection = EventMachine.connect(resolve_guzzoni, 443, SiriProxy::Connection::Guzzoni) 39 | self.plugin_manager.guzzoni_conn = self.other_connection 40 | other_connection.other_connection = self #hehe 41 | other_connection.plugin_manager = plugin_manager 42 | end 43 | 44 | def received_object(object) 45 | return plugin_manager.process_filters(object, :from_iphone) 46 | 47 | #plugin_manager.object_from_client(object, self) 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /lib/siriproxy/plugin.rb: -------------------------------------------------------------------------------- 1 | require 'cora' 2 | 3 | class SiriProxy::Plugin < Cora::Plugin 4 | attr_accessor :plugin_name 5 | 6 | def initialize(config) 7 | 8 | end 9 | 10 | def request_completed 11 | self.manager.send_request_complete_to_iphone 12 | end 13 | 14 | #use send_object(object, target: :guzzoni) to send to guzzoni 15 | def send_object(object, options={}) 16 | (object = object.to_hash) rescue nil #convert SiriObjects to a hash 17 | options[:target] = options[:target] ||= :iphone 18 | 19 | if(options[:target] == :iphone) 20 | self.manager.guzzoni_conn.inject_object_to_output_stream(object) 21 | elsif(options[:target] == :guzzoni) 22 | self.manager.iphone_conn.inject_object_to_output_stream(object) 23 | end 24 | end 25 | 26 | def last_ref_id 27 | self.manager.iphone_conn.last_ref_id 28 | end 29 | 30 | #direction should be :from_iphone, or :from_guzzoni 31 | def process_filters(object, direction) 32 | return nil if object == nil 33 | f = filters[object["class"]] 34 | if(f != nil && (f[:direction] == :both || f[:direction] == direction)) 35 | object = instance_exec(object, &f[:block]) 36 | end 37 | 38 | object 39 | end 40 | 41 | class << self 42 | def filter(class_names, options={}, &block) 43 | [class_names].flatten.each do |class_name| 44 | filters[class_name] = { 45 | direction: (options[:direction] ||= :both), 46 | block: block 47 | } 48 | end 49 | end 50 | 51 | def filters 52 | @filters ||= {} 53 | end 54 | end 55 | 56 | def filters 57 | self.class.filters 58 | end 59 | 60 | def to_s 61 | self.plugin_name 62 | end 63 | 64 | end 65 | -------------------------------------------------------------------------------- /lib/siriproxy/dns.rb: -------------------------------------------------------------------------------- 1 | require 'rubydns' 2 | 3 | class SiriProxy::Dns 4 | attr_accessor :interfaces, :upstream, :thread 5 | 6 | def initialize 7 | @interfaces = [ 8 | [:tcp, "0.0.0.0", 53], 9 | [:udp, "0.0.0.0", 53] 10 | ] 11 | 12 | servers = [] 13 | 14 | $APP_CONFIG.upstream_dns.each { |dns_addr| 15 | servers << [:udp, dns_addr, 53] 16 | servers << [:tcp, dns_addr, 53] 17 | } 18 | 19 | @upstream = RubyDNS::Resolver.new(servers) 20 | end 21 | 22 | def start(log_level=Logger::WARN) 23 | @thread = Thread.new { 24 | begin 25 | self.run(log_level) 26 | $SP_DNS_STARTED = true 27 | rescue RuntimeError => e 28 | if e.message.match /^no acceptor/ 29 | puts "[Error - Server] Either you're not root or tcp/udp port 53 is in use. DNS server is disabled" 30 | $SP_DNS_STARTED = true #Yeah, it didn't start, but we don't want to sit around and wait for it. 31 | else 32 | puts "[Error - Server] DNS Error: #{e.message}" 33 | puts "[Error - Server] DNS Server has crashed. Terminating SiriProxy" 34 | exit 1 35 | end 36 | rescue Exception => e 37 | puts "[Error - Server] DNS Error: #{e.message}" 38 | puts "[Error - Server] DNS Server has crashed. Terminating SiriProxy" 39 | exit 1 40 | end 41 | } 42 | end 43 | 44 | def stop 45 | Thread.kill(@thread) 46 | end 47 | 48 | def run(log_level=Logger::WARN,server_ip=$APP_CONFIG.server_ip) 49 | if server_ip 50 | upstream = @upstream 51 | 52 | # Start the RubyDNS server 53 | RubyDNS::run_server(:listen => @interfaces) do 54 | @logger.level = log_level 55 | 56 | match(/guzzoni.apple.com/, Resolv::DNS::Resource::IN::A) do |transaction| 57 | transaction.respond!(server_ip) 58 | end 59 | 60 | # Default DNS handler 61 | otherwise do |transaction| 62 | transaction.passthrough!(upstream) 63 | end 64 | end 65 | 66 | puts "[Info - Server] DNS Server started, tainting 'guzzoni.apple.com' with #{server_ip}" 67 | end 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /lib/siriproxy/interpret_siri.rb: -------------------------------------------------------------------------------- 1 | ###### 2 | # The idea behind this class is that you can call the different 3 | # methods to get different interpretations of a Siri object. 4 | # For instance, you can "unknown_intent" and it will check 5 | # to see if an object is a "Common#unknownIntent" response and 6 | # call the provided processor method with the appropriate info. 7 | # processor method signatures are provided in comments above each 8 | # method. 9 | # 10 | # each method will return "nil" if the object is not the valid 11 | # type. If it is, it will return the result of the processor. 12 | ##### 13 | class SiriProxy::Interpret 14 | class << self 15 | #Checks if the object is Guzzoni responding that it can't 16 | #determine the intent of the query 17 | #processor(object, connection, unknown_text) 18 | def unknown_intent(object, connection, processor) 19 | return false if object == nil 20 | return false if (!(object["properties"]["views"][0]["properties"]["dialogIdentifier"] == "Common#unknownIntent") rescue true) 21 | 22 | searchUtterance = object["properties"]["views"][1]["properties"]["commands"][0]["properties"]["commands"][0]["properties"]["utterance"] 23 | searchText = searchUtterance.split("^")[3] 24 | return processor.call(object, connection, searchText) 25 | 26 | return false 27 | end 28 | 29 | #Checks if the object is Guzzoni responding that it recognized 30 | #speech. Sends "best interpretation" phrase to processor 31 | #processor(object, connection, phrase) 32 | def speech_recognized(object) 33 | return nil if object == nil 34 | return nil if (!(object["class"] == "SpeechRecognized") rescue true) 35 | phrase = "" 36 | 37 | object["properties"]["recognition"]["properties"]["phrases"].map { |phraseObj| 38 | phraseObj["properties"]["interpretations"].first["properties"]["tokens"].map { |token| 39 | tokenProps = token["properties"] 40 | 41 | phrase = phrase[0..-2] if tokenProps["removeSpaceBefore"] and phrase[-1] == " " 42 | phrase << tokenProps["text"] 43 | phrase << " " if !tokenProps["removeSpaceAfter"] 44 | } 45 | } 46 | 47 | phrase.strip 48 | end 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /lib/siriproxy.rb: -------------------------------------------------------------------------------- 1 | require 'eventmachine' 2 | require 'zlib' 3 | require 'pp' 4 | 5 | class String 6 | def to_hex(seperator=" ") 7 | bytes.to_a.map{|i| i.to_s(16).rjust(2, '0')}.join(seperator) 8 | end 9 | end 10 | 11 | class SiriProxy 12 | 13 | def initialize() 14 | # @todo shouldnt need this, make centralize logging instead 15 | $LOG_LEVEL = $APP_CONFIG.log_level.to_i 16 | 17 | EventMachine.run do 18 | if Process.uid == 0 && !$APP_CONFIG.user 19 | puts "[Notice - Server] ======================= WARNING: Running as root =============================" 20 | puts "[Notice - Server] You should use -l or the config.yml to specify and non-root user to run under" 21 | puts "[Notice - Server] Running the server as root is dangerous." 22 | puts "[Notice - Server] ==============================================================================" 23 | end 24 | 25 | begin 26 | listen_addr = $APP_CONFIG.listen || "0.0.0.0" 27 | puts "[Info - Server] Starting SiriProxy on #{listen_addr}:#{$APP_CONFIG.port}..." 28 | EventMachine::start_server(listen_addr, $APP_CONFIG.port, SiriProxy::Connection::Iphone, $APP_CONFIG.upstream_dns) { |conn| 29 | puts "[Info - Guzzoni] Starting conneciton #{conn.inspect}" if $LOG_LEVEL < 1 30 | conn.plugin_manager = SiriProxy::PluginManager.new() 31 | conn.plugin_manager.iphone_conn = conn 32 | } 33 | 34 | retries = 0 35 | while $APP_CONFIG.server_ip && !$SP_DNS_STARTED && retries <= 5 36 | puts "[Info - Server] DNS server is not running yet, waiting #{2**retries} second#{'s' if retries > 1}..." 37 | sleep 2**retries 38 | retries += 1 39 | end 40 | 41 | if retries > 5 42 | puts "[Error - Server] DNS server did not start up." 43 | exit 1 44 | end 45 | 46 | EventMachine.set_effective_user($APP_CONFIG.user) if $APP_CONFIG.user 47 | puts "[Info - Server] SiriProxy up and running." 48 | 49 | rescue RuntimeError => err 50 | if err.message == "no acceptor" 51 | raise "[Error - Server] Cannot start the server on port #{$APP_CONFIG.port} - are you root, or have another process on this port already?" 52 | else 53 | raise 54 | end 55 | end 56 | end 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /lib/siriproxy/plugin_manager.rb: -------------------------------------------------------------------------------- 1 | require 'cora' 2 | require 'pp' 3 | 4 | class SiriProxy::PluginManager < Cora 5 | attr_accessor :plugins, :iphone_conn, :guzzoni_conn 6 | 7 | def initialize() 8 | load_plugins() 9 | end 10 | 11 | def load_plugins() 12 | @plugins = [] 13 | if $APP_CONFIG.plugins 14 | $APP_CONFIG.plugins.each do |pluginConfig| 15 | begin 16 | if pluginConfig.is_a? String 17 | className = pluginConfig 18 | requireName = "siriproxy-#{className.downcase}" 19 | else 20 | className = pluginConfig['name'] 21 | requireName = pluginConfig['require'] || "siriproxy-#{className.downcase}" 22 | end 23 | require requireName 24 | plugin = SiriProxy::Plugin.const_get(className).new(pluginConfig) 25 | plugin.plugin_name = className 26 | plugin.manager = self 27 | @plugins << plugin 28 | rescue Exception=>e 29 | if pluginConfig['name'] 30 | puts "[Error] Failed to load plugin: #{pluginConfig['name']} reason: #{e.message}" 31 | else 32 | puts "[Error] Failed to load a plugin that has no name, check your config.yml" 33 | end 34 | end 35 | end 36 | end 37 | log "Plugins loaded: #{@plugins.join(', ')}" 38 | end 39 | 40 | def process_filters(object, direction) 41 | object_class = object.class #This way, if we change the object class we won't need to modify this code. 42 | 43 | if object['class'] == 'SetRequestOrigin' 44 | properties = object['properties'] 45 | set_location(properties['latitude'], properties['longitude'], properties) 46 | end 47 | 48 | plugins.each do |plugin| 49 | #log "Processing filters on #{plugin} for '#{object["class"]}'" 50 | new_obj = plugin.process_filters(object, direction) 51 | object = new_obj if(new_obj == false || new_obj.class == object_class) #prevent accidental poorly formed returns 52 | return nil if object == false #if any filter returns "false," then the object should be dropped 53 | end 54 | 55 | return object 56 | end 57 | 58 | def process(text) 59 | begin 60 | result = super(text) 61 | self.guzzoni_conn.block_rest_of_session if result 62 | return result 63 | rescue Exception=>e 64 | log "Plugin Crashed: #{e}" 65 | respond e.to_s, spoken: "a plugin crashed" 66 | return true 67 | end 68 | end 69 | 70 | def send_request_complete_to_iphone 71 | log "Sending Request Completed" 72 | object = generate_request_completed(self.guzzoni_conn.last_ref_id) 73 | self.guzzoni_conn.inject_object_to_output_stream(object) 74 | end 75 | 76 | def respond(text, options={}) 77 | self.guzzoni_conn.inject_object_to_output_stream(generate_siri_utterance(self.guzzoni_conn.last_ref_id, text, (options[:spoken] or text), options[:prompt_for_response] == true)) 78 | end 79 | 80 | def no_matches 81 | return false 82 | end 83 | 84 | def log(text) 85 | puts "[Info - Plugin Manager] #{text}" if $LOG_LEVEL >= 1 86 | end 87 | end 88 | -------------------------------------------------------------------------------- /scripts/gen_certs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | commonName=$2 4 | 5 | if [ "${commonName}" == "" ] 6 | then 7 | commonName="SiriProxyCA" 8 | fi 9 | 10 | # Feel free to change any of these defaults 11 | countryName="US" 12 | stateOrProvinceName="Missouri" 13 | localityName="" 14 | organizationName="Siri Proxy" 15 | organizationalUnitName="" 16 | emailAddress="" 17 | 18 | #You probably don't need to modify these unless you know what you're doing. 19 | SIRI_PROXY_ROOT=$1 20 | SIRI_PROXY_SETTINGS=~/.siriproxy 21 | LOG_FILE=$SIRI_PROXY_SETTINGS/cert.log 22 | TMP_DIR=/tmp 23 | TMP_CA_DIR=/tmp/siriCA #THIS ($dir) ALSO MUST BE MODIFIED IN openssl.cnf IF YOU CHANGE IT! 24 | 25 | ## Do not edit below here! 26 | 27 | echo "" > $LOG_FILE 28 | 29 | echo "Creating CA directory" 30 | mkdir -p $TMP_CA_DIR/{certs,crl,newcerts,private} 31 | touch $TMP_CA_DIR/index.txt 32 | echo 01 > $TMP_CA_DIR/crtnumber 33 | 34 | echo "Generating '${commonName}' CA request" 35 | echo "${countryName}" > $TMP_DIR/ca.args 36 | echo "${stateOrProvinceName}" >> $TMP_DIR/ca.args 37 | echo "${localityName}" >> $TMP_DIR/ca.args 38 | echo "${organizationName}" >> $TMP_DIR/ca.args 39 | echo "${organizationalUnitName}" >> $TMP_DIR/ca.args 40 | echo "${commonName}" >> $TMP_DIR/ca.args 41 | echo "${emailAddress}" >> $TMP_DIR/ca.args 42 | echo "" >> $TMP_DIR/ca.args 43 | echo "" >> $TMP_DIR/ca.args 44 | 45 | cat $TMP_DIR/ca.args | openssl req -new -config $SIRI_PROXY_ROOT/scripts/openssl.cnf -keyout $TMP_CA_DIR/private/cakey.pem -out $TMP_CA_DIR/careq.pem -passin pass:1234 -passout pass:1234 >> $LOG_FILE 2>> $LOG_FILE 46 | 47 | echo "Self-signing '${commonName}' CA" 48 | openssl ca -create_serial -passin pass:1234 -config $SIRI_PROXY_ROOT/scripts/openssl.cnf -out $TMP_CA_DIR/cacert.pem -outdir $TMP_CA_DIR/newcerts -days 1095 -batch -keyfile $TMP_CA_DIR/private/cakey.pem -selfsign -extensions v3_ca -infiles $TMP_CA_DIR/careq.pem >> $LOG_FILE 2>> $LOG_FILE 49 | 50 | echo "Generating guzzoni.apple.com certificate request" 51 | echo "Generating '${commonName}' CA request" 52 | echo "${countryName}" > $TMP_DIR/ca.args 53 | echo "${stateOrProvinceName}" >> $TMP_DIR/ca.args 54 | echo "${localityName}" >> $TMP_DIR/ca.args 55 | echo "${organizationName}" >> $TMP_DIR/ca.args 56 | echo "${organizationalUnitName}" >> $TMP_DIR/ca.args 57 | echo "guzzoni.apple.com" >> $TMP_DIR/ca.args 58 | echo "${emailAddress}" >> $TMP_DIR/ca.args 59 | echo "" >> $TMP_DIR/ca.args 60 | echo "" >> $TMP_DIR/ca.args 61 | cat $TMP_DIR/ca.args | openssl req -new -keyout $TMP_DIR/newkey.pem -config $SIRI_PROXY_ROOT/scripts/openssl.cnf -out $TMP_DIR/newreq.pem -days 1095 -passin pass:1234 -passout pass:1234 >> $LOG_FILE 2>> $LOG_FILE 62 | 63 | echo "Generating guzzoni.apple.com certificate" 64 | yes | openssl ca -policy policy_anything -out $TMP_DIR/newcert.pem -config $SIRI_PROXY_ROOT/scripts/openssl.cnf -passin pass:1234 -keyfile $TMP_CA_DIR/private/cakey.pem -cert $TMP_CA_DIR/cacert.pem -infiles $TMP_DIR/newreq.pem >> $LOG_FILE 2>> $LOG_FILE 65 | 66 | echo "Removing passphrase from guzzoni.apple.com key" 67 | yes | openssl rsa -in $TMP_DIR/newkey.pem -out $SIRI_PROXY_SETTINGS/server.passless.key -passin pass:1234 >> $LOG_FILE 2>> $LOG_FILE 68 | 69 | echo "Cleaning up..." 70 | mv $TMP_DIR/newcert.pem $SIRI_PROXY_SETTINGS/server.passless.crt 71 | mv $TMP_CA_DIR/cacert.pem $SIRI_PROXY_SETTINGS/ca.pem 72 | rm -rf $TMP_DIR/new{key,req}.pem $TMP_CA_DIR $TMP_DIR/ca.args 73 | 74 | echo "Done! (For details on any errors, check '${LOG_FILE}')" 75 | echo "-------------------------------------------------------------" 76 | echo "" 77 | echo "Please install ${SIRI_PROXY_SETTINGS}/ca.pem onto your phone!" 78 | echo "(Note: You can do this by emailing the file to yourself)" 79 | echo "" 80 | echo "-------------------------------------------------------------" -------------------------------------------------------------------------------- /plugins/siriproxy-example/lib/siriproxy-example.rb: -------------------------------------------------------------------------------- 1 | require 'cora' 2 | require 'siri_objects' 3 | require 'pp' 4 | 5 | ####### 6 | # This is a "hello world" style plugin. It simply intercepts the phrase "test siri proxy" and responds 7 | # with a message about the proxy being up and running (along with a couple other core features). This 8 | # is good base code for other plugins. 9 | # 10 | # Remember to add other plugins to the "config.yml" file if you create them! 11 | ###### 12 | 13 | class SiriProxy::Plugin::Example < SiriProxy::Plugin 14 | def initialize(config) 15 | #if you have custom configuration options, process them here! 16 | end 17 | 18 | #get the user's location and display it in the logs 19 | #filters are still in their early stages. Their interface may be modified 20 | filter "SetRequestOrigin", direction: :from_iphone do |object| 21 | puts "[Info - User Location] lat: #{object["properties"]["latitude"]}, long: #{object["properties"]["longitude"]}" 22 | 23 | #Note about returns from filters: 24 | # - Return false to stop the object from being forwarded 25 | # - Return a Hash to substitute or update the object 26 | # - Return nil (or anything not a Hash or false) to have the object forwarded (along with any 27 | # modifications made to it) 28 | end 29 | 30 | listen_for /where am i/i do 31 | say "Your location is: #{location.address}" 32 | end 33 | 34 | listen_for /test siri proxy/i do 35 | say "Siri Proxy is up and running!" #say something to the user! 36 | 37 | request_completed #always complete your request! Otherwise the phone will "spin" at the user! 38 | end 39 | 40 | #Demonstrate that you can have Siri say one thing and write another"! 41 | listen_for /you don't say/i do 42 | say "Sometimes I don't write what I say", spoken: "Sometimes I don't say what I write" 43 | end 44 | 45 | #demonstrate state change 46 | listen_for /siri proxy test state/i do 47 | set_state :some_state #set a state... this is useful when you want to change how you respond after certain conditions are met! 48 | say "I set the state, try saying 'confirm state change'" 49 | 50 | request_completed #always complete your request! Otherwise the phone will "spin" at the user! 51 | end 52 | 53 | listen_for /confirm state change/i, within_state: :some_state do #this only gets processed if you're within the :some_state state! 54 | say "State change works fine!" 55 | set_state nil #clear out the state! 56 | 57 | request_completed #always complete your request! Otherwise the phone will "spin" at the user! 58 | end 59 | 60 | #demonstrate asking a question 61 | listen_for /siri proxy test question/i do 62 | response = ask "Is this thing working?" #ask the user for something 63 | 64 | if(response =~ /yes/i) #process their response 65 | say "Great!" 66 | else 67 | say "You could have just said 'yes'!" 68 | end 69 | 70 | request_completed #always complete your request! Otherwise the phone will "spin" at the user! 71 | end 72 | 73 | #demonstrate capturing data from the user (e.x. "Siri proxy number 15") 74 | listen_for /siri proxy number ([0-9,]*[0-9])/i do |number| 75 | say "Detected number: #{number}" 76 | 77 | request_completed #always complete your request! Otherwise the phone will "spin" at the user! 78 | end 79 | 80 | #demonstrate injection of more complex objects without shortcut methods. 81 | listen_for /test map/i do 82 | add_views = SiriAddViews.new 83 | add_views.make_root(last_ref_id) 84 | map_snippet = SiriMapItemSnippet.new 85 | map_snippet.items << SiriMapItem.new 86 | utterance = SiriAssistantUtteranceView.new("Testing map injection!") 87 | add_views.views << utterance 88 | add_views.views << map_snippet 89 | 90 | #you can also do "send_object object, target: :guzzoni" in order to send an object to guzzoni 91 | send_object add_views #send_object takes a hash or a SiriObject object 92 | 93 | request_completed #always complete your request! Otherwise the phone will "spin" at the user! 94 | end 95 | end 96 | -------------------------------------------------------------------------------- /lib/siriproxy/command_line.rb: -------------------------------------------------------------------------------- 1 | require 'optparse' 2 | require 'yaml' 3 | require 'ostruct' 4 | 5 | # @todo want to make SiriProxy::Commandline without having to 6 | # require 'siriproxy'. Im sure theres a better way. 7 | class SiriProxy 8 | 9 | end 10 | 11 | class SiriProxy::CommandLine 12 | $LOG_LEVEL = 0 13 | 14 | BANNER = <<-EOS 15 | Siri Proxy is a proxy server for Apple's Siri "assistant." The idea is to allow for the creation of custom handlers for different actions. This can allow developers to easily add functionality to Siri. 16 | 17 | See: http://github.com/plamoni/SiriProxy/ 18 | 19 | Usage: siriproxy COMMAND OPTIONS 20 | 21 | Commands: 22 | server Start up the Siri proxy server 23 | gencerts Generate a the certificates needed for SiriProxy 24 | bundle Install any dependancies needed by plugins 25 | console Launch the plugin test console 26 | update [dir] Updates to the latest code from GitHub or from a provided directory 27 | help Show this usage information 28 | 29 | Options: 30 | Option Command Description 31 | EOS 32 | 33 | def initialize 34 | @branch = nil 35 | parse_options 36 | command = ARGV.shift 37 | subcommand = ARGV.shift 38 | case command 39 | when 'server' then run_server(subcommand) 40 | when 'gencerts' then gen_certs 41 | when 'bundle' then run_bundle(subcommand) 42 | when 'console' then run_console 43 | when 'update' then update(subcommand) 44 | when 'help' then usage 45 | when 'dnsonly' then dns 46 | else usage 47 | end 48 | end 49 | 50 | def run_console 51 | load_code 52 | init_plugins 53 | 54 | # this is ugly, but works for now 55 | SiriProxy::PluginManager.class_eval do 56 | def respond(text, options={}) 57 | puts "=> #{text}" 58 | end 59 | def process(text) 60 | super(text) 61 | end 62 | def send_request_complete_to_iphone 63 | end 64 | def no_matches 65 | puts "No plugin responded" 66 | end 67 | end 68 | SiriProxy::Plugin.class_eval do 69 | def last_ref_id 70 | 0 71 | end 72 | def send_object(object, options={:target => :iphone}) 73 | puts "=> #{object}" 74 | end 75 | end 76 | 77 | cora = SiriProxy::PluginManager.new 78 | repl = -> prompt { print prompt; cora.process(gets.chomp!) } 79 | loop { repl[">> "] } 80 | end 81 | 82 | def run_bundle(subcommand='') 83 | setup_bundler_path 84 | puts `bundle #{subcommand} #{ARGV.join(' ')}` 85 | end 86 | 87 | def run_server(subcommand='start') 88 | load_code 89 | init_plugins 90 | start_server 91 | # @todo: support for forking server into bg and start/stop/restart 92 | # subcommand ||= 'start' 93 | # case subcommand 94 | # when 'start' then start_server 95 | # when 'stop' then stop_server 96 | # when 'restart' then restart_server 97 | # end 98 | end 99 | 100 | def start_server 101 | if $APP_CONFIG.server_ip 102 | require 'siriproxy/dns' 103 | dns_server = SiriProxy::Dns.new 104 | dns_server.start() 105 | end 106 | proxy = SiriProxy.new 107 | proxy.start() 108 | end 109 | 110 | def gen_certs 111 | ca_name = @ca_name ||= "" 112 | command = File.join(File.dirname(__FILE__), '..', "..", "scripts", 'gen_certs.sh') 113 | sp_root = File.join(File.dirname(__FILE__), '..', "..") 114 | puts `#{command} "#{sp_root}" "#{ca_name}"` 115 | end 116 | 117 | def update(directory=nil) 118 | if(directory) 119 | puts "=== Installing from '#{directory}' ===" 120 | puts `cd #{directory} && rake install` 121 | puts "=== Bundling ===" if $?.exitstatus == 0 122 | puts `siriproxy bundle` if $?.exitstatus == 0 123 | puts "=== SUCCESS ===" if $?.exitstatus == 0 124 | 125 | exit $?.exitstatus 126 | else 127 | branch_opt = @branch ? "-b #{@branch}" : "" 128 | @branch = "master" if @branch == nil 129 | puts "=== Installing latest code from git://github.com/plamoni/SiriProxy.git [#{@branch}] ===" 130 | 131 | tmp_dir = "/tmp/SiriProxy.install." + (rand 9999).to_s.rjust(4, "0") 132 | 133 | `mkdir -p #{tmp_dir}` 134 | puts `git clone #{branch_opt} git://github.com/plamoni/SiriProxy.git #{tmp_dir}` if $?.exitstatus == 0 135 | puts "=== Performing Rake Install ===" if $?.exitstatus == 0 136 | puts `cd #{tmp_dir} && rake install` if $?.exitstatus == 0 137 | puts "=== Bundling ===" if $?.exitstatus == 0 138 | puts `siriproxy bundle` if $?.exitstatus == 0 139 | puts "=== Cleaning Up ===" and puts `rm -rf #{tmp_dir}` if $?.exitstatus == 0 140 | puts "=== SUCCESS ===" if $?.exitstatus == 0 141 | 142 | exit $?.exitstatus 143 | end 144 | end 145 | 146 | def dns 147 | require 'siriproxy/dns' 148 | $APP_CONFIG.use_dns = true 149 | server = SiriProxy::Dns.new 150 | server.run(Logger::DEBUG) 151 | end 152 | 153 | def usage 154 | puts "\n#{@option_parser}\n" 155 | end 156 | 157 | private 158 | 159 | def parse_options 160 | config_file = File.expand_path(File.join('~', '.siriproxy', 'config.yml')); 161 | 162 | unless File.exists?(config_file) 163 | default_config = config_file 164 | config_file = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config.example.yml')) 165 | end 166 | 167 | $APP_CONFIG = OpenStruct.new(YAML.load_file(config_file)) 168 | 169 | # Google Public DNS servers 170 | $APP_CONFIG.upstream_dns ||= %w[8.8.8.8 8.8.4.4] 171 | 172 | @branch = nil 173 | @option_parser = OptionParser.new do |opts| 174 | opts.on('-d', '--dns ADDRESS', '[server] Launch DNS server guzzoni.apple.com with ADDRESS (requires root)') do |ip| 175 | $APP_CONFIG.server_ip = ip 176 | end 177 | opts.on('-l', '--log LOG_LEVEL', '[server] The level of debug information displayed (higher is more)') do |log_level| 178 | $APP_CONFIG.log_level = log_level 179 | end 180 | opts.on('-L', '--listen ADDRESS', '[server] Address to listen on (central or node)') do |listen| 181 | $APP_CONFIG.listen = listen 182 | end 183 | opts.on('-D', '--upstream-dns SERVERS', Array, '[server] List of upstream DNS servers to use. Defaults to \'[8.8.8.8, 8.8.4.4]\'') do |servers| 184 | $APP_CONFIG.upstream_dns = servers 185 | end 186 | opts.on('-p', '--port PORT', '[server] Port number for server (central or node)') do |port_num| 187 | $APP_CONFIG.port = port_num 188 | end 189 | opts.on('-u', '--user USER', '[server] The user to run as after launch') do |user| 190 | $APP_CONFIG.user = user 191 | end 192 | opts.on('-b', '--branch BRANCH', '[update] Choose the branch to update from (default: master)') do |branch| 193 | @branch = branch 194 | end 195 | opts.on('-n', '--name CA_NAME', '[gencerts] Define a common name for the CA (default: "SiriProxyCA")') do |ca_name| 196 | @ca_name = ca_name 197 | end 198 | opts.on_tail('-v', '--version', ' Show version') do 199 | require "siriproxy/version" 200 | puts "SiriProxy version #{SiriProxy::VERSION}" 201 | exit 202 | end 203 | end 204 | @option_parser.banner = BANNER 205 | @option_parser.parse!(ARGV) 206 | end 207 | 208 | def setup_bundler_path 209 | require 'pathname' 210 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../../Gemfile", 211 | Pathname.new(__FILE__).realpath) 212 | end 213 | 214 | def load_code 215 | setup_bundler_path 216 | 217 | require 'bundler' 218 | require 'bundler/setup' 219 | 220 | require 'siriproxy' 221 | require 'siriproxy/connection' 222 | require 'siriproxy/connection/iphone' 223 | require 'siriproxy/connection/guzzoni' 224 | 225 | require 'siriproxy/plugin' 226 | require 'siriproxy/plugin_manager' 227 | end 228 | 229 | def init_plugins 230 | pManager = SiriProxy::PluginManager.new 231 | pManager.plugins.each_with_index do |plugin, i| 232 | if plugin.respond_to?('plugin_init') 233 | $APP_CONFIG.plugins[i]['init'] = plugin.plugin_init 234 | end 235 | end 236 | pManager = nil 237 | end 238 | end 239 | -------------------------------------------------------------------------------- /lib/siriproxy/connection.rb: -------------------------------------------------------------------------------- 1 | require 'cfpropertylist' 2 | require 'siriproxy/interpret_siri' 3 | 4 | class SiriProxy::Connection < EventMachine::Connection 5 | include EventMachine::Protocols::LineText2 6 | 7 | attr_accessor :other_connection, :name, :ssled, :output_buffer, :input_buffer, :processed_headers, :unzip_stream, :zip_stream, :consumed_ace, :unzipped_input, :unzipped_output, :last_ref_id, :plugin_manager 8 | 9 | def last_ref_id=(ref_id) 10 | @last_ref_id = ref_id 11 | self.other_connection.last_ref_id = ref_id if other_connection.last_ref_id != ref_id 12 | end 13 | 14 | def initialize 15 | super 16 | self.processed_headers = false 17 | self.output_buffer = "" 18 | self.input_buffer = "" 19 | self.unzipped_input = "" 20 | self.unzipped_output = "" 21 | self.unzip_stream = Zlib::Inflate.new 22 | self.zip_stream = Zlib::Deflate.new 23 | self.consumed_ace = false 24 | end 25 | 26 | def post_init 27 | self.ssled = false 28 | end 29 | 30 | def ssl_handshake_completed 31 | self.ssled = true 32 | 33 | puts "[Info - #{self.name}] SSL completed for #{self.name}" if $LOG_LEVEL > 1 34 | end 35 | 36 | def receive_line(line) #Process header 37 | puts "[Header - #{self.name}] #{line}" if $LOG_LEVEL > 2 38 | if(line == "") #empty line indicates end of headers 39 | puts "[Debug - #{self.name}] Found end of headers" if $LOG_LEVEL > 3 40 | set_binary_mode 41 | self.processed_headers = true 42 | end 43 | self.output_buffer << (line + "\x0d\x0a") #Restore the CR-LF to the end of the line 44 | 45 | flush_output_buffer() 46 | end 47 | 48 | def receive_binary_data(data) 49 | self.input_buffer << data 50 | 51 | ##Consume the "0xAACCEE02" data at the start of the stream if necessary (by forwarding it to the output buffer) 52 | if(self.consumed_ace == false) 53 | self.output_buffer << input_buffer[0..3] 54 | self.input_buffer = input_buffer[4..-1] 55 | self.consumed_ace = true; 56 | end 57 | 58 | begin 59 | process_compressed_data() 60 | 61 | flush_output_buffer() 62 | rescue 63 | puts "[Info - #{self.name}] Got invalid data (non-ACE protocol?), terminating the connection." 64 | 65 | self.close_connection 66 | end 67 | end 68 | 69 | def flush_output_buffer 70 | return if output_buffer.empty? 71 | 72 | if other_connection.ssled 73 | puts "[Debug - #{self.name}] Forwarding #{self.output_buffer.length} bytes of data to #{other_connection.name}" if $LOG_LEVEL > 5 74 | #puts self.output_buffer.to_hex if $LOG_LEVEL > 5 75 | other_connection.send_data(output_buffer) 76 | self.output_buffer = "" 77 | else 78 | puts "[Debug - #{self.name}] Buffering some data for later (#{self.output_buffer.length} bytes buffered)" if $LOG_LEVEL > 5 79 | #puts self.output_buffer.to_hex if $LOG_LEVEL > 5 80 | end 81 | end 82 | 83 | def process_compressed_data 84 | self.unzipped_input << unzip_stream.inflate(self.input_buffer) 85 | self.input_buffer = "" 86 | puts "========UNZIPPED DATA (from #{self.name} =========" if $LOG_LEVEL > 5 87 | puts unzipped_input.to_hex if $LOG_LEVEL > 5 88 | puts "==================================================" if $LOG_LEVEL > 5 89 | 90 | while(self.has_next_object?) 91 | object = read_next_object_from_unzipped() 92 | 93 | if(object != nil) #will be nil if the next object is a ping/pong 94 | new_object = prep_received_object(object) #give the world a chance to mess with folks 95 | 96 | inject_object_to_output_stream(new_object) if new_object != nil #might be nil if "the world" decides to rid us of the object 97 | end 98 | end 99 | end 100 | 101 | def has_next_object? 102 | return false if unzipped_input.empty? #empty 103 | unpacked = unzipped_input[0...5].unpack('H*').first 104 | return true if(unpacked.match(/^0[34]/)) #Ping or pong 105 | return true if(unpacked.match(/^ff/)) #clear context 106 | 107 | if unpacked.match(/^[0-9][15-9]/) 108 | puts "ROGUE PACKET!!! WHAT IS IT?! TELL US!!! IN IRC!! COPY THE STUFF FROM BELOW" 109 | puts unpacked.to_hex 110 | end 111 | 112 | objectLength = unpacked.match(/^0200(.{6})/)[1].to_i(16) 113 | return ((objectLength + 5) < unzipped_input.length) #determine if the length of the next object (plus its prefix) is less than the input buffer 114 | end 115 | 116 | def read_next_object_from_unzipped 117 | unpacked = unzipped_input[0...5].unpack('H*').first 118 | info = unpacked.match(/^(..)(.{8})$/) 119 | 120 | if(info[1] == "03" || info[1] == "04" || info[1] == "ff") #Ping or pong -- just get these out of the way (and log them for good measure) 121 | object = unzipped_input[0...5] 122 | self.unzipped_output << object 123 | 124 | type = (info[1] == "03") ? "Ping" : ((info[1] == "04") ? "Pong" : "Clear Context") 125 | puts "[#{type} - #{self.name}] (#{info[2].to_i(16)})" if $LOG_LEVEL > 3 126 | self.unzipped_input = unzipped_input[5..-1] 127 | 128 | flush_unzipped_output() 129 | return nil 130 | end 131 | 132 | object_size = info[2].to_i(16) 133 | prefix = unzipped_input[0...5] 134 | object_data = unzipped_input[5...object_size+5] 135 | self.unzipped_input = unzipped_input[object_size+5..-1] 136 | 137 | parse_object(object_data) 138 | end 139 | 140 | 141 | def parse_object(object_data) 142 | plist = CFPropertyList::List.new(:data => object_data) 143 | object = CFPropertyList.native_types(plist.value) 144 | 145 | object 146 | end 147 | 148 | def inject_object_to_output_stream(object) 149 | if object["refId"] != nil && !object["refId"].empty? 150 | @block_rest_of_session = false if @block_rest_of_session && self.last_ref_id != object["refId"] #new session 151 | self.last_ref_id = object["refId"] 152 | end 153 | 154 | puts "[Info - Forwarding object to #{self.other_connection.name}] #{object["class"]}" if $LOG_LEVEL > 1 155 | 156 | object_data = object.to_plist(:plist_format => CFPropertyList::List::FORMAT_BINARY) 157 | 158 | #Recalculate the size in case the object gets modified. If new size is 0, then remove the object from the stream entirely 159 | obj_len = object_data.length 160 | 161 | if(obj_len > 0) 162 | prefix = [(0x0200000000 + obj_len).to_s(16).rjust(10, '0')].pack('H*') 163 | self.unzipped_output << prefix + object_data 164 | end 165 | 166 | flush_unzipped_output() 167 | end 168 | 169 | def flush_unzipped_output 170 | self.zip_stream << self.unzipped_output 171 | self.unzipped_output = "" 172 | self.output_buffer << zip_stream.flush 173 | 174 | flush_output_buffer() 175 | end 176 | 177 | def prep_received_object(object) 178 | #workaround for #143 179 | if object["class"] == "FinishSpeech" or object["class"] == "SpeechRecognized" 180 | @block_rest_of_session = false 181 | end 182 | 183 | if object["refId"] == self.last_ref_id && @block_rest_of_session 184 | puts "[Info - Dropping Object from Guzzoni] #{object["class"]}" if $LOG_LEVEL > 1 185 | pp object if $LOG_LEVEL > 3 186 | return nil 187 | end 188 | 189 | puts "[Info - #{self.name}] Received Object: #{object["class"]}" if $LOG_LEVEL == 1 190 | puts "[Info - #{self.name}] Received Object: #{object["class"]} (group: #{object["group"]})" if $LOG_LEVEL == 2 191 | puts "[Info - #{self.name}] Received Object: #{object["class"]} (group: #{object["group"]}, ref_id: #{object["refId"]}, ace_id: #{object["aceId"]})" if $LOG_LEVEL > 2 192 | pp object if $LOG_LEVEL > 3 193 | 194 | #keeping this for filters 195 | new_obj = received_object(object) 196 | if new_obj == nil 197 | puts "[Info - Dropping Object from #{self.name}] #{object["class"]}" if $LOG_LEVEL > 1 198 | pp object if $LOG_LEVEL > 3 199 | return nil 200 | end 201 | 202 | #block the rest of the session if a plugin claims ownership 203 | speech = SiriProxy::Interpret.speech_recognized(object) 204 | if speech != nil 205 | inject_object_to_output_stream(object) 206 | block_rest_of_session if plugin_manager.process(speech) 207 | return nil 208 | end 209 | 210 | 211 | #object = new_obj if ((new_obj = SiriProxy::Interpret.unknown_intent(object, self, plugin_manager.method(:unknown_command))) != false) 212 | #object = new_obj if ((new_obj = SiriProxy::Interpret.speech_recognized(object, self, plugin_manager.method(:speech_recognized))) != false) 213 | 214 | object 215 | end 216 | 217 | #Stub -- override in subclass 218 | def received_object(object) 219 | 220 | object 221 | end 222 | 223 | end 224 | -------------------------------------------------------------------------------- /lib/siri_objects.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'uuidtools' 3 | 4 | def generate_siri_utterance(ref_id, text, speakableText=text, listenAfterSpeaking=false) 5 | object = SiriAddViews.new 6 | object.make_root(ref_id) 7 | object.views << SiriAssistantUtteranceView.new(text, speakableText, "Misc#ident", listenAfterSpeaking) 8 | return object.to_hash 9 | end 10 | 11 | def generate_request_completed(ref_id, callbacks=nil) 12 | object = SiriRequestCompleted.new() 13 | object.callbacks = callbacks if callbacks != nil 14 | object.make_root(ref_id) 15 | return object.to_hash 16 | end 17 | 18 | class SiriObject 19 | attr_accessor :klass, :group, :properties 20 | 21 | def initialize(klass, group) 22 | @klass = klass 23 | @group = group 24 | @properties = {} 25 | end 26 | 27 | #watch out for circular references! 28 | def to_hash 29 | hash = { 30 | "class" => self.klass, 31 | "group" => self.group, 32 | "properties" => {} 33 | } 34 | 35 | (hash["refId"] = ref_id) rescue nil 36 | (hash["aceId"] = ace_id) rescue nil 37 | 38 | properties.each_key { |key| 39 | if properties[key].class == Array 40 | hash["properties"][key] = [] 41 | self.properties[key].each { |val| hash["properties"][key] << (val.to_hash rescue val) } 42 | else 43 | hash["properties"][key] = (properties[key].to_hash rescue properties[key]) 44 | end 45 | } 46 | 47 | hash 48 | end 49 | 50 | def make_root(ref_id=nil, ace_id=nil) 51 | self.extend(SiriRootObject) 52 | 53 | self.ref_id = (ref_id || random_ref_id) 54 | self.ace_id = (ace_id || random_ace_id) 55 | end 56 | end 57 | 58 | def add_property_to_class(klass, prop) 59 | klass.send(:define_method, (prop.to_s + "=").to_sym) { |value| 60 | self.properties[prop.to_s] = value 61 | } 62 | 63 | klass.send(:define_method, prop.to_s.to_sym) { 64 | self.properties[prop.to_s] 65 | } 66 | end 67 | 68 | module SiriRootObject 69 | attr_accessor :ref_id, :ace_id 70 | 71 | def random_ref_id 72 | UUIDTools::UUID.random_create.to_s.upcase 73 | end 74 | 75 | def random_ace_id 76 | UUIDTools::UUID.random_create.to_s 77 | end 78 | end 79 | 80 | class SiriAddViews < SiriObject 81 | def initialize(scrollToTop=false, temporary=false, dialogPhase="Completion", views=[]) 82 | super("AddViews", "com.apple.ace.assistant") 83 | self.scrollToTop = scrollToTop 84 | self.views = views 85 | self.temporary = temporary 86 | self.dialogPhase = dialogPhase 87 | end 88 | end 89 | add_property_to_class(SiriAddViews, :scrollToTop) 90 | add_property_to_class(SiriAddViews, :views) 91 | add_property_to_class(SiriAddViews, :temporary) 92 | add_property_to_class(SiriAddViews, :dialogPhase) 93 | 94 | ##### 95 | # VIEWS 96 | ##### 97 | 98 | class SiriAssistantUtteranceView < SiriObject 99 | def initialize(text="", speakableText=text, dialogIdentifier="Misc#ident", listenAfterSpeaking=false) 100 | super("AssistantUtteranceView", "com.apple.ace.assistant") 101 | self.text = text 102 | self.speakableText = speakableText 103 | self.dialogIdentifier = dialogIdentifier 104 | self.listenAfterSpeaking = listenAfterSpeaking 105 | end 106 | end 107 | add_property_to_class(SiriAssistantUtteranceView, :text) 108 | add_property_to_class(SiriAssistantUtteranceView, :speakableText) 109 | add_property_to_class(SiriAssistantUtteranceView, :dialogIdentifier) 110 | add_property_to_class(SiriAssistantUtteranceView, :listenAfterSpeaking) 111 | 112 | class SiriMapItemSnippet < SiriObject 113 | def initialize(userCurrentLocation=true, items=[]) 114 | super("MapItemSnippet", "com.apple.ace.localsearch") 115 | self.userCurrentLocation = userCurrentLocation 116 | self.items = items 117 | end 118 | end 119 | add_property_to_class(SiriMapItemSnippet, :userCurrentLocation) 120 | add_property_to_class(SiriMapItemSnippet, :items) 121 | 122 | class SiriButton < SiriObject 123 | def initialize(text="Button Text", commands=[]) 124 | super("Button", "com.apple.ace.assistant") 125 | self.text = text 126 | self.commands = commands 127 | end 128 | end 129 | add_property_to_class(SiriButton, :text) 130 | add_property_to_class(SiriButton, :commands) 131 | 132 | class SiriAnswerSnippet < SiriObject 133 | def initialize(answers=[], confirmationOptions=nil) 134 | super("Snippet", "com.apple.ace.answer") 135 | self.answers = answers 136 | 137 | if confirmationOptions 138 | # need to figure out good way to do API for this 139 | self.confirmationOptions = confirmationOptions 140 | end 141 | 142 | end 143 | end 144 | add_property_to_class(SiriAnswerSnippet, :answers) 145 | add_property_to_class(SiriAnswerSnippet, :confirmationOptions) 146 | 147 | ##### 148 | # Items 149 | ##### 150 | 151 | class SiriMapItem < SiriObject 152 | def initialize(label="Apple Headquarters", location=SiriLocation.new, detailType="BUSINESS_ITEM") 153 | super("MapItem", "com.apple.ace.localsearch") 154 | self.label = label 155 | self.detailType = detailType 156 | self.location = location 157 | end 158 | end 159 | add_property_to_class(SiriMapItem, :label) 160 | add_property_to_class(SiriMapItem, :detailType) 161 | add_property_to_class(SiriMapItem, :location) 162 | 163 | ##### 164 | # Commands 165 | ##### 166 | 167 | class SiriSendCommands < SiriObject 168 | def initialize(commands=[]) 169 | super("SendCommands", "com.apple.ace.system") 170 | self.commands=commands 171 | end 172 | end 173 | add_property_to_class(SiriSendCommands, :commands) 174 | 175 | class SiriConfirmationOptions < SiriObject 176 | def initialize(submitCommands=[], cancelCommands=[], denyCommands=[], confirmCommands=[], denyText="Cancel", cancelLabel="Cancel", submitLabel="Send", confirmText="Send", cancelTrigger="Deny") 177 | super("ConfirmationOptions", "com.apple.ace.assistant") 178 | 179 | self.submitCommands = submitCommands 180 | self.cancelCommands = cancelCommands 181 | self.denyCommands = denyCommands 182 | self.confirmCommands = confirmCommands 183 | 184 | self.denyText = denyText 185 | self.cancelLabel = cancelLabel 186 | self.submitLabel = submitLabel 187 | self.confirmText = confirmText 188 | self.cancelTrigger = cancelTrigger 189 | end 190 | end 191 | add_property_to_class(SiriConfirmationOptions, :submitCommands) 192 | add_property_to_class(SiriConfirmationOptions, :cancelCommands) 193 | add_property_to_class(SiriConfirmationOptions, :denyCommands) 194 | add_property_to_class(SiriConfirmationOptions, :confirmCommands) 195 | add_property_to_class(SiriConfirmationOptions, :denyText) 196 | add_property_to_class(SiriConfirmationOptions, :cancelLabel) 197 | add_property_to_class(SiriConfirmationOptions, :submitLabel) 198 | add_property_to_class(SiriConfirmationOptions, :confirmText) 199 | add_property_to_class(SiriConfirmationOptions, :cancelTrigger) 200 | 201 | class SiriConfirmSnippetCommand < SiriObject 202 | def initialize(request_id = "") 203 | super("ConfirmSnippet", "com.apple.ace.assistant") 204 | self.request_id = request_id 205 | end 206 | end 207 | add_property_to_class(SiriConfirmSnippetCommand, :request_id) 208 | 209 | class SiriCancelSnippetCommand < SiriObject 210 | def initialize(request_id = "") 211 | super("ConfirmSnippet", "com.apple.ace.assistant") 212 | self.request_id = request_id 213 | end 214 | end 215 | add_property_to_class(SiriCancelSnippetCommand, :request_id) 216 | 217 | ##### 218 | # Objects 219 | ##### 220 | 221 | class SiriLocation < SiriObject 222 | def initialize(label="Apple", street="1 Infinite Loop", city="Cupertino", stateCode="CA", countryCode="US", postalCode="95014", latitude=37.3317031860352, longitude=-122.030089795589) 223 | super("Location", "com.apple.ace.system") 224 | self.label = label 225 | self.street = street 226 | self.city = city 227 | self.stateCode = stateCode 228 | self.countryCode = countryCode 229 | self.postalCode = postalCode 230 | self.latitude = latitude 231 | self.longitude = longitude 232 | end 233 | end 234 | add_property_to_class(SiriLocation, :label) 235 | add_property_to_class(SiriLocation, :street) 236 | add_property_to_class(SiriLocation, :city) 237 | add_property_to_class(SiriLocation, :stateCode) 238 | add_property_to_class(SiriLocation, :countryCode) 239 | add_property_to_class(SiriLocation, :postalCode) 240 | add_property_to_class(SiriLocation, :latitude) 241 | add_property_to_class(SiriLocation, :longitude) 242 | 243 | class SiriAnswer < SiriObject 244 | def initialize(title="", lines=[]) 245 | super("Object", "com.apple.ace.answer") 246 | self.title = title 247 | self.lines = lines 248 | end 249 | end 250 | add_property_to_class(SiriAnswer, :title) 251 | add_property_to_class(SiriAnswer, :lines) 252 | 253 | class SiriAnswerLine < SiriObject 254 | def initialize(text="", image="") 255 | super("ObjectLine", "com.apple.ace.answer") 256 | self.text = text 257 | self.image = image 258 | end 259 | end 260 | add_property_to_class(SiriAnswerLine, :text) 261 | add_property_to_class(SiriAnswerLine, :image) 262 | 263 | ##### 264 | # Guzzoni Commands (commands that typically come from the server side) 265 | ##### 266 | 267 | class SiriGetRequestOrigin < SiriObject 268 | def initialize(desiredAccuracy="HundredMeters", searchTimeout=8.0, maxAge=1800) 269 | super("GetRequestOrigin", "com.apple.ace.system") 270 | self.desiredAccuracy = desiredAccuracy 271 | self.searchTimeout = searchTimeout 272 | self.maxAge = maxAge 273 | end 274 | end 275 | add_property_to_class(SiriGetRequestOrigin, :desiredAccuracy) 276 | add_property_to_class(SiriGetRequestOrigin, :searchTimeout) 277 | add_property_to_class(SiriGetRequestOrigin, :maxAge) 278 | 279 | class SiriRequestCompleted < SiriObject 280 | def initialize(callbacks=[]) 281 | super("RequestCompleted", "com.apple.ace.system") 282 | self.callbacks = callbacks 283 | end 284 | end 285 | add_property_to_class(SiriRequestCompleted, :callbacks) 286 | 287 | ##### 288 | # iPhone Responses (misc meta data back to the server) 289 | ##### 290 | 291 | class SiriStartRequest < SiriObject 292 | def initialize(utterance="Testing", handsFree=false, proxyOnly=false) 293 | super("StartRequest", "com.apple.ace.system") 294 | self.utterance = utterance 295 | self.handsFree = handsFree 296 | if proxyOnly # dont send local when false since its non standard 297 | self.proxyOnly = proxyOnly 298 | end 299 | end 300 | end 301 | add_property_to_class(SiriStartRequest, :utterance) 302 | add_property_to_class(SiriStartRequest, :handsFree) 303 | add_property_to_class(SiriStartRequest, :proxyOnly) 304 | 305 | 306 | class SiriSetRequestOrigin < SiriObject 307 | def initialize(longitude=-122.030089795589, latitude=37.3317031860352, desiredAccuracy="HundredMeters", altitude=0.0, speed=1.0, direction=1.0, age=0, horizontalAccuracy=50.0, verticalAccuracy=10.0) 308 | super("SetRequestOrigin", "com.apple.ace.system") 309 | self.horizontalAccuracy = horizontalAccuracy 310 | self.latitude = latitude 311 | self.desiredAccuracy = desiredAccuracy 312 | self.altitude = altitude 313 | self.speed = speed 314 | self.longitude = longitude 315 | self.verticalAccuracy = verticalAccuracy 316 | self.direction = direction 317 | self.age = age 318 | end 319 | end 320 | add_property_to_class(SiriSetRequestOrigin, :horizontalAccuracy) 321 | add_property_to_class(SiriSetRequestOrigin, :latitude) 322 | add_property_to_class(SiriSetRequestOrigin, :desiredAccuracy) 323 | add_property_to_class(SiriSetRequestOrigin, :altitude) 324 | add_property_to_class(SiriSetRequestOrigin, :speed) 325 | add_property_to_class(SiriSetRequestOrigin, :longitude) 326 | add_property_to_class(SiriSetRequestOrigin, :verticalAccuracy) 327 | add_property_to_class(SiriSetRequestOrigin, :direction) 328 | add_property_to_class(SiriSetRequestOrigin, :age) 329 | 330 | 331 | 332 | -------------------------------------------------------------------------------- /scripts/openssl.cnf: -------------------------------------------------------------------------------- 1 | # 2 | # OpenSSL example configuration file. 3 | # This is mostly being used for generation of certificate requests. 4 | # 5 | 6 | # This definition stops the following lines choking if HOME isn't 7 | # defined. 8 | HOME = . 9 | RANDFILE = $ENV::HOME/.rnd 10 | 11 | # Extra OBJECT IDENTIFIER info: 12 | #oid_file = $ENV::HOME/.oid 13 | oid_section = new_oids 14 | 15 | # To use this configuration file with the "-extfile" option of the 16 | # "openssl x509" utility, name here the section containing the 17 | # X.509v3 extensions to use: 18 | # extensions = 19 | # (Alternatively, use a configuration file that has only 20 | # X.509v3 extensions in its main [= default] section.) 21 | 22 | [ new_oids ] 23 | 24 | # We can add new OIDs in here for use by 'ca', 'req' and 'ts'. 25 | # Add a simple OID like this: 26 | # testoid1=1.2.3.4 27 | # Or use config file substitution like this: 28 | # testoid2=${testoid1}.5.6 29 | 30 | # Policies used by the TSA examples. 31 | tsa_policy1 = 1.2.3.4.1 32 | tsa_policy2 = 1.2.3.4.5.6 33 | tsa_policy3 = 1.2.3.4.5.7 34 | 35 | #################################################################### 36 | [ ca ] 37 | default_ca = CA_default # The default ca section 38 | 39 | 40 | #################################################################### 41 | [ CA_default ] 42 | 43 | dir = /tmp/siriCA # Where everything is kept 44 | certs = $dir/certs # Where the issued certs are kept 45 | crl_dir = $dir/crl # Where the issued crl are kept 46 | database = $dir/index.txt # database index file. 47 | #unique_subject = no # Set to 'no' to allow creation of 48 | # several ctificates with same subject. 49 | new_certs_dir = $dir/newcerts # default place for new certs. 50 | 51 | certificate = $dir/cacert.pem # The CA certificate 52 | serial = $dir/serial # The current serial number 53 | crlnumber = $dir/crlnumber # the current crl number 54 | # must be commented out to leave a V1 CRL 55 | crl = $dir/crl.pem # The current CRL 56 | private_key = $dir/private/cakey.pem# The private key 57 | RANDFILE = $dir/private/.rand # private random number file 58 | 59 | x509_extensions = usr_cert # The extentions to add to the cert 60 | 61 | # Comment out the following two lines for the "traditional" 62 | # (and highly broken) format. 63 | name_opt = ca_default # Subject Name options 64 | cert_opt = ca_default # Certificate field options 65 | 66 | # Extension copying option: use with caution. 67 | # copy_extensions = copy 68 | 69 | # Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs 70 | # so this is commented out by default to leave a V1 CRL. 71 | # crlnumber must also be commented out to leave a V1 CRL. 72 | # crl_extensions = crl_ext 73 | 74 | default_days = 365 # how long to certify for 75 | default_crl_days= 30 # how long before next CRL 76 | default_md = sha1 # use public key default MD 77 | preserve = no # keep passed DN ordering 78 | 79 | # A few difference way of specifying how similar the request should look 80 | # For type CA, the listed attributes must be the same, and the optional 81 | # and supplied fields are just that :-) 82 | policy = policy_match 83 | 84 | # For the CA policy 85 | [ policy_match ] 86 | countryName = match 87 | stateOrProvinceName = match 88 | organizationName = match 89 | organizationalUnitName = optional 90 | commonName = supplied 91 | emailAddress = optional 92 | 93 | # For the 'anything' policy 94 | # At this point in time, you must list all acceptable 'object' 95 | # types. 96 | [ policy_anything ] 97 | countryName = optional 98 | stateOrProvinceName = optional 99 | localityName = optional 100 | organizationName = optional 101 | organizationalUnitName = optional 102 | commonName = supplied 103 | emailAddress = optional 104 | 105 | #################################################################### 106 | [ req ] 107 | default_bits = 1024 108 | default_keyfile = privkey.pem 109 | distinguished_name = req_distinguished_name 110 | attributes = req_attributes 111 | x509_extensions = v3_ca # The extentions to add to the self signed cert 112 | default_md = sha1 113 | 114 | 115 | # Passwords for private keys if not present they will be prompted for 116 | # input_password = secret 117 | # output_password = secret 118 | 119 | # This sets a mask for permitted string types. There are several options. 120 | # default: PrintableString, T61String, BMPString. 121 | # pkix : PrintableString, BMPString (PKIX recommendation before 2004) 122 | # utf8only: only UTF8Strings (PKIX recommendation after 2004). 123 | # nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings). 124 | # MASK:XXXX a literal mask value. 125 | # WARNING: ancient versions of Netscape crash on BMPStrings or UTF8Strings. 126 | string_mask = utf8only 127 | 128 | # req_extensions = v3_req # The extensions to add to a certificate request 129 | 130 | [ req_distinguished_name ] 131 | countryName = Country Name (2 letter code) 132 | countryName_default = AU 133 | countryName_min = 2 134 | countryName_max = 2 135 | 136 | stateOrProvinceName = State or Province Name (full name) 137 | stateOrProvinceName_default = Some-State 138 | 139 | localityName = Locality Name (eg, city) 140 | 141 | 0.organizationName = Organization Name (eg, company) 142 | 0.organizationName_default = Internet Widgits Pty Ltd 143 | 144 | # we can do this but it is not needed normally :-) 145 | #1.organizationName = Second Organization Name (eg, company) 146 | #1.organizationName_default = World Wide Web Pty Ltd 147 | 148 | organizationalUnitName = Organizational Unit Name (eg, section) 149 | #organizationalUnitName_default = 150 | 151 | commonName = Common Name (eg, YOUR name) 152 | commonName_max = 64 153 | 154 | emailAddress = Email Address 155 | emailAddress_max = 64 156 | 157 | # SET-ex3 = SET extension number 3 158 | 159 | [ req_attributes ] 160 | challengePassword = A challenge password 161 | challengePassword_min = 4 162 | challengePassword_max = 20 163 | 164 | unstructuredName = An optional company name 165 | 166 | [ usr_cert ] 167 | 168 | # These extensions are added when 'ca' signs a request. 169 | 170 | # This goes against PKIX guidelines but some CAs do it and some software 171 | # requires this to avoid interpreting an end user certificate as a CA. 172 | 173 | basicConstraints=CA:FALSE 174 | 175 | # Here are some examples of the usage of nsCertType. If it is omitted 176 | # the certificate can be used for anything *except* object signing. 177 | 178 | # This is OK for an SSL server. 179 | # nsCertType = server 180 | 181 | # For an object signing certificate this would be used. 182 | # nsCertType = objsign 183 | 184 | # For normal client use this is typical 185 | # nsCertType = client, email 186 | 187 | # and for everything including object signing: 188 | # nsCertType = client, email, objsign 189 | 190 | # This is typical in keyUsage for a client certificate. 191 | # keyUsage = nonRepudiation, digitalSignature, keyEncipherment 192 | 193 | # This will be displayed in Netscape's comment listbox. 194 | nsComment = "OpenSSL Generated Certificate" 195 | 196 | # PKIX recommendations harmless if included in all certificates. 197 | subjectKeyIdentifier=hash 198 | authorityKeyIdentifier=keyid,issuer 199 | 200 | # This stuff is for subjectAltName and issuerAltname. 201 | # Import the email address. 202 | # subjectAltName=email:copy 203 | # An alternative to produce certificates that aren't 204 | # deprecated according to PKIX. 205 | # subjectAltName=email:move 206 | 207 | # Copy subject details 208 | # issuerAltName=issuer:copy 209 | 210 | #nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem 211 | #nsBaseUrl 212 | #nsRevocationUrl 213 | #nsRenewalUrl 214 | #nsCaPolicyUrl 215 | #nsSslServerName 216 | 217 | # This is required for TSA certificates. 218 | # extendedKeyUsage = critical,timeStamping 219 | 220 | [ v3_req ] 221 | 222 | # Extensions to add to a certificate request 223 | 224 | basicConstraints = CA:FALSE 225 | keyUsage = nonRepudiation, digitalSignature, keyEncipherment 226 | 227 | [ v3_ca ] 228 | 229 | 230 | # Extensions for a typical CA 231 | 232 | 233 | # PKIX recommendation. 234 | 235 | subjectKeyIdentifier=hash 236 | 237 | authorityKeyIdentifier=keyid:always,issuer 238 | 239 | # This is what PKIX recommends but some broken software chokes on critical 240 | # extensions. 241 | #basicConstraints = critical,CA:true 242 | # So we do this instead. 243 | basicConstraints = CA:true 244 | 245 | # Key usage: this is typical for a CA certificate. However since it will 246 | # prevent it being used as an test self-signed certificate it is best 247 | # left out by default. 248 | # keyUsage = cRLSign, keyCertSign 249 | 250 | # Some might want this also 251 | # nsCertType = sslCA, emailCA 252 | 253 | # Include email address in subject alt name: another PKIX recommendation 254 | # subjectAltName=email:copy 255 | # Copy issuer details 256 | # issuerAltName=issuer:copy 257 | 258 | # DER hex encoding of an extension: beware experts only! 259 | # obj=DER:02:03 260 | # Where 'obj' is a standard or added object 261 | # You can even override a supported extension: 262 | # basicConstraints= critical, DER:30:03:01:01:FF 263 | 264 | [ crl_ext ] 265 | 266 | # CRL extensions. 267 | # Only issuerAltName and authorityKeyIdentifier make any sense in a CRL. 268 | 269 | # issuerAltName=issuer:copy 270 | authorityKeyIdentifier=keyid:always 271 | 272 | [ proxy_cert_ext ] 273 | # These extensions should be added when creating a proxy certificate 274 | 275 | # This goes against PKIX guidelines but some CAs do it and some software 276 | # requires this to avoid interpreting an end user certificate as a CA. 277 | 278 | basicConstraints=CA:FALSE 279 | 280 | # Here are some examples of the usage of nsCertType. If it is omitted 281 | # the certificate can be used for anything *except* object signing. 282 | 283 | # This is OK for an SSL server. 284 | # nsCertType = server 285 | 286 | # For an object signing certificate this would be used. 287 | # nsCertType = objsign 288 | 289 | # For normal client use this is typical 290 | # nsCertType = client, email 291 | 292 | # and for everything including object signing: 293 | # nsCertType = client, email, objsign 294 | 295 | # This is typical in keyUsage for a client certificate. 296 | # keyUsage = nonRepudiation, digitalSignature, keyEncipherment 297 | 298 | # This will be displayed in Netscape's comment listbox. 299 | nsComment = "OpenSSL Generated Certificate" 300 | 301 | # PKIX recommendations harmless if included in all certificates. 302 | subjectKeyIdentifier=hash 303 | authorityKeyIdentifier=keyid,issuer 304 | 305 | # This stuff is for subjectAltName and issuerAltname. 306 | # Import the email address. 307 | # subjectAltName=email:copy 308 | # An alternative to produce certificates that aren't 309 | # deprecated according to PKIX. 310 | # subjectAltName=email:move 311 | 312 | # Copy subject details 313 | # issuerAltName=issuer:copy 314 | 315 | #nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem 316 | #nsBaseUrl 317 | #nsRevocationUrl 318 | #nsRenewalUrl 319 | #nsCaPolicyUrl 320 | #nsSslServerName 321 | 322 | # This really needs to be in place for it to be a proxy certificate. 323 | proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:3,policy:foo 324 | 325 | #################################################################### 326 | [ tsa ] 327 | 328 | default_tsa = tsa_config1 # the default TSA section 329 | 330 | [ tsa_config1 ] 331 | 332 | # These are used by the TSA reply generation only. 333 | dir = ./demoCA # TSA root directory 334 | serial = $dir/tsaserial # The current serial number (mandatory) 335 | crypto_device = builtin # OpenSSL engine to use for signing 336 | signer_cert = $dir/tsacert.pem # The TSA signing certificate 337 | # (optional) 338 | certs = $dir/cacert.pem # Certificate chain to include in reply 339 | # (optional) 340 | signer_key = $dir/private/tsakey.pem # The TSA private key (optional) 341 | 342 | default_policy = tsa_policy1 # Policy if request did not specify it 343 | # (optional) 344 | other_policies = tsa_policy2, tsa_policy3 # acceptable policies (optional) 345 | digests = md5, sha1 # Acceptable message digests (mandatory) 346 | accuracy = secs:1, millisecs:500, microsecs:100 # (optional) 347 | clock_precision_digits = 0 # number of digits after dot. (optional) 348 | ordering = yes # Is ordering defined for timestamps? 349 | # (optional, default: no) 350 | tsa_name = yes # Must the TSA name be included in the reply? 351 | # (optional, default: no) 352 | ess_cert_id_chain = no # Must the ESS cert id chain be included? 353 | # (optional, default: no) 354 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Siri Proxy 2 | ========== 3 | 4 | SiriProxy and iOS 7 5 | ------------------- 6 | 7 | ***SiriProxy does not (at this time) work with iOS 7***. Significant changes made to the Siri protocol stack have rendered SiriProxy inoperable with iOS 7. Some of the changes are easy to patch, others may wind up requiring significant work. See [#542](https://github.com/plamoni/SiriProxy/issues/542) for ongoing discussion regarding the effort to make SiriProxy work with iOS 7. However, SiriProxy may *never* support iOS 7. So if SiriProxy is important, you should avoid upgrading your device. 8 | 9 | 10 | About 11 | ----- 12 | Siri Proxy is a proxy server for Apple's Siri "assistant." The idea is to allow for the creation of custom handlers for different actions. This can allow developers to easily add functionality to Siri. 13 | 14 | The main example I provide is a plugin to control [my thermostat](http://www.radiothermostat.com/latestnews.html#advanced) with Siri. It responds to commands such as, "What's the status of the thermostat?", or "Set the thermostat to 68 degrees", or even "What's the inside temperature?" 15 | 16 | Notice About Plugins 17 | -------------------- 18 | 19 | We recently changed the way plugins work very significantly. That being the case, your old plugins won't work. 20 | 21 | New plugins should be independent Gems. Take a look at the included [example plugin](https://github.com/plamoni/SiriProxy/tree/master/plugins/siriproxy-example) for some inspiration. We will try to keep that file up to date with the latest features. 22 | 23 | The State of This Project 24 | ------------------------- 25 | 26 | Please remember that this project is super-pre-alpha right now. If you're not a developer with a good bit of experience with networks, you're probably not even going to get the proxy running. But if you do (we are willing to help to an extent, check the IRC chat and my Twitter feed [@plamoni](http://www.twitter.com/plamoni)), then test out building a plugin. It's very easy to do and takes almost no time at all for most experienced developers. Check the demo videos and other plugins below for inspiration! 27 | 28 | 29 | Find us on IRC 30 | -------------- 31 | 32 | We now have an IRC channel. Check out the #SiriProxy channel on irc.freenode.net. 33 | 34 | Demo Video 35 | ----------- 36 | 37 | See the system in action here: [http://www.youtube.com/watch?v=AN6wy0keQqo](http://www.youtube.com/watch?v=AN6wy0keQqo) 38 | 39 | More Demo Videos and Other Plugins 40 | ---------------------------------- 41 | 42 | For a list of current plugins and some more demo videos, check the [Plugins page](https://github.com/plamoni/SiriProxy/wiki/Plugins) on the wiki. 43 | 44 | Set-up Instructions 45 | ------------------- 46 | 47 | **NEW Instructions for 0.5.0** 48 | 49 | Note that the installation instructions have changed. It's no longer necessary to install dnsmasq. Also, SiriProxy is available via rubygems for easy installation. 50 | 51 | **Set up RVM and Ruby 2.0.0** 52 | 53 | If you don't already have Ruby 2.0.0 (or at least 1.9.3) installed through RVM, please do so in order to make sure you can follow the steps later. Experts can ignore this. If you're unsure, follow these directions carefully: 54 | 55 | 1. Install pre-requisites. Veries by system. For a fresh Ubuntu 12.10 install, these seem to be good: 56 | 57 | `sudo apt-get install libxslt1.1 libxslt-dev xvfb build-essential git-core curl libyaml-dev libssl-dev` 58 | 59 | 2. Download and install RVM (if you don't have it already): 60 | * Download/install RVM: 61 | `curl -L https://get.rvm.io | bash -s stable --ruby` 62 | * Update .bashrc: 63 | `echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc` 64 | `echo 'export PATH=$HOME/.rvm/bin:$PATH' >> ~/.bashrc` 65 | * Activate changes: 66 | `. ~/.bashrc` 67 | 68 | 3. Install Ruby 2.0.0 (if you don't have it already): 69 | 70 | `rvm install 2.0.0` 71 | 72 | 4. Set RVM to use/default to 2.0.0: 73 | 74 | `rvm use 2.0.0 --default` 75 | 76 | **Set up SiriProxy** 77 | 78 | 1. Install SiriProxy Gem 79 | 80 | `gem install siriproxy` 81 | 82 | 2. Create `~/.siriproxy` directory 83 | 84 | `mkdir ~/.siriproxy` 85 | 86 | 3. Generate Certificates 87 | 88 | `siriproxy gencerts` 89 | 90 | 4. Transfer certificate to your phone (it will be located at `~/.siriproxy/ca.pem`, email it to your phone) 91 | 5. Start SiriProxy (`XXX.XXX.XXX.XXX` should be replaced with your server's IP address, e.g. `192.168.1.100`), `nobody` can be replaced with any un-privileged user. 92 | 93 | `rvmsudo siriproxy server -d XXX.XXX.XXX.XXX -u nobody` 94 | 95 | 6. Tell your phone to use your SiriProxy server as its DNS server (under your Wifi settings) 96 | 7. Test that the server is running by saying "Test Siri Proxy" to your phone. 97 | 98 | FAQ 99 | --- 100 | 101 | **Will this let me run Siri on my none Siri devices (eg. iPhone 4, iPod Touch, iPhone 3G, Microwave, etc)?** 102 | 103 | No. Please stop asking. 104 | 105 | **What is your opinion on h1siri, public SiriProxy servers, and other Siri "ports"?** 106 | 107 | Glad you asked! Watch this: [http://youtu.be/Y_Q6PfxBSbA](http://youtu.be/Y_Q6PfxBSbA) 108 | 109 | **How do I generate the certificate?** 110 | 111 | Certificates can now be easily generated using `siriproxy gencerts` once you install the SiriProxy gem. See the instructions above. 112 | 113 | **How do I set up a DNS server to forward Guzzoni.apple.com traffic to my computer?** 114 | 115 | Check out my video on this: 116 | 117 | [http://www.youtube.com/watch?v=a9gO4L0U59s](http://www.youtube.com/watch?v=a9gO4L0U59s) 118 | 119 | **Will this work outside my home network?** 120 | 121 | No, it won't. But, as suggested by STBullard on YouTube, you COULD VPN into your home network from outside your house in order to make this work. That would not require a jailbreak. Of course, it also means ALL your traffic gets funneled through your home network. The nice thing about adding an entry to your /etc/hosts file (on a jailbroken phone) is that it funnels only Siri traffic through your home network, and not all your traffic. 122 | 123 | **Can you provide me with an iPhone 4S UDID?** 124 | 125 | No. Don't even ask. 126 | 127 | **I'm getting a bunch of "[Info - Guzzoni] Object: SessionValidationFailed" messages. What's wrong?!** 128 | 129 | You're probably using a device without an official Siri. You need to be using an official Siri device (or have a UDID you can sub in) in order to make use of SiriProxy. Sorry, this is not designed to be a way around that limitation. (Thanks to [@brownie545](http://www.twitter.com/brownie545) for providing information on what happens when you use a unofficial Siri-devices) 130 | 131 | **How do I remove the certificate from my iPhone when I'm done?** 132 | 133 | Just go into your phone's Settings app, then go to "General->Profiles." Your CA will probably be the only thing listed under "Configuration Profiles." It will be listed as "SiriProxyCA" Just click it and click "Remove" and it will be removed. (Thanks to [@tidegu](http://www.twitter.com/tidegu) for asking!) 134 | 135 | **Does this require a jailbreak?** 136 | 137 | No. The only action you need to take on the phone is to install the root CA's public key. 138 | 139 | **Using Siri causes a whole bunch of the following messages, followed by SiriProxy crashing!** 140 | 141 | Create server for iPhone connection 142 | start conn #, @zip_stream=#, @consumed_ace=false, @name="iPhone", @ssled=false> 143 | [Info - Plugin Manager] Plugins loaded: [#>] 144 | 145 | This is actually really common (but can be tricky to fix). The problem is that your SiriProxy server is using your tainted DNS server. So what happens is this: 146 | 147 | 1. Your iPhone connects to your server, thinking it's `guzzoni.apple.com` 148 | 2. Your server connects to *itself*, thinking that *it's* `guzzoni.apple.com` 149 | 3. Your server thinks another iPhone has connected, and repeats step 2. 150 | 151 | This goes on forever, or at least a second or two before the server up and dies. The trick is that you need to make sure your server isn't connecting to itself when it requests a connection to `guzzoni.apple.com`. This is actually the default behavior, but many people accidentally mess things up by either (1) setting up their server to use itself as a DNS server (while using dnsmasq to taint the entry for `guzzoni.apple.com`), or (2) putting their server on a network where the DNS server issued by DHCP is tainted to point to the wrong `guzzoni.apple.com`. 152 | 153 | So the fix for this varies based on your setup, but one possible fix for scenario 1 (above) on many *NIX machines is to edit `/etc/resolve.conf` and change the `nameserver` entry to `8.8.8.8` (one of Google's public DNS servers). Do this and then restart networking (or just restart the computer) and things should start working. 154 | 155 | Your network setup may be different. This is THE most complex part of setting up SiriProxy (getting DNS set up correctly). So once you have this working, you are probably home free. Keep with it, good luck, and have fun! 156 | 157 | 158 | Running SiriProxy as an unprivileged user 159 | ----------------------------------------- 160 | 161 | This used to be really hard. Now it's very easy. Just run `rvmsudo siriproxy server -u USER` and SiriProxy will set it's userid to `USER`'s userid. 162 | 163 | Running SiriProxy via Upstart 164 | ----------------------------- 165 | 166 | **NOTE: This section needs to be updated.** It was written before some of the newer features for SiriProxy. It should be much simpler now. 167 | 168 | Here's the upstart script I created for my home SiriProxy server. It respawns on a crash because SiriProxy is delicate and likes to crash. My server is running BackTrack 5 (a derivative of Ubuntu 10.04, I believe) and I use it as my wireless access point, making it an obvious location for SiriProxy: 169 | 170 | description "SiriProxy server" 171 | 172 | #Not sure if this is right, but it seems to work. 173 | start on (started networking 174 | and filesystem) 175 | 176 | stop on runlevel [!023456] 177 | 178 | respawn 179 | 180 | exec start-stop-daemon --start --exec /home/siriproxy/src/SiriProxy/siriproxy2000.sh 181 | 182 | Here are the contents of `siriproxy2000.sh` (as referenced above): 183 | 184 | #!/bin/bash 185 | 186 | #make sure that rvm is set up 187 | [[ -s "/home/siriproxy/.rvm/scripts/rvm" ]] && . "/home/siriproxy/.rvm/scripts/rvm" 188 | 189 | #feel free to insert logging if needed. 190 | siriproxy server --port 2000 > /dev/null 2>&1 191 | 192 | Note that I run my server on port 2000 as the siriproxy user. See the comments above about running as an unprivileged user. 193 | 194 | 195 | Acknowledgements 196 | ---------------- 197 | I really can't give enough credit to [Applidium](http://applidium.com/en/news/cracking_siri/) and the [tools they created](https://github.com/applidium/Cracking-Siri). While I've been toying with Siri for a while, their proof of concept for intercepting and interpreting the Siri protocol was invaluable. Although all the code included in the project (so far) is my own, much of the base logic behind my code is based on the sample code they provided. They do great work. 198 | 199 | I also want to give a shout-out to [Arch Reactor](http://www.archreactor.org) - my local Hackerspace. Hackerspaces are a fantastic place to go learn about stuff like this. I was able to get some help from folks there, and more importantly, I got encouragement to do stuff like this. Check [Hackerspaces.org](http://www.hackerspaces.org) for a hackerspace in your area and make sure to check it out! 200 | 201 | Regarding Licensing 202 | ------------------- 203 | 204 | It's a pain. MIT seems nice. Go hunt through the commit history if you're interested in knowing about SiriProxy's long and frustrating licensing history. 205 | 206 | License (MIT) 207 | ------------- 208 | 209 | SiriProxy - A tampering proxy server for the Siri (Ace) Protocol. 210 | Copyright (c) 2013 Pete Lamonica 211 | 212 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 213 | 214 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 215 | 216 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 217 | 218 | Disclaimer 219 | ---------- 220 | I'm not affiliated with Apple in any way. They don't endorse this application. They own all the rights to Siri (and all associated trademarks). 221 | 222 | This software is provided as-is with no warranty whatsoever. Apple could do things to block this kind of behavior if they want. Also, if you cause problems (by sending lots of trash to the Guzzoni servers or anything), I fully support Apple's right to ban your UDID (making your phone unable to use Siri). They can, and I wouldn't blame them if they do. 223 | 224 | I'm a huge fan of Apple and the work that they do. Siri is a very cool feature and I'm pretty excited to explore it and add functionality. Please refrain from using this software for anything malicious. 225 | 226 | Also, this is my first project done in Ruby. Please don't be too critical of my code. 227 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . --------------------------------------------------------------------------------