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:
5
app.yaml
5
app.yaml
@@ -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
|
||||
|
||||
27
appengine.py
27
appengine.py
@@ -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()
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user