ThunderEX / py-kms

A KMS server written in python.
Other
395 stars 113 forks source link

No Key Management Service (KMS) could be contacted (through VPN) #16

Closed NickJH closed 6 years ago

NickJH commented 6 years ago

Hi, I've posted an issue at https://forums.mydigitallife.net/threads/emulated-kms-servers-on-non-windows-platforms.50234/page-63#post-1397488 where a PC at the end of an OpenVPN tunnel is no longer able to activate its licence. Using Wireshark at the server end I could see (I think) zero length replies from py-kms. I tried previous versions of py-kms and they were the same. Installing vlmscd worked. I run py-kms with no additional parameters and it has worked for years so I suspect something M$ have done. It is the same from my LAN see the tcpdump below: tcpdump: [root@server bin]# tcpdump -i any port 1688 -n tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes 18:52:07.070978 IP 172.17.2.118.57242 > 172.17.2.1.nsjtp-data: Flags [S], seq 3930345398, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0 18:52:07.071011 IP 172.17.2.1.nsjtp-data > 172.17.2.118.57242: Flags [S.], seq 3616433661, ack 3930345399, win 29200, options [mss 1460,nop,nop,sackOK,nop,wscale 7], length 0 18:52:07.071164 IP 172.17.2.118.57242 > 172.17.2.1.nsjtp-data: Flags [.], ack 1, win 2053, length 0 18:52:07.071309 IP 172.17.2.118.57242 > 172.17.2.1.nsjtp-data: Flags [P.], seq 1:117, ack 1, win 2053, length 116 18:52:07.071323 IP 172.17.2.1.nsjtp-data > 172.17.2.118.57242: Flags [.], ack 117, win 229, length 0 18:52:07.073444 IP 172.17.2.1.nsjtp-data > 172.17.2.118.57242: Flags [P.], seq 1:85, ack 117, win 229, length 84 18:52:07.073570 IP 172.17.2.118.57242 > 172.17.2.1.nsjtp-data: Flags [.], ack 85, win 2052, length 0 18:52:07.073577 IP 172.17.2.118.57242 > 172.17.2.1.nsjtp-data: Flags [P.], seq 117:401, ack 85, win 2052, length 284 18:52:07.077392 IP 172.17.2.1.nsjtp-data > 172.17.2.118.57242: Flags [F.], seq 85, ack 401, win 237, length 0 18:52:07.078055 IP 172.17.2.118.57242 > 172.17.2.1.nsjtp-data: Flags [F.], seq 401, ack 86, win 2052, length 0 18:52:07.078077 IP 172.17.2.1.nsjtp-data > 172.17.2.118.57242: Flags [.], ack 402, win 237, length 0

172.17.2.1 is the server 172.17.2.118 is my client on my LAN.

Running py-kms interactively I get :

python /usr/src/py-kms/server.py

TCP server listening at 0.0.0.0 on port 1688. Connection accepted: 172.17.2.118:57268 Received V4 request on Tue Dec 19 18:55:58 2017. Connection closed: 172.17.2.118:57268

Exception happened during processing of request from ('172.17.2.118', 57268) Traceback (most recent call last): File "/usr/lib64/python2.7/SocketServer.py", line 295, in _handle_request_noblock self.process_request(request, client_address) File "/usr/lib64/python2.7/SocketServer.py", line 321, in process_request self.finish_request(request, client_address) File "/usr/lib64/python2.7/SocketServer.py", line 334, in finish_request self.RequestHandlerClass(request, client_address, self) File "/usr/lib64/python2.7/SocketServer.py", line 649, in init self.handle() File "/usr/src/py-kms/server.py", line 136, in handle res = handler.populate().bytes() File "/usr/src/py-kms/rpcBase.py", line 41, in populate return self.generateResponse(self.parseRequest()) File "/usr/src/py-kms/rpcRequest.py", line 18, in generateResponse responseData = kmsBase.generateKmsResponseData(request['pduData'], self.config) File "/usr/src/py-kms/kmsBase.py", line 307, in generateKmsResponseData return messagehandler.executeRequestLogic() File "/usr/src/py-kms/kmsRequestV4.py", line 83, in executeRequestLogic response = self.serverLogic(requestData['request']) File "/usr/src/py-kms/kmsBase.py", line 159, in serverLogic local_dt = utc.localize(dt).astimezone(timezones.localtz()).strftime('%Y-%m-%d %H:%M:%S %Z (UTC%z)') File "/usr/src/py-kms/timezones.py", line 75, in localtz _localtz = detect_timezone() File "/usr/src/py-kms/timezones.py", line 99, in detect_timezone tz = _detect_timezone_etc_localtime() File "/usr/src/py-kms/timezones.py", line 138, in _detect_timezone_etc_localtime tz = _tzinfome(tzname) File "/usr/src/py-kms/timezones.py", line 56, in _tzinfome tzinfo = pytz.timezone(tzinfo) File "/usr/lib/python2.7/site-packages/pytz/init.py", line 170, in timezone _tzinfo_cache[zone] = build_tzinfo(zone, fp) File "/usr/lib/python2.7/site-packages/pytz/tzfile.py", line 33, in build_tzinfo assert magic == _byte_string('TZif'), 'Got magic %s' % repr(magic) AssertionError: Got magic '# Al'

