Skip to content

Commit

Permalink
Merge branch 'refs/heads/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
plamoni committed Dec 7, 2011
2 parents 008eccd + b5ed673 commit b9228ab
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 13 deletions.
1 change: 1 addition & 0 deletions .rvmrc
@@ -0,0 +1 @@
rvm 1.9.3@SiriProxy --create
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -19,7 +19,7 @@ if config.plugins
if plugin.is_a? String if plugin.is_a? String
gem "siriproxy-#{plugin.downcase}" gem "siriproxy-#{plugin.downcase}"
else else
gem "siriproxy-#{plugin['gem'] || plugin['name'].downcase}", :path => plugin['path'], :git => plugin['git'], :require => plugin['require'] gem "siriproxy-#{plugin['gem'] || plugin['name'].downcase}", :path => plugin['path'], :git => plugin['git'], :branch => plugin['branch'], :require => plugin['require']
end end
end end
end end
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -85,7 +85,7 @@ Clone this repo locally, then navigate into the SiriProxy directory (the root of
`siriproxy bundle` `siriproxy bundle`
8. Start SiriProxy (must start as root because it uses a port < 1024): 8. Start SiriProxy (must start as root because it uses a port < 1024):
`rvmsudo siriproxy server` `rvmsudo siriproxy server`
9. Test that the server is running by saying "Text Siri Proxy" to your phone. 9. Test that the server is running by saying "Test Siri Proxy" to your phone.


Note: on some machines, rvmsudo changes "`~`" to "`/root/`". This means that you may need to symlink your "`.siriproxy`" directory to "`/root/`" in order to get the application to work: Note: on some machines, rvmsudo changes "`~`" to "`/root/`". This means that you may need to symlink your "`.siriproxy`" directory to "`/root/`" in order to get the application to work:


Expand Down
6 changes: 5 additions & 1 deletion lib/siriproxy/command_line.rb
Expand Up @@ -98,9 +98,10 @@ def start_server
end end


def gen_certs def gen_certs
ca_name = @ca_name ||= ""
command = File.join(File.dirname(__FILE__), '..', "..", "scripts", 'gen_certs.sh') command = File.join(File.dirname(__FILE__), '..', "..", "scripts", 'gen_certs.sh')
sp_root = File.join(File.dirname(__FILE__), '..', "..") sp_root = File.join(File.dirname(__FILE__), '..', "..")
puts `#{command} "#{sp_root}"` puts `#{command} "#{sp_root}" "#{ca_name}"`
end end


def update(directory=nil) def update(directory=nil)
Expand Down Expand Up @@ -151,6 +152,9 @@ def parse_options
opts.on('-b', '--branch BRANCH', '[update] Choose the branch to update from (default: master)') do |branch| opts.on('-b', '--branch BRANCH', '[update] Choose the branch to update from (default: master)') do |branch|
@branch = branch @branch = branch
end end
opts.on('-n', '--name CA_NAME', '[gencerts] Define a common name for the CA (default: "SiriProxyCA")') do |ca_name|
@ca_name = ca_name
end
opts.on_tail('-v', '--version', ' show version') do opts.on_tail('-v', '--version', ' show version') do
require "siriproxy/version" require "siriproxy/version"
puts "SiriProxy version #{SiriProxy::VERSION}" puts "SiriProxy version #{SiriProxy::VERSION}"
Expand Down
14 changes: 12 additions & 2 deletions lib/siriproxy/connection.rb
Expand Up @@ -96,6 +96,11 @@ def has_next_object?
return false if unzipped_input.empty? #empty return false if unzipped_input.empty? #empty
unpacked = unzipped_input[0...5].unpack('H*').first unpacked = unzipped_input[0...5].unpack('H*').first
return true if(unpacked.match(/^0[34]/)) #Ping or pong return true if(unpacked.match(/^0[34]/)) #Ping or pong

if unpacked.match(/^[0-9][15-9]/)
puts "ROGUE PACKET!!! WHAT IS IT?! TELL US!!! IN IRC!! COPY THE STUFF FROM BELOW"
puts unpacked.to_hex
end
objectLength = unpacked.match(/^0200(.{6})/)[1].to_i(16) objectLength = unpacked.match(/^0200(.{6})/)[1].to_i(16)
return ((objectLength + 5) < unzipped_input.length) #determine if the length of the next object (plus its prefix) is less than the input buffer return ((objectLength + 5) < unzipped_input.length) #determine if the length of the next object (plus its prefix) is less than the input buffer
end end
Expand Down Expand Up @@ -174,7 +179,12 @@ def prep_received_object(object)
pp object if $LOG_LEVEL > 3 pp object if $LOG_LEVEL > 3


#keeping this for filters #keeping this for filters
object = received_object(object) new_obj = received_object(object)
if new_obj == nil
puts "[Info - Dropping Object from #{self.name}] #{object["class"]}" if $LOG_LEVEL > 1
pp object if $LOG_LEVEL > 3
return nil
end


#block the rest of the session if a plugin claims ownership #block the rest of the session if a plugin claims ownership
speech = SiriProxy::Interpret.speech_recognized(object) speech = SiriProxy::Interpret.speech_recognized(object)
Expand All @@ -193,7 +203,7 @@ def prep_received_object(object)


#Stub -- override in subclass #Stub -- override in subclass
def received_object(object) def received_object(object)

object object
end end


Expand Down
4 changes: 2 additions & 2 deletions lib/siriproxy/connection/guzzoni.rb
Expand Up @@ -13,8 +13,8 @@ def connection_completed
end end


def received_object(object) def received_object(object)
object return plugin_manager.process_filters(object, :from_guzzoni)

#plugin_manager.object_from_guzzoni(object, self) #plugin_manager.object_from_guzzoni(object, self)
end end


Expand Down
3 changes: 2 additions & 1 deletion lib/siriproxy/connection/iphone.rb
Expand Up @@ -24,7 +24,8 @@ def ssl_handshake_completed
end end


def received_object(object) def received_object(object)
object return plugin_manager.process_filters(object, :from_iphone)

#plugin_manager.object_from_client(object, self) #plugin_manager.object_from_client(object, self)
end end
end end
34 changes: 33 additions & 1 deletion lib/siriproxy/plugin.rb
Expand Up @@ -6,8 +6,9 @@ def request_completed
end end


#use send_object(object, target: :guzzoni) to send to guzzoni #use send_object(object, target: :guzzoni) to send to guzzoni
def send_object(object, options={:target => :iphone}) def send_object(object, options={})
(object = object.to_hash) rescue nil #convert SiriObjects to a hash (object = object.to_hash) rescue nil #convert SiriObjects to a hash
options[:target] = options[:target] ||= :iphone


if(options[:target] == :iphone) if(options[:target] == :iphone)
self.manager.guzzoni_conn.inject_object_to_output_stream(object) self.manager.guzzoni_conn.inject_object_to_output_stream(object)
Expand All @@ -19,4 +20,35 @@ def send_object(object, options={:target => :iphone})
def last_ref_id def last_ref_id
self.manager.iphone_conn.last_ref_id self.manager.iphone_conn.last_ref_id
end end

#direction should be :from_iphone, or :from_guzzoni
def process_filters(object, direction)
return nil if object == nil
f = filters[object["class"]]
if(f != nil && (f[:direction] == :both || f[:direction] == direction))
object = instance_exec(object, &f[:block])
end

object
end

class << self
def filter(class_names, options={}, &block)
[class_names].flatten.each do |class_name|
filters[class_name] = {
direction: (options[:direction] ||= :both),
block: block
}
end
end

def filters
@filters ||= {}
end
end

def filters
self.class.filters
end

end end
12 changes: 12 additions & 0 deletions lib/siriproxy/plugin_manager.rb
Expand Up @@ -28,6 +28,18 @@ def load_plugins()
log "Plugins laoded: #{@plugins}" log "Plugins laoded: #{@plugins}"
end end


def process_filters(object, direction)
object_class = object.class #This way, if we change the object class we won't need to modify this code.
plugins.each do |plugin|
#log "Processing filters on #{plugin} for '#{object["class"]}'"
new_obj = plugin.process_filters(object, direction)
object = new_obj if(new_obj == false || new_obj.class == object_class) #prevent accidental poorly formed returns
return nil if object == false #if any filter returns "false," then the object should be dropped
end

return object
end

def process(text) def process(text)
result = super(text) result = super(text)
self.guzzoni_conn.block_rest_of_session if result self.guzzoni_conn.block_rest_of_session if result
Expand Down
2 changes: 1 addition & 1 deletion lib/siriproxy/version.rb
@@ -1,3 +1,3 @@
class SiriProxy class SiriProxy
VERSION = "0.0.1" VERSION = "0.2.3"
end end
15 changes: 14 additions & 1 deletion plugins/siriproxy-example/lib/siriproxy-example.rb
@@ -1,8 +1,9 @@
require 'cora' require 'cora'
require 'siri_objects' require 'siri_objects'
require 'pp'


####### #######
# This is a "hello world" style plugin. It simply intercepts the phrase "text siri proxy" and responds # This is a "hello world" style plugin. It simply intercepts the phrase "test siri proxy" and responds
# with a message about the proxy being up and running (along with a couple other core features). This # with a message about the proxy being up and running (along with a couple other core features). This
# is good base code for other plugins. # is good base code for other plugins.
# #
Expand All @@ -14,6 +15,18 @@ def initialize(config)
#if you have custom configuration options, process them here! #if you have custom configuration options, process them here!
end end


#get the user's location and display it in the logs
#filters are still in their early stages. Their interface may be modified
filter "SetRequestOrigin", direction: :from_iphone do |object|
puts "[Info - User Location] lat: #{object["properties"]["latitude"]}, long: #{object["properties"]["longitude"]}"

#Note about returns from filters:
# - Return false to stop the object from being forwarded
# - Return a Hash to substitute or update the object
# - Return nil (or anything not a Hash or false) to have the object forwarded (along with any
# modifications made to it)
end

listen_for /test siri proxy/i do listen_for /test siri proxy/i do
say "Siri Proxy is up and running!" #say something to the user! say "Siri Proxy is up and running!" #say something to the user!


Expand Down
7 changes: 6 additions & 1 deletion scripts/gen_certs.sh
@@ -1,13 +1,18 @@
#!/usr/bin/env bash #!/usr/bin/env bash


commonName=$2

if [ "${commonName}" == "" ]
then
commonName="SiriProxyCA"
fi


# Feel free to change any of these defaults # Feel free to change any of these defaults
countryName="US" countryName="US"
stateOrProvinceName="Missouri" stateOrProvinceName="Missouri"
localityName="" localityName=""
organizationName="Siri Proxy" organizationName="Siri Proxy"
organizationalUnitName="" organizationalUnitName=""
commonName="SiriProxyCA"
emailAddress="" emailAddress=""


#You probably don't need to modify these unless you know what you're doing. #You probably don't need to modify these unless you know what you're doing.
Expand Down
5 changes: 4 additions & 1 deletion scripts/openssl.cnf
Expand Up @@ -36,6 +36,7 @@ tsa_policy3 = 1.2.3.4.5.7
[ ca ] [ ca ]
default_ca = CA_default # The default ca section default_ca = CA_default # The default ca section



#################################################################### ####################################################################
[ CA_default ] [ CA_default ]


Expand Down Expand Up @@ -72,7 +73,7 @@ cert_opt = ca_default # Certificate field options


default_days = 365 # how long to certify for default_days = 365 # how long to certify for
default_crl_days= 30 # how long before next CRL default_crl_days= 30 # how long before next CRL
default_md = default # use public key default MD default_md = sha1 # use public key default MD
preserve = no # keep passed DN ordering preserve = no # keep passed DN ordering


# A few difference way of specifying how similar the request should look # A few difference way of specifying how similar the request should look
Expand Down Expand Up @@ -108,6 +109,8 @@ default_keyfile = privkey.pem
distinguished_name = req_distinguished_name distinguished_name = req_distinguished_name
attributes = req_attributes attributes = req_attributes
x509_extensions = v3_ca # The extentions to add to the self signed cert x509_extensions = v3_ca # The extentions to add to the self signed cert
default_md = sha1



# Passwords for private keys if not present they will be prompted for # Passwords for private keys if not present they will be prompted for
# input_password = secret # input_password = secret
Expand Down

0 comments on commit b9228ab

Please sign in to comment.