aquaticprime 1.0.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 (4) hide show
  1. data/LICENSE +21 -0
  2. data/README +56 -0
  3. data/lib/aquaticprime.rb +104 -0
  4. metadata +86 -0
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2010 John Labovitz and Benjamin Rister
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,56 @@
1
+ Ruby AquaticPrime Implementation
2
+ Original implementation by John Labovitz
3
+ Updated and gemmed by Benjamin Rister
4
+ http://github.com/bdrister/AquaticPrime
5
+
6
+
7
+ == DESCRIPTION:
8
+
9
+ AquaticPrime is a cryptographically secure licensing method for shareware applications. The Ruby implementation currently only generates licenses, and is intended for use in online stores.
10
+
11
+ See http://github.com/bdrister/AquaticPrime for information about the overall design and usage of AquaticPrime.
12
+
13
+
14
+ == INSTALL:
15
+
16
+ For a freestanding install:
17
+ gem install aquaticprime
18
+
19
+ If using Bundler (e.g. Rails 3), add this to your Gemfile…
20
+ gem 'aquaticprime'
21
+ …then run "bundle install".
22
+
23
+
24
+ == EXAMPLE:
25
+
26
+ require 'aquaticprime'
27
+
28
+ publicKey = '0xE9D8BF...' # from AquaticPrime Developer License Utility
29
+ privateKey = '0x9BE7F9...' # from AquaticPrime Developer License Utility
30
+ aquatic_prime = AquaticPrime.new(publicKey, privateKey)
31
+ puts aquatic_prime.license_data('name' => 'User Name', 'email' => 'User Email')
32
+
33
+
34
+ == LICENSE:
35
+
36
+ The MIT License
37
+
38
+ Copyright (c) 2010 John Labovitz and Benjamin Rister
39
+
40
+ Permission is hereby granted, free of charge, to any person obtaining a copy
41
+ of this software and associated documentation files (the "Software"), to deal
42
+ in the Software without restriction, including without limitation the rights
43
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
44
+ copies of the Software, and to permit persons to whom the Software is
45
+ furnished to do so, subject to the following conditions:
46
+
47
+ The above copyright notice and this permission notice shall be included in
48
+ all copies or substantial portions of the Software.
49
+
50
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
51
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
52
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
53
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
54
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
55
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
56
+ THE SOFTWARE.
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # AquaticPrime is a cryptographically secure licensing method for shareware
4
+ # applications. The Ruby implementation currently only generates licenses, and
5
+ # is intended for use in online stores.
6
+ # Written by John Labovitz <johnl@johnlabovitz.com>.
7
+ # Updated by Benjamin Rister <aquaticprime@decimus.net>.
8
+
9
+ require 'rubygems'
10
+
11
+ require 'digest/sha1'
12
+ require 'plist'
13
+ require 'stringio'
14
+
15
+
16
+ module Math
17
+
18
+ # Calculates x^a mod m. Useful for public key encryption calculations.
19
+ def self.powmod(x, a, m)
20
+ r = 1
21
+ while a > 0
22
+ if a % 2 == 1
23
+ r = (r * x) % m
24
+ end
25
+ a = a >> 1
26
+ x = (x * x) % m
27
+ end
28
+ r
29
+ end
30
+
31
+ end
32
+
33
+
34
+ # AquaticPrime instances are associated with a given public/private key
35
+ # pair, and generate signed license plists for input Hash instances.
36
+
37
+ class AquaticPrime
38
+
39
+ # Returns a new AquaticPrime generator with the given public and private keys.
40
+ # Keys should be provided as hex strings.
41
+ def initialize(pubKey, privKey)
42
+ @pubKey = pubKey
43
+ @privKey = privKey
44
+ end
45
+
46
+ # Calculates the cryptographic signature for a given Hash, returned as a
47
+ # String.
48
+ # This is generally only of internal interest, but on rare instances
49
+ # clients may wish to calculate this value.
50
+ def signature(information)
51
+ total = information.sort{|a,b| a[0].downcase <=> b[0].downcase || a[0] <=> b[0]}.map{|key,value| value}.join('')
52
+
53
+ hash = Digest::SHA1.hexdigest(total)
54
+ hash = '0001' + ('ff' * 105) + '00' + hash
55
+
56
+ sig = Math.powmod(hash.hex, @privKey.hex, @pubKey.hex)
57
+
58
+ # Convert from a big number to a binary string.
59
+ sig = sig.to_s(16)
60
+ sig = ('0' * (256 - sig.length)) + sig
61
+ sig = sig.unpack('a2' * (sig.length/2)).map { |x| x.hex }.pack('c' * (sig.length/2))
62
+
63
+ sig
64
+ end
65
+
66
+ # Returns a String containing a signed license plist based on the given
67
+ # license_info Hash.
68
+ # The result is suitable content for a license file via a download, email
69
+ # attachment, or any other delivery mechanism to the end user.
70
+ def license_data(license_info)
71
+ signed_license_info = license_info.dup
72
+
73
+ # Sign the license info.
74
+ # If a value in the plist is a StringIO object, it handily ends up as a base64-encoded <data> key
75
+ signed_license_info['Signature'] = StringIO.new(signature(license_info))
76
+
77
+ signed_license_info.to_plist
78
+ end
79
+
80
+ end
81
+
82
+
83
+ if $0 == __FILE__
84
+ # testing keys
85
+ pubKey = '0xAAD0DC5705017D4AA1CD3FA194771E97B263E68308DC09D3D9297247D175CCD05DFE410B9426D3C8019BA6B92D34F21B454D8D8AC8CAD2FB37850987C02592012D658911442C27F4D9B050CFA3F7C07FF81CFEEBE33E1E43595B2ACCC2019DC7247829017A91D40020F9D8BF67300CE744263B4F34FF42E3A7BE3CF37C4004EB'
86
+ privKey = '0x71E092E4AE00FE31C1337FC10DA4BF0FCC4299ACB092B137E61BA185364E888AE9542B5D0D6F37DAABBD19D0C8CDF6BCD8DE5E5C85DC8CA77A58B1052AC3B6AA5C7EA2E58BD484050184D2E241CFCB1D6AB4AC8617499056060833D8F6699B9C54E3BAA36123AFD5B4DDE6F2ADFC08F6970C3BA5C80B9A0A04CB6C6B73DD512B'
87
+
88
+ aquatic_prime = AquaticPrime.new(pubKey, privKey)
89
+
90
+ easy_license = {
91
+ 'Email' => 'user@email.com',
92
+ 'Name' => 'User'
93
+ }
94
+ puts 'EASY LICENSE RESULTS:'
95
+ puts aquatic_prime.license_data(easy_license)
96
+
97
+ hard_license = {
98
+ 'Email' => 'user@email.com',
99
+ 'Name' => 'Üsér Diacriticà',
100
+ 'lowercase key' => 'Keys should be sorted case-insensitive'
101
+ }
102
+ puts 'HARD LICENSE RESULTS:'
103
+ puts aquatic_prime.license_data(hard_license)
104
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aquaticprime
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - John Labovitz
14
+ - Benjamin Rister
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-10-08 00:00:00 -04:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: plist
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 5
31
+ segments:
32
+ - 3
33
+ - 1
34
+ version: "3.1"
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description:
38
+ email:
39
+ - johnl@johnlabovitz.com
40
+ - aquaticprime@decimus.net
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ extra_rdoc_files: []
46
+
47
+ files:
48
+ - README
49
+ - LICENSE
50
+ - lib/aquaticprime.rb
51
+ has_rdoc: true
52
+ homepage: http://github.com/bdrister/AquaticPrime
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.3.7
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: AquaticPrime is a cryptographically secure licensing method for shareware applications. The Ruby implementation currently only generates licenses, and is intended for use in online stores.
85
+ test_files: []
86
+