Thread: Apollo LoginDecoder

Results 1 to 10 of 10
  1. #1 Apollo LoginDecoder 
    Registered Member Mini's Avatar
    Join Date
    Jul 2007
    Posts
    285
    Thanks given
    5
    Thanks received
    7
    Rep Power
    35
    Could someone explain why this code doesn't cooperate with certain client revisions?
    I don't understand why my 474 clients don't connect to this but it came from the Apollo484 and my 317 client will.

    Code:
    	private Object decodePayload(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
    		if (buffer.readableBytes() >= loginLength) {
    			ChannelBuffer payload = buffer.readBytes(loginLength);
    			int releaseNumber = payload.readInt();
    			int lowMemoryFlag = payload.readUnsignedByte();
    			if (lowMemoryFlag != 0 && lowMemoryFlag != 1) 
    				throw new Exception("Invalid value for low memory flag");
    
    			boolean lowMemory = lowMemoryFlag == 1;
    			
    			for (int i = 0; i < 24; i++)
    				payload.readByte();
    			
    			int[] archiveCrcs = new int[16];
    			for (int i = 0; i < 16; i++) 
    				archiveCrcs[i] = payload.readInt();
    
    			loginLength--;
    			
    			int securePayloadLength = payload.readUnsignedByte();
    			int secureBytesLength = (loginLength - 93);
    			if (securePayloadLength != secureBytesLength) 
    				throw new Exception("Secure payload length mismatch");
    			
    			byte[] secureBytes = new byte[secureBytesLength];
    			payload.readBytes(secureBytes);
    			ChannelBuffer securePayload = ChannelBuffers.wrappedBuffer(new BigInteger(secureBytes).modPow(RSA_EXPONENT, RSA_MODULUS).toByteArray());
    
    			int secureId = securePayload.readUnsignedByte();
    			if (secureId != 10) 
    				throw new Exception("Invalid secure payload id");
    
    			long clientSeed = securePayload.readLong();
    			long reportedServerSeed = securePayload.readLong();
    			
    			if (reportedServerSeed != serverSeed) 
    				throw new Exception("Server seed mismatch");
    			
    			String username = NameUtil.decodeBase37(securePayload.readLong());
    			String password = ChannelBufferUtil.readString(securePayload);
    			
    			if (username.length() > 12 || password.length() > 20) 
    				throw new Exception("Username or password too long");
    
    			int[] seed = new int[4];
    			seed[0] = (int) (clientSeed >> 32);
    			seed[1] = (int) clientSeed;
    			seed[2] = (int) (serverSeed >> 32);
    			seed[3] = (int) serverSeed;
    
    			IsaacRandom decodingRandom = new IsaacRandom(seed);
    			for (int i = 0; i < seed.length; i++) 
    				seed[i] += 50;
    			IsaacRandom encodingRandom = new IsaacRandom(seed);
    
    			PlayerCredentials credentials = new PlayerCredentials(username, password, usernameHash);
    			IsaacRandomPair randomPair = new IsaacRandomPair(encodingRandom, decodingRandom);
    			LoginRequest req = new LoginRequest(credentials, randomPair, reconnecting, lowMemory, releaseNumber, archiveCrcs);
    			if (buffer.readable()) {
    				return new Object[] { req, buffer.readBytes(buffer.readableBytes()) };
    			} else {
    				return req;
    			}
    		}
    		return null;
    	}
    Reply With Quote  
     

  2. #2  
    SERGEANT OF THE MASTER SERGEANTS MOST IMPORTANT PERSON OF EXTREME SERGEANTS TO THE MAX!

    cube's Avatar
    Join Date
    Jun 2007
    Posts
    8,871
    Thanks given
    1,854
    Thanks received
    4,745
    Rep Power
    5000
    Make sure it makes it through the previous steps too (handshake and header), they are different in 317 and 474 as far as I remember.
    You could also do some debugging by putting println's etc around the code to see where it may possibly fail

    Attached image

    Reply With Quote  
     

  3. #3  
    Registered Member Mini's Avatar
    Join Date
    Jul 2007
    Posts
    285
    Thanks given
    5
    Thanks received
    7
    Rep Power
    35
    Quote Originally Posted by S Quare Quxx View Post
    Make sure it makes it through the previous steps too (handshake and header), they are different in 317 and 474 as far as I remember.
    You could also do some debugging by putting println's etc around the code to see where it may possibly fail
    Although I haven't checked the previous steps. I did have prints around this code and I noticed that for example:

    Code:
    int securePayloadLength = payload.readUnsignedByte();
    			int secureBytesLength = (loginLength - 93);
    			if (securePayloadLength != secureBytesLength) 
    				throw new Exception("Secure payload length mismatch");
    When I changed "93" to a number that would make the if statement work, it would throw an exception on the next. And the number to replace 93 with wasn't consistent. It also changed when I used different logins which is problematic.


    A more detailed explanation of my problem...
    I threw a system print before the code I posted above to determine the loginLength. This changes with different name/password lengths. I have studied the Rs474 LoginDecoder and have recognized the similar system however it is similar to the extent that it has everything around the above code, but not the code or anything equivalent.
    Reply With Quote  
     

  4. #4  
    Registered Member

    Join Date
    Sep 2009
    Posts
    1,919
    Thanks given
    480
    Thanks received
    1,687
    Rep Power
    1262
    Subtract by 41 instead of 93? Thats the only difference I can see. The RSA keys are supposed to change as well.
    Attached image
    Reply With Quote  
     

  5. #5  
    Registered Member Mini's Avatar
    Join Date
    Jul 2007
    Posts
    285
    Thanks given
    5
    Thanks received
    7
    Rep Power
    35
    Quote Originally Posted by Cjay0091 View Post
    Subtract by 41 instead of 93? Thats the only difference I can see. The RSA keys are supposed to change as well.
    I printed the variables in the if statement that is throwing my client

    Code:
    loginLength--;
    			System.out.print("Done5");
    			System.out.print(loginLength);
    			int securePayloadLength = payload.readUnsignedByte();
    			int secureBytesLength = (loginLength - 114);
    			System.out.print(secureBytesLength);
    			System.out.print(securePayloadLength);
    			if (securePayloadLength != secureBytesLength) 
    				throw new Exception("Secure payload length mismatch");
    The thing is loginLength changes upon username/password length. I think it varied from 119-135 as you can see that would cause trouble with the if statement. I set it to 114(loginLength=124) for the time being to suite my common username and of course was halted by the next if statement.

    As far as RSA keys do they differ that from client to client? My current client has no RSA keys, but when I did add them(to another 474 client) at one point it changed nothing.
    Reply With Quote  
     

  6. #6  
    Registered Member

    Join Date
    Sep 2009
    Posts
    1,919
    Thanks given
    480
    Thanks received
    1,687
    Rep Power
    1262
    It doesn't change the result, but the keys have to be 512 bits.

    Search for Niki's tutorial.
    Attached image
    Reply With Quote  
     

  7. #7  
    Registered Member Mini's Avatar
    Join Date
    Jul 2007
    Posts
    285
    Thanks given
    5
    Thanks received
    7
    Rep Power
    35
    Quote Originally Posted by Cjay0091 View Post
    It doesn't change the result, but the keys have to be 512 bits.

    Search for Niki's tutorial.
    Well that did change my problem. I managed to add the RSA keys from the server. Now this is crashing my client

    Code:
    	private Object decodeHandshake(ChannelHandlerContext ctx, Channel channel,
    			ChannelBuffer buffer) throws Exception {
    		if (buffer.readable()) {
    			usernameHash = buffer.readUnsignedByte();
    			serverSeed = random.nextLong();
    			ChannelBuffer resp = ChannelBuffers.buffer(9);
    			System.out.print("Done1");
    			resp.writeByte(LoginConstants.STATUS_EXCHANGE_DATA);
    			resp.writeLong(serverSeed);
    			channel.write(resp);
    			setState(LoginDecoderState.LOGIN_HEADER);
    			System.out.print("Done2");
    		}
    		return null;
    	}
    I'm just throwing this up here... I'll study it for a bit, but if you all have something to share, go for it.
    Reply With Quote  
     

  8. #8  
    Member Apollo LoginDecoder Market Banned


    Luke132's Avatar
    Join Date
    Dec 2007
    Age
    35
    Posts
    12,574
    Thanks given
    199
    Thanks received
    7,106
    Rep Power
    5000
    download scu's 474 server and see what changed, or look at the client and work it out and become an rsps master, choose wisely bro

    Attached imageAttached image
    Reply With Quote  
     

  9. #9  
    Registered Member Mini's Avatar
    Join Date
    Jul 2007
    Posts
    285
    Thanks given
    5
    Thanks received
    7
    Rep Power
    35
    Yeah it's odd. I used the client that came with rs2-server 474 and my original problem still occurred.
    However if I use the 474 client I downloaded from another topic it never even passes decodeHandshake.

    I've been studying the code and other code consistently for the past 30 hours or so, as I'm sitting in a hospital with nothing better to do.
    Reply With Quote  
     

  10. #10  
    Registered Member DarkSlayerz's Avatar
    Join Date
    Nov 2008
    Posts
    928
    Thanks given
    88
    Thanks received
    44
    Rep Power
    46
    bump, im getting this error to?
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Apollo
    By Graham in forum Downloads
    Replies: 390
    Last Post: 05-11-2017, 09:06 PM
  2. [Apollo]NPC Updating[Apollo]
    By The Wanderer in forum Tutorials
    Replies: 41
    Last Post: 09-06-2013, 02:19 AM
  3. [Apollo]
    By Lee in forum Help
    Replies: 3
    Last Post: 07-24-2012, 03:34 PM
  4. [Apollo or any] XML Controller [Apollo or any]
    By Tamatea in forum Snippets
    Replies: 5
    Last Post: 03-28-2012, 05:08 PM
  5. Apollo please help!
    By Bernard in forum Help
    Replies: 0
    Last Post: 01-13-2012, 04:14 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •