From d330564d2b88424d79157ba33e623afc8517ddac Mon Sep 17 00:00:00 2001 From: speyrefitte Date: Wed, 17 Dec 2014 18:19:36 +0100 Subject: [PATCH] bug fix --- rdpy/protocol/rdp/gcc.py | 4 ++-- rdpy/protocol/rdp/mcs.py | 5 +---- rdpy/protocol/rdp/sec.py | 12 +++++++++++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/rdpy/protocol/rdp/gcc.py b/rdpy/protocol/rdp/gcc.py index 6c6133f..dd3c4eb 100644 --- a/rdpy/protocol/rdp/gcc.py +++ b/rdpy/protocol/rdp/gcc.py @@ -403,12 +403,12 @@ class RSAPublicKey(CompositeType): def __init__(self, readLen): CompositeType.__init__(self, readLen = readLen) self.magic = UInt32Le(0x31415352, constant = True) - self.keylen = UInt32Le(lambda:sizeof(self.modulus)) + self.keylen = UInt32Le(lambda:(sizeof(self.modulus) + sizeof(self.padding))) self.bitlen = UInt32Le(lambda:((self.keylen.value - 8) * 8)) self.datalen = UInt32Le(lambda:((self.bitlen.value / 8) - 1)) self.pubExp = UInt32Le() self.modulus = String(readLen = UInt16Le(lambda:(self.keylen.value - 8))) - self.padding = String(readLen = UInt8(8)) + self.padding = String("\x00" * 8, readLen = UInt8(8)) class ChannelDef(CompositeType): """ diff --git a/rdpy/protocol/rdp/mcs.py b/rdpy/protocol/rdp/mcs.py index 2b465e4..0a20c29 100644 --- a/rdpy/protocol/rdp/mcs.py +++ b/rdpy/protocol/rdp/mcs.py @@ -488,14 +488,11 @@ class Server(MCSLayer): """ #basic rdp security layer if self._transport._selectedProtocol == 0: - certificate = gcc.ProprietaryServerCertificate() - certificate.PublicKeyBlob.modulus.value = hex(self._presentation._rsaPublicKey.n)[2:-1].decode('hex')[::-1] - certificate.PublicKeyBlob.pubExp.value = self._presentation._rsaPublicKey.e self._serverSettings.SC_SECURITY.encryptionMethod.value = gcc.EncryptionMethod.ENCRYPTION_FLAG_128BIT self._serverSettings.SC_SECURITY.encryptionLevel.value = gcc.EncryptionLevel.ENCRYPTION_LEVEL_HIGH self._serverSettings.SC_SECURITY.serverRandom.value = rsa.randnum.read_random_bits(256) - self._serverSettings.SC_SECURITY.serverCertificate.certData = certificate + self._serverSettings.SC_SECURITY.serverCertificate.certData = self._presentation.getCertificate() self._serverSettings.SC_CORE.clientRequestedProtocol.value = self._transport._requestedProtocol self.setNextState(self.recvConnectInitial) diff --git a/rdpy/protocol/rdp/sec.py b/rdpy/protocol/rdp/sec.py index 35ed65b..1b380a2 100644 --- a/rdpy/protocol/rdp/sec.py +++ b/rdpy/protocol/rdp/sec.py @@ -591,7 +591,7 @@ class Server(SecLayer): @param presentation: {Layer} """ SecLayer.__init__(self, presentation) - self._rsaPublicKey, self._rsaPrivateKey = rsa.newkeys(512) + self._rsaPublicKey, self._rsaPrivaterKey = rsa.newkeys(512) def connect(self): """ @@ -602,6 +602,16 @@ class Server(SecLayer): self.setNextState(self.recvClientRandom) else: self.setNextState(self.recvInfoPkt) + + def getCertificate(self): + """ + @summary: generate proprietary certificate from rsa public key + """ + certificate = gcc.ProprietaryServerCertificate() + certificate.PublicKeyBlob.modulus.value = hex(self._rsaPublicKey.n)[2:-1].decode('hex')[::-1] + certificate.PublicKeyBlob.pubExp.value = self._rsaPublicKey.e + certificate.SignatureBlob.value = "\x00" * 72 + return certificate def recvClientRandom(self, s): """