Пример #1
0
/* mo_mkpasswd - mkpasswd message handler
 *	parv[1] = password
 *	parv[2] = type
 */
static int
mo_mkpasswd(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{
    char *salt;
    const char *hashtype;
    const char hashdefault[] = "SHA512";

    if(EmptyString(parv[1])) {
        sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MKPASSWD");
        return 0;
    }

    if(parc < 3)
        hashtype = hashdefault;
    else
        hashtype = parv[2];

    if(!irccmp(hashtype, "SHA256"))
        salt = make_sha256_salt(16);
    else if(!irccmp(hashtype, "SHA512"))
        salt = make_sha512_salt(16);
    else if(!irccmp(hashtype, "MD5"))
        salt = make_md5_salt(8);
    else {
        sendto_one_notice(source_p,
                          ":MKPASSWD syntax error:  MKPASSWD pass [SHA256|SHA512|MD5]");
        return 0;
    }

    sendto_one_notice(source_p, ":Hash [%s] for %s: %s", hashtype, parv[1], rb_crypt(parv[1], salt));
    return 0;
}
Пример #2
0
/*
** mo_test
**      parv[0] = sender prefix
**      parv[1] = parameter
*/
static void mo_mkpasswd(struct Client *client_p, struct Client *source_p,
                   int parc, char *parv[])
{		 
  int is_md5 = 0;

  if (parc == 3)
  {
    if (!irccmp(parv[2], "MD5"))
    {
      is_md5 = 1;
    }
    else if (!irccmp(parv[2], "DES"))
    {
      /* Not really needed, but we may want to have a default encryption
       * setting somewhere down the road
       */
      is_md5 = 0;
    }
    else
    {
      sendto_one(source_p, ":%s NOTICE %s :MKPASSWD syntax error:  MKPASSWD pass [DES|MD5]", me.name, parv[0]);
      return;
    }
  }

  if (parc == 1)
    sendto_one(source_p, form_str(source_p,ERR_NEEDMOREPARAMS),
               me.name, parv[0], "MKPASSWD");
  else
    sendto_one(source_p, ":%s NOTICE %s :Encryption for [%s]:  %s",
               me.name, parv[0], parv[1], crypt(parv[1],
               is_md5 ? make_md5_salt() : make_salt()));
}
Пример #3
0
/* m_mkpasswd - mkpasswd message handler
 *	parv[1] = password
 *	parv[2] = type
 */
static int
m_mkpasswd(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{
	static time_t last_used = 0;
	char *salt;
	const char *hashtype;
	const char hashdefault[] = "SHA512";
	if (EmptyString(parv[1])) {
		sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MKPASSWD");
		return 0;
	}
	if (parc < 3)
		hashtype = hashdefault;
	else
		hashtype = parv[2];
	if ((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) {
		/* safe enough to give this on a local connect only */
		sendto_one(source_p, form_str(RPL_LOAD2HI), me.name, source_p->name, "MKPASSWD");
		return 0;
	} else
		last_used = rb_current_time();
	if (!irccmp(hashtype, "SHA256"))
		salt = make_sha256_salt(16);
	else if (!irccmp(hashtype, "SHA512"))
		salt = make_sha512_salt(16);
	else if (!irccmp(hashtype, "MD5"))
		salt = make_md5_salt(8);
	else {
		sendto_one_notice(source_p,
		                  ":MKPASSWD syntax error:  MKPASSWD pass [SHA256|SHA512|MD5]");
		return 0;
	}
	sendto_one_notice(source_p, ":Hash [%s] for %s: %s", hashtype, parv[1], rb_crypt(parv[1], salt));
	return 0;
}
Пример #4
0
static int
m_mkpasswd(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{
	static time_t last_used = 0;
	int is_md5 = 0;

	if((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
	{
		/* safe enough to give this on a local connect only */
		sendto_one(source_p, form_str(RPL_LOAD2HI), me.name, parv[0]);
		return 0;
	}
	else
	{
		last_used = CurrentTime;
	}

	if(parc == 3)
	{
		if(!irccmp(parv[2], "MD5"))
		{
			is_md5 = 1;
		}
		else if(!irccmp(parv[2], "DES"))
		{
			/* Not really needed, but we may want to have a default encryption
			 * setting somewhere down the road
			 */
			is_md5 = 0;
		}
		else
		{
			sendto_one(source_p,
				   ":%s NOTICE %s :MKPASSWD syntax error:  MKPASSWD pass [DES|MD5]",
				   me.name, parv[0]);
			return 0;
		}
	}

	if(parc == 1)
		sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "MKPASSWD");
	else
		sendto_one(source_p, ":%s NOTICE %s :Encryption for [%s]:  %s",
			   me.name, parv[0], parv[1], crypt(parv[1],
							    is_md5 ? make_md5_salt() :
							    make_salt()));

	return 0;
}
Пример #5
0
int
main(int argc, char *argv[])
{
	char *plaintext = NULL;
	int c;
	char *saltpara = NULL;
	char *salt;
	int flag = 0;
	int length = 0;		/* Not Set */
	int rounds = 0;		/* Not set, since extended DES needs 25 and blowfish needs
				 ** 4 by default, a side effect of this being the encryption
				 ** type parameter must be specified before the rounds
				 ** parameter.
				 */

	while((c = getopt(argc, argv, "xymdber:h?l:s:p:")) != -1)
	{
		switch (c)
		{
		case 'm':
			flag |= FLAG_MD5;
			break;
		case 'd':
			flag |= FLAG_DES;
			break;
		case 'b':
			flag |= FLAG_BLOWFISH;
			rounds = 4;
			break;
		case 'e':
			flag |= FLAG_EXT;
			rounds = 25;
			break;
		case 'l':
			flag |= FLAG_LENGTH;
			length = atoi(optarg);
			break;
		case 'r':
			flag |= FLAG_ROUNDS;
			rounds = atoi(optarg);
			break;
		case 's':
			flag |= FLAG_SALT;
			saltpara = optarg;
			break;
		case 'p':
			flag |= FLAG_PASS;
			plaintext = optarg;
			break;
		case 'x':
			flag |= FLAG_SHA256;
			break;
		case 'y':
			flag |= FLAG_SHA512;
			break;
		case 'h':
			full_usage();
			/* NOT REACHED */
			break;
		case '?':
			brief_usage();
			/* NOT REACHED */
			break;
		default:
			printf("Invalid Option: -%c\n", c);
			break;
		}
	}

	if(flag & FLAG_MD5)
	{
		if(length == 0)
			length = 8;
		if(flag & FLAG_SALT)
			salt = make_md5_salt_para(saltpara);
		else
			salt = make_md5_salt(length);
	}
	else if(flag & FLAG_BLOWFISH)
	{
		if(length == 0)
			length = 22;
		if(flag & FLAG_SALT)
			salt = make_bf_salt_para(rounds, saltpara);
		else
			salt = make_bf_salt(rounds, length);
	}
	else if(flag & FLAG_SHA256)
	{
		if(length == 0)
			length = 16;
		if(flag & FLAG_SALT)
			salt = make_sha256_salt_para(saltpara);
		else
			salt = make_sha256_salt(length);
	}
	else if(flag & FLAG_SHA512)
	{
		if(length == 0)
			length = 16;
		if(flag & FLAG_SALT)
			salt = make_sha512_salt_para(saltpara);
		else
			salt = make_sha512_salt(length);
	}
	else if(flag & FLAG_EXT)
	{
		/* XXX - rounds needs to be done */
		if(flag & FLAG_SALT)
		{
			if((strlen(saltpara) == 4))
			{
				salt = make_ext_salt_para(rounds, saltpara);
			}
			else
			{
				printf("Invalid salt, please enter 4 alphanumeric characters\n");
				exit(1);
			}
		}
		else
		{
			salt = make_ext_salt(rounds);
		}
	}
	else
	{
		if(flag & FLAG_SALT)
		{
			if((strlen(saltpara) == 2))
			{
				salt = saltpara;
			}
			else
			{
				printf("Invalid salt, please enter 2 alphanumeric characters\n");
				exit(1);
			}
		}
		else
		{
			salt = make_des_salt();
		}
	}

	if(flag & FLAG_PASS)
	{
		if(!plaintext)
			printf("Please enter a valid password\n");
	}
	else
	{
		plaintext = getpass("plaintext: ");
	}

	printf("%s\n", rb_crypt(plaintext, salt));
	return 0;
}
Пример #6
0
int main(int argc, char *argv[])
{
  char *plaintext = NULL;
  extern char *optarg;
  extern int optind;
  int c;
  char *saltpara = NULL;
  char *salt;
  int flag = 0;
  int length = 8;

  srandom(time(NULL));

  while( (c=getopt(argc, argv, "mdh?l:s:p:")) != -1)
  {
    switch(c)
    {
      case 'm':
        flag |= FLAG_MD5;
        break;
      case 'd':
        flag |= FLAG_DES;
        break;
      case 'l':
        flag |= FLAG_LENGTH;
        length = atoi(optarg);
        break;
      case 's':
        flag |= FLAG_SALT;
        saltpara = optarg;
        break;
      case 'p':
        flag |= FLAG_PASS;
        plaintext = optarg;
        break;
      case 'h':
      case '?':
        usage();
        break;
      default:
        printf("Invalid Option: -%c\n", c);
        break;
    }
  }

  if (flag & FLAG_MD5)
  {
    if (flag & FLAG_SALT)
      salt = make_md5_salt_para(saltpara);
    else
      salt = make_md5_salt(length);
  }
  else
  {
    if (flag & FLAG_SALT)
    {
      if ((strlen(saltpara) == 2))
      {
        salt = saltpara;
      }
      else
      {
        printf("Invalid salt, please enter 2 alphanumeric characters\n");
        exit(1);
      }
    }
    else
    {
      salt = make_des_salt();
    }
  }

  if (flag & FLAG_PASS)
  {
    if (!plaintext)
      printf("Please enter a valid password\n");
  }
  else
  {
    plaintext = getpass("plaintext: ");
  }

  printf("%s\n", crypt(plaintext, salt));
  return 0;
}