示例#1
0
  public XDataForm(JabberDataBlock data, String id, String from) {
    this.id = id;
    this.from = from;

    cmdOk = new Command(SR.get(SR.MS_SEND), Command.OK /*Command.SCREEN*/, 1);
    cmdCancel = new Command(SR.get(SR.MS_BACK), Command.BACK, 99);
    // #ifdef DEBUG_CONSOLE
    // #         midlet.BombusQD.debug.add("captcha<<< " + data.toString(),10);
    // #endif

    JabberDataBlock challenge = data.findNamespace("captcha", "urn:xmpp:captcha");
    JabberDataBlock xdata = challenge.findNamespace("x", "jabber:x:data");
    JabberDataBlock oob = data.findNamespace("x", "jabber:x:oob");

    String url = oob.getChildBlockText("url");
    String title = xdata.getChildBlockText("title");

    Vector xData = xdata.getChildBlocks();

    if (null == title) title = "";

    f = new Form(title);
    items = new Vector(0);

    if (url.length() > 0) {
      TextField formItem = new TextField("URL", url, url.length(), TextField.UNEDITABLE);
      f.append(formItem);
    }

    XDataField field;
    String msgcid = "";

    int size = xData.size();
    for (int i = 0; i < size; ++i) {
      JabberDataBlock ch = (JabberDataBlock) xData.elementAt(i);

      if (ch.getTagName().equals("instructions")) {
        f.append(ch.getText());
        f.append("\n");
        continue;
      }
      ;
      if (!ch.getTagName().equals("field")) continue;

      field = new XDataField(ch);
      items.addElement(field);

      if (field.hidden) continue;

      if (field.media != null) msgcid = field.mediaUri.substring(4);
      f.append(field.formItem);
    }

    JabberDataBlock dataImage = data.findNamespace("data", "urn:xmpp:bob");
    String cid = dataImage.getAttribute("cid");
    if (cid.indexOf(msgcid) == 0) {
      try {
        byte[] bytes = Strconv.fromBase64(dataImage.getText());
        Image img = Image.createImage(bytes, 0, bytes.length);
        f.append(new ImageItem(null, img, Item.LAYOUT_CENTER, null));
      } catch (OutOfMemoryError eom) {
        // #ifdef DEBUG_CONSOLE
        // #                 midlet.BombusQD.debug.add("XDataForm OutOfMem",10);
        // #endif
      } catch (Exception e) {
      }
    }

    f.setCommandListener(this);
    f.addCommand(cmdOk);
    f.addCommand(cmdCancel);

    this.parentView = BombusQD.sd.canvas.getCanvas();
    BombusQD.setCurrentView(f);
  }
示例#2
0
  /**
   * Generates X-GOOGLE-TOKEN response by communication with http://www.google.com (algorithm from
   * MGTalk/NetworkThread.java)
   *
   * @param userName
   * @param passwd
   * @return
   */
  public String responseXGoogleToken() {
    try {
      String firstUrl =
          "https://www.google.com:443/accounts/ClientAuth?Email="
              + Strconv.unicodeToUTF(account.getUserName())
              + "%40"
              + account.getServer()
              + "&Passwd="
              + Strconv.unicodeToUTF(account.getPassword())
              + "&PersistentCookie=false&source=bombusqd";

      // log.addMessage("Connecting to www.google.com");
      // #if Android
      // #            URL url = new URL(firstUrl);
      // #            HttpsURLConnection c = (HttpsURLConnection) url.openConnection();
      // #            InputStream is = c.getInputStream();
      // #else
      HttpsConnection c = (HttpsConnection) Connector.open(firstUrl);
      InputStream is = c.openInputStream();
      // #endif

      String sid = readLine(is);
      if (!sid.startsWith("SID=")) {
        throw new SecurityException(SR.get(SR.MS_LOGIN_FAILED));
      }

      String lsid = readLine(is);

      String secondUrl =
          "https://www.google.com:443/accounts/IssueAuthToken?"
              + sid
              + "&"
              + lsid
              + "&service=mail&Session=true";
      is.close();
      // #if Android
      // #            url = new URL(secondUrl);
      // #            c = (HttpsURLConnection) url.openConnection();
      // #            is = c.getInputStream();
      // #else
      c.close();
      c = null;
      c = (HttpsConnection) Connector.open(secondUrl);
      is = c.openInputStream();
      // #endif
      String token = "\0" + Strconv.unicodeToUTF(account.getUserName()) + "\0" + readLine(is);
      is.close();
      // #if !Android
      c.close();
      // #endif
      return Strconv.toBase64(token);

    } catch (javax.microedition.pki.CertificateException e) {
      throw new SecurityException(e.getMessage());
    } catch (SecurityException e) {
      throw e;
    } catch (Exception e) {
      // #ifdef DEBUG
      // #             e.printStackTrace();
      // #endif
      // listener.loginFailed("Google token error");
    }
    return null;
  }