gitlab-license 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gitlab/license.rb +26 -10
- data/lib/gitlab/license/encryptor.rb +44 -9
- data/lib/gitlab/license/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a87318ee3ba270b898c8fdd55958d02f219d0ab
|
4
|
+
data.tar.gz: 6d9394ee078fc45357a4e39a7c79bae098c6d956
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19c9de17bb52fcb767e62d1af7c1350ac523ad26073636d57fe6cb2945a29be20374a49ac5d98b83d78e9c393c81f27d801f72ba1da9fb4c79252ef4437fe526
|
7
|
+
data.tar.gz: 6eab5c49867731fbc886b6e678b910f9501b862f75646c28657301e8c1be00eb65fdffb87a609ed38668c70c0424a68fc93bdd78a419c7b29b69fa51ee907304
|
data/lib/gitlab/license.rb
CHANGED
@@ -8,24 +8,40 @@ require "gitlab/license/encryptor"
|
|
8
8
|
|
9
9
|
module Gitlab
|
10
10
|
class License
|
11
|
+
class Error < StandardError; end
|
12
|
+
class ImportError < Error; end
|
13
|
+
class ValidationError < Error; end
|
14
|
+
|
11
15
|
class << self
|
12
|
-
|
16
|
+
attr_reader :encryption_key
|
13
17
|
@encryption_key = nil
|
14
18
|
|
15
|
-
def
|
16
|
-
|
17
|
-
raise "No RSA encryption key provided."
|
19
|
+
def encryption_key=(key)
|
20
|
+
if key && !key.is_a?(OpenSSL::PKey::RSA)
|
21
|
+
raise ArgumentError, "No RSA encryption key provided."
|
18
22
|
end
|
19
23
|
|
20
|
-
|
24
|
+
@encryption_key = key
|
21
25
|
end
|
22
26
|
|
23
|
-
def
|
24
|
-
|
27
|
+
def encryptor
|
28
|
+
@encryptor ||= Encryptor.new(self.encryption_key)
|
25
29
|
end
|
26
30
|
|
27
|
-
def
|
28
|
-
|
31
|
+
def import(data)
|
32
|
+
begin
|
33
|
+
license_json = encryptor.decrypt(data)
|
34
|
+
rescue Encryptor::Error
|
35
|
+
raise ImportError, "License data could not be decrypted."
|
36
|
+
end
|
37
|
+
|
38
|
+
begin
|
39
|
+
attributes = JSON.parse(license_json)
|
40
|
+
rescue JSON::ParseError
|
41
|
+
raise ImportError, "License data is invalid JSON."
|
42
|
+
end
|
43
|
+
|
44
|
+
new(attributes)
|
29
45
|
end
|
30
46
|
end
|
31
47
|
|
@@ -51,7 +67,7 @@ module Gitlab
|
|
51
67
|
end
|
52
68
|
|
53
69
|
def validate!
|
54
|
-
raise "License is invalid" unless valid?
|
70
|
+
raise ValidationError, "License is invalid" unless valid?
|
55
71
|
end
|
56
72
|
|
57
73
|
def will_expire?
|
@@ -1,15 +1,23 @@
|
|
1
1
|
module Gitlab
|
2
2
|
class License
|
3
3
|
class Encryptor
|
4
|
+
class Error < StandardError; end
|
5
|
+
class KeyError < Error; end
|
6
|
+
class DecryptionError < Error; end
|
7
|
+
|
4
8
|
attr_accessor :key
|
5
9
|
|
6
10
|
def initialize(key)
|
11
|
+
if key && !key.is_a?(OpenSSL::PKey::RSA)
|
12
|
+
raise KeyError, "No RSA encryption key provided."
|
13
|
+
end
|
14
|
+
|
7
15
|
@key = key
|
8
16
|
end
|
9
17
|
|
10
18
|
def encrypt(data)
|
11
19
|
unless key.private?
|
12
|
-
raise "Provided key is not a private key."
|
20
|
+
raise KeyError, "Provided key is not a private key."
|
13
21
|
end
|
14
22
|
|
15
23
|
# Encrypt the data using symmetric AES encryption.
|
@@ -35,26 +43,53 @@ module Gitlab
|
|
35
43
|
|
36
44
|
def decrypt(data)
|
37
45
|
unless key.public?
|
38
|
-
raise "Provided key is not a public key."
|
46
|
+
raise KeyError, "Provided key is not a public key."
|
39
47
|
end
|
40
48
|
|
41
|
-
json_data = Base64.decode64(data)
|
42
|
-
|
49
|
+
json_data = Base64.decode64(data.chomp)
|
50
|
+
|
51
|
+
begin
|
52
|
+
encryption_data = JSON.parse(json_data)
|
53
|
+
rescue JSON::ParserError
|
54
|
+
raise DecryptionError, "Encryption data is invalid JSON."
|
55
|
+
end
|
56
|
+
|
57
|
+
unless %w(data key iv).all? { |key| encryption_data[key] }
|
58
|
+
raise DecryptionError, "Required field missing from encryption data."
|
59
|
+
end
|
43
60
|
|
44
61
|
encrypted_data = Base64.decode64(encryption_data["data"])
|
45
62
|
encrypted_key = Base64.decode64(encryption_data["key"])
|
46
63
|
aes_iv = Base64.decode64(encryption_data["iv"])
|
47
64
|
|
48
|
-
|
49
|
-
|
65
|
+
begin
|
66
|
+
# Decrypt the AES key using asymmetric RSA encryption.
|
67
|
+
aes_key = self.key.public_decrypt(encrypted_key)
|
68
|
+
rescue OpenSSL::PKey::RSAError
|
69
|
+
raise DecryptionError, "AES encryption key could not be decrypted."
|
70
|
+
end
|
50
71
|
|
51
72
|
# Decrypt the data using symmetric AES encryption.
|
52
73
|
cipher = OpenSSL::Cipher::AES128.new(:CBC)
|
53
74
|
cipher.decrypt
|
54
|
-
cipher.key = aes_key
|
55
|
-
cipher.iv = aes_iv
|
56
75
|
|
57
|
-
|
76
|
+
begin
|
77
|
+
cipher.key = aes_key
|
78
|
+
rescue OpenSSL::Cipher::CipherError
|
79
|
+
raise DecryptionError, "AES encryption key is invalid."
|
80
|
+
end
|
81
|
+
|
82
|
+
begin
|
83
|
+
cipher.iv = aes_iv
|
84
|
+
rescue OpenSSL::Cipher::CipherError
|
85
|
+
raise DecryptionError, "AES IV is invalid."
|
86
|
+
end
|
87
|
+
|
88
|
+
begin
|
89
|
+
data = cipher.update(encrypted_data) + cipher.final
|
90
|
+
rescue OpenSSL::Cipher::CipherError
|
91
|
+
raise DecryptionError, "Data could not be decrypted."
|
92
|
+
end
|
58
93
|
|
59
94
|
data
|
60
95
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab-license
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Douwe Maan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|