security 0.0.1 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '0980117aec9bb1d85ec00fefc9ea234d0f66b7b80d3932e6f90c99d606ed6e96'
4
+ data.tar.gz: 0f49377f8092f1170da75ffda17f65c0213f77bdc1ed371c6993f4b016b4ca9d
5
+ SHA512:
6
+ metadata.gz: 5899c11de7a95d4babea7edfcdaaa469dbbec27edd2f746afbc276bda596c54f17641db99aed2e362acac66b842c313b29b2345526d4eb8edba228f61d2486f0
7
+ data.tar.gz: '08f05552094356cdbe5841deee2316f4ba7ab080026b4a7a77771ae00ae9f7c0920cc9a4946f1bb8c8d4b1523237e4131041a331c69c44f7a0fab32402b44a62'
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source :rubygems
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
data/Gemfile.lock CHANGED
@@ -1,18 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- security (0.0.1)
4
+ security (0.1.4)
5
5
 
6
6
  GEM
7
- remote: http://rubygems.org/
7
+ remote: https://rubygems.org/
8
8
  specs:
9
- rake (0.9.2.2)
10
- rspec (0.6.4)
9
+ rake (12.3.3)
11
10
 
12
11
  PLATFORMS
13
12
  ruby
14
13
 
15
14
  DEPENDENCIES
16
- rake (~> 0.9.2)
17
- rspec (~> 0.6.1)
15
+ rake (~> 12.3, >= 12.3.3)
18
16
  security!
17
+
18
+ BUNDLED WITH
19
+ 2.1.4
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Mattt Thompson (http://mattt.me/)
1
+ Copyright (c) 2012 – 2021 Mattt (https://mat.tt/)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,24 +1,23 @@
1
1
  # Security
2
- **Library for interacting with the Mac OS X Keychain**
3
2
 
4
- > This library currently only implements the necessary commands for password management for [Cupertino](https://github.com/mattt/cupertino). As such, some methods are stubbed out to raise `NotImplementedError`.
3
+ **A library for interacting with the macOS Keychain**
4
+
5
+ > This library implements only the commands necessary for password management in
6
+ > [Cupertino](https://github.com/mattt/cupertino).
7
+ > As such, some methods are stubbed out to raise `NotImplementedError`.
5
8
 
6
9
  ## Usage
7
10
 
8
11
  ```ruby
9
- Security::Keychain::default_keychain.filename #=> "/Users/johnnyappleseed/Library/Keychains/login.keychain"
12
+ Security::Keychain::default_keychain.filename #=> "/Users/jappleseed/Library/Keychains/login.keychain"
10
13
 
11
14
  Security::InternetPassword.find(server: "itunesconnect.apple.com").password #=> "p4ssw0rd"
12
15
  ```
13
16
 
14
- ## Contact
15
-
16
- Mattt Thompson
17
+ ## License
17
18
 
18
- - http://github.com/mattt
19
- - http://twitter.com/mattt
20
- - m@mattt.me
19
+ MIT
21
20
 
22
- ## License
21
+ ## Contact
23
22
 
24
- Security is available under the MIT license. See the LICENSE file for more info.
23
+ Mattt ([@mattt](https://twitter.com/mattt))
data/lib/security.rb CHANGED
@@ -1,7 +1,4 @@
1
- module Security
2
- VERSION = "0.0.1"
3
- end
4
-
1
+ require 'security/version'
5
2
  require 'security/keychain'
6
3
  require 'security/certificate'
7
4
  require 'security/password'
@@ -16,4 +16,4 @@ module Security
16
16
  end
17
17
  end
18
18
  end
19
- end
19
+ end
@@ -1,3 +1,5 @@
1
+ require 'shellwords'
2
+
1
3
  module Security
2
4
  class Keychain
3
5
  DOMAINS = [:user, :system, :common, :dynamic]
@@ -9,19 +11,19 @@ module Security
9
11
  end
10
12
 
11
13
  def info
12
- system %{security show-keychain-info "#{@filename}"}
14
+ system %{security show-keychain-info #{@filename.shellescape}}
13
15
  end
14
16
 
15
17
  def lock
16
- system %{security lock-keychain "#{@filename}"}
18
+ system %{security lock-keychain #{@filename.shellescape}}
17
19
  end
18
20
 
19
21
  def unlock(password)
20
- system %{security unlock-keychain -p #{password} "#{@filename}"}
22
+ system %{security unlock-keychain -p #{password.shellescape} #{@filename.shellescape}}
21
23
  end
22
24
 
23
25
  def delete
24
- system %{security delete-keychain "#{@filename}"}
26
+ system %{security delete-keychain #{@filename.shellescape}}
25
27
  end
26
28
 
27
29
  class << self
@@ -32,7 +34,7 @@ module Security
32
34
  def list(domain = :user)
33
35
  raise ArgumentError "Invalid domain #{domain}, expected one of: #{DOMAINS}" unless DOMAINS.include?(domain)
34
36
 
35
- keychains_from_command('list-keychains', domain)
37
+ keychains_from_output(`security list-keychains -d #{domain}`)
36
38
  end
37
39
 
38
40
  def lock
@@ -40,22 +42,22 @@ module Security
40
42
  end
41
43
 
42
44
  def unlock(password)
43
- system %{security unlock-keychain -p #{password}}
45
+ system %{security unlock-keychain -p #{password.shellescape}}
44
46
  end
45
47
 
46
48
  def default_keychain
47
- keychains_from_command('default-keychain').first
49
+ keychains_from_output(`security default-keychain`).first
48
50
  end
49
51
 
50
52
  def login_keychain
51
- keychains_from_command('login-keychain').first
53
+ keychains_from_output(`security login-keychain`).first
52
54
  end
53
55
 
54
56
  private
55
57
 
56
- def keychains_from_command(command, *args)
57
- `security #{[command, *args].compact.join(' ')}`.split(/\n/).collect{|line| new(line.strip.gsub(/^\"|\"$/, ""))}
58
+ def keychains_from_output(output)
59
+ output.split(/\n/).collect{|line| new(line.strip.gsub(/^\"|\"$/, ""))}
58
60
  end
59
- end
61
+ end
60
62
  end
61
63
  end
@@ -1,3 +1,5 @@
1
+ require 'shellwords'
2
+
1
3
  module Security
2
4
  class Password
3
5
  attr_reader :keychain, :attributes, :password
@@ -7,14 +9,14 @@ module Security
7
9
  def initialize(keychain, attributes, password)
8
10
  @keychain = Keychain.new(keychain)
9
11
  @attributes = attributes
10
- @password = password
12
+ @password = password
11
13
  end
12
14
 
13
15
  class << self
14
16
  private
15
17
 
16
18
  def password_from_output(output)
17
- return nil if /^security\: / === output
19
+ return nil if /^security\: / === output
18
20
 
19
21
  keychain, attributes, password = nil, {}, nil
20
22
  output.split(/\n/).each do |line|
@@ -33,22 +35,21 @@ module Security
33
35
 
34
36
  def flags_for_options(options = {})
35
37
  flags = options.dup
36
- flags[:a] ||= options.delete(:account)
37
- flags[:c] ||= options.delete(:creator)
38
- flags[:C] ||= options.delete(:type)
39
- flags[:D] ||= options.delete(:kind)
40
- flags[:G] ||= options.delete(:value)
41
- flags[:j] ||= options.delete(:comment)
42
- flags[:s] ||= options.delete(:service) || options.delete(:server)
43
-
44
- flags.delete_if{|k,v| v.nil?}.collect{|k, v| "-#{k} #{v}".strip}.join(" ")
38
+ flags[:a] ||= flags.delete(:account)
39
+ flags[:c] ||= flags.delete(:creator)
40
+ flags[:C] ||= flags.delete(:type)
41
+ flags[:D] ||= flags.delete(:kind)
42
+ flags[:G] ||= flags.delete(:value)
43
+ flags[:j] ||= flags.delete(:comment)
44
+
45
+ flags.delete_if{|k,v| v.nil?}.collect{|k, v| "-#{k} #{v.shellescape}".strip}.join(" ")
45
46
  end
46
47
  end
47
48
  end
48
49
 
49
50
  class GenericPassword < Password
50
51
  class << self
51
- def add(account, service, password, options = {})
52
+ def add(service, account, password, options = {})
52
53
  options[:a] = account
53
54
  options[:s] = service
54
55
  options[:w] = password
@@ -57,31 +58,34 @@ module Security
57
58
  end
58
59
 
59
60
  def find(options)
60
- options[:g] = ''
61
-
62
- password_from_output(`security 2>&1 find-generic-password #{flags_for_options(options)}`)
61
+ password_from_output(`security 2>&1 find-generic-password -g #{flags_for_options(options)}`)
63
62
  end
64
63
 
65
64
  def delete(options)
66
65
  system "security delete-generic-password #{flags_for_options(options)}"
67
66
  end
67
+
68
+ private
69
+
70
+ def flags_for_options(options = {})
71
+ options[:s] ||= options.delete(:service)
72
+ super(options)
73
+ end
68
74
  end
69
75
  end
70
76
 
71
77
  class InternetPassword < Password
72
78
  class << self
73
- def add(account, server, password, options = {})
79
+ def add(server, account, password, options = {})
74
80
  options[:a] = account
75
81
  options[:s] = server
76
82
  options[:w] = password
77
-
83
+
78
84
  system "security add-internet-password #{flags_for_options(options)}"
79
85
  end
80
86
 
81
87
  def find(options)
82
- options[:g] = ''
83
-
84
- password_from_output(`security 2>&1 find-internet-password #{flags_for_options(options)}`)
88
+ password_from_output(`security 2>&1 find-internet-password -g #{flags_for_options(options)}`)
85
89
  end
86
90
 
87
91
  def delete(options)
@@ -91,6 +95,7 @@ module Security
91
95
  private
92
96
 
93
97
  def flags_for_options(options = {})
98
+ options[:s] ||= options.delete(:server)
94
99
  options[:p] ||= options.delete(:path)
95
100
  options[:P] ||= options.delete(:port)
96
101
  options[:r] ||= options.delete(:protocol)
@@ -0,0 +1,3 @@
1
+ module Security
2
+ VERSION = "0.1.4"
3
+ end
Binary file
data/security.gemspec CHANGED
@@ -4,16 +4,15 @@ require "security"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "security"
7
- s.authors = ["Mattt Thompson"]
8
- s.email = "m@mattt.me"
9
- s.homepage = "http://mattt.me"
7
+ s.authors = ["Mattt"]
8
+ s.email = "mattt@me.com"
9
+ s.homepage = "https://mat.tt/"
10
10
  s.version = Security::VERSION
11
11
  s.platform = Gem::Platform::RUBY
12
- s.summary = "Security"
13
- s.description = "Library for interacting with the Mac OS X Keychain"
12
+ s.license = "MIT"
13
+ s.summary = "Interact with the macOS Keychain"
14
14
 
15
- s.add_development_dependency "rspec", "~> 0.6.1"
16
- s.add_development_dependency "rake", "~> 0.9.2"
15
+ s.add_development_dependency 'rake', '~> 12.3', '>= 12.3.3'
17
16
 
18
17
  s.files = Dir["./**/*"].reject { |file| file =~ /\.\/(bin|log|pkg|script|spec|test|vendor)/ }
19
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -1,82 +1,74 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: security
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.1.4
6
5
  platform: ruby
7
6
  authors:
8
- - Mattt Thompson
7
+ - Mattt
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-07-21 00:00:00.000000000Z
11
+ date: 2021-03-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: rspec
16
- requirement: &70220282679320 !ruby/object:Gem::Requirement
17
- none: false
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '12.3'
20
+ - - ">="
20
21
  - !ruby/object:Gem::Version
21
- version: 0.6.1
22
+ version: 12.3.3
22
23
  type: :development
23
24
  prerelease: false
24
- version_requirements: *70220282679320
25
- - !ruby/object:Gem::Dependency
26
- name: rake
27
- requirement: &70220282678600 !ruby/object:Gem::Requirement
28
- none: false
25
+ version_requirements: !ruby/object:Gem::Requirement
29
26
  requirements:
30
- - - ~>
27
+ - - "~>"
31
28
  - !ruby/object:Gem::Version
32
- version: 0.9.2
33
- type: :development
34
- prerelease: false
35
- version_requirements: *70220282678600
36
- description: Library for interacting with the Mac OS X Keychain
37
- email: m@mattt.me
29
+ version: '12.3'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 12.3.3
33
+ description:
34
+ email: mattt@me.com
38
35
  executables: []
39
36
  extensions: []
40
37
  extra_rdoc_files: []
41
38
  files:
42
- - ./Gemfile
43
- - ./Gemfile.lock
44
- - ./lib/security/certificate.rb
45
- - ./lib/security/keychain.rb
46
- - ./lib/security/password.rb
47
- - ./lib/security.rb
48
- - ./LICENSE
49
- - ./Rakefile
50
- - ./README.md
51
- - ./security.gemspec
52
- homepage: http://mattt.me
53
- licenses: []
39
+ - "./Gemfile"
40
+ - "./Gemfile.lock"
41
+ - "./LICENSE.md"
42
+ - "./README.md"
43
+ - "./Rakefile"
44
+ - "./lib/security.rb"
45
+ - "./lib/security/certificate.rb"
46
+ - "./lib/security/keychain.rb"
47
+ - "./lib/security/password.rb"
48
+ - "./lib/security/version.rb"
49
+ - "./security-0.1.3.gem"
50
+ - "./security.gemspec"
51
+ homepage: https://mat.tt/
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
54
55
  post_install_message:
55
56
  rdoc_options: []
56
57
  require_paths:
57
58
  - lib
58
59
  required_ruby_version: !ruby/object:Gem::Requirement
59
- none: false
60
60
  requirements:
61
- - - ! '>='
61
+ - - ">="
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
- segments:
65
- - 0
66
- hash: -4232387281816222953
67
64
  required_rubygems_version: !ruby/object:Gem::Requirement
68
- none: false
69
65
  requirements:
70
- - - ! '>='
66
+ - - ">="
71
67
  - !ruby/object:Gem::Version
72
68
  version: '0'
73
- segments:
74
- - 0
75
- hash: -4232387281816222953
76
69
  requirements: []
77
- rubyforge_project:
78
- rubygems_version: 1.8.15
70
+ rubygems_version: 3.1.2
79
71
  signing_key:
80
- specification_version: 3
81
- summary: Security
72
+ specification_version: 4
73
+ summary: Interact with the macOS Keychain
82
74
  test_files: []