Skip to content

Commit 3ebf579

Browse files
committed
Add basic methods
0 parents  commit 3ebf579

11 files changed

+208
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/.bundle/
2+
/.yardoc
3+
/Gemfile.lock
4+
/_yardoc/
5+
/coverage/
6+
/doc/
7+
/pkg/
8+
/spec/reports/
9+
/tmp/

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: ruby
2+
rvm:
3+
- 2.1.5

Gemfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in iostrust.gemspec
4+
gemspec
5+
6+
7+
group :development do
8+
gem 'bacon'
9+
gem 'rake'
10+
end

README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Iostrust
2+
3+
This gems allows you to add trust certificate into the ios simulators.
4+
5+
The work is based on the *IOSTrustStore Structure* specification file
6+
from https://https://github.com/ADVTOOLS/ADVTrustStore
7+
8+
## Installation
9+
10+
```ruby
11+
gem 'iostrust'
12+
```
13+
14+
# Usage
15+
16+
17+
18+
19+
20+
21+

Rakefile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require "bundler/gem_tasks"
2+
3+
namespace :spec do
4+
desc 'All specs'
5+
task :all do
6+
sh "bundle exec bacon #{FileList['spec/*.rb'].join(' ')}"
7+
end
8+
end
9+

iostrust.gemspec

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# coding: utf-8
2+
lib = File.expand_path('../lib', __FILE__)
3+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4+
require 'iostrust/version'
5+
6+
Gem::Specification.new do |spec|
7+
spec.name = "iostrust"
8+
spec.version = Iostrust::VERSION
9+
spec.authors = ["Yannick heinrich"]
10+
spec.email = ["[email protected]"]
11+
12+
spec.summary = %q{TODO: Write a short summary, because Rubygems requires one.}
13+
spec.description = %q{TODO: Write a longer description or delete this line.}
14+
spec.homepage = "TODO: Put your gem's website or public repo URL here."
15+
16+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17+
spec.bindir = "exe"
18+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19+
spec.require_paths = ["lib"]
20+
21+
if spec.respond_to?(:metadata)
22+
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
23+
end
24+
25+
spec.add_dependency "commander", "~> 4.3"
26+
spec.add_dependency "commander", "~> 4.3"
27+
spec.add_dependency "sqlite3"
28+
end

lib/iostrust.rb

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require "iostrust/version"
2+
require "iostrust/simulator"
3+
4+
module Iostrust
5+
private
6+
TRUSTED_STORE_SQLITE = 'TrustStore.sqlite3'
7+
SIMULATOR_HOME_LIBRARY_PATTERNS = [
8+
"Application Support/iPhone Simulator/3.*/Library/Keychains/",
9+
"Application Support/iPhone Simulator/4.*/Library/Keychains/",
10+
"Developer/CoreSimulator/Devices/**/data/Library/Keychains/",
11+
"Application Support/iPhone Simulator/User/Library/Keychains/"
12+
]
13+
14+
def self.path_for_pattern(pattern)
15+
return File.join(Dir.home, 'Library', pattern, TRUSTED_STORE_SQLITE)
16+
end
17+
18+
public
19+
def self.simulators
20+
simulators = []
21+
SIMULATOR_HOME_LIBRARY_PATTERNS.each do |pattern|
22+
found_paths = Dir.glob(path_for_pattern(pattern))
23+
simulators.push(*found_paths)
24+
end
25+
simulators
26+
end
27+
28+
end

