예제 #1
0
파일: ENCRYPT.java 프로젝트: x97mdr/JGroups
  /**
   * Does the actual work for decrypting - if version does not match current cipher then tries the
   * previous cipher
   */
  private Message decryptMessage(Cipher cipher, Message msg) throws Exception {
    EncryptHeader hdr = (EncryptHeader) msg.getHeader(this.id);
    if (!Arrays.equals(hdr.getVersion(), getSymVersion())) {
      log.warn(
          "attempting to use stored cipher as message does not use current encryption version ");
      cipher = keyMap.get(new AsciiString(hdr.getVersion()));
      if (cipher == null) {
        log.warn("unable to find a matching cipher in previous key map");
        return null;
      }
      log.trace("decrypting using previous cipher version");
      synchronized (cipher) {
        return _decrypt(cipher, msg, hdr.encryptEntireMessage());
      }
    }

    return _decrypt(cipher, msg, hdr.encryptEntireMessage());
  }
예제 #2
0
파일: ENCRYPT.java 프로젝트: x97mdr/JGroups
  protected void handleUpEvent(Message msg, EncryptHeader hdr) {
    // check if we had some sort of encrypt control header if using supplied key we should not
    // process it
    if (suppliedKey) {
      log.warn("we received an encrypt header of %s while in configured mode", hdr.getType());
      return;
    }

    // see what sort of encrypt control message we have received
    switch (hdr.getType()) {
        // if a key request
      case EncryptHeader.KEY_REQUEST:
        log.debug("received a key request from peer %s", msg.getSrc());

        // if a key request send response key back
        try {
          // extract peer's public key
          PublicKey tmpKey = generatePubKey(msg.getBuffer());
          // send back the secret key we have
          sendSecretKey(getSecretKey(), tmpKey, msg.getSrc());
        } catch (Exception e) {
          log.warn("unable to reconstitute peer's public key");
        }
        break;
      case EncryptHeader.SECRETKEY:
        log.debug("received a secretkey response from keyserver %s", msg.getSrc());

        try {
          SecretKey tmp = decodeKey(msg.getBuffer());
          if (tmp == null) sendKeyRequest(); // unable to understand response, let's try again
          else {
            // otherwise lets set the returned key as the shared key
            setKeys(tmp, hdr.getVersion());
            log.debug("decoded secretkey response");
          }
        } catch (Exception e) {
          log.warn("unable to process received public key", e);
        }
        break;
      default:
        log.warn("received ignored encrypt header of %s", hdr.getType());
        break;
    }
  }