[root@server bin]# python /usr/src/py-kms/server.py TCP server listening at 0.0.0.0 on port 1688. Connection accepted: 172.17.2.118:57268 Received V4 request on Tue Dec 19 18:55:58 2017. Connection closed: 172.17.2.118:57268

Exception happened during processing of request from ('172.17.2.118', 57268) Traceback (most recent call last): File "/usr/lib64/python2.7/SocketServer.py", line 295, in _handle_request_noblock self.process_request(request, client_address) File "/usr/lib64/python2.7/SocketServer.py", line 321, in process_request self.finish_request(request, client_address) File "/usr/lib64/python2.7/SocketServer.py", line 334, in finish_request self.RequestHandlerClass(request, client_address, self) File "/usr/lib64/python2.7/SocketServer.py", line 649, in init self.handle() File "/usr/src/py-kms/server.py", line 136, in handle res = handler.populate().bytes() File "/usr/src/py-kms/rpcBase.py", line 41, in populate return self.generateResponse(self.parseRequest()) File "/usr/src/py-kms/rpcRequest.py", line 18, in generateResponse responseData = kmsBase.generateKmsResponseData(request['pduData'], self.config) File "/usr/src/py-kms/kmsBase.py", line 307, in generateKmsResponseData return messagehandler.executeRequestLogic() File "/usr/src/py-kms/kmsRequestV4.py", line 83, in executeRequestLogic response = self.serverLogic(requestData['request']) File "/usr/src/py-kms/kmsBase.py", line 159, in serverLogic local_dt = utc.localize(dt).astimezone(timezones.localtz()).strftime('%Y-%m-%d %H:%M:%S %Z (UTC%z)') File "/usr/src/py-kms/timezones.py", line 75, in localtz _localtz = detect_timezone() File "/usr/src/py-kms/timezones.py", line 99, in detect_timezone tz = _detect_timezone_etc_localtime() File "/usr/src/py-kms/timezones.py", line 138, in _detect_timezone_etc_localtime tz = _tzinfome(tzname) File "/usr/src/py-kms/timezones.py", line 56, in _tzinfome tzinfo = pytz.timezone(tzinfo) File "/usr/lib/python2.7/site-packages/pytz/init.py", line 170, in timezone _tzinfo_cache[zone] = build_tzinfo(zone, fp) File "/usr/lib/python2.7/site-packages/pytz/tzfile.py", line 33, in build_tzinfo assert magic == _byte_string('TZif'), 'Got magic %s' % repr(magic) AssertionError: Got magic '# Al'

Sorry, but I don't know why the font has gone bold or the font size has changed.

ThunderEX commented 6 years ago

A simple workaround is just to delete timezones.py.

This file is used to display time in local time zone in server side. But it depends on pytz module, which often have some problem with old pytz module or rare OS/distribution.

If you remove it, this feature will be skipped and activation still works.

NickJH commented 6 years ago

Thanks. I can confirm that removing timzones.py (and timezones.pyc) allows py-kms to activate a license. FWIW I use ClearOS 7.x which should be binary compatible with Centos7 and probably EL7. The python version is 2.7.5-58.el7.x86_64 so I don't think this counts as a rare distro. I have a /etc/localtime file which is a symlink to "../usr/share/zoneinfo/Europe/London". My python skills don't allow me to debug further very quickly.

[edit] pytz is version 2016.10-2.el7.noarch [/edit]

ThunderEX commented 6 years ago

today I looked into this issue. It seems time from KMS client is local time without time zone info. So with pytz or not, we still won't know time zone of client. Thus, I pushed 45150d6e998eb5ef4368065ebdd83d20794e71f7 to remove pytz and timezones.py permanently.