def get(self): reason = "OK" self.set_status(200, reason=reason) start_time_str = Time.DateTimeToISO( self.application.master_secret.start_time), self.write({ 'startTime': start_time_str, 'service_name': 'D-TA server', 'message': reason }) return
def get(self): # Remote request information if 'User-Agent' in self.request.headers.keys(): UA = self.request.headers['User-Agent'] else: UA = 'unknown' request_info = '%s %s %s %s ' % ( self.request.method, self.request.path, self.request.remote_ip, UA) # Get arguments try: app_id = str(self.get_argument('app_id')) expires = self.get_argument('expires') signature = self.get_argument('signature') except tornado.web.MissingArgumentError as ex: reason = ex.log_message log.error("%s %s" % (request_info, reason)) self.set_status(403, reason=reason) self.content_type = 'application/json' self.write({'message': reason}) self.finish() return request_info = request_info + app_id # Get path used for signature path = self.request.path path = path.replace("/", "") # Check signature is valid and that timestamp has not expired M = str("%s%s%s" % (path, Keys.app_id, expires)) valid, reason, code = verifySignature(M, signature, Keys.app_key, expires) if not valid: return_data = {'code': code, 'message': reason} log.error("%s %s" % (request_info, reason)) self.set_status(status_code=code, reason=reason) self.content_type = 'application/json' self.write(return_data) self.finish() return try: server_secret_hex = self.application.master_secret.get_server_secret( ) except secrets.SecretsError as e: log.error( 'M-Pin Server Secret Generation Failed: {0}. Request info: {1}' .format(e, request_info)) return_data = { 'errorCode': e.message, 'reason': 'M-Pin Server Secret Generation Failed', } self.set_status(500, reason=reason) self.content_type = 'application/json' self.write(return_data) self.finish() return # Hash server secret share server_secret = server_secret_hex.decode("hex") hash_server_secret_hex = hashlib.sha256(server_secret).hexdigest() log.info("%s hash_server_secret_hex: %s" % (request_info, hash_server_secret_hex)) # Returned data reason = "OK" self.set_status(200, reason=reason) self.content_type = 'application/json' return_data = { 'serverSecret': server_secret_hex, 'startTime': Time.DateTimeToISO(self.application.master_secret.start_time), 'message': reason } self.write(return_data) log.debug("%s %s" % (request_info, return_data)) self.finish() return