widgetSelected(
SelectionEvent event )
{
final TableItem[] selection = buddy_table.getSelection();
UIInputReceiver prompter = ui_instance.getInputReceiver();
prompter.setLocalisedTitle( lu.getLocalisedMessageText( "azbuddy.ui.menu.send" ));
prompter.setLocalisedMessage( lu.getLocalisedMessageText( "azbuddy.ui.menu.send_msg" ) );
try{
prompter.prompt(new UIInputReceiverListener() {
public void UIInputReceiverClosed(UIInputReceiver prompter) {
String text = prompter.getSubmittedInput();
if ( text != null ){
for (int i=0;i<selection.length;i++){
BuddyPluginBuddy buddy = (BuddyPluginBuddy)selection[i].getData();
plugin.getAZ2Handler().sendAZ2Message( buddy, text );
}
}
}
});
}catch( Throwable e ){
}
};
});
// chat
final MenuItem chat_item = new MenuItem(menu, SWT.PUSH);
chat_item.setText( lu.getLocalisedMessageText( "azbuddy.ui.menu.chat" ) );
chat_item.addSelectionListener(
new SelectionAdapter()
{
public void
widgetSelected(
SelectionEvent event )
{
TableItem[] selection = buddy_table.getSelection();
BuddyPluginBuddy[] buddies = new BuddyPluginBuddy[selection.length];
for (int i=0;i<selection.length;i++){
BuddyPluginBuddy buddy = (BuddyPluginBuddy)selection[i].getData();
buddies[i] = buddy;
}
plugin.getAZ2Handler().createChat( buddies );
};
});
// ping
final MenuItem ping_item = new MenuItem(menu, SWT.PUSH);
ping_item.setText( lu.getLocalisedMessageText( "azbuddy.ui.menu.ping" ) );
ping_item.addSelectionListener(
new SelectionAdapter()
{
public void
widgetSelected(
SelectionEvent event )
{
TableItem[] selection = buddy_table.getSelection();
for (int i=0;i<selection.length;i++){
BuddyPluginBuddy buddy = (BuddyPluginBuddy)selection[i].getData();
try{
buddy.ping();
}catch( Throwable e ){
print( "Ping failed", e );
}
}
};
});
// ygm
final MenuItem ygm_item = new MenuItem(menu, SWT.PUSH);
ygm_item.setText( lu.getLocalisedMessageText( "azbuddy.ui.menu.ygm" ) );
ygm_item.addSelectionListener(
new SelectionAdapter()
{
public void
widgetSelected(
SelectionEvent event )
{
TableItem[] selection = buddy_table.getSelection();
for (int i=0;i<selection.length;i++){
BuddyPluginBuddy buddy = (BuddyPluginBuddy)selection[i].getData();
try{
buddy.setMessagePending();
}catch( Throwable e ){
print( "YGM failed", e );
}
}
};
});
// encrypt
final MenuItem encrypt_item = new MenuItem(menu, SWT.PUSH);
encrypt_item.setText( lu.getLocalisedMessageText( "azbuddy.ui.menu.enc" ) );
encrypt_item.addSelectionListener(
new SelectionAdapter()
{
public void
widgetSelected(
SelectionEvent event )
{
TableItem[] selection = buddy_table.getSelection();
String str = readFromClipboard();
if( str != null ){
StringBuffer sb = new StringBuffer();
for (int i=0;i<selection.length;i++){
BuddyPluginBuddy buddy = (BuddyPluginBuddy)selection[i].getData();
try{
byte[] contents = str.getBytes( "UTF-8" );
BuddyPlugin.cryptoResult result = buddy.encrypt( contents );
sb.append( "key: " );
sb.append( plugin.getPublicKey());
sb.append( "\r\n" );
sb.append( "hash: " );
sb.append( Base32.encode( result.getChallenge()));
sb.append( "\r\n" );
sb.append( "payload: " );
sb.append( Base32.encode( result.getPayload()));
sb.append( "\r\n\r\n" );
}catch( Throwable e ){
print( "YGM failed", e );
}
}
writeToClipboard( sb.toString());
}
};
});
// decrypt
final MenuItem decrypt_item = new MenuItem(menu, SWT.PUSH);
decrypt_item.setText( lu.getLocalisedMessageText( "azbuddy.ui.menu.dec" ) );
decrypt_item.addSelectionListener(
new SelectionAdapter()
{
public void
widgetSelected(
SelectionEvent event )
{
String str = readFromClipboard();
if ( str != null ){
String[] bits = str.split( "\n" );
StringBuffer sb = new StringBuffer();
BuddyPluginBuddy buddy = null;
byte[] hash = null;
for (int i=0;i<bits.length;i++){
String bit = bits[i].trim();
if ( bit.length() > 0 ){
int pos = bit.indexOf( ':' );
if ( pos == -1 ){
continue;
}
String lhs = bit.substring( 0, pos ).trim();
String rhs = bit.substring( pos+1 ).trim();
if ( lhs.equals( "key" )){
buddy = plugin.getBuddyFromPublicKey( rhs );
}else if ( lhs.equals( "hash" )){
hash = Base32.decode( rhs );
}else if ( lhs.equals( "payload" )){
byte[] payload = Base32.decode( rhs );
if ( buddy != null ){
try{
BuddyPlugin.cryptoResult result = buddy.decrypt( payload );
byte[] sha1 = new SHA1Simple().calculateHash( result.getChallenge());
sb.append( "key: " );
sb.append( buddy.getPublicKey());
sb.append( "\r\n" );
sb.append( "hash_ok: " + Arrays.equals( hash, sha1 ));
sb.append( "\r\n" );
sb.append( "payload: " );
sb.append( new String( result.getPayload(), "UTF-8" ));
sb.append( "\r\n\r\n" );
}catch( Throwable e ){
print( "decrypt failed", e );
}
}
}
}
}
if ( sb.length() > 0 ){
writeToClipboard( sb.toString());
}
}
};
});
// sign
final MenuItem sign_item = new MenuItem(menu, SWT.PUSH);
sign_item.setText( lu.getLocalisedMessageText( "azbuddy.ui.menu.sign" ) );
sign_item.addSelectionListener(
new SelectionAdapter()
{
public void
widgetSelected(
SelectionEvent event )
{
String str = readFromClipboard();
if ( str != null ){
StringBuffer sb = new StringBuffer();
try{
sb.append( "key: " );
sb.append( plugin.getPublicKey());
sb.append( "\r\n" );
byte[] payload = str.getBytes( "UTF-8" );
sb.append( "data: " );
sb.append( Base32.encode( payload ));
sb.append( "\r\n" );
byte[] sig = plugin.sign( payload );
sb.append( "sig: " );
sb.append( Base32.encode( sig ));
sb.append( "\r\n" );
}catch( Throwable e ){
print( "sign failed", e );
}
if ( sb.length() > 0 ){
writeToClipboard( sb.toString());
}
}
};
});
// verify
final MenuItem verify_item = new MenuItem(menu, SWT.PUSH);
verify_item.setText( lu.getLocalisedMessageText( "azbuddy.ui.menu.verify" ) );
verify_item.addSelectionListener(
new SelectionAdapter()
{
public void
widgetSelected(
SelectionEvent event )
{
String str = readFromClipboard();
if ( str != null ){
String[] bits = str.split( "\n" );
StringBuffer sb = new StringBuffer();
String pk = null;
byte[] data = null;
for (int i=0;i<bits.length;i++){
String bit = bits[i].trim();
if ( bit.length() > 0 ){
int pos = bit.indexOf( ':' );
if ( pos == -1 ){
continue;
}
String lhs = bit.substring( 0, pos ).trim();
String rhs = bit.substring( pos+1 ).trim();
if ( lhs.equals( "key" )){
pk = rhs;
}else if ( lhs.equals( "data" )){
data = Base32.decode( rhs );
}else if ( lhs.equals( "sig" )){
byte[] sig = Base32.decode( rhs );
if ( pk != null && data != null ){
try{
sb.append( "key: " );
sb.append( pk );
sb.append( "\r\n" );
boolean ok = plugin.verify( pk, data, sig );
sb.append( "sig_ok: " + ok );
sb.append( "\r\n" );
sb.append( "data: " );
sb.append( new String( data, "UTF-8" ));
sb.append( "\r\n\r\n" );
}catch( Throwable e ){
print( "decrypt failed", e );
}
}
}
}
}
if ( sb.length() > 0 ){
writeToClipboard( sb.toString());
}
}
};
});
// cats
Menu cat_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
MenuItem cat_item = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(cat_item, "azbuddy.ui.menu.cat" );
cat_item.setMenu(cat_menu);
// cats - share
final MenuItem cat_share_item = new MenuItem(cat_menu, SWT.PUSH);
cat_share_item.setText( lu.getLocalisedMessageText( "azbuddy.ui.menu.cat.share" ) );
cat_share_item.addSelectionListener(
new SelectionAdapter()
{
public void
widgetSelected(
SelectionEvent event )
{
UIInputReceiver prompter = ui_instance.getInputReceiver();
prompter.setLocalisedTitle( lu.getLocalisedMessageText( "azbuddy.ui.menu.cat.set" ));
prompter.setLocalisedMessage( lu.getLocalisedMessageText( "azbuddy.ui.menu.cat.set_msg" ));
prompter.prompt(new UIInputReceiverListener() {
public void UIInputReceiverClosed(UIInputReceiver prompter) {
String cats = prompter.getSubmittedInput();
if ( cats != null ){
cats = cats.trim();