Initial commit
Add the skeleton for widevine-proxy

This is loosely based on james commit d8a06a913c83cc82b03d84ee5b1f43afdbad0b5e and
the documentation available in Confluence:

"Guide: Create REST/Web App with Base and Embedded Jetty (The ComoYo Way)"
https://confluence.skunk-works.no/confluence/pages/viewpage.action?pageId=8031613

It has been modified  based on feedback from Petter Westby to prepare the
WebServer component to be more general and reusable. See
https://gist.github.com/54c4c9f3ee5a203f6177 and
https://gist.github.com/3f95ee05c79ef548f2a4

Concretely, the WebServer gains a Builder inner-class, allowing projects to tune
their instance of WebServer appropriately. For now, we will take the pragmatic
approach and start with yet-another-copy of WebServer in widevine-proxy, and
refactor it and other projects as time permits.
Add support for logging requests handled by the WebServer

You can set the requestLogDir using WebServer.Builder.requestLogDir(). Logging
will be enabled if the parameter to requestLogDir() is non-null.
Merge pull request #3 from bradleythughes/master

Skeleton for the widevine-proxy
Don't pass null hostname to InetSocketAddress's constructor

The constructor throws an IllegalArgumentException if hostname is null,
so don't do this. If builder.host is null, we should create
InetSocketAddress with only the port (which uses the wildcard address).

This commit adds a unit-test to ensure that the WebServer can be created
with various combinations of host:port, and that the WebServer can be
started and shutdown for each combination.
Merge pull request #4 from bradleythughes/master

Don't pass null hostname to InetSocketAddress's constructor
Initial implementation of widevine-proxy logic

The proxy expects to receive Widevine formatted queries with a
"comoyoticket" user data. The "comoyoticket" is a Base64 encoded ticket
string.

The proxy does a minimal amount of processing and verification beyond
what is required by Widevine:

1. Parse the Comoyo license ticket.
2. Ensure that the ticket has not been altered.
3. Check that the assetid query parameter matches the wvid in the ticket.

If any of these operations fails, we return an error code in the range
reserved by Widevine for custom error codes. All of these scenarios are
covered by unit-tests.

After our verification steps are complete, we append our portal ID,
the current time, and a signature. The format for the signature is
specified by Widevine.

Note that we do not yet forward license requests to the Widevine
license servers (neither staging nor production).
Implement and test the actual proxy

This commit introduces the WidevineProxy interface which
RootResource uses to forward the query it receives to the upstream
license servers. The WidevineProxyImpl implements the interface to
forward to the staging Widevine license servers. The
RootResourceTest has been updated to mock a WidevineProxy instead
of sending the request upstream.

This commit also introduces Guice for dependency injection,
inspired by adaptation-engine. As a result, some of the
initialisation originally in Main.main() using WebServer.Builder
has been moved to the WidevineProxyJerseyServletModule. The unused
API has been removed from WebServer.Builder.
Make RootResource.root() more defensive

Return 403 HTTP status if any required arguments are missing (instead
of 500 due to NPE while parsing the userdata string).

Tests need to pass clientid now as well to continue working.
Send license verification errors correctly

The Proxy Integration documentation from Widevine says that we
should send the error codes encoded as part of the HTTP response,
not as HTTP status as I had previously done.

This commit adds a helper function to encode the status code and
assetid in base64. When encountering license ticket problems, we
send back this base64 string as part of an HTTP 200 (ok) response.

Unit-tests have been updated to handle the status codes correctly.
Add --ticket-key argument to widevine-proxy

This makes it possible to pass the secret key for generating license
tickets as a base64 encoded string argument.

The default value is just an example key and only used for testing.
Add --widevine-portal-id, --widevine-iv, and --widevine-key arguments to widevine-proxy

This makes it possible to pass the portal id, key and IV obtained
from Widevine as base64 encoded string arguments.

The default portal id is the real assigned value from Widevine and
will be used in staging and production. The default key and iv values
are example values and only used for testing.
Add --widevine-upstream-uri argument to widevine-proxy

This argument will be used to configure to where license requests
should be forwarded.

The default value is the staging upstream license server and is
only used for testing.
Revert "Add support for logging requests handled by the WebServer"

This reverts commit 24f0aff26587edd64a73c2e4d69576b9d35eb555.

This gives a clean slate to implement logging to a logserver via
Base.
Use slf4j to log incoming requests
Make command-line arguments required for widevine-proxy

This avoids hardcoding bogus/test values as defaults.

The unit tests still need to setup the Config with the expected test
values though.
Merge pull request #1 from bradleythughes/master

Proxy implementation and tests
Test that well formed requests actually succeed

If a license request succeeds, the Widevine documentation says that
the license server will return a license status of 1 followed by the
Widevine assetid. Mock the widevineProxy in
shouldReturnOkForProperRequests() to return exactly this and test that
the value falls through. Otherwise, it would be possible to return
one of our custom errors, but the test would not pick up the problem.
Make comoyoticket parsing more robust in RootResource

If we receive malformed userdata, don't allow RootResource to throw
any runtime exceptions. This can happen if "userdata=comoyoticket:",
for example, which causes Ticket.parse() to throw.

Add tests for various forms of malformed userdata, including:

userdata=somethingcompletelynonsensical
userdata=happy:true
userdata=comoyoticket:
userdata=comoyoticket:Y:U:NO:PLAY:MOVIE
Improve code coverage metrics for the WebServer class

Some simple changes to make sure the code coverage metrics are accurate
for what can and should be tested. The private default constructor
has been removed, as it's not needed (or tested, or used). The shutdown()
method call stop() and join() on the WebServer, not the server member.

The WebServerTest should also check that the Builder.contextPath()
doesn't cause the constructor to throw.

After these changes, cobertura reports 92%/100% line/branch coverage
for WebServer.