Ejemplo n.º 1
0
 @Override
 public DD_SK decode(Decoder dec) throws ASN1DecoderFail {
   String default_orgGID = null;
   String default_orgGIDH = null;
   Decoder d = dec.getContent();
   if (d.getTypeByte() == DD.TAG_AP0)
     version = d.getFirstObject(true).getInteger(DD.TAG_AP0).intValue();
   if (d.getTypeByte() == DD.TAG_AC0)
     sk = d.getFirstObject(true).getSequenceOfAL(DD_SK_Entry.getASN1Tag(), new DD_SK_Entry());
   if (d.getTypeByte() == DD.TAG_AC1)
     peer = d.getFirstObject(true).getSequenceOfAL(D_Peer.getASN1Type(), D_Peer.getEmpty());
   if (d.getTypeByte() == DD.TAG_AC2) {
     org =
         d.getFirstObject(true)
             .getSequenceOfAL(D_Organization.getASN1Type(), D_Organization.getEmpty());
     if (org.size() == 1) {
       default_orgGID = org.get(0).getGID();
       default_orgGIDH = org.get(0).getGIDH();
       if (DEBUG)
         System.out.println(
             "DD_SK: has a GID for orgs: " + default_orgGID + " H=" + default_orgGIDH);
     }
   }
   if (d.getTypeByte() == DD.TAG_AC3)
     neigh =
         d.getFirstObject(true)
             .getSequenceOfAL(D_Neighborhood.getASN1Type(), D_Neighborhood.getEmpty());
   if (d.getTypeByte() == DD.TAG_AC4)
     constit =
         d.getFirstObject(true)
             .getSequenceOfAL(D_Constituent.getASN1Type(), D_Constituent.getEmpty());
   if (d.getTypeByte() == DD.TAG_AC5)
     witn = d.getFirstObject(true).getSequenceOfAL(D_Witness.getASN1Type(), D_Witness.getEmpty());
   if (d.getTypeByte() == DD.TAG_AC6) {
     moti = d.getFirstObject(true).getSequenceOfAL(D_Motion.getASN1Type(), D_Motion.getEmpty());
     for (D_Motion m : moti) {
       if (m.getOrganizationGIDH() == null) {
         if (_DEBUG) System.out.println("DD_SK: put a GIDH for " + m);
         m.setOrganizationGID(default_orgGIDH);
         if (_DEBUG) System.out.println("DD_SK: did put a GIDH for " + m);
       } else if (DEBUG) System.out.println("DD_SK: had a GIDH for " + m);
     }
   }
   if (d.getTypeByte() == DD.TAG_AC7)
     just =
         d.getFirstObject(true)
             .getSequenceOfAL(D_Justification.getASN1Type(), D_Justification.getEmpty());
   if (d.getTypeByte() == DD.TAG_AC8)
     vote = d.getFirstObject(true).getSequenceOfAL(D_Vote.getASN1Type(), D_Vote.getEmpty());
   if (d.getTypeByte() == DD.TAG_AC10)
     tran =
         d.getFirstObject(true)
             .getSequenceOfAL(D_Translations.getASN1Type(), D_Translations.getEmpty());
   if (d.getTypeByte() == DD.TAG_AP1) sender = D_Peer.getEmpty().decode(d.getFirstObject(true));
   if (d.getTypeByte() == DD.TAG_AP2) signature = d.getFirstObject(true).getBytes(DD.TAG_AP2);
   return this;
 }
Ejemplo n.º 2
0
 @Override
 public Encoder getEncoder() {
   Encoder enc = getSignEncoder();
   if (sender != null) enc.addToSequence(sender.getEncoder().setASN1Type(DD.TAG_AP1));
   if (signature != null) enc.addToSequence(new Encoder(signature).setASN1Type(DD.TAG_AP2));
   enc.setASN1Type(Encoder.CLASS_APPLICATION, Encoder.PC_CONSTRUCTED, getASN1Tag());
   return enc;
 }
