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

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


    return writer.toByteArray();
  }

  public static HelloExtension fromByteArray(byte[] byteArray) {
    DatagramReader reader = new DatagramReader(byteArray);

    int listLength = reader.read(LIST_LENGTH_BITS);

    List<ECPointFormat> ecPointFormatList = new ArrayList<ECPointFormat>();
    while (listLength > 0) {
      ECPointFormat format = ECPointFormat.getECPointFormatById(reader.read(POINT_FORMAT_BITS));
      ecPointFormatList.add(format);
     
      // one point format uses 1 byte
      listLength -= 1;
    }
View Full Code Here


    return writer.toByteArray();
  }

  public static HandshakeMessage fromByteArray(byte[] byteArray) {
    DatagramReader reader = new DatagramReader(byteArray);
   
    int length = reader.read(CERTIFICATE_TYPES_LENGTH_BITS);
    List<ClientCertificateType> certificateTypes = new ArrayList<ClientCertificateType>();
    for (int i = 0; i < length; i++) {
      int code = reader.read(CERTIFICATE_TYPE_BITS);
      certificateTypes.add(ClientCertificateType.getTypeByCode(code));
    }
   
    length = reader.read(SUPPORTED_SIGNATURE_LENGTH_BITS);
    List<SignatureAndHashAlgorithm> supportedSignatureAlgorithms = new ArrayList<SignatureAndHashAlgorithm>();
    for (int i = 0; i < length; i += 2) {
      int codeHash = reader.read(SUPPORTED_SIGNATURE_BITS);
      int codeSignature = reader.read(SUPPORTED_SIGNATURE_BITS);
      supportedSignatureAlgorithms.add(new SignatureAndHashAlgorithm(HashAlgorithm.getAlgorithmByCode(codeHash), SignatureAlgorithm.getAlgorithmByCode(codeSignature)));
    }
   
    length = reader.read(CERTIFICATE_AUTHORITIES_LENGTH_BITS);
    List<DistinguishedName> certificateAuthorities = new ArrayList<DistinguishedName>();
    while (length > 0) {
      int nameLength = reader.read(CERTIFICATE_AUTHORITY_LENGTH_BITS);
      byte[] name = reader.readBytes(nameLength);
      certificateAuthorities.add(new DistinguishedName(name));
     
      length -= 2 + name.length;
     
    }
View Full Code Here

    return writer.toByteArray();
  }

  public static HandshakeMessage fromByteArray(byte[] byteArray) {
    DatagramReader reader = new DatagramReader(byteArray);

    byte[] verifyData = reader.readBytesLeft();

    return new Finished(verifyData);
  }
View Full Code Here

    return sb.toString();
  };
 
  public static HelloExtension fromByteArray(byte[] byteArray) {
    DatagramReader reader = new DatagramReader(byteArray);
   
    List<CertificateType> certificateTypes = new ArrayList<CertificateType>();
   
    // the client's extension needs at least 2 bytes, while the server's is exactly 1 byte long
    boolean isClientExtension = true;
    if (byteArray.length > 1) {
      int length = reader.read(LIST_FIELD_LENGTH_BITS);
      for (int i = 0; i < length; i++) {
        certificateTypes.add(CertificateType.getTypeFromCode(reader.read(EXTENSION_TYPE_BITS)));
      }
    } else {
      certificateTypes.add(CertificateType.getTypeFromCode(reader.read(EXTENSION_TYPE_BITS)));
      isClientExtension = false;
    }

    return new ClientCertificateTypeExtension(isClientExtension, certificateTypes);
  }
View Full Code Here

    return writer.toByteArray();
  }

  public static HandshakeMessage fromByteArray(byte[] byteArray) {
    DatagramReader reader = new DatagramReader(byteArray);

    // according to http://tools.ietf.org/html/rfc5246#section-4.7 the
    // signature algorithm must also be included
    int hashAlgorithm = reader.read(HASH_ALGORITHM_BITS);
    int signatureAlgorithm = reader.read(SIGNATURE_ALGORITHM_BITS);
    SignatureAndHashAlgorithm signAndHash = new SignatureAndHashAlgorithm(hashAlgorithm, signatureAlgorithm);

    int length = reader.read(SIGNATURE_LENGTH_BITS);
    byte[] signature = reader.readBytes(length);

    return new CertificateVerify(signAndHash, signature);
  }
