コード例 #1
0
ファイル: ENCRYPT.java プロジェクト: x97mdr/JGroups
  private void encryptAndSend(Message msg) throws Exception {
    EncryptHeader hdr = new EncryptHeader(EncryptHeader.ENCRYPT, getSymVersion());
    if (this.encrypt_entire_message) hdr.type |= EncryptHeader.ENCRYPT_ENTIRE_MSG;

    if (encrypt_entire_message) {
      if (msg.getSrc() == null) msg.setSrc(local_addr);

      Buffer serialized_msg = Util.streamableToBuffer(msg);
      byte[] encrypted_msg =
          code(
              serialized_msg.getBuf(),
              serialized_msg.getOffset(),
              serialized_msg.getLength(),
              false);

      // exclude existing headers, they will be seen again when we decrypt and unmarshal the msg at
      // the receiver
      Message tmp = msg.copy(false, false).setBuffer(encrypted_msg).putHeader(this.id, hdr);
      down_prot.down(new Event(Event.MSG, tmp));
      return;
    }

    // copy neeeded because same message (object) may be retransmitted -> no double encryption
    Message msgEncrypted =
        msg.copy(false)
            .putHeader(this.id, hdr)
            .setBuffer(code(msg.getRawBuffer(), msg.getOffset(), msg.getLength(), false));
    down_prot.down(new Event(Event.MSG, msgEncrypted));
  }
コード例 #2
0
ファイル: UDP.java プロジェクト: NZDIS/jgroups
  /** Send a message to the address specified in dest */
  void sendUdpMessage(Message msg) throws Exception {
    IpAddress dest;
    Message copy;
    Event evt;

    dest = (IpAddress) msg.getDest(); // guaranteed not to be null
    setSourceAddress(msg);

    if (Trace.debug) {
      Trace.debug(
          "UDP.sendUdpMessage()",
          "sending message to "
              + msg.getDest()
              + " (src="
              + msg.getSrc()
              + "), headers are "
              + msg.getHeaders());

      // Don't send if destination is local address. Instead, switch dst and src and put in
      // up_queue.
      // If multicast message, loopback a copy directly to us (but still multicast). Once we receive
      // this,
      // we will discard our own multicast message
    }
    if (loopback && (dest.equals(local_addr) || dest.isMulticastAddress())) {
      copy = msg.copy();
      copy.removeHeader(name);
      copy.setSrc(local_addr);
      copy.setDest(dest);
      evt = new Event(Event.MSG, copy);

      /* Because Protocol.up() is never called by this bottommost layer, we call up() directly in the observer.
      This allows e.g. PerfObserver to get the time of reception of a message */
      if (observer != null) {
        observer.up(evt, up_queue.size());
      }
      if (Trace.debug) {
        Trace.info("UDP.sendUdpMessage()", "looped back local message " + copy);
      }
      passUp(evt);
      if (!dest.isMulticastAddress()) {
        return;
      }
    }

    if (use_outgoing_packet_handler) {
      outgoing_queue.add(msg);
      return;
    }

    send(msg);
  }
コード例 #3
0
 /**
  * ns4 is declared on Body and is used in faultcode. So making sure it is picked up after copy()
  */
 public void testCopy20() throws Exception {
   String soap18Msg =
       "<S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/'>"
           + "<S:Body xmlns:ns4='http://schemas.xmlsoap.org/soap/envelope/'>"
           + "<S:Fault>"
           + "<faultcode>ns4:Server</faultcode>"
           + "<faultstring>com.sun.istack.XMLStreamException2</faultstring>"
           + "</S:Fault>"
           + "</S:Body>"
           + "</S:Envelope>";
   Message message = useStreamCodec(soap18Msg);
   message.copy();
   SOAPFaultBuilder.create(message).createException(null);
 }
コード例 #4
0
ファイル: ENCRYPT.java プロジェクト: x97mdr/JGroups
 /**
  * used to drain the up queue - synchronized so we can call it safely despite access from
  * potentially two threads at once
  */
 private void drainUpQueue() {
   if (log.isTraceEnabled()) {
     int size = upMessageQueue.size();
     if (size > 0) log.trace("draining %d messages from the up queue", size);
   }
   while (true) {
     try {
       Message tmp = upMessageQueue.poll(0L, TimeUnit.MILLISECONDS);
       if (tmp == null) break;
       Message msg = decryptMessage(null, tmp.copy()); // need to copy for possible xmits
       if (msg != null) up_prot.up(new Event(Event.MSG, msg));
     } catch (Throwable t) {
       log.error(Util.getMessage("FailedDecryptingAndSendingMessageUpWhenDrainingQueue"), t);
     }
   }
 }
