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
version: 1
runtime: python
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /keys/.*
script: appengine.py
script: appengine.application
- url: /(index\.html)?
static_files: appengine_index.html

View File

@@ -1,11 +1,11 @@
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from django.utils import simplejson as json
import json
import webapp2
from generate_key import *
class KeysHandler(webapp.RequestHandler):
def __init__(self):
class KeysHandler(webapp2.RequestHandler):
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'))
def _gen_json(self, ksv, key, is_sink):
@@ -15,7 +15,6 @@ class KeysHandler(webapp.RequestHandler):
'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'
@@ -31,21 +30,15 @@ class KeysHandler(webapp.RequestHandler):
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))
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):
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)', KeysHandler),
('/keys/random_ksv', KsvHandler),
], debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()

View File

@@ -10,18 +10,18 @@
</head>
<body>
<h1>HDCP key generator</h1>
<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/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>
<p><a href="http://github.com/rjw57/hdcp-genkey">Source code</a>
available from <a href="http://gihub.com/">github</a>.</p>
<p><a href="https://github.com/rjw57/hdcp-genkey">Source code</a>
available from <a href="https://github.com/">github</a>.</p>
</body>
</html>

View File

@@ -25,13 +25,9 @@
# (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
# Magic required for google app engine
try:
from django.utils import simplejson as json
except:
import json
import json
import string
import random
from optparse import OptionParser