diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 884ef18..0000000 --- a/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: ruby -rvm: - - 2.1.5 diff --git a/lib/iostrust.rb b/lib/iostrust.rb index e77c67a..2396b52 100644 --- a/lib/iostrust.rb +++ b/lib/iostrust.rb @@ -4,16 +4,15 @@ module Iostrust private - TRUSTED_STORE_SQLITE = 'TrustStore.sqlite3' SIMULATOR_HOME_LIBRARY_PATTERNS = [ - "Application Support/iPhone Simulator/3.*/Library/Keychains/", - "Application Support/iPhone Simulator/4.*/Library/Keychains/", - "Developer/CoreSimulator/Devices/**/data/Library/Keychains/", - "Application Support/iPhone Simulator/User/Library/Keychains/" + "Application Support/iPhone Simulator/3.*/Library/", + "Application Support/iPhone Simulator/4.*/Library/", + "Developer/CoreSimulator/Devices/**/data/Library/", + "Application Support/iPhone Simulator/User/Library/" ] def self.path_for_pattern(pattern) - return File.join(Dir.home, 'Library', pattern, TRUSTED_STORE_SQLITE) + return File.join(Dir.home, 'Library', pattern) end public diff --git a/lib/iostrust/simulator.rb b/lib/iostrust/simulator.rb index 2f947ce..b1d97ef 100644 --- a/lib/iostrust/simulator.rb +++ b/lib/iostrust/simulator.rb @@ -6,7 +6,7 @@ module Iostrust class Simulator def initialize(path) - @path = path + @path = File.join(path, 'Keychains/TrustStore.sqlite3') end def backup_path @@ -22,12 +22,20 @@ def restore FileUtils.mv(backup_path, @path) end + def add_cert(cert) puts "Start adding to #{@path}:" - puts "Backup" - backup() - puts "Adding #{cert.cert_name}" + keychain_dir = File.dirname(@path) + is_new_db = !Dir.exists?(keychain_dir) + if is_new_db + Dir.mkdir keychain_dir + else + puts "Backup..." + backup() + end + puts "Adding #{cert.cert_name}..." + SQLite3::Database.new @path do |db| sha1 = SQLite3::Blob.new(cert.sha1) @@ -36,6 +44,9 @@ def add_cert(cert) data = SQLite3::Blob.new(cert.data) begin + if is_new_db + db.execute "CREATE TABLE tsettings(sha1 BLOB NOT NULL DEFAULT '',subj BLOB NOT NULL DEFAULT '',tset BLOB,data BLOB,PRIMARY KEY(sha1));" + end db.execute "INSERT INTO 'tsettings' (sha1, subj, tset, data) VALUES(?,?,?,?)", sha1, subj, tset, data rescue SQLite3::ConstraintException => e puts "Certificates was not added : Already presents" diff --git a/spec/certificate_spec.rb b/spec/certificate_spec.rb index 9aeec3f..0a7486e 100644 --- a/spec/certificate_spec.rb +++ b/spec/certificate_spec.rb @@ -13,12 +13,4 @@ @cert = Iostrust::Certificate.new(@cert_file_path) @cert.should.not.be.nil end - - it 'should add cert to database' do - Iostrust.simulators_paths.each do |sim_path| - sim = Iostrust::Simulator.new(sim_path) - sim.restore - sim.add_cert(@cert) - end - end end \ No newline at end of file