Fixed CDN problem with KabelDeutschland streaming proxy

What’s new

As some of you already noted, there have been some issues with getting the channel-list from the KabelDeutschland API. They migrated to a new Content-Delivery-Network which does not support a get-header-Request anymore. This causes the proxy to generate invalid channel-links and your were unable to watch the streams.

This should be fixed by now. I committed the fix within the PHP and the GO version of the proxy and also compiled the binaries to a new version 0.1.3.

Please give me feedback if the problem is solved for you.

Binaries Download

Shared Folder at mega.co.nz (mirror at dropbox)

Sourcecode Repositories

PHP

https://github.com/edi-design/kd-streaming-proxy

GO

https://github.com/edi-design/kd-go

Version 0.1.2 of the KabelDeutschland streaming proxy

What’s new

This time, it is only a small update. I just added some improvements a couple of the users asked for. The most notable new feature is the ability to skip the certificate check. User Michael had the problem that his QNAP (TS-210) has no root certificates installed. This ended him up with an error message and prevented him from using the proxy.

I added a start-up trigger to disable the CA-Check. It is called -no-check-certificate.

 

Download

Shared Folder at mega.co.nz (mirror at dropbox)

Usage

To see a list of all triggers the proxy supports simply add -h.

If you want to see, if the disabling of the certificate check works, add -v -no-check-certificate. This disables the check and enables verbose mode to see a lot more informations.

 

Updated KabelDeutschland streaming proxy

What’s new

The last time, I released my KabelDeutschland streaming proxy as a result of the reverse-engineering of the KabelDeutschland API. There have been a few minor issues, mainly in using the proxy together with some other tools like Kodi / XBMC or some stream-recorder based on ffmpeg.

Today i’d like to announce a new version of the KabelDeutschland streaming proxy that solves these issues. We are now able to use it together with the media-center software.

The playlist-handling has been fully rewritten to avoid the multiple redirects during playback. This was the main problem why ffmpeg could not read the playlist and its streams and prevented the media-center from playing the channels.

You can now select the quality of the stream by adding this param to the call. There are 3 options available, low | medium | high. Load your desired quality by opening http://[ip-address]/medium. If there was no quality-selector given, it will return the medium streams. There is still the debug option available by adding /txt at the end of the url after the quality identifier http://[ip-address]/medium/txt.

Below you will find the binaries for all supported architectures but there was also an update at the PHP version of this tool. This update can be grabbed from github.

Download

Shared Folder at mega.co.nz (mirror at dropbox)

Use cases

The last time i mentioned that i was trying to get the proxy running in conclusion with Kodi / XBMC and some other useful tools. Here is a short description of how to get these tools to work with the KabelDeutschland streaming proxy.

Kodi / XBMC

To watch live TV using this proxy in Kodi or XBMC, you have to enable an add-on called PVR IPTV Simple Client. This can be found under the PVR-Clients section in the add-ons category. After enabling it, there needs to be one configuration to be set-up, the Url of the playlist has to be added as seen on the screens. Also the checkbox cache m3u at local storage has to be unchecked so it reloads the playlist every time Kodi starts. After enabling and configuring the add-on, the last step is to enable Live-TV at the Kodi settings by checking the box under Settings -> Live TV.

Now you should see an option at the main menu named TV. Select the channel sub-option and enjoy the program.

The first time, the loading of the channel-list could take up to one minute, so please be patient.

Tvstreamrecord