View Full Code Here

    return writer.toByteArray();
  }

  public static HandshakeMessage fromByteArray(byte[] byteArray) {
    DatagramReader reader = new DatagramReader(byteArray);

    int major = reader.read(VERSION_BITS);
    int minor = reader.read(VERSION_BITS);
    ProtocolVersion version = new ProtocolVersion(major, minor);

    int cookieLength = reader.read(COOKIE_LENGTH_BITS);
    Cookie cookie = new Cookie(reader.readBytes(cookieLength));

    return new HelloVerifyRequest(version, cookie);
  }
View Full Code Here

    return writer.toByteArray();
  }

  public static HandshakeMessage fromByteArray(byte[] byteArray, boolean useRawPublicKey) {

    DatagramReader reader = new DatagramReader(byteArray);

    int certificateChainLength = reader.read(CERTIFICATE_LENGTH_BITS);
   
    CertificateMessage message;
    if (useRawPublicKey) {
      int certificateLength = reader.read(CERTIFICATE_LENGTH_BITS);
      byte[] rawPublicKey = reader.readBytes(certificateLength);
      message = new CertificateMessage(rawPublicKey);
    } else {
      List<Certificate> certs = new ArrayList<Certificate>();

      CertificateFactory certificateFactory = null;
      while (certificateChainLength > 0) {
        int certificateLength = reader.read(CERTIFICATE_LENGTH_BITS);
        byte[] certificate = reader.readBytes(certificateLength);

        // the size of the length and the actual length of the encoded certificate
        certificateChainLength -= (CERTIFICATE_LENGTH_BITS/8) + certificateLength;

        try {
View Full Code Here

    return writer.toByteArray();
  }

  public static HandshakeMessage fromByteArray(byte[] byteArray, KeyExchangeAlgorithm keyExchange, boolean useRawPublicKey) throws HandshakeException {
    DatagramReader reader = new DatagramReader(byteArray);
    HandshakeType type = HandshakeType.getTypeByCode(reader.read(MESSAGE_TYPE_BITS));

    int length = reader.read(MESSAGE_LENGTH_BITS);

    int messageSeq = reader.read(MESSAGE_SEQ_BITS);

    int fragmentOffset = reader.read(FRAGMENT_OFFSET_BITS);
    int fragmentLength = reader.read(FRAGMENT_LENGTH_BITS);

    byte[] bytesLeft = reader.readBytes(fragmentLength);
   
    if (length != fragmentLength) {
      // fragmented message received
      return new FragmentedHandshakeMessage(type, length, messageSeq, fragmentOffset, bytesLeft);
    }
View Full Code Here

    return writer.toByteArray();
  }

  public static HelloExtensions fromByteArray(byte[] byteArray) throws HandshakeException {
    DatagramReader reader = new DatagramReader(byteArray);
    List<HelloExtension> extensions = new ArrayList<HelloExtension>();

    int length = reader.read(LENGTH_BITS);

    while (length > 0) {

      ExtensionType type = ExtensionType.getExtensionTypeById(reader.read(TYPE_BITS));
      int extensionLength = reader.read(EXTENSION_LENGTH_BITS);
     
      if (type != null) {
        HelloExtension helloExtension = HelloExtension.fromByteArray(reader.readBytes(extensionLength), type);
        extensions.add(helloExtension);
      }

      // the extensions length + 2 bytes for type field and 2 bytes for
      // length field
View Full Code Here

    return writer.toByteArray();
  }

  public static HelloExtension fromByteArray(byte[] byteArray) {
    DatagramReader reader = new DatagramReader(byteArray);

    int listLength = reader.read(LIST_LENGTH_BITS);

    List<Integer> ellipticCurveList = new ArrayList<Integer>();
    while (listLength > 0) {
      int id = reader.read(CURVE_BITS);
      ellipticCurveList.add(id);

      listLength -= 2;
    }
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.