add a simple Google appengine implementation
Add a really simple Google app engine implementation.
This commit is contained in:
12
app.yaml
Normal file
12
app.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
application: hdcpgen
|
||||
version: 1
|
||||
runtime: python
|
||||
api_version: 1
|
||||
|
||||
handlers:
|
||||
- url: /keys/.*
|
||||
script: appengine.py
|
||||
|
||||
- url: /(index\.html)?
|
||||
static_files: appengine_index.html
|
||||
upload: appengine_index.html
|
||||
51
appengine.py
Normal file
51
appengine.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from google.appengine.ext import webapp
|
||||
from google.appengine.ext.webapp.util import run_wsgi_app
|
||||
from django.utils import simplejson as json
|
||||
|
||||
from generate_key import *
|
||||
|
||||
class KeysHandler(webapp.RequestHandler):
|
||||
def __init__(self):
|
||||
self._key_matrix = read_key_file(open('master-key.txt'))
|
||||
|
||||
def _gen_json(self, ksv, key, is_sink):
|
||||
return json.dumps( {
|
||||
'ksv': ('%010x' % ksv),
|
||||
'key': map(lambda x: '%014x' % x, key),
|
||||
'type': 'sink' if is_sink else 'source' },
|
||||
sort_keys=True, indent=False)
|
||||
|
||||
|
||||
def get(self, key_type, ksv_string = None):
|
||||
self.response.headers['Content-Type'] = 'application/json'
|
||||
|
||||
if ksv_string is not None:
|
||||
ksv = int(ksv_string, 16)
|
||||
else:
|
||||
ksv = gen_ksv()
|
||||
|
||||
if key_type == 'source':
|
||||
key = gen_source_key(ksv, self._key_matrix)
|
||||
elif key_type == 'sink':
|
||||
key = gen_sink_key(ksv, self._key_matrix)
|
||||
else:
|
||||
raise RuntimeError('Unknown key type: %s' % key_type)
|
||||
|
||||
self.response.out.write(self._gen_json(ksv, key, True if key_type == 'sink' else False))
|
||||
|
||||
class KsvHandler(webapp.RequestHandler):
|
||||
def get(self):
|
||||
self.response.headers['Content-Type'] = 'text/plain'
|
||||
self.response.out.write('%010x' % gen_ksv())
|
||||
|
||||
application = webapp.WSGIApplication([
|
||||
('/keys/(sink|source)/([0-9a-f]{10})', KeysHandler),
|
||||
('/keys/(sink|source)', KeysHandler),
|
||||
('/keys/random_ksv', KsvHandler),
|
||||
], debug=True)
|
||||
|
||||
def main():
|
||||
run_wsgi_app(application)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
27
appengine_index.html
Normal file
27
appengine_index.html
Normal file
@@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta name="generator" content=
|
||||
"HTML Tidy for Linux (vers 25 March 2009), see www.w3.org" />
|
||||
|
||||
<title>HDCP Key Generator</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>HDCP key generator</h1>
|
||||
|
||||
<p>The following links generate a random HDCP source or sink key
|
||||
as a machine-readable JSON object.</p>
|
||||
|
||||
<ul>
|
||||
<li><a href="keys/source">Generate random source key.</a></li>
|
||||
|
||||
<li><a href="keys/sink">Generate random sink key.</a></li>
|
||||
</ul>
|
||||
|
||||
<p><a href="http://github.com/rjw57/hdcp-genkey">Source code</a>
|
||||
available from <a href="http://gihub.com/">github</a>.</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -25,7 +25,14 @@
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import string, random, json
|
||||
import string, random
|
||||
|
||||
# Magic required for google app engine
|
||||
try:
|
||||
from django.utils import simplejson as json
|
||||
except:
|
||||
import json
|
||||
|
||||
from optparse import OptionParser
|
||||
|
||||
MASTER_KEY_SRC = 'master-key.txt'
|
||||
|
||||
Reference in New Issue
Block a user