Ejemplo n.º 1
0
 /**
  * Decodes session ID.
  *
  * @param message - message to get session ID from
  * @return Session ID.
  */
 public static int decodeSessionID(RmcpMessage message) {
   int offset = 2;
   if (decodePayloadType(message.getData()[1]) == PayloadType.Oem) {
     offset += 6;
   }
   return decodeSessionID(message.getData(), offset);
 }
Ejemplo n.º 2
0
  /**
   * Decodes IPMI v2.0 message fields.
   *
   * @param rmcpMessage - RMCP message to decode.
   * @return decoded message
   * @see Ipmiv20Message
   * @throws IllegalArgumentException when delivered RMCP message does not contain encapsulated IPMI
   *     message or when AuthCode field is incorrect (integrity check fails).
   * @throws InvalidKeyException - when initiation of the integrity algorithm fails
   */
  @Override
  public IpmiMessage decode(RmcpMessage rmcpMessage)
      throws IllegalArgumentException, InvalidKeyException {
    Ipmiv20Message message = new Ipmiv20Message(cipherSuite.getConfidentialityAlgorithm());

    byte[] raw = rmcpMessage.getData();

    message.setAuthenticationType(decodeAuthenticationType(raw[0]));

    message.setPayloadEncrypted(decodeEncryption(raw[1]));

    message.setPayloadAuthenticated(decodeAuthentication(raw[1]));

    message.setPayloadType(decodePayloadType(raw[1]));

    int offset = 2;

    if (message.getPayloadType() == PayloadType.Oem) {
      message.setOemIANA(decodeOEMIANA(raw));
      offset += 4;

      message.setOemPayloadID(decodeOEMPayloadId(raw, offset));
      offset += 2;
    }

    message.setSessionID(decodeSessionID(raw, offset));
    offset += 4;

    message.setSessionSequenceNumber(decodeSessionSequenceNumber(raw, offset));
    offset += 4;

    int payloadLength = decodePayloadLength(raw, offset);
    offset += 2;

    if (message.isPayloadEncrypted()) {
      message.setPayload(
          decodePayload(raw, offset, payloadLength, message.getConfidentialityAlgorithm()));
    } else {
      message.setPayload(decodePayload(raw, offset, payloadLength, new ConfidentialityNone()));
    }

    offset += payloadLength;

    if (message.getAuthenticationType() != AuthenticationType.None
        && !(message.getAuthenticationType() == AuthenticationType.RMCPPlus
            && !message.isPayloadAuthenticated())
        && message.getSessionID() != 0) {
      offset = skipIntegrityPAD(raw, offset);
      message.setAuthCode(decodeAuthCode(raw, offset));
      if (!validateAuthCode(raw, offset)) {
        logger.warn("Integrity check failed");
      }
    }

    return message;
  }