app/models/message.rb
# read message for this server
# is_client:
# - true - client side of communication - called from Server.ping
# - false - server side of communication - called from util_controller.ping via Message.receive_messages
# pseudo_user_ids:
# - only relevant for client==true. called from Server.ping
#   hash with user ids in outgoing users message
#   user ids must be in response to outgoing users message
#   only relevant for direct server to server user compare
#   not relevant in forwarded users messages
# received_msgtype:
# - only relevant for client=false. mark when server has made a respond for a msgtype
read message for this server
is_client:
true - client side of communication - called from Server.ping
false - server side of communication - called from util_controller.ping via Message.receive_messages
pseudo_user_ids:
only relevant for client==true. called from Server.ping
hash with user ids in outgoing users message
user ids must be in response to outgoing users message
only relevant for direct server to server user compare
not relevant in forwarded users messages
received_msgtype:
only relevant for client=false. mark when server has made a respond for a msgtype
read message for this server is_client : true - client side of communication - called from Server . ping false - server side of communication - called from util_controller . ping via Message . receive_messages pseudo_user_ids : only relevant for client == true . called from Server . ping hash with user ids in outgoing users message user ids must be in response to outgoing users message only relevant for direct server to server user compare not relevant in forwarded users messages received_msgtype : only relevant for client = false . mark when server has made a respond for a msgtype
def receive_message (is_client, pseudo_user_ids, received_msgtype)
    logger.debug "new mail: #{self.to_json}"
    server = Server.find_by_new_did(self.from_did)
    logger.debug2 "received mix encrypted message"
    private_key = OpenSSL::PKey::RSA.new SystemParameter.private_key
    password_rsa_enc = Base64.decode64(self.key)
    password = private_key.private_decrypt(password_rsa_enc, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
    logger.secret2 "password = #{password}"
    message_json_enc_base64 = self.message
    message_json_enc = Base64.decode64(message_json_enc_base64)
    message_json = message_json_enc.decrypt(:symmetric, :password => password)
    logger.secret2 "message_json = #{message_json}"
    message = JSON.parse(message_json)
    if message['msgtype'] == 'users'
      return "Cannot receive users message. Server secret was not found. Server secret should have been received in login request" if !server.secret
      error = server.receive_compare_users_message(message['users'], is_client, pseudo_user_ids, received_msgtype) 
      return error ? error : nil
    end
    if message['msgtype'] == 'online'
      error = server.receive_online_users_message(message['users'], is_client, received_msgtype) 
      return error ? error : nil
    end
    if message['msgtype'] == 'sha256'
      error = server.receive_sha256_changed_message(message['seq'], message['users'])
      return error ? error : nil
    end
    if message['msgtype'] == 'pubkeys'
      error = server.receive_public_keys_message(message['users'], is_client, received_msgtype) 
      return error ? error : nil
    end
    if message['msgtype'] == 'client'
      error = server.receive_client_messages(message['messages'], is_client, received_msgtype) 
      return error ? error : nil
    end
    if message['msgtype'] == 'verify_gifts'
      error, self.keep_message = server.receive_verify_gifts_message(message)
      return error ? error : nil
    end
    if message['msgtype'] == 'verify_comments'
      error, self.keep_message = server.receive_verify_comments_msg(message)
      return error ? error : nil
    end
    logger.error2 "mstype #{message["msgtype"]} not implemented"
    return nil
  end
def receive_message ( is_client , pseudo_user_ids , received_msgtype ) logger . debug "new mail: #{self.to_json}" server = Server . find_by_new_did ( self . from_did ) logger . debug2 "received mix encrypted message" private_key = OpenSSL :: PKey :: RSA . new SystemParameter . private_key password_rsa_enc = Base64 . decode64 ( self . key ) password = private_key . private_decrypt ( password_rsa_enc , OpenSSL :: PKey :: RSA :: PKCS1_OAEP_PADDING ) logger . secret2 "password = #{password}" message_json_enc_base64 = self . message message_json_enc = Base64 . decode64 ( message_json_enc_base64 ) message_json = message_json_enc . decrypt ( :symmetric , :password => password ) logger . secret2 "message_json = #{message_json}" message = JSON . parse ( message_json ) if message [ 'msgtype' ] == 'users' return "Cannot receive users message. Server secret was not found. Server secret should have been received in login request" if ! server . secret error = server . receive_compare_users_message ( message [ 'users' ] , is_client , pseudo_user_ids , received_msgtype ) return error ? error : nil end if message [ 'msgtype' ] == 'online' error = server . receive_online_users_message ( message [ 'users' ] , is_client , received_msgtype ) return error ? error : nil end if message [ 'msgtype' ] == 'sha256' error = server . receive_sha256_changed_message ( message [ 'seq' ] , message [ 'users' ] ) return error ? error : nil end if message [ 'msgtype' ] == 'pubkeys' error = server . receive_public_keys_message ( message [ 'users' ] , is_client , received_msgtype ) return error ? error : nil end if message [ 'msgtype' ] == 'client' error = server . receive_client_messages ( message [ 'messages' ] , is_client , received_msgtype ) return error ? error : nil end if message [ 'msgtype' ] == 'verify_gifts' error , self . keep_message = server . receive_verify_gifts_message ( message ) return error ? error : nil end if message [ 'msgtype' ] == 'verify_comments' error , self . keep_message = server . receive_verify_comments_msg ( message ) return error ? error : nil end logger . error2 "mstype #{message["msgtype"]} not implemented" return nil end
read message for this server
is_client:
 true - client side of communication - called from Server.ping
 false - server side of communication - called from util_controller.ping via Message.receive_messages
pseudo_user_ids:
 only relevant for client==true.
read message for this server is_client : true - client side of communication - called from Server . ping false - server side of communication - called from util_controller . ping via Message . receive_messages pseudo_user_ids : only relevant for client == true .
# find password in mix encrypted message. mix encryption. rsa encrypted random password in key and message encrypted with this random password # decrypt message # false: server side of communication # false: server side of communication # false: server side of communication # false: server side of communication
is_client
<not_specific>
pseudo_user_ids
<not_specific>
received_msgtype
<not_specific>