I crashed into this tool (http://pavion.github.io/tvstreamrecord/) by looking for some new stuff for my Synology DS215j. It has a prebuilt package so i decided to give it a try and installed it. I imported the generated playlist but unfortunately i was not able to record the stream. As i described in my introduction, the problem was ffmpeg that could not handle redirects in playlists but with the new version of the KabelDeutschland streaming proxy it was easy to get the recorder running. Nevertheless there are some tweaks you have to do before it works.

As a step by step introduction we will start by adding the playlist. Open http://[Synology]:8030, click on the Channels-tab and click the Import button. Select your generated playlist. After the upload, you will see a list of all channels. You can now grab the EPG information at one of the two EPG tabs. Now we have to change the configuration. Switch over to Config -> FFMPEG support and add http to the list of stream-type. Hit submit-changes.

Now the last step is to change the path for your recordings under the General tab.

Thats it, you are now able to create a scheduled record.

Simplified KabelDeutschland streaming proxy

Review

A few days go i wrote about How to reverse engineer the KabelDeutschland API. Attached to this post there was a PHP script hosted on github to get your own streaming proxy running.

After testing and spreading the word with some people i came to the decision that the procedure was far too complicated. The need of a webserver and the large number of configuration options were unnecessary.

That’s why i build a single binary version, written in go.

Limitation

This tool does not remove the restrictions made by KabelDeutschland. You will need an internet and a TV contract with them. It only give you the ability to use their streams besides the iOS app.

Download

Binaries for all major platforms can be found at the shared folder.

Shared Folder at mega.co.nz (mirror at dropbox)

Select the binary suitable for your machine.

Tested environments

  • Macbook Pro Mid 2012, OSX 10.10.2
  • Synology DS215j (arm)
  • RaspberryPi (arm)
  • Windows XP 32bit

Please drop me a line if it works or not on your system.

Installation

Grab the config.json and edit it with your customer-service-center credentials. You can also change the port if you like.

On windows, double-click the executable file. On Linux/Mac you have to use your terminal, navigate to the folder you downloaded the binary and type the following command.

If you got a permission denied error, you have to set the executable bit for the binary

On all systems you will see the same output if everything went fine.

You will see the list of interfaces, the proxy listens to. All of them are ready to use to serve the channel playlist.

On certain Windows systems, it is not possible to display the interface list. The proxy will work nevertheless. Simply paste your known IP-Adress or one of your loopback addresses.

Installation on a Synology Diskstation

By now the easiest way to install the KabelDeutschland proxy is to download the arm-version of the binary and put it to your home-folder on the diskstation. Put the edited config.json next to it. Now you have to log into your nas  using ssh as your user and run the following command.

This creates a new screen, starts the proxy and immediately detaches the screen. That means the process runs in the background.

In order to be able to use the screen command, your box has to be bootsrapped. You can find the instructions to do this here: Bootrap the DS215j. Installation of screen will be done with this command as root.

You can connect to the proxy using the IP-address of your diskstation. http://[diskstation]:8787.

To stop the process, attach to the screen and press control+c. Attaching works using this command.

Predefined package

Synology has its own package manager and I’ll try to build a repository containing the proxy as a installable package. This will provide a way more easier solution. I will keep you updated.

Usage

Copy one of the links form the terminal output and paste it into your desired media player. It should load the playlist automatically. In VLC it looks like on the screenshot. You can now switch between the channels. The playlist contains links pointing to the proxy. This link handles the license generation, KabelDeutschland used to verify the stream.

How to reverse-engineer the KabelDeutschland tv-streaming API

The main intention

As a paying customer for many years, with both cable-tv and cable-internet, i found it very frustrating to not be able to watch tv on my smartphone or tablet but only on my tv. Back in 2014 my provider KabelDeutschland pulled out an tv-app for iOS that enables exactly this functionality but only for Apple mobile-devices. I always hoped that they would release an Android version shortly after but until today every customer-service-request regarding this topic leads to a “it will be available somewhere in the future” and “we can’t provide it because of some technical difficulties”. As a software developer and hardware engineer i know that this answer is just nonsense. If it runs in iOS there shouldn’t be any problem to get it up and running on Android and even on desktop.

Besides the intention to simply prove, that it is possible to get the streaming working on other devices, i had a more direct need. I bought a whole home-cinema setup including an Epson EH-TW 6100 beamer, an Onkyo Dolby Atmos capable surround-system and an Amazon Fire TV. I was not able to watch TV on this setup, because i had no DVB-C receiver to attach it to the system. But being able to install XBMC/Kodi paired with the IPTV plugin, it would be easy to do so, if there were any streaming sources.

Important Information

You need to have two contracts with KD. One for cable-tv and one for internet over cable. The second one is necessary because the streams are only available inside of their own network.

If you like to go further please be sure to met both dependencies.

Reverse-engineer the API

Final conclusion

I am aware that this part of this article should be at the end but i think some of you are not that interested in the hard details on how to do a man-in-the-middle-attack to uncover the KD API. So i decided to write this first. You can grab the fully functional streaming-proxy script as a repository in my github account: edi-design/kd-streaming-proxy. There is a README on how to get it up and running but i will provide a more detailed version below.

But by now i will continue with the description of the whole information-gathering-process.

Needed hardware and tools

Setup Burp and the iDevice

The first step is to download Burp and start it using the command line. Because Burp is written in Java you need at least the Java Runtime Environment.

Open your preferred console and type the following command to start Burp.

You will the following window. First we need to disable the intercept-function, push the button until it says intercept is of.

Burp Suite - intercept is off

Burp Suite – intercept is off

Next we go to the Options Tab and change the interface from 127.0.0.1:8080 to *:8080. This can be done by clicking the edit-button and select the All interfaces checkbox.

Burp interfaces

Burp interfaces

This is the complete part of configuring Burp. Now we switch over to our iPhone and connect it to the same network the computer running Burp is connected to. The next step is configuring Burp as proxy for this network. Go to Settings -> Wifi -> click on your Network -> HTTP Proxy Manual and add your computers IP-Adress as server.

iPhone proxy configuration

iPhone proxy configuration

Because part of the communication between the app and the KabelDeutschland API is SSL-encrypted, we need to install the Burp-provided SSL certificate. This provides us with the possibility to read the encrypted communication in plain text.

Open Safari on your iPhone and browse to http://burp. Click on CA Certificate. This will download the cert and asks you if you want to install it. Ignore the possible security risk. You can delete it afterwards.

Capturing some data

After the preparation has been finished we can now start the TV-app and collect the data it sends and gets from their backend services.

Burp should now look like this.

Captured data

Captured data

Analyzing the data

Starting to analyze the data by reading every call with its request and response, step by step.

The first call before even asking for credentials goes against an getconfig endpoint. It provides the app with all the necessary information regarding the api.

The response.

In this data we see the JsonGateway, this is the main entry-point. The second relevant information is the initObj. If you take a look at all further calls this object is needed as a mandatory param to identify against their api.

The sign-in

Before we can do any further calls, we need to have a valid session. The app does a SSOSignIn request to gather information about a SiteGuid and a DomainId. Both of these have to be appended to our formerly captured initObj. At this point you need your KD-CSC credentials. These are typically username and password you need to view your contract or invoice. KD use it to determine wether you are a cable customer or not.

The response.

Get the channel-list

Since we now have all the information to query the channel-list endpoint, lets do it. Finding the call inside of the Burp result is easy, search for GetChannelMediaList. Thanks to KD almost all of there methods are self-explanatory.

The list of all possible tv-channel will be returned, including a streaming link. I will only show an excerpt of it, because the whole response is nearly 3000 lines of json. The first element in my case contains all information about Das Erste (ARD).

Watching the stream?

Seeing the output above, it should be very easy to watch the stream. We’ve got an url that looks like a valid stream, but if you click on it, it gives you an access denied.

After some more digging into the log of Burp, i saw that there was another call named GetLicensedLinks, always called after selecting a channel to view. It provides as response the valid streaming link.

This call takes, next to the obvious initObj, two other params, the FileId and the Link. Both can be gathered from the above channel-list call.

Seeing the response, there is our most-wanted information.

You can paste one of the two urls into VLC media player and you will be able to watch the channel.

Conclusion

Because the whole process is a bit tricky and time-consuming, especially if you just want to sit down and watch tv, thats why i provided a little PHP-script at github (https://github.com/edi-design/kd-streaming-proxy). This script will do all of the work for you. You will need a webserver running inside of your home, because of the mandatory KD internet contract. Calling the script without params will provide you with the download of a playlist, containing all of the channels provided. This playlist contains links to the script itself with the channel id as param. Every time it gets called, it generate a new valid licensed link and redirects to it, that enables you to watch the stream.

I hope it is easy enough to set up and handle. As a simple webserver i can recommend the Synology NAS or a raspberry pi.

If you have any questions, feel free to ask.