Package com.valhalla.jbother.jabber.smack

Examples of com.valhalla.jbother.jabber.smack.SecureExtension


     */
    public boolean sendBuddyMessage(String text) {
        String to = buddy.getUser();
        int sel = resourceBox.getSelectedIndex();

        SecureExtension secureExtension = new SecureExtension();
        SecureExtension signedExtension = new SecureExtension("signed");

        // if they've selected a resource, send to it
        if (sel != 0 && sel != 1 && sel != -1) {
            to += "/" + (String) resourceBox.getSelectedItem();
        }

        ArrayList send = new ArrayList();

        if (sel != 1 || resourceBox.getItemCount() <= 2) {
            send.add(to);
        }
        // if they've selected to send to all resources, send to all
        else {
            Set keys = buddy.keySet();
            Iterator i = keys.iterator();
            while (i.hasNext()) {
                String key = (String) i.next();
                if (!key.equals("N/A")) {
                    send.add(buddy.getUser() + "/" + key);
                }
            }
        }

        String gnupgSecurityVariant = Settings.getInstance().getProperty(
                "gnupgSecurityVariant");
        String gnupgSecretKey = Settings.getInstance().getProperty(
                "gnupgSecretKeyID");
        String gnupgPublicKey = buddy.getPubKey();
        if (JBotherLoader.isGPGEnabled() &&
        // BuddyList.getInstance().isEncrypting()
                buddy.isEncrypting() && (gnupgSecretKey != null)
                 && (gnupgPublicKey != null)) {
            GnuPG gnupg = new GnuPG();
            String encryptedData = null;
            String signedData = null;

            if (gnupgSecurityVariant == null) {
                gnupgSecurityVariant = "0";
                Settings.getInstance().setProperty("gnupgSecurityVariant", "0");
            }

            if ((gnupgSecurityVariant.equals("0"))
                     || (gnupgSecurityVariant.equals("1"))) {
                encryptedData = gnupg.encryptExtension(text, gnupgSecretKey,
                        gnupgPublicKey);
                if (encryptedData != null) {
                    secureExtension.setData(encryptedData);
                }
            }
            if ((gnupgSecurityVariant.equals("0"))
                     || (gnupgSecurityVariant.equals("2"))) {
                signedData = gnupg.signExtension(text, gnupgSecretKey);
                if (signedData != null) {
                    signedExtension.setData(signedData);
                }
            }

            if ((encryptedData == null) && (signedData == null)) {
                buddy.isEncrypting(false);
                encryptButton.setIcon(Standard.getIcon("images/buttons/ssl_no.png"));
                Standard.warningMessage(null,
                        resources.getString("gnupgError"), resources.getString("gnupgErrorEncrypting")
                         + ".\n\n"
                         + resources.getString("reason")
                         + ":\n\n"
                         + gnupg.getResult()
                         + gnupg.getErrorString()
                         + "\n"
                         + resources.getString("gnupgTryOrSendUnencrypted")
                         + ".");
                return false;
            }
        }

        for (int i = 0; i < send.size(); i++) {
            Chat chat = null;

            if (buddy instanceof MUCBuddyStatus) {
                MultiUserChat muc = ((MUCBuddyStatus) buddy).getMUC();
                chat = muc.createPrivateChat(buddy.getUser());
            } else {
                chat = (Chat) chats.get((String) send.get(i));
            }

            if (chat == null) {
                chat = BuddyList.getInstance().getConnection().createChat(
                        (String) send.get(i));
                chats.put((String) send.get(i), chat);
            }

            Message message = chat.createMessage();
            if (secureExtension.getData() != null) {
                message.setBody("[This message is encrypted]");
                message.addExtension(secureExtension);
            } else {
                message.setBody(text);
            }
            if (signedExtension.getData() != null) {
                message.addExtension(signedExtension);
            }


            if (buddy.isAskForDelivered()) {
View Full Code Here


                };
            }

            GnuPG gnupg = new GnuPG();
            String signedData = null;
            SecureExtension signedExtension = new SecureExtension( "signed" );
            String gnupgSecretKey = Settings.getInstance().getProperty(
                    "gnupgSecretKeyID" );

            if( JBotherLoader.isGPGEnabled()
                     && Settings.getInstance().getBoolean( "gnupgSignPresence" )
                     && gnupgSecretKey != null )
            {
                signedData = gnupg.signExtension( result, gnupgSecretKey );
                if( signedData != null )
                {
                    signedData = signedData.replaceAll( "(\n)+$", "" );
                    signedExtension.setData( signedData );
                    presence.addExtension( signedExtension );
                }

            }
            connection.sendPacket( presence );
View Full Code Here

     * @exception Exception
     *                if an error occurs while parsing the XML
     */
    public PacketExtension parseExtension(XmlPullParser parser)
            throws Exception {
        SecureExtension t = new SecureExtension("encrypted");
        t.setData(parser.nextText());
        return t;
    }
View Full Code Here

     * @exception Exception
     *                if an error occurs while parsing the XML
     */
    public PacketExtension parseExtension(XmlPullParser parser)
            throws Exception {
        SecureExtension t = new SecureExtension("signed");
        t.setData(parser.nextText());
        return t;
    }
View Full Code Here

TOP

Related Classes of com.valhalla.jbother.jabber.smack.SecureExtension

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.