rmega 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ed425ea5b0da557c00e5e2abd80b00ddb72f7d32e4a12c6ee3e79d65a0e4a34
4
- data.tar.gz: d4ddf7dcb5e5b40433da1e03eec12ccf91c3b400009493158c2b5055c5bc6119
3
+ metadata.gz: 48d1cd2037a5511fdc9adc693fbd1b6e74331327a3e46a93e2326a3c9aef7f42
4
+ data.tar.gz: 159cd701d79d5fdb8d903a562f01fff6a439fedb2d6efff926acf8df772182f0
5
5
  SHA512:
6
- metadata.gz: 466832e6ceedaf3df21715c17bec1a507dde658db7821aae46f6427bda5e1031ed34d454f97b0ef90b4a5ee9f86da877af51cfbfd78f0b64cb36fd93be957b2a
7
- data.tar.gz: f3928e47b107ab5693c3daa73c9d6725e94f622e539e4d30e96b3fff8c2af0b4394e38068b5f7508c6dc4b3802c45a5a3c8014ba2a967ba3e8da6b56fa07fa2f
6
+ metadata.gz: 74c4ac1a15aeafeea21aed3dce4f17e8bdc7f82bf50608d776bc3c9df27e57ece398e8b8cf1b77d6dcd34114a020b7b1bcbcf3bdeca398da80b0ab80c3e72f39
7
+ data.tar.gz: 48a51f07da3be0c88619068afa1fc93a42d4f77dc008ddf6a5504a66aa536584e46af9e3c799fcf8f70fec44c6d31c5aabdaf74bd13257fa4910df9418c793b9
@@ -1,3 +1,10 @@
1
+ ## 0.2.7
2
+
3
+ ### New Features
4
+ * Add support for login ver. 2 (newer accounts only)
5
+ * Add new error codes
6
+ * Fixed crash when uploading file with invalid UTF-8 characters
7
+
1
8
  ## 0.2.6
2
9
 
3
10
  ### New Features
@@ -8,6 +8,7 @@ require 'openssl'
8
8
  require 'digest/md5'
9
9
  require 'json'
10
10
  require 'securerandom'
11
+ require 'pbkdf2'
11
12
 
12
13
  # Used only in specs
13
14
  require 'yaml'
@@ -26,6 +26,9 @@ module Rmega
26
26
  -20 => 'Write failed',
27
27
  -21 => 'Read failed',
28
28
  -22 => 'Invalid application key; request not processed',
29
+ -23 => 'SSL verification failed',
30
+ -24 => 'Not enough quota',
31
+ -26 => '2FA required',
29
32
  }.freeze
30
33
 
31
34
  def initialize(http_response)
@@ -7,7 +7,7 @@ module Rmega
7
7
  node_key = NodeKey.random
8
8
 
9
9
  # encrypt attributes
10
- _attr = serialize_attributes(:n => name.strip)
10
+ _attr = serialize_attributes(:n => Utils.utf8(name).strip)
11
11
  _attr = aes_cbc_encrypt(node_key.aes_key, _attr)
12
12
 
13
13
  # Encrypt node key
@@ -31,14 +31,14 @@ module Rmega
31
31
  def serialize_attributes(hash)
32
32
  str = "MEGA"
33
33
  str << hash.to_json
34
- str << ("\x00" * (16 - (str.size % 16)))
34
+ str << ("\x00" * (16 - (str.bytesize % 16)))
35
35
  return str
36
36
  end
37
37
 
38
38
  def rename(new_name)
39
39
  node_key = NodeKey.load(decrypted_file_key)
40
40
 
41
- _attr = serialize_attributes(attributes.merge("n" => new_name))
41
+ _attr = serialize_attributes(attributes.merge("n" => Utils.utf8(new_name)))
42
42
  _attr = aes_cbc_encrypt(node_key.aes_key, _attr)
43
43
  _attr = Utils.base64urlencode(_attr)
44
44
 
@@ -69,7 +69,7 @@ module Rmega
69
69
  pool.shutdown
70
70
 
71
71
  # encrypt attributes
72
- _attr = serialize_attributes(:n => ::File.basename(path))
72
+ _attr = serialize_attributes(:n => Utils.utf8(::File.basename(path)))
73
73
  _attr = aes_cbc_encrypt(rnd_node_key.aes_key, _attr)
74
74
 
75
75
  # Calculate meta_mac
@@ -86,12 +86,31 @@ module Rmega
86
86
  # * The user master_key (128 bit for AES) encrypted with the password_hash
87
87
  # * The RSA private key ecrypted with the master_key
88
88
  # * A brand new session_id encrypted with the RSA private key
89
- def login(email, password)
89
+ def login(email, password)
90
+ # discover the version of the account (1: old accounts, >=2: newer accouts)
91
+ resp = request(a: 'us0', user: email.strip)
92
+ account_version = resp["v"].to_i
93
+
90
94
  # Derive an hash from the user password
91
- password_hash = hash_password(password)
92
- u_hash = user_hash(password_hash, email.strip.downcase)
95
+ if account_version == 1
96
+ password_hash = hash_password(password)
97
+ u_hash = user_hash(password_hash, email.strip.downcase)
98
+ else
99
+ df2 = PBKDF2.new(
100
+ :password => password,
101
+ :salt => Utils.base64urldecode(resp['s']),
102
+ :iterations => 100000,
103
+ :hash_function => :sha512,
104
+ :key_length => 16 * 2,
105
+ ).bin_string
106
+ password_hash = df2[0,16]
107
+ u_hash = Utils.base64urlencode(df2[16,32])
108
+ end
93
109
 
94
- resp = request(a: 'us', user: email.strip, uh: u_hash)
110
+ # Send the login request
111
+ req = {a: 'us', user: email.strip, uh: u_hash}
112
+ req[:sek] = Utils.base64urlencode(SecureRandom.random_bytes(16)) if account_version != 1
113
+ resp = request(req)
95
114
 
96
115
  @master_key = aes_cbc_decrypt(password_hash, Utils.base64urldecode(resp['k']))
97
116
  @rsa_privk = decrypt_rsa_private_key(resp['privk'])
@@ -40,5 +40,12 @@ module Rmega
40
40
  ary
41
41
  end.map(&:chr).join
42
42
  end
43
+
44
+ def utf8(s)
45
+ str = s.dup
46
+ str.force_encoding("UTF-8")
47
+ str.encode!("UTF-8", invalid: :replace, replace: "-")
48
+ return str
49
+ end
43
50
  end
44
51
  end
@@ -1,4 +1,4 @@
1
1
  module Rmega
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  HOMEPAGE = "https://github.com/topac/rmega"
4
4
  end
@@ -17,6 +17,8 @@ Gem::Specification.new do |gem|
17
17
  gem.license = 'MIT'
18
18
  gem.required_ruby_version = '>= 1.9.3'
19
19
 
20
+ gem.add_dependency "pbkdf2-ruby"
21
+
20
22
  gem.add_development_dependency "pry"
21
23
  gem.add_development_dependency "rspec"
22
24
  gem.add_development_dependency "rake"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmega
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - topac
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-05 00:00:00.000000000 Z
11
+ date: 2020-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pbkdf2-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: pry
15
29
  requirement: !ruby/object:Gem::Requirement