pymensago/iscmds.py
def devkey(conn: ServerConnection, devid: utils.UUID, oldpair: EncryptionPair, newpair: EncryptionPair):
	'''Replaces the specified device's key stored on the server'''
	if not devid.is_valid():
		return RetVal(MsgBadRequest, 'Invalid device ID').set_value('status', 400)

	status = conn.send_message({
		'Action' : "DEVKEY",
		'Data' : { 
			'Device-ID': devid.as_string(),
			'Old-Key': oldpair.public.as_string(),
			'New-Key': newpair.public.as_string()
		}
	})
	if status.error():
		return status

	# Receive, decrypt, and return the server challenge
	response = conn.read_response(server_response)
	if response.error():
		return response
	
	if response['Code'] != 100:
		return wrap_server_error(response)

	if 'Challenge' not in response['Data'] or 'New-Challenge' not in response['Data']:
		return RetVal(ErrServerError, 'server did not return both device challenges')
	
	status = oldpair.decrypt(response['Data']['Challenge'])
	if status.error():
		cancel(conn)
		return RetVal(DecryptionFailure, 'failed to decrypt device challenge for old key')

	request = {
		'Action' : "DEVKEY",
		'Data' : { 
			'Response' : status['data']
		}
	}

	status = newpair.decrypt(response['Data']['New-Challenge'])
	if status.error():
		cancel(conn)
		return RetVal(DecryptionFailure, 'failed to decrypt device challenge for new key')
	request['Data']['New-Response'] = status['data']
	status = conn.send_message(request)
	if status.error():
		return status

	response = conn.read_response(None)
	if response.error():
		return response
	
	if response['Code'] == 200:
		return RetVal()
	
	return wrap_server_error(response)
Replaces the specified device's key stored on the server
Replaces the specified device's key stored on the server
Replaces the specified device ' s key stored on the server
def devkey(conn: ServerConnection, devid: utils.UUID, oldpair: EncryptionPair, newpair: EncryptionPair):
	if not devid.is_valid():
		return RetVal(MsgBadRequest, 'Invalid device ID').set_value('status', 400)
	status = conn.send_message({
		'Action' : "DEVKEY",
		'Data' : { 
			'Device-ID': devid.as_string(),
			'Old-Key': oldpair.public.as_string(),
			'New-Key': newpair.public.as_string()
		}
	})
	if status.error():
		return status
	response = conn.read_response(server_response)
	if response.error():
		return response
	if response['Code'] != 100:
		return wrap_server_error(response)
	if 'Challenge' not in response['Data'] or 'New-Challenge' not in response['Data']:
		return RetVal(ErrServerError, 'server did not return both device challenges')
	status = oldpair.decrypt(response['Data']['Challenge'])
	if status.error():
		cancel(conn)
		return RetVal(DecryptionFailure, 'failed to decrypt device challenge for old key')
	request = {
		'Action' : "DEVKEY",
		'Data' : { 
			'Response' : status['data']
		}
	}
	status = newpair.decrypt(response['Data']['New-Challenge'])
	if status.error():
		cancel(conn)
		return RetVal(DecryptionFailure, 'failed to decrypt device challenge for new key')
	request['Data']['New-Response'] = status['data']
	status = conn.send_message(request)
	if status.error():
		return status
	response = conn.read_response(None)
	if response.error():
		return response
	if response['Code'] == 200:
		return RetVal()
	return wrap_server_error(response)
def devkey ( conn : ServerConnection , devid : utils . UUID , oldpair : EncryptionPair , newpair : EncryptionPair ) : if not devid . is_valid ( ) : return RetVal ( MsgBadRequest , 'Invalid device ID' ) . set_value ( 'status' , 400 ) status = conn . send_message ( { 'Action' : "DEVKEY" , 'Data' : { 'Device-ID' : devid . as_string ( ) , 'Old-Key' : oldpair . public . as_string ( ) , 'New-Key' : newpair . public . as_string ( ) } } ) if status . error ( ) : return status response = conn . read_response ( server_response ) if response . error ( ) : return response if response [ 'Code' ] != 100 : return wrap_server_error ( response ) if 'Challenge' not in response [ 'Data' ] or 'New-Challenge' not in response [ 'Data' ] : return RetVal ( ErrServerError , 'server did not return both device challenges' ) status = oldpair . decrypt ( response [ 'Data' ] [ 'Challenge' ] ) if status . error ( ) : cancel ( conn ) return RetVal ( DecryptionFailure , 'failed to decrypt device challenge for old key' ) request = { 'Action' : "DEVKEY" , 'Data' : { 'Response' : status [ 'data' ] } } status = newpair . decrypt ( response [ 'Data' ] [ 'New-Challenge' ] ) if status . error ( ) : cancel ( conn ) return RetVal ( DecryptionFailure , 'failed to decrypt device challenge for new key' ) request [ 'Data' ] [ 'New-Response' ] = status [ 'data' ] status = conn . send_message ( request ) if status . error ( ) : return status response = conn . read_response ( None ) if response . error ( ) : return response if response [ 'Code' ] == 200 : return RetVal ( ) return wrap_server_error ( response )
Replaces the specified device's key stored on the server
Replaces the specified device ' s key stored on the server
'''Replaces the specified device's key stored on the server''' # Receive, decrypt, and return the server challenge
conn
ServerConnection
devid
utils.UUID
oldpair
EncryptionPair
newpair
EncryptionPair