s7n 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/.gitignore +7 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +28 -0
  4. data/LICENCE +24 -0
  5. data/README.rdoc +54 -0
  6. data/Rakefile +67 -0
  7. data/bin/s7ncli +23 -0
  8. data/lib/s7n.rb +12 -0
  9. data/lib/s7n/action.rb +7 -0
  10. data/lib/s7n/attribute.rb +226 -0
  11. data/lib/s7n/cipher.rb +110 -0
  12. data/lib/s7n/configuration.rb +41 -0
  13. data/lib/s7n/entry.rb +106 -0
  14. data/lib/s7n/entry_collection.rb +44 -0
  15. data/lib/s7n/entry_template.rb +10 -0
  16. data/lib/s7n/exception.rb +116 -0
  17. data/lib/s7n/file.rb +77 -0
  18. data/lib/s7n/gpass_file.rb +203 -0
  19. data/lib/s7n/key.rb +83 -0
  20. data/lib/s7n/message_catalog.rb +5 -0
  21. data/lib/s7n/s7n_file.rb +47 -0
  22. data/lib/s7n/s7ncli.rb +226 -0
  23. data/lib/s7n/s7ncli/attribute_command.rb +83 -0
  24. data/lib/s7n/s7ncli/command.rb +215 -0
  25. data/lib/s7n/s7ncli/entry_collection_command.rb +63 -0
  26. data/lib/s7n/s7ncli/entry_command.rb +728 -0
  27. data/lib/s7n/s7ncli/option.rb +101 -0
  28. data/lib/s7n/secret_generator.rb +30 -0
  29. data/lib/s7n/undo_stack.rb +7 -0
  30. data/lib/s7n/unicode_data.rb +29 -0
  31. data/lib/s7n/utils.rb +37 -0
  32. data/lib/s7n/version.rb +3 -0
  33. data/lib/s7n/world.rb +158 -0
  34. data/po/ja/s7n.po +533 -0
  35. data/po/s7n.pot +533 -0
  36. data/s7n.gemspec +30 -0
  37. data/test/s7n/attribute_test.rb +50 -0
  38. data/test/s7n/gpass_file_test.rb +169 -0
  39. data/test/s7n/gpass_file_test/passwords.gps.empty +1 -0
  40. data/test/s7n/gpass_file_test/passwords.gps.one_entry +2 -0
  41. data/test/s7n/gpass_file_test/passwords.gps.three_entries +3 -0
  42. data/test/s7n/gpass_file_test/passwords.gps.with_folders +0 -0
  43. data/test/s7n/secret_generator_test.rb +29 -0
  44. data/test/s7n/unicode_data_test.rb +28 -0
  45. data/test/s7n/world_test.rb +35 -0
  46. data/test/test_helper.rb +11 -0
  47. metadata +153 -0
