Package org.tinyradius.util

Examples of org.tinyradius.util.RadiusException


    int type = in.read() & 0x0ff;
    int identifier = in.read() & 0x0ff;
    int length = (in.read() & 0x0ff) << 8 | (in.read() & 0x0ff);
 
    if (request != null && request.getPacketIdentifier() != identifier)
      throw new RadiusException("bad packet: invalid packet identifier (request: " + request.getPacketIdentifier() + ", response: " + identifier);
    if (length < RADIUS_HEADER_LENGTH)
      throw new RadiusException("bad packet: packet too short (" + length + " bytes)");
    if (length > MAX_PACKET_LENGTH)
      throw new RadiusException("bad packet: packet too long (" + length + " bytes)");
 
    // read rest of packet
    byte[] authenticator = new byte[16];
    byte[] attributeData = new byte[length - RADIUS_HEADER_LENGTH];
    in.read(authenticator);
    in.read(attributeData);
 
    // check and count attributes
    int pos = 0;
    int attributeCount = 0;
    while (pos < attributeData.length) {
      if (pos + 1 >= attributeData.length)
        throw new RadiusException("bad packet: attribute length mismatch");
      int attributeLength = attributeData[pos + 1] & 0x0ff;
      if (attributeLength < 2)
        throw new RadiusException("bad packet: invalid attribute length");
      pos += attributeLength;
      attributeCount++;
    }
    if (pos != attributeData.length)
      throw new RadiusException("bad packet: attribute length mismatch");
 
    // create RadiusPacket object; set properties
    RadiusPacket rp = createRadiusPacket(type);
    rp.setPacketType(type);
    rp.setPacketIdentifier(identifier);
View Full Code Here


  throws RadiusException {
    byte[] authenticator = createResponseAuthenticator(sharedSecret, packetLength, attributes, requestAuthenticator);
    byte[] receivedAuth = getAuthenticator();
    for (int i = 0; i < 16; i++)
      if (authenticator[i] != receivedAuth[i])
        throw new RadiusException("response authenticator invalid");
  }
View Full Code Here

  protected void checkRequestAuthenticator(String sharedSecret, int packetLength, byte[] attributes) throws RadiusException {
    byte[] expectedAuthenticator = updateRequestAuthenticator(sharedSecret, packetLength, attributes);
    byte[] receivedAuth = getAuthenticator();
    for (int i = 0; i < 16; i++)
      if (expectedAuthenticator[i] != receivedAuth[i])
        throw new RadiusException("request authenticator invalid");
  }
View Full Code Here

    } else if (chapPassword != null && chapChallenge != null) {
      setAuthProtocol(AUTH_CHAP);
      this.chapPassword = chapPassword.getAttributeData();
      this.chapChallenge = chapChallenge.getAttributeData();
    } else
      throw new RadiusException("Access-Request: User-Password or CHAP-Password/CHAP-Challenge missing");
  }
View Full Code Here

  throws RadiusException {
    if (encryptedPass == null || encryptedPass.length < 16) {
      // PAP passwords require at least 16 bytes
      logger.warn("invalid Radius packet: User-Password attribute with malformed PAP password, length = " +
          encryptedPass.length + ", but length must be greater than 15");
      throw new RadiusException("malformed User-Password attribute");
    }
   
    MessageDigest md5 = getMd5Digest();
    byte[] lastBlock = new byte[16];
   
View Full Code Here

  private boolean verifyChapPassword(String plaintext)
  throws RadiusException {
    if (plaintext == null || plaintext.length() == 0)
      throw new IllegalArgumentException("plaintext must not be empty");
    if (chapChallenge == null || chapChallenge.length != 16)
      throw new RadiusException("CHAP challenge must be 16 bytes");
    if (chapPassword == null || chapPassword.length != 17)
      throw new RadiusException("CHAP password must be 17 bytes");
   
    byte chapIdentifier = chapPassword[0];
    MessageDigest md5 = getMd5Digest();
      md5.reset();
      md5.update(chapIdentifier);
View Full Code Here

    protected void proxyPacketReceived(RadiusPacket packet, InetSocketAddress remote)
    throws IOException, RadiusException {
      // retrieve my Proxy-State attribute (the last)
      List proxyStates = packet.getAttributes(33);
      if (proxyStates == null || proxyStates.size() == 0)
        throw new RadiusException("proxy packet without Proxy-State attribute");
      RadiusAttribute proxyState = (RadiusAttribute)proxyStates.get(proxyStates.size() - 1);
     
      // retrieve proxy connection from cache
      String state = new String(proxyState.getAttributeData());
        RadiusProxyConnection proxyConnection = (RadiusProxyConnection)proxyConnections.remove(state);
View Full Code Here

   * @see org.tinyradius.attribute.RadiusAttribute#readAttribute(byte[], int, int)
   */
  public void readAttribute(byte[] data, int offset, int length)
  throws RadiusException {
    if (length != 6)
      throw new RadiusException("integer attribute: expected 4 bytes data");
    super.readAttribute(data, offset, length);
  }
View Full Code Here

   * @param data
   */
  public void readAttribute(byte[] data, int offset, int length)
  throws RadiusException {
    if (length < 2)
      throw new RadiusException("attribute length too small: " + length);
    int attrType = data[offset] & 0x0ff;
    int attrLen = data[offset + 1] & 0x0ff;
    byte[] attrData = new byte[attrLen - 2];
    System.arraycopy(data, offset + 2, attrData, 0, attrLen - 2);
    setAttributeType(attrType);
View Full Code Here

   * @see org.tinyradius.attribute.RadiusAttribute#readAttribute(byte[], int, int)
   */
  public void readAttribute(byte[] data, int offset, int length)
  throws RadiusException {
    if (length != 6)
      throw new RadiusException("IP attribute: expected 4 bytes data");
    super.readAttribute(data, offset, length);
  }
View Full Code Here

TOP

Related Classes of org.tinyradius.util.RadiusException

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.