lib/iostrust/certificate.rb

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require 'openssl'
2+
require 'digest/sha1'
3+
4+
module Iostrust
5+
class Certificate
6+
7+
@@PLIST = <<PLIST
8+
<?xml version="1.0" encoding="UTF-8"?>
9+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
10+
<plist version="1.0">
11+
<array/>
12+
</plist>
13+
PLIST
14+
15+
def initialize(cert_path)
16+
raw_cert = File.read cert_path
17+
@cert = OpenSSL::X509::Certificate.new raw_cert
18+
end
19+
20+
def tset
21+
return @@PLIST
22+
end
23+
24+
def data
25+
@cert.to_der
26+
end
27+
28+
def sha1
29+
str = Digest::SHA1.hexdigest(data)
30+
[str].pack('H*')
31+
end
32+
33+
def subj
34+
subj = ""
35+
asn_subject = OpenSSL::ASN1.decode(@cert.subject)
36+
asn_subject.each do |asn_sub|
37+
subj << asn_sub.to_der
38+
end
39+
subj
40+
end
41+
42+
end
43+
end
44+
45+
46+

lib/iostrust/version.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Iostrust
2+
VERSION = "0.1.0"
3+
end

spec/cert.crt

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIFhDCCBGygAwIBAgIGAUx02NHzMA0GCSqGSIb3DQEBCwUAMIHGMVgwVgYDVQQDDE9DaGFybGVz
3+
IFByb3h5IEN1c3RvbSBSb290IENlcnRpZmljYXRlIChidWlsdCBvbiBPV1RHVkFPTFQwMjkubG9j
4+
YWwsIDEgQXByIDIwMTUpMSQwIgYDVQQLDBtodHRwOi8vY2hhcmxlc3Byb3h5LmNvbS9zc2wxETAP
5+
BgNVBAoMCFhLNzIgTHRkMREwDwYDVQQHDAhBdWNrbGFuZDERMA8GA1UECAwIQXVja2xhbmQxCzAJ
6+
BgNVBAYTAk5aMB4XDTAwMDEwMTAwMDAwMFoXDTQ0MDUyODExNTgyOFowgcYxWDBWBgNVBAMMT0No
7+
YXJsZXMgUHJveHkgQ3VzdG9tIFJvb3QgQ2VydGlmaWNhdGUgKGJ1aWx0IG9uIE9XVEdWQU9MVDAy
8+
OS5sb2NhbCwgMSBBcHIgMjAxNSkxJDAiB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m7nLyl+2U2rA4Orc
22+
MA0GCSqGSIb3DQEBCwUAA4IBAQALnk11QlNbTA8imKo1plzKjFwl3k7IH1zh4i+//B4Hu5oULyVv
23+
V03zaAmOqipKH0uF2gGXBC4Zzqd0b6KxhCVT3qlx+2bur9i+EeuS37IvsDUVOwq/oc5aFPyC5MOp
24+
xAh90dEZnR9CKdG60CN3pxeKoX/LXJeAlJDdU2Y2xGXd057vZ9+RjgvwehJn82P3uTVQTRp+xoHt
25+
686/OSmKiaZOmfDedXmsulhzUFP4Vva+6Bfi/jN39gYWGm+fn5wHY760PPzxIIe0sndorwF2dkWf
26+
zX5KlXn8liemqirFVZpCneChwWjoVB5UrK/sWuPqr6EXrjghS+Bfxc9BF/a7Wsf2
27+
-----END CERTIFICATE-----

spec/certificate_spec.rb

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'bacon'
2+
3+
require_relative '../lib/iostrust/certificate'
4+
require_relative '../lib/iostrust/simulator'
5+
require_relative '../lib/iostrust'
6+
7+
describe 'Certificate loading' do
8+
before do
9+
@cert_file_path = File.join(File.dirname(__FILE__), 'cert.crt')
10+
end
11+
it 'should load the certificate' do
12+
cert_file = File.join(File.dirname(__FILE__), 'cert.crt')
13+
@cert = Iostrust::Certificate.new(@cert_file_path)
14+
@cert.should.not.be.nil
15+
end
16+
17+
it 'should add cert to database' do
18+
Iostrust.simulators.each do |sim_path|
19+
sim = Iostrust::Simulator.new(sim_path)
20+
sim.restore
21+
sim.add_cert(@cert)
22+
end
23+
end
24+
end

0 commit comments

Comments
 (0)