Ejemplo n.º 1
0
//-----------------------------------------------------------------------------
worker_c::error_e worker_c::service_handshake_request( Reveal::Core::authorization_ptr auth ) { 

  Reveal::Core::session_ptr session;
  Reveal::Core::user_ptr user;

  Reveal::Core::authorization_c::type_e type = auth->get_type();
  if( type == Reveal::Core::authorization_c::TYPE_IDENTIFIED ) {
    // validate user credentials

    printf( "client requested identified authorization: id[%s]\n", auth->get_user().c_str() );

    // TODO : Logging

    if( is_user_valid( auth, user ) ) {
      if( create_session( auth, session ) ) {
        printf( "created session: " ); session->print();

        auth->set_error( Reveal::Core::authorization_c::ERROR_NONE );
        auth->set_user( user->id );
        auth->set_type( Reveal::Core::authorization_c::TYPE_SESSION );
        auth->set_session( session->session_id );

        send_valid_handshake_response( auth );
      } else {
        // TODO : handle failed session insert into database

      }
    } else {
      printf( "ERROR: failed to find %s in user table\n", auth->get_user().c_str() );

      // failed query and failed authentication
      auth->set_error( Reveal::Core::authorization_c::ERROR_INVALID_IDENTITY );

      send_invalid_handshake_response( auth );
    }
  } else if( type == Reveal::Core::authorization_c::TYPE_ANONYMOUS ) {

    printf( "client requested anonymous authorization\n" );

    // TODO : Logging

    if( create_session( auth, session ) ) {
      printf( "created session: " ); session->print();

      auth->set_type( Reveal::Core::authorization_c::TYPE_SESSION );
      auth->set_session( session->session_id );

      send_valid_handshake_response( auth );
    } else {
      // TODO : handle failed session insert into database
    }
  } else if( type == Reveal::Core::authorization_c::TYPE_SESSION ) {
    // this should only occur if a session was disrupted to the point that 
    // the client is trying to resume after being completely disconnected 
    // from the server.  This is the most suspicious case though and 
    // probably should be denied as it is possible to session hijack if allowed.
  }

  return ERROR_NONE;
}
Ejemplo n.º 2
0
int main() {

    //register_user("ezhuang", "john1990", "test");
    //register_user("hahaha","dadada","test");
    //register_user("ddd","poo","test");
    //match_user("ezhuang", "john1990", "test");
    //match_user("hahaha","dadada","test");
    //match_user("ezhuang", "john1990", "test");
    //delete_user("hahaha","dadada","test");







    printf("Available commands:\n(1) register_user\n(2) delete_user\n(3) is_user_valid\n(4) match_user\n(5) change_user_password\n(6) quit\n\n\n");

    unsigned char command[1024];
    int operation_status ;
    while(1) {
        printf("enter a command: ");
        scanf("%s",command) ;
        // printf("\n") ;
        operation_status = OKAY ;
        if(!strcmp(command,"register_user")) {
            printf("username: "******"%s",username) ;
            printf("password: "******"%s",password) ;
            printf("password file name: ");
            unsigned char pFile[1024] ;
            scanf("%s",pFile);

            operation_status = register_user(username,password,pFile) ;
        }
        else if(!strcmp(command,"delete_user")) {
            printf("username: "******"%s",username) ;

            printf("password: "******"%s",password) ;

            printf("password file name: ");
            unsigned char pFile[1024] ;
            scanf("%s",pFile);

            operation_status = delete_user(username,password, pFile) ;

        }
        else if(!strcmp(command,"is_user_valid")) {
            printf("username: "******"%s",username) ;
            printf("password file name: ");
            unsigned char pFile[1024] ;
            scanf("%s",pFile);

            operation_status = is_user_valid(username,pFile) ;

        }
        else if(!strcmp(command,"match_user")) {
            printf("username: "******"%s",username) ;
            printf("password: "******"%s",password) ;
            printf("password file name: ");
            unsigned char pFile[1024] ;
            scanf("%s",pFile);

            operation_status = match_user(username,password,pFile) ;

        }
        else if(!strcmp(command,"change_user_password")) {
            printf("username: "******"%s",username) ;
            printf("current password: "******"%s",password) ;
            printf("new password: "******"%s",npassword) ;

            printf("password file name: ");
            unsigned char pFile[1024] ;
            scanf("%s",pFile);

            operation_status = change_user_password(username,password,npassword, pFile) ;

        }
        else if(!strcmp(command,"quit")) {
            printf("INFO: Got the quit command\n");
            printf("Program terminating\n");
            break;
        }
        else {
            printf("ERROR: Unknown command %s\n",command);
            printf("INFO: Ignoring command\n") ;
        }

        if(operation_status == ERROR)
            printf("Operation %s failed\n",command) ;
    }
    return 0;
}