def on_get_public_key(info, error=None): if not info or error: logger.error('SigninDialog.on_get_public_key: %s, %s' % (info, error)) self.signin_failed( _('Failed to request public key, please try again')) else: pubkey = info['pubkey'] nonlocal rsakey rsakey = info['key'] nonlocal password_enc password_enc = util.RSA_encrypt(pubkey, password) gutil.async_call(auth.post_login, cookie, tokens, username, password_enc, rsakey, verifycode, codeString, callback=on_post_login)
def signin(self, auto_signin=True): self.profile = None self.screen.nodelay(0) self.screen.addstr(2, 2, "Baidu Yun Login") self.screen.addstr(4, 2, "Please input your ID and Password") self.screen.addstr(6, 2, "Press Any Key to continue ... ") self.screen.refresh() self.screen.getch() curses.echo() win = curses.newwin(height, width, begin_y, begin_x) win.border(0) win.addstr(2, 2, "UserName:"******"Cookie is valid. Press any key to continue.") win.refresh() win.getch() return True win.addstr(4, 2, "Password: (Won't be shown)") win.refresh() curses.noecho() password = win.getstr(5, 2, 20).decode(encoding='utf-8') curses.echo() self.cookie = RequestCookie() self.tokens = {} verifycode = '' codeString = '' password_enc = '' rsakey = '' win.addstr(7, 2, "Get BaiduID...") win.refresh() uid_cookie = auth.get_BAIDUID() if not uid_cookie: win.addstr(8, 2, " Get BaiduID failed, press any key to exit") win.refresh() win.getch() return False self.cookie.load_list(uid_cookie) win.addstr(8, 2, "Get token...") win.refresh() info = auth.get_token(self.cookie) if not info: win.addstr(9, 2, " Get Token failed, press any key to exit") win.refresh() win.getch() return False hosupport, token = info self.cookie.load_list(hosupport) self.cookie.load('cflag=65535%3A1; PANWEB=1;') self.tokens['token'] = token win.addstr(9, 2, "Get UBI...") win.refresh() ubi_cookie = auth.get_UBI(self.cookie, self.tokens) self.cookie.load_list(ubi_cookie) win.addstr(10, 2, "Check login...") win.refresh() ubi_cookie, status = auth.check_login(self.cookie, self.tokens, username) self.cookie.load_list(ubi_cookie) codeString = status['data']['codeString'] vcodetype = status['data']['vcodetype'] if codeString: win.addstr(11, 2, "Vcode is needed but not supported") win.addstr(12, 2, "Press any key to quit") win.refresh() win.getch() return False win.addstr(11, 2, "Get public key...") win.refresh() info = auth.get_public_key(self.cookie, self.tokens) pubkey = info['pubkey'] rsakey = info['key'] password_enc = util.RSA_encrypt(pubkey, password) win.addstr(12, 2, "login...") win.refresh() info = auth.post_login(self.cookie, self.tokens, username, password_enc, rsakey) errno, query = info if errno == 0: self.cookie.load_list(query) win.addstr(13, 2, "Get bds_token ...") win.refresh() bdstoken = auth.get_bdstoken(self.cookie) self.tokens['bdstoken'] = bdstoken win.addstr(14, 2, "Login finished, press any key to continue") win.refresh() win.getch() elif errno == 257: win.addstr(13, 2, "need vcode, but not supported") win.addstr(14, 2, "Press any key to quit") win.refresh() win.getch() return False elif errno == 4: win.addstr(13, 2, "invalid password!") win.addstr(14, 2, "Press any key to quit") win.refresh() win.getch() return False else: win.addstr(13, 2, "Something is wrong") win.addstr(14, 2, "Press any key to quit") win.refresh() win.getch() return False self.dump_auth(self.username, self.cookie, self.tokens) return True