Skip to content

Commit

Permalink
If the trust store is new, create a fresh new
Browse files Browse the repository at this point in the history
database
  • Loading branch information
yageek committed Apr 15, 2015
1 parent 7db28ca commit d3ffbe8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
3 changes: 0 additions & 3 deletions .travis.yml

This file was deleted.

11 changes: 5 additions & 6 deletions lib/iostrust.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions lib/iostrust/simulator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Iostrust
class Simulator

def initialize(path)
@path = path
@path = File.join(path, 'Keychains/TrustStore.sqlite3')
end

def backup_path
Expand All @@ -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)
Expand All @@ -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"
Expand Down
8 changes: 0 additions & 8 deletions spec/certificate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d3ffbe8

Please sign in to comment.