Updated GAE code for Python 2.7 and webapp2, switched to HTTPS links in the index page, switched to the standard Python JSON library, enabled threading.

This commit is contained in:
cyrozap
2013-09-21 00:37:15 -04:00
parent 2274792ed0
commit 003e65e2e1
4 changed files with 21 additions and 31 deletions

View File

@@ -1,11 +1,12 @@
application: hdcpgen application: hdcpgen
version: 1 version: 1
runtime: python runtime: python27
api_version: 1 api_version: 1
threadsafe: true
handlers: handlers:
- url: /keys/.* - url: /keys/.*
script: appengine.py script: appengine.application
- url: /(index\.html)? - url: /(index\.html)?
static_files: appengine_index.html static_files: appengine_index.html

View File

@@ -1,11 +1,11 @@
from google.appengine.ext import webapp import json
from google.appengine.ext.webapp.util import run_wsgi_app import webapp2
from django.utils import simplejson as json
from generate_key import * from generate_key import *
class KeysHandler(webapp.RequestHandler): class KeysHandler(webapp2.RequestHandler):
def __init__(self): def __init__(self, request, response):
# Set self.request, self.response and self.app.
self.initialize(request, response)
self._key_matrix = read_key_file(open('master-key.txt')) self._key_matrix = read_key_file(open('master-key.txt'))
def _gen_json(self, ksv, key, is_sink): def _gen_json(self, ksv, key, is_sink):
@@ -15,7 +15,6 @@ class KeysHandler(webapp.RequestHandler):
'type': 'sink' if is_sink else 'source' }, 'type': 'sink' if is_sink else 'source' },
sort_keys=True, indent=False) sort_keys=True, indent=False)
def get(self, key_type, ksv_string = None): def get(self, key_type, ksv_string = None):
self.response.headers['Content-Type'] = 'application/json' self.response.headers['Content-Type'] = 'application/json'
@@ -31,21 +30,15 @@ class KeysHandler(webapp.RequestHandler):
else: else:
raise RuntimeError('Unknown key type: %s' % key_type) raise RuntimeError('Unknown key type: %s' % key_type)
self.response.out.write(self._gen_json(ksv, key, True if key_type == 'sink' else False)) self.response.write(self._gen_json(ksv, key, True if key_type == 'sink' else False))
class KsvHandler(webapp.RequestHandler): class KsvHandler(webapp2.RequestHandler):
def get(self): def get(self):
self.response.headers['Content-Type'] = 'text/plain' self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('%010x' % gen_ksv()) self.response.write('%010x' % gen_ksv())
application = webapp.WSGIApplication([ application = webapp2.WSGIApplication([
('/keys/(sink|source)/([0-9a-f]{10})', KeysHandler), ('/keys/(sink|source)/([0-9a-f]{10})', KeysHandler),
('/keys/(sink|source)', KeysHandler), ('/keys/(sink|source)', KeysHandler),
('/keys/random_ksv', KsvHandler), ('/keys/random_ksv', KsvHandler),
], debug=True) ], debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()

View File

@@ -10,18 +10,18 @@
</head> </head>
<body> <body>
<h1>HDCP key generator</h1> <h1>HDCP Key Generator</h1>
<p>The following links generate a random HDCP source or sink key <p>The following links generate a random HDCP source or sink key
as a machine-readable JSON object.</p> as a machine-readable JSON object.</p>
<ul> <ul>
<li><a href="keys/source">Generate random source key.</a></li> <li><a href="keys/source">Generate random source key</a></li>
<li><a href="keys/sink">Generate random sink key.</a></li> <li><a href="keys/sink">Generate random sink key</a></li>
</ul> </ul>
<p><a href="http://github.com/rjw57/hdcp-genkey">Source code</a> <p><a href="https://github.com/rjw57/hdcp-genkey">Source code</a>
available from <a href="http://gihub.com/">github</a>.</p> available from <a href="https://github.com/">github</a>.</p>
</body> </body>
</html> </html>

View File

@@ -25,13 +25,9 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import string, random import json
import string
# Magic required for google app engine import random
try:
from django.utils import simplejson as json
except:
import json
from optparse import OptionParser from optparse import OptionParser