Permalink
Browse files

Update protocol.

  • Loading branch information...
fxb committed Apr 30, 2010
1 parent 90f9670 commit 090b45fb6780fcb6b5dd0d83afab5b4f6e9116e6
@@ -206,6 +206,6 @@ public int hashCode(){
}
public String toString(){
- return String.format("[Playlist: %s, %s]", this.author, this.name, this.revision);
+ return String.format("[Playlist: %s, %s, %d]", this.author, this.name, this.revision);
}
}
@@ -73,4 +73,8 @@ public void setChecksum(long checksum){
public Iterator<Playlist> iterator(){
return this.playlists.iterator();
}
+
+ public String toString(){
+ return String.format("[PlaylistContainer: %s, %d]", this.author, this.revision);
+ }
}
@@ -106,26 +106,24 @@ public void sendInitialPacket() throws ProtocolException {
);
/* Append fields to buffer. */
- buffer.putShort((short)3); /* Version: 3 */
+ buffer.putShort((short)3); /* Version 3 */
buffer.putShort((short)0); /* Length (update later) */
- buffer.putInt(0x00000300); /* Unknown */
- buffer.putInt(this.session.clientVersion);
- buffer.putInt(this.session.clientRevision);
- buffer.putInt(0x00000000); /* Unknown */
- buffer.putInt(0x01000000); /* Unknown */
- buffer.put(this.session.clientId); /* 4 bytes */
+ buffer.putInt(this.session.clientOs);
buffer.putInt(0x00000000); /* Unknown */
+ buffer.putInt(this.session.clientRevision);
+ buffer.putInt(0x00000000); /* Windows: 0x1541ECD0, Mac OSX: 0x00000000 */
+ buffer.putInt(0x01000000); /* Windows: 0x01000000, Mac OSX: 0x01040000 */
+ buffer.putInt(this.session.clientId); /* 4 bytes, Windows: 0x010B0029, Mac OSX: 0x026A0200 */
+ buffer.putInt(0x00000001); /* Unknown */
buffer.put(this.session.clientRandom); /* 16 bytes */
buffer.put(this.session.dhClientKeyPair.getPublicKeyBytes()); /* 96 bytes */
buffer.put(this.session.rsaClientKeyPair.getPublicKeyBytes()); /* 128 bytes */
buffer.put((byte)0); /* Random length */
buffer.put((byte)this.session.username.length); /* Username length */
buffer.putShort((short)0x0100); /* Unknown */
- /* Random bytes here. */
+ /* Random bytes here... */
buffer.put(this.session.username);
- buffer.put((byte)0x40); /* Unknown */
- //buffer.put((byte)0x5c); /* Unknown */
- //buffer.put((byte)(0x00)); /* Unknown */
+ buffer.put((byte)0x40); /* Unknown (probably flags), 0x5F */
/* Update length byte. */
buffer.putShort(2, (short)buffer.position());
@@ -189,19 +187,28 @@ public void receiveInitialPacket() throws ProtocolException {
break;
}
- /* If substatus is 'Client upgrade required', read and append upgrade URL. */
+ /* If substatus is 'Client upgrade required', update client revision. */
if(this.session.serverRandom[1] == 0x01){
if((ret = this.receive(buffer, 0x11a)) > 0){
paddingLength = buffer[0x119] & 0xFF;
if((ret = this.receive(buffer, paddingLength)) > 0){
String msg = new String(Arrays.copyOfRange(buffer, 0, ret));
- Pattern pattern = Pattern.compile("\\.([0-9]+)\\.exe");
+ Pattern pattern = Pattern.compile("([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.[0-9a-z]+");
Matcher matcher = pattern.matcher(msg);
/* Update client revision. */
if(matcher.find()){
- this.session.clientRevision = Integer.parseInt(matcher.group(1));
+ /*
+ * 0x0266EF51: 40.300.369 -> 0.4.3.369.gd0ec4115
+ * 0x0266EF5C: 40.300.380 -> 0.4.3.380.g88163066
+ * 0x0266EF5C: 40.300.383 -> 0.4.3.380.g278a6e51
+ *
+ * major * 1000000000 (???) + minor * 10000000 + maintenance * 100000 + build.
+ */
+ this.session.clientRevision = Integer.parseInt(matcher.group(2)) * 10000000;
+ this.session.clientRevision += Integer.parseInt(matcher.group(3)) * 100000;
+ this.session.clientRevision += Integer.parseInt(matcher.group(4));
}
message.append(msg);
@@ -345,7 +352,7 @@ public void sendAuthenticationPacket() throws ProtocolException {
buffer.put((byte)0); /* Unknown. */
buffer.putShort((short)this.session.puzzleSolution.length);
buffer.putInt(0x0000000); /* Unknown. */
- //buffer.put(randomBytes); /* Zero random bytes :-) */
+ /* Random bytes here... */
buffer.put(this.session.puzzleSolution); /* 8 bytes */
buffer.flip();
@@ -789,10 +796,11 @@ public void sendPlaylistRequest(ChannelListener listener, String id) throws Prot
buffer.put((byte)0x02); /* Playlist identifier. TODO: 0x03 spotted. */
}
- buffer.putInt(-1); /* Revision. */
+ /* TODO */
+ buffer.putInt(-1); /* Revision. -1: no cached data. */
buffer.putInt(0); /* Number of entries. */
- buffer.putInt(-1); /* Checksum. */
- buffer.put((byte)0x01); /* Collaborative. */
+ buffer.putInt(1); /* Checksum. */
+ buffer.put((byte)0x00); /* Collaborative. */
buffer.flip();
/* Register channel. */
@@ -23,9 +23,9 @@
private Protocol protocol;
/* Client identification */
- protected byte[] clientId;
- protected int clientVersion;
- protected int clientRevision;
+ protected int clientId;
+ protected int clientOs;
+ protected int clientRevision;
/* 16 bytes of Shannon encryption output with random key */
protected byte[] clientRandom;
@@ -81,18 +81,27 @@
protected byte[] initialClientPacket;
protected byte[] initialServerPacket;
- /* Always up to date! ;-P */
- public static final int CLIENT_VERSION = 0x00031700; /* 0.3.23 */
- public static final int CLIENT_REVISION = 99998;
+ /* Client operating systems. */
+ protected static final int CLIENT_OS_WINDOWS_X86 = 0x00000000; /* Windows x86 */
+ protected static final int CLIENT_OS_MACOSX_X86 = 0x00000100; /* Mac OSX x86 */
+ protected static final int CLIENT_OS_UNKNOWN_1 = 0x00000200; /* libspotify (guess) */
+ protected static final int CLIENT_OS_UNKNOWN_2 = 0x00000300; /* iPhone? / Android? / Symbian? */
+ protected static final int CLIENT_OS_UNKNOWN_3 = 0x00000400; /* iPhone? / Android? / Symbian? */
+ protected static final int CLIENT_OS_MACOSX_PPC = 0x00000500; /* Mac OSX PPC */
+ protected static final int CLIENT_OS_UNKNOWN_4 = 0x00000600; /* iPhone? / Android? / Symbian? */
+
+ /* Client ID and revision (Always up to date! ;-P) */
+ protected static final int CLIENT_ID = 0x01040101; /* 0x010B0029 */
+ protected static final int CLIENT_REVISION = 0xFFFFFFFF;
/* Constructor for a new spotify session. */
public Session(){
/* Initialize protocol with this session. */
this.protocol = new Protocol(this);
- /* Set client identification. */
- this.clientId = new byte[]{0x01, 0x04, 0x01, 0x01}; // new byte[]{0x01, 0x0B, 0x00, 0x29}
- this.clientVersion = CLIENT_VERSION;
+ /* Set client properties. */
+ this.clientId = CLIENT_ID;
+ this.clientOs = CLIENT_OS_WINDOWS_X86;
this.clientRevision = CLIENT_REVISION;
/* Client and server generate 16 random bytes each. */
@@ -105,6 +114,8 @@ public Session(){
this.serverBlob = new byte[256];
/* Allocate buffer for salt and auth hash. */
+ this.username = null;
+ this.password = null;
this.salt = new byte[10];
this.authHash = new byte[20];
@@ -172,7 +183,7 @@ public Protocol authenticate(String username, String password) throws Connection
/* Connect to a spotify server. */
this.protocol.connect();
- /* Send and receive inital packets. */
+ /* Send and receive initial packets. */
try{
this.protocol.sendInitialPacket();
this.protocol.receiveInitialPacket();

0 comments on commit 090b45f

Please sign in to comment.