@@ -0,0 +1,7 @@
1
+ /pkg
2
+ /data
3
+ \#*\#
4
+ *~
5
+ *.bak
6
+ /work
7
+ /tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in s7n.gemspec
4
+ gemspec
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ s7n (0.1.0)
5
+ gettext
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ gettext (2.2.0)
11
+ locale
12
+ locale (2.0.5)
13
+ rr (1.0.4)
14
+ shoulda (3.0.1)
15
+ shoulda-context (~> 1.0.0)
16
+ shoulda-matchers (~> 1.0.0)
17
+ shoulda-context (1.0.0)
18
+ shoulda-matchers (1.0.0)
19
+ test-unit (2.4.8)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ rr
26
+ s7n!
27
+ shoulda
28
+ test-unit
data/LICENCE ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2009, TAKAO Kouji <kouji@takao7.net>
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are
5
+ met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above
10
+ copyright notice, this list of conditions and the following
11
+ disclaimer in the documentation and/or other materials
12
+ provided with the distribution.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
+ DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
18
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
22
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
23
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24
+ POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,54 @@
1
+ == s7n - 機密情報を管理するソフトウェア
2
+
3
+ s7n(セブンと読みます)は、あるウェブサイトやリモートサーバのパスフレーズ
4
+ や、クレジットカードの暗証番号などの機密情報を管理するソフトウェアです。
5
+ 修正 BSD ライセンスに従って公開・配布を行っているオープンソースソフトウェ
6
+ アです。
7
+
8
+ 機密情報は、マスターキーと呼ばれるパスフレーズを使って、
9
+ 秘密鍵暗号鍵方式の一つを用いて暗号化します。
10
+ 万が一、機密情報を格納しているファイルが盗まれてしまった場合でも、
11
+ ちょっとやそっとでは機密情報を覗き見ることはできません。
12
+
13
+ == ゴール
14
+
15
+ s7n は次の目標に向かって開発を進めています。
16
+
17
+ * クリップボードを利用せずにアプリケーションへのパスフレーズの入力ができること
18
+ * pwgen のようなコマンドラインのパスワードジェネレータと同じくらい簡単に新しいパスフレーズを含むアカウント情報を発行できること
19
+ * GNOME、ncurses やコマンドラインなど、ユーザの好みに合わせて UI を選択できること
20
+ * Windows、Mac OS X、Linux、iPhone などのさまざまなプラットフォームで動作すること
21
+
22
+ == 機能
23
+
24
+ * 秘密鍵暗号鍵方式を用いた強固な暗号化
25
+ * 多彩な編集機能(コピー&ペースト、UNDO/REDOなど)
26
+ * 簡単便利な検索機能
27
+ * 組み込みのセキュアパスワードのジェネレータ
28
+
29
+ == 動作環境
30
+
31
+ * ruby 1.9.3
32
+
33
+ 以下のライブラリを有効にしておくこと。
34
+ * readline
35
+ * openssl
36
+
37
+ == インストール
38
+
39
+ まず、ruby 1.9.3 をインストールしてください。このとき、readline、openssl
40
+ ライブラリを有効にしてください。
41
+
42
+ $ gem install s7n
43
+
44
+ == 開発者
45
+
46
+ * 高尾 宏治 <kouji@takao7.net>
47
+
48
+ == 連絡先
49
+
50
+ s7n に関するお問い合わせは高尾 宏治 <kouji@takao7.net> までお願いします。
51
+
52
+ == ライセンス
53
+
54
+ LICENCE ファイルを参照してください。
@@ -0,0 +1,67 @@
1
+ require 'bundler/gem_helper'
2
+ Bundler::GemHelper.new(Dir.pwd).instance_eval do
3
+ desc "Build #{name}-#{version}.gem into the pkg directory"
4
+ task 'build' => [:makemo] do
5
+ build_gem
6
+ end
7
+
8
+ desc "Build and install #{name}-#{version}.gem into system gems"
9
+ task 'install' do
10
+ install_gem
11
+ end
12
+
13
+ desc "Create tag #{version_tag} and build and push #{name}-#{version}.gem to Rubygems"
14
+ task 'release' do
15
+ release_gem
16
+ end
17
+ end
18
+ require "rake"
19
+ require "rake/testtask"
20
+ require "rdoc/task"
21
+
22
+ require "rubygems"
23
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __FILE__)
24
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
25
+
26
+ require File.expand_path("../lib/s7n/version", __FILE__)
27
+
28
+ Rake::RDocTask.new do |rd|
29
+ rd.main = "README.rdoc"
30
+ rd.rdoc_files.include("README.rdoc", "{lib/**/*.rb,ext/**/*.c}")
31
+ rd.options = ["--line-numbers", "--inline-source", "--title", "s7n",
32
+ "--main", "README.rdoc"]
33
+ rd.rdoc_dir = "doc/rdoc"
34
+ end
35
+
36
+ GETTEXT_TEXT_DOMAIN = "s7n"
37
+ GETTEXT_TARGETS = Dir.glob("{bin/s7ncli,lib/**/*.rb}")
38
+
39
+ desc "Create pot file"
40
+ task :makepot do
41
+ require "gettext/tools"
42
+ GetText::RGetText.run(GETTEXT_TARGETS, "po/s7n.pot")
43
+ end
44
+
45
+ desc "Update pot/po files."
46
+ task :updatepo do
47
+ require "gettext/tools"
48
+ GetText.update_pofiles(GETTEXT_TEXT_DOMAIN,
49
+ GETTEXT_TARGETS,
50
+ [GETTEXT_TEXT_DOMAIN, S7n::VERSION].join(" "))
51
+ end
52
+
53
+ desc "Create mo-files"
54
+ task :makemo do
55
+ require 'gettext/tools'
56
+ GetText.create_mofiles(verbose: true)
57
+ end
58
+
59
+ Rake::TestTask.new do |t|
60
+ require "test-unit"
61
+
62
+ t.libs << "lib"
63
+ t.libs << "test"
64
+ t.test_files = FileList["test/**/*_{helper,test}.rb"]
65
+ end
66
+
67
+ task :default => :test
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require "rubygems"
5
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __FILE__)
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
7
+
8
+ $:.unshift(File.expand_path("../../lib", __FILE__))
9
+
10
+ require "gettext"
11
+
12
+ require "s7n"
13
+ require "s7n/s7ncli"
14
+
15
+ include S7n
16
+
17
+ path = File.expand_path("../data/locale/", File.dirname(__FILE__))
18
+ GetText.bindtextdomain("s7n", :path => path)
19
+ S7nCli.run(ARGV)
20
+
21
+ # Local Variables:
22
+ # mode: ruby
23
+ # End:
@@ -0,0 +1,12 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require "s7n/version"
4
+
5
+ # S7 の名前空間を定義。
6
+ module S7n
7
+ end
8
+
9
+ require "s7n/world"
10
+ require "s7n/s7n_file"
11
+ require "s7n/exception"
12
+ require "s7n/gpass_file"
@@ -0,0 +1,7 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module S7n
4
+ # 操作を表現する。
5
+ class Action
6
+ end
7
+ end
@@ -0,0 +1,226 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require "date"
4
+ require "gettext"
5
+
6
+ module S7n
7
+ # 属性を表現する。
8
+ class Attribute
9
+ include GetText
10
+
11
+ # サポートしている属性のクラス。
12
+ @@attribute_classes = {}
13
+
14
+ class << self
15
+ def create_instance(type, options)
16
+ return @@attribute_classes[type].new(options)
17
+ end
18
+
19
+ # 属性の型名の配列を返す。
20
+ def types
21
+ return @@attribute_classes.keys
22
+ end
23
+
24
+ private
25
+
26
+ def type(name)
27
+ @@attribute_classes[name] = self
28
+ self.const_set("TYPE", name)
29
+ end
30
+ end
31
+
32
+ # 名前。
33
+ attr_accessor :name
34
+
35
+ # 機密情報かどうか。true であれば機密情報、false であればそうでない。
36
+ attr_accessor :secret
37
+
38
+ # 値を編集できるかどうか。true であれば編集でき、false であれ
39
+ # ばそうでない。
40
+ attr_accessor :editabled
41
+
42
+ # 削除できるかどうか。true であれば削除できず、false であれ
43
+ # ばそうでない。
44
+ attr_accessor :protected
45
+
46
+ def initialize(options)
47
+ self.name = options["name"]
48
+ self.value = options["value"]
49
+ self.secret = options["secret"] ? true : false
50
+ if options.key?("editabled")
51
+ self.editabled = options["editabled"] ? true : false
52
+ else
53
+ self.editabled = true
54
+ end
55
+ self.protected = options["protected"] ? true : false
56
+ end
57
+
58
+ # value を取得する。
59
+ def value
60
+ if @value.nil?
61
+ return nil
62
+ else
63
+ return get_value
64
+ end
65
+ end
66
+
67
+ # value を設定する。
68
+ def value=(val)
69
+ if val.nil?
70
+ @value = val
71
+ else
72
+ set_value(val)
73
+ end
74
+ end
75
+
76
+ # 属性の型を取得する。
77
+ def type
78
+ return self.class.const_get("TYPE")
79
+ end
80
+
81
+ # 機密情報かどうかを取得する。
82
+ # 機密情報の場合、true を返す。そうでなれば false を返す。
83
+ def secret?
84
+ return secret ? true : false
85
+ end
86
+
87
+ # ユーザによる値の編集ができるかどうかを取得する。
88
+ # 編集できる場合、true を返す。そうでなければ true を返す。
89
+ def editable?
90
+ return editabled ? true : false
91
+ end
92
+
93
+ # ユーザによる削除ができるかどうかを取得する。
94
+ # 削除できる場合、true を返す。そうでなければ true を返す。
95
+ def protected?
96
+ return protected ? true : false
97
+ end
98
+
99
+ # value を表示するために文字列に変換する。
100
+ # このとき、 secret が true であれば「*」でマスクする。
101
+ def display_value(secret = @secret)
102
+ if secret
103
+ return "*" * value.to_s.length
104
+ else
105
+ return value.to_s
106
+ end
107
+ end
108
+
109
+ private
110
+
111
+ def get_value
112
+ return @value
113
+ end
114
+
115
+ def set_value(val)
116
+ @value = val
117
+ end
118
+ end
119
+
120
+ # 文字列の属性を表現する。
121
+ class TextAttribute < Attribute
122
+ type("text")
123
+
124
+ private
125
+
126
+ def get_value
127
+ return @value.to_s.force_encoding("utf-8")
128
+ end
129
+
130
+ def set_value(val)
131
+ @value = val.to_s.dup.force_encoding("utf-8")
132
+ end
133
+ end
134
+
135
+ # 数値の属性を表現する。
136
+ class NumericAttribute < Attribute
137
+ type("numeric")
138
+
139
+ private
140
+
141
+ def get_value
142
+ return @value.to_i
143
+ end
144
+
145
+ def set_value(val)
146
+ @value = val.to_i
147
+ end
148
+ end
149
+
150
+ # 真偽値の属性を表現する。
151
+ class BooleanAttribute < Attribute
152
+ type("boolean")
153
+
154
+ # value を表示するために文字列に変換する。
155
+ # secret が true であれば「*」を返す。
156
+ # そうでなければ、Yes か No を返す。
157
+ def display_value(secret = @secret)
158
+ if secret
159
+ return "*"
160
+ else
161
+ return value ? _("Yes") : _("No")
162
+ end
163
+ end
164
+
165
+ private
166
+
167
+ def get_value
168
+ return @value ? true : false
169
+ end
170
+
171
+ def set_value(val)
172
+ @value = val ? true : false
173
+ end
174
+ end
175
+
176
+ # 日時の属性を表現する。
177
+ class DateTimeAttribute < Attribute
178
+ type("datetime")
179
+
180
+ # value を表示するために文字列に変換する。
181
+ # secret が true であれば「*」を返す。
182
+ # そうでなければ、「%Y/%m/%d %H:%M:%S」でフォーマットした文字列を返す。
183
+ # また、時分秒が全て0の場合は「%Y/%m/%d」でフォーマットする。
184
+ def display_value(secret = @secret)
185
+ if secret
186
+ return "*"
187
+ else
188
+ format = "%Y/%m/%d"
189
+ if value.hour != 0 || value.min != 0 || value.sec != 0
190
+ format << " %H:%M:%S"
191
+ end
192
+ return value.strftime(format)
193
+ end
194
+ end
195
+
196
+ private
197
+
198
+ def get_value
199
+ return @value.to_datetime
200
+ end
201
+
202
+ def set_value(val)
203
+ case val
204
+ when Time, DateTime, Date
205
+ @value = val.to_datetime
206
+ else
207
+ @value = DateTime.parse(val.to_s)
208
+ end
209
+ end
210
+ end
211
+
212
+ # ファイルの属性を表現する。
213
+ class FileAttribute < Attribute
214
+ type("file")
215
+ end
216
+
217
+ # 画像の属性を表現する。
218
+ class FigureAttribute < FileAttribute
219
+ type("figure")
220
+ end
221
+
222
+ # 不明な属性を表現する。
223
+ class UnknownAttribute < Attribute
224
+ type("unknown")
225
+ end
226
+ end