Package ch.ethz.inf.vs.scandium.util

Examples of ch.ethz.inf.vs.scandium.util.DatagramReader


   * @return the object representations of the DTLS records
   */
  public static List<Record> fromByteArray(byte[] byteArray) {
    List<Record> records = new ArrayList<Record>();
   
    DatagramReader reader = new DatagramReader(byteArray);
   
    while (reader.bytesAvailable()) {

      int type = reader.read(CONTENT_TYPE_BITS);
      ContentType contentType = ContentType.getTypeByValue(type);
     
      if (contentType==null) {
        LOGGER.warning(String.format("Received illegal record content type: %s", type));
        break;
      }
 
      int major = reader.read(VERSION_BITS);
      int minor = reader.read(VERSION_BITS);
      ProtocolVersion version = new ProtocolVersion(major, minor);
 
      int epoch = reader.read(EPOCH_BITS);
      long sequenceNumber = reader.readLong(SEQUENCE_NUMBER_BITS);
 
      int length = reader.read(LENGTH_BITS);
 
      // delay decryption/interpretation of fragment
      byte[] fragmentBytes = reader.readBytes(length);
 
      records.add(new Record(contentType, version, epoch, sequenceNumber, length, fragmentBytes));
    }
   
    return records;
View Full Code Here


     * The decrypted message is always 16 bytes shorter than the cipher (8
     * for the authentication tag and 8 for the explicit nonce).
     */
    byte[] additionalData = generateAdditionalData(getLength() - 16);

    DatagramReader reader = new DatagramReader(byteArray);
   
    // create explicit nonce from values provided in DTLS record
    byte[] explicitNonce = generateExplicitNonce();
    // retrieve actual explicit nonce as contained in GenericAEADCipher struct (8 bytes long)
    byte[] explicitNonceUsed = reader.readBytes(8);
    if (!Arrays.equals(explicitNonce, explicitNonceUsed) && LOGGER.isLoggable(Level.FINE)) {
      StringBuffer b = new StringBuffer("The explicit nonce used by the sender does not match the values provided in the DTLS record");
      b.append("\nUsed    : ").append(ByteArrayUtils.toHexString(explicitNonceUsed));
      b.append("\nExpected: ").append(ByteArrayUtils.toHexString(explicitNonce));
      LOGGER.log(Level.FINE, b.toString());
    }

    byte[] nonce = getNonce(iv, explicitNonceUsed);
    byte[] decrypted = CCMBlockCipher.decrypt(key, nonce, additionalData, reader.readBytesLeft(), 8);

    return decrypted;
  }
View Full Code Here

TOP

Related Classes of ch.ethz.inf.vs.scandium.util.DatagramReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.