lib/lastpass/fetcher.rb in lastpass-1.5.0 vs lib/lastpass/fetcher.rb in lastpass-1.6.0

- old
+ new

@@ -7,24 +7,26 @@ key_iteration_count = request_iteration_count username request_login username, password, key_iteration_count, multifactor_password, client_id end def self.logout session, web_client = http - response = web_client.get "https://lastpass.com/logout.php?mobile=1", + response = web_client.get "https://lastpass.com/logout.php?method=cli&noredirect=1", cookies: {"PHPSESSID" => URI.encode(session.id)} raise NetworkError unless response.response.is_a? Net::HTTPOK end def self.fetch session, web_client = http - response = web_client.get "https://lastpass.com/getaccts.php?mobile=1&b64=1&hash=0.0&hasplugin=3.0.23&requestsrc=android", + response = web_client.get "https://lastpass.com/getaccts.php?mobile=1&b64=1&hash=0.0&hasplugin=3.0.23&requestsrc=cli", format: :plain, cookies: {"PHPSESSID" => URI.encode(session.id)} raise NetworkError unless response.response.is_a? Net::HTTPOK - Blob.new decode_blob(response.parsed_response), session.key_iteration_count + Blob.new decode_blob(response.parsed_response), + session.key_iteration_count, + session.encrypted_private_key end def self.request_iteration_count username, web_client = http response = web_client.post "https://lastpass.com/iterations.php", body: {email: username} @@ -48,16 +50,16 @@ multifactor_password = nil, client_id = nil, web_client = http body = { - method: "mobile", - web: 1, - xml: 1, + method: "cli", + xml: 2, username: username, hash: make_hash(username, password, key_iteration_count), - iterations: key_iteration_count + iterations: key_iteration_count, + includeprivatekeyenc: 1 } body[:otp] = multifactor_password if multifactor_password body[:imei] = client_id if client_id @@ -73,15 +75,18 @@ create_session parsed_response, key_iteration_count or raise login_error parsed_response end def self.create_session parsed_response, key_iteration_count - ok = parsed_response["ok"] + ok = (parsed_response["response"] || {})["ok"] if ok.is_a? Hash session_id = ok["sessionid"] if session_id.is_a? String - return Session.new session_id, key_iteration_count + private_key = ok["privatekeyenc"] + private_key = nil if private_key == "" + + return Session.new session_id, key_iteration_count, private_key end end nil end @@ -93,10 +98,10 @@ exceptions = { "unknownemail" => LastPassUnknownUsernameError, "unknownpassword" => LastPassInvalidPasswordError, "googleauthrequired" => LastPassIncorrectGoogleAuthenticatorCodeError, "googleauthfailed" => LastPassIncorrectGoogleAuthenticatorCodeError, - "yubikeyrestricted" => LastPassIncorrectYubikeyPasswordError, + "otprequired" => LastPassIncorrectYubikeyPasswordError, } cause = error["cause"] message = error["message"]