Ejemplo n.º 3
0
 @Override
 public String getNiceDescription() {
   String result = "";
   for (DD_SK_Entry _sk : sk)
     result += "SK[: sk=" + _sk.name + "]"; // Util.concat(sk, ";;;", "NULL");
   for (D_Peer _peer : peer) result += " Safe=[" + _peer.getName() + "]";
   for (D_Organization _org : org) result += " Org=[" + _org.getName() + "]";
   for (D_Constituent _constit : constit) result += " Cons=[" + _constit.getNameFull() + "]";
   for (D_Witness _witn : witn) result += " Witn=[" + _witn.witnessed_global_constituentID + "]";
   for (D_Motion _moti : moti) result += " Moti=[" + _moti.getTitleStrOrMy() + "]";
   for (D_Justification _just : just) result += " Just=[" + _just.getTitleStrOrMy() + "]";
   for (D_News _news : news) result += " News=[" + _news.getTitleStrOrMy() + "]";
   for (D_Vote _vote : vote)
     result += " Vote=[" + _vote.getChoice() + " " + _vote.getMotionGID() + "]";
   // to implement
   if (tran.size() > 0) result += " tran=" + Util.concat(tran, ",,,", "NULL");
   result += "]";
   return result;
 }
Ejemplo n.º 4
0
 /**
  * Sets the sender and computes the signature
  *
  * @param me
  */
 public void sign_and_set_sender(D_Peer me) {
   if (me == null) {
     sender = null;
     signature = null;
     return;
   }
   // signature = null;
   byte[] msg = this.getSignEncoder().getBytes();
   signature = Util.sign(msg, me.getSK());
   this.sender = me;
 }
Ejemplo n.º 5
0
  /**
   * @param message
   * @param peerGID
   * @param peer
   * @return the message actually sent (and its sequence numbers)
   */
  public static ChatMessage sendMessage(String message, String peerGID, D_Peer peer) {
    if (DEBUG) System.out.println("PLUGIN CHAT: Main: sendMessage enter: " + message);
    if (peer != null && peerGID == null) peerGID = peer.getGID();
    // create a hashtable where ht(key=peerGID ) ==> cm (chatMessage)
    ChannelDataOut channeldata_out = ChannelDataOut.get(peerGID);
    ChannelDataIn channeldata_in = ChannelDataIn.get(peerGID);
    if (DEBUG)
      System.out.println("PLUGIN CHAT: Main: sendMessage got channel out: " + channeldata_out);
    if (DEBUG)
      System.out.println("PLUGIN CHAT: Main: sendMessage got channel in: " + channeldata_in);
    ChatMessage cm = new ChatMessage();
    cm.session_id = channeldata_out.getSessionID();
    // cm.session_id_ack = cmsg.session_id;
    cm.message_type = ChatMessage.MT_TEXT;
    cm.first_in_this_sequence =
        channeldata_out.getFirstInSequence(); // cmsg.first_in_this_sequence;

    ChatElem ce = new ChatElem();
    ce.type = 0; // name
    ce.val = Main.name;
    cm.content = new ArrayList<ChatElem>();
    cm.content.add(ce);

    cm.msg = message;
    // first time message to this peer
    cm.session_id_ack = channeldata_in.getSessionID();
    cm.last_acknowledged_in_sequence = channeldata_in.getLastInSequence();
    cm.received_out_of_sequence = channeldata_in.getOutOfSequence();
    cm.sequence = channeldata_out.getNextSequence();
    // msgTrackingSend.put(peer_GID, cm); // only store the last message info for each peer
    // save to DB for history ( peer_GID:sender(myself): Date/Time : msg as object )
    if (DEBUG) System.out.println("PLUGIN CHAT: Main: send: " + cm);

    // confirm the sending into the GUI
    receiver.addSentMessage(cm, peerGID, channeldata_out);

    byte[] _msg = cm.encode();
    net.ddp2p.common.plugin_data.PluginRequest envelope =
        new net.ddp2p.common.plugin_data.PluginRequest();
    envelope.msg = _msg;
    envelope.peer_GID = peerGID; // destination
    envelope.type = net.ddp2p.common.plugin_data.PluginRequest.MSG;
    envelope.plugin_GID = (String) Main.getPluginDataHashtable().get("plugin_GID");
    if (DEBUG) System.out.println("PLUGIN CHAT: Main: send envelope: " + envelope);
    Main.enqueue(envelope);
    if (DEBUG) System.out.println("PLUGIN CHAT: Main: sendMessage exit");
    return cm;
  }
Ejemplo n.º 6
0
 /**
  * Verifies the signature. Always false if there is no sender.
  *
  * @return
  */
 public boolean verify() {
   if (sender == null) return false;
   byte[] msg = this.getSignEncoder().getBytes();
   return Util.verifySign(msg, sender.getPK(), signature);
 }