コード例 #5
0
ファイル: ENCRYPT.java プロジェクト: x97mdr/JGroups
    public Message visit(Message msg, MessageBatch batch) {
      EncryptHeader hdr;

      if (msg == null
          || (msg.getLength() == 0 && !encrypt_entire_message)
          || ((hdr = (EncryptHeader) msg.getHeader(id)) == null)) return null;

      if (hdr.getType() == EncryptHeader.ENCRYPT) {
        // if queueing then pass into queue to be dealt with later
        if (queue_up) {
          queueUpMessage(msg, batch);
          return null;
        }

        // make sure we pass up any queued messages first
        if (!suppliedKey) drainUpQueue();

        if (lock == null) {
          int index = getNextIndex();
          lock = decoding_locks[index];
          cipher = decoding_ciphers[index];
          lock.lock();
        }

        try {
          Message tmpMsg = decryptMessage(cipher, msg.copy()); // need to copy for possible xmits
          if (tmpMsg != null) batch.replace(msg, tmpMsg);
        } catch (Exception e) {
          log.error(
              "failed decrypting message from %s (offset=%d, length=%d, buf.length=%d): %s, headers are %s",
              msg.getSrc(),
              msg.getOffset(),
              msg.getLength(),
              msg.getRawBuffer().length,
              e,
              msg.printHeaders());
        }
      } else {
        batch.remove(
            msg); // a control message will get handled by ENCRYPT and should not be passed up
        handleUpEvent(msg, hdr);
      }
      return null;
    }
コード例 #6
0
ファイル: ENCRYPT.java プロジェクト: x97mdr/JGroups
  @SuppressWarnings("UnusedParameters")
  protected Object handleEncryptedMessage(Message msg, Event evt, EncryptHeader hdr)
      throws Exception {
    // if queueing then pass into queue to be dealt with later
    if (queue_up) {
      log.trace("queueing up message as no session key established: %s", msg);
      upMessageQueue.put(msg);
      return null;
    }

    // make sure we pass up any queued messages first
    // could be more optimised but this can wait we only need this if not using supplied key
    if (!suppliedKey) drainUpQueue();

    // try and decrypt the message - we need to copy msg as we modify its
    // buffer (http://jira.jboss.com/jira/browse/JGRP-538)
    Message tmpMsg = decryptMessage(null, msg.copy()); // need to copy for possible xmits
    if (tmpMsg != null) return up_prot.up(new Event(Event.MSG, tmpMsg));
    log.warn("unrecognised cipher; discarding message");
    return null;
  }
コード例 #7
0
 public void testCopy16() throws IOException {
   String soap16Msg =
       "<S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/'> <S:Body> <a> </a><b> </b> <c/> </S:Body> </S:Envelope>";
   Message message = useStreamCodec(soap16Msg);
   message.copy();
 }
コード例 #8
0
 public void testCopyWithSpaces() throws IOException {
   String soap12Msg =
       "<?xml version='1.0'?><S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/'> <S:Header> <m:ut xmlns:m='a'> <u xmlns='' id='a'>user</u> </m:ut> <b> hello </b> </S:Header> <S:Body> <ns2:c xmlns:ns2='local'> <clientName>Test</clientName> <ns2:year>2007</ns2:year> </ns2:c> </S:Body> </S:Envelope>";
   Message message = useStreamCodec(soap12Msg);
   message.copy();
 }
コード例 #9
0
 public void testCopyStreamMessage1() throws IOException {
   String soap11Msg =
       "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><Header xmlns='http://schemas.xmlsoap.org/soap/envelope/'> <SubscriptionInfo xmlns='http://ws.strikeiron.com'> <LicenseStatusCode>0</LicenseStatusCode> </SubscriptionInfo> </Header> <soap:Body> <GetCountryCodesResponse xmlns='http://www.strikeiron.com'> <GetCountryCodesResult/></GetCountryCodesResponse></soap:Body></soap:Envelope>";
   Message message = useStreamCodec(soap11Msg);
   message.copy();
 }