uits 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ gem "nokogiri", "1.5.0"
4
+ # Add dependencies to develop your gem here.
5
+ # Include everything needed to run rake, tests, features, etc.
6
+ group :development do
7
+ gem "shoulda", ">= 0"
8
+ gem "bundler", "~> 1.0.0"
9
+ gem "jeweler", "~> 1.6.4"
10
+ gem "rcov", ">= 0"
11
+ end
@@ -0,0 +1,22 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ nokogiri (1.5.0)
10
+ rake (0.9.2)
11
+ rcov (0.9.11)
12
+ shoulda (2.11.3)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ bundler (~> 1.0.0)
19
+ jeweler (~> 1.6.4)
20
+ nokogiri (= 1.5.0)
21
+ rcov
22
+ shoulda
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Diganta
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = uits
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to uits
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Diganta. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ require 'openssl'
6
+
7
+ begin
8
+ Bundler.setup(:default, :development)
9
+ rescue Bundler::BundlerError => e
10
+ $stderr.puts e.message
11
+ $stderr.puts "Run `bundle install` to install missing gems"
12
+ exit e.status_code
13
+ end
14
+ require 'rake'
15
+
16
+ begin
17
+ require 'jeweler'
18
+ Jeweler::Tasks.new do |gem|
19
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
20
+ gem.name = "uits"
21
+ gem.required_ruby_version = ">= 1.8.6"
22
+ gem.homepage = "http://github.com/diganta/uits"
23
+ gem.platform = Gem::Platform::RUBY
24
+ gem.license = "MIT"
25
+ gem.summary = %Q{Get UITS code for audio file.}
26
+ gem.description = %Q{Gem to get UITS code.}
27
+ gem.email = "diganta@circarconsulting.com"
28
+ gem.authors = ["Diganta Mandal"]
29
+ gem.version = "0.0.0"
30
+ gem.add_development_dependency "shoulda", ">= 0"
31
+ gem.add_dependency "nokogiri", "1.5.0"
32
+ # dependencies defined in Gemfile
33
+ end
34
+ Jeweler::RubygemsDotOrgTasks.new
35
+ rescue LoadError
36
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
37
+ end
38
+
39
+ require 'rake/testtask'
40
+ Rake::TestTask.new(:test) do |test|
41
+ test.libs << 'lib' << 'test'
42
+ test.pattern = 'test/**/test_*.rb'
43
+ test.verbose = true
44
+ end
45
+
46
+ require 'rcov/rcovtask'
47
+ Rcov::RcovTask.new do |test|
48
+ test.libs << 'test'
49
+ test.pattern = 'test/**/test_*.rb'
50
+ test.verbose = true
51
+ test.rcov_opts << '--exclude "gems/*"'
52
+ end
53
+
54
+ task :default => :test
55
+
56
+ require 'rake/rdoctask'
57
+ Rake::RDocTask.new do |rdoc|
58
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
59
+
60
+ rdoc.rdoc_dir = 'rdoc'
61
+ rdoc.title = "uits #{version}"
62
+ rdoc.rdoc_files.include('README*')
63
+ rdoc.rdoc_files.include('lib/**/*.rb')
64
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,98 @@
1
+ module Uits
2
+ #
3
+ def get_xmlfile(options = {})
4
+ raise ArgumentError, "Must required some data to get UITS." if options.blank?
5
+ raise ArgumentError, "Must provide Distributor." if options[:distributor].blank?
6
+ raise ArgumentError, "Must provide Product Id." if options[:productid].blank?
7
+ raise ArgumentError, "Must provide Asset ID." if options[:assetid].blank?
8
+ raise ArgumentError, "Must provide either Transaction ID or User ID." if options[:tid].blank? && options[:uid].blank?
9
+ raise ArgumentError, "Must provide Media." if options[:media].blank?
10
+ raise ArgumentError, "Must provide Name to whom get UITS." if options[:uits_for].blank?
11
+ raise ArgumentError, "Must provide Passphrase to get UITS." if options[:passphrase].blank?
12
+ raise ArgumentError, "Passphrase must not be less than 3 charecters." if options[:passphrase].to_s.length < 3.blank?
13
+
14
+ nonce = ActiveSupport::SecureRandom.base64(6) # The nonce is a random value generated at the time of sale whose Base64 encoded length is 8 digits
15
+ distributor = options[:distributor].to_s # This is the retailer or distributor’s name or an associated globally unique identifier in clear text example "Sony"
16
+ time = Time.now.iso8601 # The date and time of the purchase (not download or signature) in ISO 8601 format
17
+ productid = options[:productid].to_s # Track XML Product/Track/Metadata/PhysicalProduct/ProductCode example "00602517178656"
18
+ assetid = options[:assetid].to_s # Track XML Catalog/Action/Product/Track/Metadata/ISRC example "USUV70603512"
19
+ tid = !options[:tid].blank? ? options[:tid].to_s : nil # The transaction ID is the unique identifier for the transaction example "39220345237"
20
+ uid = !options[:uid].blank? ? options[:uid].to_s : nil # The User ID is the unique identifier for the user example "A74GHY8976547B"
21
+ media = OpenSSL::Digest::SHA256.digest(options[:media]) # example "d5b17cc1975d3095c6353f3fdced45ae867c06e02c1efb7c09662cdc796724b0"
22
+
23
+ first_part = "<uits:UITS xmlns:uits='http://www.udirector.net/schemas/2009/uits/1.1' xmlns:xsi='http://www.w3.org/2001/XMLSchema-­‐instance'>"
24
+ metadata = "<metadata>
25
+ <nonce>#{nonce}</nonce>
26
+ <Distributor>#{distributor.to_s}</Distributor>
27
+ <Time>#{time.to_s}</Time>
28
+ <ProductId type='UPC' completed='false'>#{productid.to_s}</ProductId>
29
+ <AssetID type='ISRC'>#{assetid.to_s}</AssetID>
30
+ <TID version='1'>#{tid.to_s}</TID>
31
+ <UID version='1'>#{uid.to_s}</UID>
32
+ <URL/>
33
+ <PA/>
34
+ <Media algorithm='SHA256'>#{media.to_s}</Media>
35
+ </metadata>"
36
+ canonicalization = metadata.to_s
37
+ rsa = RSA2048.new(options[:uits_for].to_s, options[:passphrase].to_s)
38
+ keyid = Base64.encode64(OpenSSL::Digest::SHA1.digest(canonicalization))
39
+ sig = rsa.signature(keyid)
40
+ signature = '<signature keyID="'+keyid.to_s+'" algorithm="RSA2048">'+sig.to_s+'</signature>'
41
+ last_part = '</uits:UITS>'
42
+ xml = first_part.to_s + metadata.to_s + signature.to_s + last_part.to_s
43
+ doc = Nokogiri.XML(xml, nil, 'UTF-8')
44
+ doc.search(%Q{//signature[@keyID]}).each do |n|
45
+ n['canonicalization'] = canonicalization
46
+ end
47
+ return doc.to_xml
48
+ end
49
+
50
+ class RSA2048
51
+ def initialize(path, passphrase)
52
+ path.gsub!(/[^0-9A-Za-z]/, '')
53
+ @passphrase = passphrase
54
+ @private_key_path = File.join(Rails.root.to_s, "lib/.rsa", path, "id_rsa")
55
+ @public_key_path = File.join(Rails.root.to_s, "lib/.rsa", path, "id_rsa.pub")
56
+ @private_key = private_key
57
+ @public_key = public_key
58
+ end
59
+
60
+ def signature(data)
61
+ Base64.encode64(@private_key.sign(OpenSSL::Digest::SHA1.new, data))
62
+ end
63
+
64
+ def varify?(sign, data)
65
+ sign = Base64.decode64(sign)
66
+ @public_key.verify(OpenSSL::Digest::SHA1.new, sign, data)
67
+ end
68
+
69
+ private
70
+
71
+ def private_key
72
+ generate_keypairs unless @private_key.blank?
73
+ return OpenSSL::PKey::RSA.new(File.read(@private_key_path), @passphrase)
74
+ end
75
+
76
+ def public_key
77
+ generate_keypairs unless @public_key.blank?
78
+ return OpenSSL::PKey::RSA.new(File.read(@public_key_path))
79
+ end
80
+
81
+ def generate_keypairs
82
+ unless File.exist?(@private_key_path) || File.exist?(@public_key_path)
83
+ FileUtils.mkdir_p(File.dirname(@private_key_path)) unless File.exists?(File.dirname(@private_key_path))
84
+ FileUtils.mkdir_p(File.dirname(@public_key_path)) unless File.exists?(File.dirname(@public_key_path))
85
+ rsa_key = OpenSSL::PKey::RSA.generate(2048)
86
+ cipher = OpenSSL::Cipher::Cipher.new("des3")
87
+ private_key = rsa_key.to_pem(cipher, @passphrase)
88
+ public_key = rsa_key.public_key.to_pem
89
+ rsa_priv = File.new(@private_key_path, "w")
90
+ rsa_priv.puts private_key
91
+ rsa_priv.close
92
+ rsa_priv = File.new(@public_key_path, "w")
93
+ rsa_priv.puts public_key
94
+ rsa_priv.close
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'uits'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestUits < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uits
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Diganta Mandal
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-10-18 00:00:00 +05:30
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: nokogiri
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - "="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 1
31
+ - 5
32
+ - 0
33
+ version: 1.5.0
34
+ prerelease: false
35
+ type: :runtime
36
+ requirement: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: shoulda
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ prerelease: false
49
+ type: :development
50
+ requirement: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: bundler
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 23
59
+ segments:
60
+ - 1
61
+ - 0
62
+ - 0
63
+ version: 1.0.0
64
+ prerelease: false
65
+ type: :development
66
+ requirement: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: jeweler
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 7
75
+ segments:
76
+ - 1
77
+ - 6
78
+ - 4
79
+ version: 1.6.4
80
+ prerelease: false
81
+ type: :development
82
+ requirement: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ name: rcov
85
+ version_requirements: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ prerelease: false
95
+ type: :development
96
+ requirement: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ name: shoulda
99
+ version_requirements: &id006 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ prerelease: false
109
+ type: :development
110
+ requirement: *id006
111
+ - !ruby/object:Gem::Dependency
112
+ name: nokogiri
113
+ version_requirements: &id007 !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - "="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 1
121
+ - 5
122
+ - 0
123
+ version: 1.5.0
124
+ prerelease: false
125
+ type: :runtime
126
+ requirement: *id007
127
+ description: Gem to get UITS code.
128
+ email: diganta@circarconsulting.com
129
+ executables: []
130
+
131
+ extensions: []
132
+
133
+ extra_rdoc_files:
134
+ - LICENSE.txt
135
+ - README.rdoc
136
+ files:
137
+ - .document
138
+ - Gemfile
139
+ - Gemfile.lock
140
+ - LICENSE.txt
141
+ - README.rdoc
142
+ - Rakefile
143
+ - VERSION
144
+ - lib/uits.rb
145
+ - test/helper.rb
146
+ - test/test_uits.rb
147
+ has_rdoc: true
148
+ homepage: http://github.com/diganta/uits
149
+ licenses:
150
+ - MIT
151
+ post_install_message:
152
+ rdoc_options: []
153
+
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ hash: 59
162
+ segments:
163
+ - 1
164
+ - 8
165
+ - 6
166
+ version: 1.8.6
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ none: false
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ hash: 3
173
+ segments:
174
+ - 0
175
+ version: "0"
176
+ requirements: []
177
+
178
+ rubyforge_project:
179
+ rubygems_version: 1.5.3
180
+ signing_key:
181
+ specification_version: 3
182
+ summary: Get UITS code for audio file.
183
+ test_files: []
184
+