Ejemplo n.º 1
0
/**
 * I hacked the javascript file named comm.js, which received from tencent
 * server, and find that f**k tencent has changed encryption algorithm
 * for password in webqq3 . The new algorithm is below(descripted with javascript):
 * var M=C.p.value; // M is the qq password 
 * var I=hexchar2bin(md5(M)); // Make a md5 digest
 * var H=md5(I+pt.uin); // Make md5 with I and uin(see below)
 * var G=md5(H+C.verifycode.value.toUpperCase());
 * 
 * @param pwd User's password
 * @param vc Verify Code. e.g. "!M6C"
 * @param uin A string like "\x00\x00\x00\x00\x54\xb3\x3c\x53", NB: it
 *        must contain 8 hexadecimal number, in this example, it equaled
 *        to "0x0,0x0,0x0,0x0,0x54,0xb3,0x3c,0x53"
 * 
 * @return Encoded password on success, else NULL on failed
 */
static char *lwqq_enc_pwd(const char *pwd, const char *vc, const char *uin)
{
	int i;
	int uin_byte_length;
	char buf[128] = {0};
	unsigned char sig[32];
	char _uin[9] = {0};

	if (!pwd || !vc || !uin) {
		lwqq_log(LOG_ERROR, "Null parameterment\n");
		return NULL;
	}


	/* Calculate the length of uin (it must be 8?) */
	uin_byte_length = strlen(uin) / 4;

	/**
	 * Ok, parse uin from string format.
	 * "\x00\x00\x00\x00\x54\xb3\x3c\x53" -> {0,0,0,0,54,b3,3c,53}
	 */
	for (i = 0; i < uin_byte_length ; i++) {
		char u[5] = {0};
		char tmp;
		strncpy(u, uin + i * 4 + 2, 2);

		errno = 0;
		tmp = strtol(u, NULL, 16);
		if (errno) {
			return NULL;
		}
		_uin[i] = tmp;
	}
	/* Equal to "var I=hexchar2bin(md5(M));" */
	md5_buffer(pwd,strlen(pwd),sig);
	memcpy(buf,sig,sizeof(sig));

	/* Equal to "var H=md5(I+pt.uin);" */
	memcpy(buf + 16, _uin, uin_byte_length);
	md5_buffer(buf, 16 + uin_byte_length, sig);
	md5_sig_to_string(sig,buf,sizeof(buf));

	/* Equal to var G=md5(H+C.verifycode.value.toUpperCase()); */
	snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s", vc);
	upcase_string(buf, strlen(buf));

	md5_buffer(buf, strlen(buf), sig);
	md5_sig_to_string(sig,buf,sizeof(buf));
	upcase_string(buf, strlen(buf));

	/* OK, seems like every is OK */
	return s_strdup(buf);
}
Ejemplo n.º 2
0
static	void	run_tests(void)
{
  unsigned char	sig[MD5_SIZE], sig2[MD5_SIZE];
  char		str[33];
  str_sig_t	*test_p;
  
  /* run our tests */
  for (test_p = tests; test_p->ss_string != NULL; test_p++) {
    /* calculate the sig for our test string */
    md5_buffer(test_p->ss_string, strlen(test_p->ss_string), sig);
    
    /* convert from the sig to a string rep */
    md5_sig_to_string(sig, str, sizeof(str));
    if (strcmp(str, test_p->ss_sig) == 0) {
      (void)printf("Sig for '%s' matches '%s'\n",
		   test_p->ss_string, test_p->ss_sig);
    }
    else {
      (void)printf("ERROR: Sig for '%s' is '%s' not '%s'\n",
		   test_p->ss_string, test_p->ss_sig, str);
    }
    
    /* convert from the string back into a MD5 signature */
    md5_sig_from_string(sig2, str);
    if (memcmp(sig, sig2, MD5_SIZE) == 0) {
      (void)printf("  String conversion also matches\n");
    }
    else {
      (void)printf("  ERROR: String conversion for '%s' failed\n",
		   test_p->ss_sig);
    }
  }
}
static int virLockManagerSanlockDiskLeaseName(const char *path,
                                              char *str,
                                              size_t strbuflen)
{
    unsigned char buf[MD5_DIGEST_SIZE];
    int i;

    if (strbuflen < ((MD5_DIGEST_SIZE * 2) + 1)) {
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("String length too small to store md5 checksum"));
        return -1;
    }

    if (!(md5_buffer(path, strlen(path), buf))) {
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("Unable to compute md5 checksum"));
        return -1;
    }

    for (i = 0 ; i < MD5_DIGEST_SIZE ; i++) {
        str[i*2] = hex[(buf[i] >> 4) & 0xf];
        str[(i*2)+1] = hex[buf[i] & 0xf];
    }
    str[(MD5_DIGEST_SIZE*2)+1] = '\0';
    return 0;
}
Ejemplo n.º 4
0
Gc_rc
gc_hash_buffer (Gc_hash hash, const void *in, size_t inlen, char *resbuf)
{
  switch (hash)
    {
#ifdef GNULIB_GC_MD2
    case GC_MD2:
      md2_buffer (in, inlen, resbuf);
      break;
#endif

#ifdef GNULIB_GC_MD4
    case GC_MD4:
      md4_buffer (in, inlen, resbuf);
      break;
#endif

#ifdef GNULIB_GC_MD5
    case GC_MD5:
      md5_buffer (in, inlen, resbuf);
      break;
#endif

#ifdef GNULIB_GC_SHA1
    case GC_SHA1:
      sha1_buffer (in, inlen, resbuf);
      break;
#endif

    default:
      return GC_INVALID_HASH;
    }

  return GC_OK;
}
Ejemplo n.º 5
0
int main()
{	
	char* s =  "d41d8cd98f00b204e9800998ecf8427e";
	char buf[16];
	char* sig = (char*)calloc(16,sizeof(char));
	md5_buffer(buf, 16, sig);
	return 0;
}
Ejemplo n.º 6
0
static void txn_name(struct file_cache *c, const char *path, char *txn)
{
	unsigned char digest[MD5_DIGEST_LENGTH];
	char shortname[DOMAIN_NAME_MAX];
	domain_name_cache_guess_short(shortname);
	md5_buffer(path, strlen(path), digest);
	sprintf(txn, "%s/txn/%s.%s.%d.XXXXXX", c->root, md5_string(digest), shortname, (int) getpid());
}
Ejemplo n.º 7
0
int manager_login_md5(Manager *m, char *username, char *password) {
	int i;
	char challenge[64];

	unsigned char md5hash[16];
	unsigned char hexdigest[33];
	unsigned char buf[32];

	ManagerMessage msg, resp;

	manager_init_message( &msg );

	/* Get the challenge */
	manager_build_message(&msg, "Action", "Challenge");
	manager_build_message(&msg, "AuthType", "MD5");
	if (manager_send_message(m, &msg ) == -1) return -1;

	manager_init_message( &resp );
	if (manager_recv_message(m, &resp) == -1) return -1;
	if (manager_message_get( &resp, "Challenge", challenge) != 0) return -1;

	/* hash the password */
	strcpy(buf, challenge);
	strcat(buf, password);
	md5_buffer( buf, strlen(buf), md5hash);

	/* make it hex */
	strcpy(hexdigest, "");
	for(i=0; i<16; i++) {
		sprintf(buf, "%02x", md5hash[i]);
		strcat(hexdigest, buf);
	}

	/* Send it back */
	manager_init_message( &msg );
	manager_build_message(&msg, "Action", "Login");
	manager_build_message(&msg, "AuthType", "MD5");
	manager_build_message(&msg, "Username", username);
	manager_build_message(&msg, "Key", hexdigest);
	manager_build_message(&msg, "Events", "off");

	if (manager_send_message(m, &msg ) == -1) return -1;

	manager_init_message( &resp );
	if (manager_recv_message(m, &resp) == -1) return -1;

	if (manager_message_get( &resp, "Response", buf) == -1) return -1;

	if (strcmp(buf, "Error") == 0) return -1;

	m->logged = 1;

	return 0;
}
Ejemplo n.º 8
0
int
main (int argc, char *argv[])
{
  /* Test vectors from RFC 1321. */

  const char *in1 = "abc";
  const char *out1 =
    "\x90\x01\x50\x98\x3C\xD2\x4F\xB0\xD6\x96\x3F\x7D\x28\xE1\x7F\x72";
  const char *in2 = "message digest";
  const char *out2 =
    "\xF9\x6B\x69\x7D\x7C\xB7\x93\x8D\x52\x5A\x2F\x31\xAA\xF1\x61\xD0";
  char buf[MD5_DIGEST_SIZE];

  if (memcmp (md5_buffer (in1, strlen (in1), buf), out1, MD5_DIGEST_SIZE) != 0)
    {
      size_t i;
      printf ("expected:\n");
      for (i = 0; i < MD5_DIGEST_SIZE; i++)
	printf ("%02x ", out1[i] & 0xFF);
      printf ("\ncomputed:\n");
      for (i = 0; i < MD5_DIGEST_SIZE; i++)
	printf ("%02x ", buf[i] & 0xFF);
      printf ("\n");
      return 1;
    }

  if (memcmp (md5_buffer (in2, strlen (in2), buf), out2, MD5_DIGEST_SIZE) != 0)
    {
      size_t i;
      printf ("expected:\n");
      for (i = 0; i < MD5_DIGEST_SIZE; i++)
	printf ("%02x ", out2[i] & 0xFF);
      printf ("\ncomputed:\n");
      for (i = 0; i < MD5_DIGEST_SIZE; i++)
	printf ("%02x ", buf[i] & 0xFF);
      printf ("\n");
      return 1;
    }

  return 0;
}
Ejemplo n.º 9
0
void md5_hex_buffer (const char *buffer, size_t len, char*resblock)
{
        unsigned char buf[16];
        char hex[]="0123456789abcdef";
        int i;
        md5_buffer(buffer,len,buf);
        for(i=0;i<16;i++){
                resblock[i*2]=hex[(buf[i]>>4)&0xf];
                resblock[i*2+1]=hex[buf[i]&0xf];
        }
        resblock[32]=0;
}
Ejemplo n.º 10
0
static virStorageVolPtr
esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
{
    virStorageVolPtr volume = NULL;
    esxPrivate *priv = conn->storagePrivateData;
    char *poolName = NULL;
    esxVI_ScsiLun *scsiLunList = NULL;
    esxVI_ScsiLun *scsiLun;
    /* MD5_DIGEST_SIZE = VIR_UUID_BUFLEN = 16 */
    unsigned char md5[MD5_DIGEST_SIZE];
    char uuid_string[VIR_UUID_STRING_BUFLEN] = "";

    /* key may be LUN device path */
    if (STRPREFIX(key, "/")) {
        return esxStorageVolLookupByPath(conn, key);
    }

    if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) {
        goto cleanup;
    }

    for (scsiLun = scsiLunList; scsiLun;
         scsiLun = scsiLun->_next) {
        memset(uuid_string, '\0', sizeof(uuid_string));
        memset(md5, '\0', sizeof(md5));

        md5_buffer(scsiLun->uuid, strlen(scsiLun->uuid), md5);
        virUUIDFormat(md5, uuid_string);

        if (STREQ(key, uuid_string)) {
            /* Found matching UUID */
            VIR_FREE(poolName);

            if (esxVI_LookupStoragePoolNameByScsiLunKey(priv->primary,
                                                        scsiLun->key,
                                                        &poolName) < 0) {
                goto cleanup;
            }

            volume = virGetStorageVol(conn, poolName, scsiLun->deviceName,
                                      uuid_string, &esxStorageBackendISCSI,
                                      NULL);
            break;
        }
    }

 cleanup:
    esxVI_ScsiLun_Free(&scsiLunList);
    VIR_FREE(poolName);

    return volume;
}
Ejemplo n.º 11
0
static int wait_for_running_txn(struct file_cache *c, const char *path)
{
	char txn[PATH_MAX];
	char dirname[PATH_MAX];
	unsigned char digest[MD5_DIGEST_LENGTH];
	DIR *dir;
	struct dirent *d;
	const char *checksum;

	md5_buffer(path, strlen(path), digest);
	checksum = md5_string(digest);

	txn[0] = 0;

	sprintf(dirname, "%s/txn", c->root);

	dir = opendir(dirname);
	if(!dir)
		return 0;

	while((d = readdir(dir))) {
		if(!strncmp(d->d_name, checksum, 32)) {
			sprintf(txn, "%s/txn/%s", c->root, d->d_name);
			break;
		}
	}

	closedir(dir);

	if(!txn[0])
		return 0;

	while(1) {
		struct stat64 info;

		debug(D_CACHE, "wait %s", txn);
		if(stat64(txn, &info) < 0)
			return 1;

		time_t current = time(0);

		if((current - info.st_mtime) < 60) {
			sleep(1);
			continue;
		} else {
			debug(D_CACHE, "override %s", txn);
			return 0;
		}
	}

}
Ejemplo n.º 12
0
static int __hms_parse_read_body( int fd, hms_msg *msg, int body_len ) {

  char *buffer = NULL, *p = NULL;
  int read_in = 0, erred = HMS_FALSE;
  char computed_checksum[33], *given_checksum = NULL;
  
  buffer = malloc( body_len + 1 );
  if(buffer == NULL ) { erred = HMS_TRUE; }
  p = buffer;

  while( read_in < body_len ) {
    int sz = read( fd, p, (body_len - read_in) );
    if( sz <= 0 ) { erred = HMS_TRUE; break; }
    else { 
      read_in += sz; 
      p += sz;
    }
  }

  if(erred == HMS_FALSE) {

#ifdef HERMES_ENABLE_CHECKSUMS
    /* Computed checksum */
    char hex_checksum[16];
    md5_buffer( buffer, body_len, (void *) hex_checksum );
    md5_sig_to_string( hex_checksum, computed_checksum, 33);

    /* Check the checksum if passed */
    int ret_chk = 0;
    ret_chk = hms_msg_get_named_header(msg, HMS_CONTENT_CHECKSUM, &given_checksum);
    if( ret_chk == 0 && given_checksum != NULL ) {
      if( strncasecmp( given_checksum, computed_checksum, sizeof(computed_checksum) ) != 0 ) {
	fprintf(stderr, "[ERROR] Checksums don't match!!\n"); fflush(stderr);
	fprintf(stderr, "[ERROR] Computed: %s Given: %s\n", computed_checksum, given_checksum );
	erred = 1;
      }// else { fprintf(stderr, "[NOTE] Checksums matched!\n"); }
    } else { fprintf(stderr, "[NOTE] No checksum provided!\n"); }
#endif

    /* Update the body */
    assert(read_in == body_len );
    hms_msg_set_body( msg, buffer, body_len );

  }

  if(buffer) { free(buffer); buffer = NULL; }
  if(given_checksum) { free(given_checksum); given_checksum = NULL; }

  return (erred == HMS_TRUE) ? -1 : 0; 

} /* end __hms_parse_read_body() */
Ejemplo n.º 13
0
static virStoragePoolPtr
esxStoragePoolLookupByName(virConnectPtr conn,
                           const char *name)
{
    esxPrivate *priv = conn->privateData;
    esxVI_ObjectContent *datastore = NULL;
    esxVI_DatastoreHostMount *hostMount = NULL;
    /* MD5_DIGEST_SIZE = VIR_UUID_BUFLEN = 16 */
    unsigned char md5[MD5_DIGEST_SIZE];
    virStoragePoolPtr pool = NULL;

    if (esxVI_LookupDatastoreByName(priv->primary, name, NULL, &datastore,
                                    esxVI_Occurrence_OptionalItem) < 0) {
        goto cleanup;
    }

    if (!datastore) {
        /* Not found, let the base storage driver handle error reporting */
        goto cleanup;
    }

    /*
     * Datastores don't have a UUID, but we can use the 'host.mountInfo.path'
     * property as source for a UUID. The mount path is unique per host and
     * cannot change during the lifetime of the datastore.
     *
     * The MD5 sum of the mount path can be used as UUID, assuming MD5 is
     * considered to be collision-free enough for this use case.
     */
    if (esxVI_LookupDatastoreHostMount(priv->primary, datastore->obj, &hostMount,
                                       esxVI_Occurrence_OptionalItem) < 0) {
        goto cleanup;
    }

    if (!hostMount) {
        /* Not found, let the base storage driver handle error reporting */
        goto cleanup;
    }

    md5_buffer(hostMount->mountInfo->path,
               strlen(hostMount->mountInfo->path), md5);

    pool = virGetStoragePool(conn, name, md5, &esxStorageBackendVMFS, NULL);

 cleanup:
    esxVI_ObjectContent_Free(&datastore);
    esxVI_DatastoreHostMount_Free(&hostMount);

    return pool;
}
Ejemplo n.º 14
0
bool validateMd5() {
	uint8 digest[16];

	md5_buffer(data, dataSize, digest);

	printf("MD5 of nhc.exe is %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
		digest[0], digest[1], digest[2], digest[3], digest[4], digest[5], digest[6], digest[7],
		digest[8], digest[9], digest[10], digest[11], digest[12], digest[13], digest[14], digest[15]);

	if (memcmp(kNhcExeMd5, digest, 16)) {
		printf("MD5 hash of nhc.exe doesn't match the expected value! Quitting...\n");
		return false;
	}
	return true;
}
Ejemplo n.º 15
0
static virStoragePoolPtr
esxStoragePoolLookupByUUID(virConnectPtr conn,
                           const unsigned char *uuid)
{
    virStoragePoolPtr pool = NULL;
    esxPrivate *priv = conn->storagePrivateData;
    esxVI_HostInternetScsiHba *hostInternetScsiHba = NULL;
    esxVI_HostInternetScsiHbaStaticTarget *target;
    /* MD5_DIGEST_SIZE = VIR_UUID_BUFLEN = 16 */
    unsigned char md5[MD5_DIGEST_SIZE];

    if (esxVI_LookupHostInternetScsiHba(priv->primary,
                                        &hostInternetScsiHba) < 0) {
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                       _("Unable to obtain iSCSI adapter"));
        goto cleanup;
    }

    /* FIXME: code just looks for software iSCSI adapter */
    if (!hostInternetScsiHba) {
        /* iSCSI adapter may not be enabled for this host */
        return NULL;
    }

    for (target = hostInternetScsiHba->configuredStaticTarget;
         target; target = target->_next) {
        md5_buffer(target->iScsiName, strlen(target->iScsiName), md5);

        if (memcmp(uuid, md5, VIR_UUID_STRING_BUFLEN) == 0) {
            break;
        }
    }

    if (!target) {
        /* pool not found, error handling done by the base driver */
        goto cleanup;
    }

    pool = virGetStoragePool(conn, target->iScsiName, md5,
                             &esxStorageBackendISCSI, NULL);

 cleanup:
    esxVI_HostInternetScsiHba_Free(&hostInternetScsiHba);

    return pool;
}
Ejemplo n.º 16
0
static virStorageVolPtr
esxStorageVolLookupByPath(virConnectPtr conn, const char *path)
{
    virStorageVolPtr volume = NULL;
    esxPrivate *priv = conn->storagePrivateData;
    esxVI_ScsiLun *scsiLunList = NULL;
    esxVI_ScsiLun *scsiLun;
    esxVI_HostScsiDisk *hostScsiDisk = NULL;
    char *poolName = NULL;
    /* MD5_DIGEST_SIZE = VIR_UUID_BUFLEN = 16 */
    unsigned char md5[MD5_DIGEST_SIZE];
    char uuid_string[VIR_UUID_STRING_BUFLEN] = "";

    if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) {
        goto cleanup;
    }

    for (scsiLun = scsiLunList; scsiLun; scsiLun = scsiLun->_next) {
        hostScsiDisk = esxVI_HostScsiDisk_DynamicCast(scsiLun);

        if (hostScsiDisk && STREQ(hostScsiDisk->devicePath, path)) {
            /* Found matching device */
            VIR_FREE(poolName);

            if (esxVI_LookupStoragePoolNameByScsiLunKey(priv->primary,
                                                        hostScsiDisk->key,
                                                        &poolName) < 0) {
                goto cleanup;
            }

            md5_buffer(scsiLun->uuid, strlen(scsiLun->uuid), md5);
            virUUIDFormat(md5, uuid_string);

            volume = virGetStorageVol(conn, poolName, path, uuid_string,
                                      &esxStorageBackendISCSI, NULL);
            break;
        }
    }

 cleanup:
    esxVI_ScsiLun_Free(&scsiLunList);
    VIR_FREE(poolName);

    return volume;
}
Ejemplo n.º 17
0
static virStorageVolPtr
esxStorageVolLookupByName(virStoragePoolPtr pool,
                          const char *name)
{
    virStorageVolPtr volume = NULL;
    esxPrivate *priv = pool->conn->storagePrivateData;
    esxVI_ScsiLun *scsiLunList = NULL;
    esxVI_ScsiLun *scsiLun;
    /* MD5_DIGEST_SIZE = VIR_UUID_BUFLEN = 16 */
    unsigned char md5[MD5_DIGEST_SIZE];
    char uuid_string[VIR_UUID_STRING_BUFLEN] = "";

    if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) {
        goto cleanup;
    }

    for (scsiLun = scsiLunList; scsiLun;
         scsiLun = scsiLun->_next) {
        if (STREQ(scsiLun->deviceName, name)) {
            /*
             * ScsiLun provides an UUID field that is unique accross
             * multiple servers. But this field length is ~55 characters
             * compute MD5 hash to transform it to an acceptable
             * libvirt format
             */
            md5_buffer(scsiLun->uuid, strlen(scsiLun->uuid), md5);
            virUUIDFormat(md5, uuid_string);

            /*
             * ScsiLun provides displayName and canonicalName but both are
             * optional and its observed that they can be NULL, using
             * deviceName to create volume.
             */
            volume = virGetStorageVol(pool->conn, pool->name, name, uuid_string,
                                      &esxStorageBackendISCSI, NULL);
            break;
        }
    }

 cleanup:
    esxVI_ScsiLun_Free(&scsiLunList);

    return volume;
}
Ejemplo n.º 18
0
int gen_md5(headers_t *headers, char *target) {
   unsigned int i, spaces1 = 0, spaces2 = 0;
   unsigned long num1 = 0, num2 = 0;
   unsigned char buf[17];
   for (i=0; i < strlen(headers->key1); i++) {
      if (headers->key1[i] == ' ') {
         spaces1 += 1;
      }
      if ((headers->key1[i] >= 48) && (headers->key1[i] <= 57)) {
         num1 = num1 * 10 + (headers->key1[i] - 48);
      }
   }
   num1 = num1 / spaces1;

   for (i=0; i < strlen(headers->key2); i++) {
      if (headers->key2[i] == ' ') {
         spaces2 += 1;
      }
      if ((headers->key2[i] >= 48) && (headers->key2[i] <= 57)) {
         num2 = num2 * 10 + (headers->key2[i] - 48);
      }
   }
   num2 = num2 / spaces2;

   /* Pack it big-endian */
   buf[0] = (num1 & 0xff000000) >> 24;
   buf[1] = (num1 & 0xff0000) >> 16;
   buf[2] = (num1 & 0xff00) >> 8;
   buf[3] =  num1 & 0xff;

   buf[4] = (num2 & 0xff000000) >> 24;
   buf[5] = (num2 & 0xff0000) >> 16;
   buf[6] = (num2 & 0xff00) >> 8;
   buf[7] =  num2 & 0xff;

   strncpy((char *)buf+8, headers->key3, 8);
   buf[16] = '\0';

   md5_buffer((const char*)&buf, 16, target);
   target[16] = '\0';

   return 1;
}
bool CCheckPassword::checkPass(const std::string& pass, const std::string& dbpass)
{
	//if(crypted) return Botan::check_bcrypt(pass, dbpass);
	//else		return (pass.compare(dbpass) == 0 ? true : false );
	int crypttype = kPlainText;
	if		(dbpass.size() == 60)	crypttype = kBcryptedText;
	else if	(dbpass.size() == 32)	crypttype = kMD5Text;

	switch(crypttype)
	{
	case kPlainText:
		{
			return (pass.compare(dbpass) == 0 ? true : false );
		}
		break;

	case kMD5Text:
		{
			char tmpPass[1024];
			char tmpResult[256];
			md5_buffer(pass.c_str(), pass.size(), tmpPass);
			md5_sig_to_string(tmpPass, tmpResult, sizeof(tmpResult));
			std::string md5String(tmpResult);
			std::transform(md5String.begin(), md5String.end(), md5String.begin(), toupper);
			std::string dbpassUpper(dbpass);
			std::transform(dbpassUpper.begin(), dbpassUpper.end(), dbpassUpper.begin(), toupper);
			return (md5String.compare(dbpassUpper) == 0 ? true : false);
		}
		break;

	case kBcryptedText:
		{
			return Botan::check_bcrypt(pass, dbpass);
		}
		break;

	default:
		return false;
		break;
	}
	return false;
}
Ejemplo n.º 20
0
String String::md5()
{
	char *md5array = new char[16];
	char *buf = new char[16];
	int i;

	String ret;

	md5_buffer(this->c_str(), (size_t) this->length(), md5array);

	for (i = 0; i < 16; i++) {
		sprintf(buf, "%02X", (unsigned char) (md5array[i]));
		ret += buf;
	}

	delete[]md5array;
	delete[]buf;

	return ret;
}
Ejemplo n.º 21
0
ObjectID Object_Chunk::CalculateID()
{
	ObjectID retval={0,0};
	List<Chunk*> chlist;
	parent->lookup_child("REBENVDT",chlist);
	if(!chlist.size()) return retval;
	((Environment_Data_Chunk*)chlist.first_entry())->lookup_child("RIFFNAME",chlist);
	if(!chlist.size()) return retval;
	char Name[100];

	strcpy(Name,((RIF_Name_Chunk*)chlist.first_entry())->rif_name);

	strcat(Name,object_data.o_name);
	char buffer[16];
	md5_buffer(Name,strlen(Name),&buffer[0]);
	buffer[7]=0;
	object_data_store->ID=*(ObjectID*)&buffer[0];
	return 	object_data_store->ID;
	
}
Ejemplo n.º 22
0
static int
check_passwd (const char *upassword,
	      const char *password,
	      const char *randomstring, const char *username)
{

  unsigned char md5digest[16];
  char tmpstr[512];

  if (strncmp (upassword, "$MD5$", 5) == 0)
    {

      sprintf (tmpstr, "%s%.128s",
	       strstr (randomstring, "$MD5$") + 5, password);
      md5_buffer (tmpstr, strlen (tmpstr), md5digest);

      sprintf (tmpstr, "$MD5$%02x%02x%02x%02x%02x%02x%02x%02x"
	       "%02x%02x%02x%02x%02x%02x%02x%02x",
	       md5digest[0], md5digest[1],
	       md5digest[2], md5digest[3],
	       md5digest[4], md5digest[5],
	       md5digest[6], md5digest[7],
	       md5digest[8], md5digest[9],
	       md5digest[10], md5digest[11],
	       md5digest[12], md5digest[13], md5digest[14], md5digest[15]);


      return (strcmp (upassword, tmpstr) == 0);

    }
  else
    {

      DBG (1, "check_passwd: received plain-text reply from user ``%s''\n",
	   username);

      return (strcmp (upassword, password) == 0);

    }
}
Ejemplo n.º 23
0
static virStoragePoolPtr
esxStoragePoolLookupByName(virConnectPtr conn,
                           const char *name)
{
    esxPrivate *priv = conn->storagePrivateData;
    esxVI_HostInternetScsiHbaStaticTarget *target = NULL;
    /* MD5_DIGEST_SIZE = VIR_UUID_BUFLEN = 16 */
    unsigned char md5[MD5_DIGEST_SIZE];
    virStoragePoolPtr pool = NULL;

    /*
     * Lookup routine are used by the base driver to determine
     * appropriate backend driver, lookup targetName as optional
     * parameter
     */
    if (esxVI_LookupHostInternetScsiHbaStaticTargetByName
          (priv->primary, name, &target, esxVI_Occurrence_OptionalItem) < 0) {
        goto cleanup;
    }

    if (!target) {
        /* pool not found, error handling done by the base driver */
        goto cleanup;
    }

    /*
     * HostInternetScsiHbaStaticTarget does not provide a uuid field,
     * but iScsiName (or widely known as IQN) is unique across the multiple
     * hosts, using it to compute key
     */
    md5_buffer(target->iScsiName, strlen(target->iScsiName), md5);

    pool = virGetStoragePool(conn, name, md5, &esxStorageBackendISCSI, NULL);

 cleanup:
    esxVI_HostInternetScsiHbaStaticTarget_Free(&target);

    return pool;
}
Ejemplo n.º 24
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : strIP - 
//			ulPortNum - 
// Output : Returns TRUE on success, FALSE on failure.
//-----------------------------------------------------------------------------
void CUISelectServer::ConnectToServer(CTString strIP, ULONG ulPortNum)
{
	if(_pNetwork->m_bSendMessage)
		return;

	CUIManager* pUIManager = CUIManager::getSingleton();

	// 소켓의 연결을 끊었다가, 다시 연결함.
	_cmiComm.Reconnect(strIP, ulPortNum);
	if(_tcpip.Socket == INVALID_SOCKET)
	{
		//CPrintF("게임 서버와 연결할 수 없습니다.\n");

		pUIManager->CloseMessageBox(MSGCMD_CONNECT_ERROR);
		CUIMsgBox_Info	MsgBoxInfo;
		MsgBoxInfo.SetMsgBoxInfo( _S( 424, "접속 오류" ), UMBS_OK, UI_SEL_SERVER, MSGCMD_CONNECT_ERROR );
		MsgBoxInfo.AddString( _S( 426, "게임 서버와 연결할 수 없습니다." ) );
		pUIManager->CreateMessageBox( MsgBoxInfo );

		_pNetwork->m_bSendMessage = FALSE;
		return;
	}

	// [091103: selo] 미국에 md5 적용함
#if defined(G_JAPAN)/* || defined(G_USA)*/ 
	// 패스워드 MD5로 암호화
	char tmpPass[1024];
	char tmpResult[256];
	md5_buffer(_pNetwork->m_strUserPW, _pNetwork->m_strUserPW.Length(), tmpPass);
	md5_sig_to_string(tmpPass, tmpResult, sizeof(tmpResult));
	CTString CT_tmpPass = tmpResult;
	CT_tmpPass.ToUpper(); // MD5로 암호화된 패스워드는 대문자로 전송(서버에서 대문자로 된 패스워드로 처리)
	_pNetwork->SendLoginMessage(_pNetwork->m_strUserID, CT_tmpPass, pUIManager->GetVersion());
#else
	_pNetwork->SendLoginMessage(_pNetwork->m_strUserID, _pNetwork->m_strUserPW, pUIManager->GetVersion());
#endif

	pUIManager->Lock(TRUE);
}
Ejemplo n.º 25
0
Placed_Hierarchy_Data_Chunk::Placed_Hierarchy_Data_Chunk(Chunk_With_Children* parent,const char* _name,int _hierarchy_index,ChunkVectorInt& _location,ChunkQuat& _orientation)
:Chunk(parent,"PLACHIDT")
{
	if(_name)
	{
		name=new char[strlen(_name)+1];
		strcpy(name,_name);
	}
	else
	{
		name=0;
	}
	location=_location;
	orientation=_orientation;
	hierarchy_index=_hierarchy_index;

	num_extra_data=0;
	extra_data=0;

	char buffer[16];
	md5_buffer(name,strlen(name),&buffer[0]);
	buffer[7]=0;
	id = *(ObjectID*)&buffer[0];
}
Ejemplo n.º 26
0
void
email_login_pop(Email *e, Ecore_Con_Event_Server_Data *ev)
{
    char *buf;
    size_t size;

    switch (e->state)
    {
    case EMAIL_STATE_SSL:
        if (!email_op_ok(ev->data, ev->size))
        {
            ERR("Could not create secure connection!");
            ecore_con_server_del(ev->server);
            return;
        }
        ecore_con_ssl_server_upgrade(e->svr, ECORE_CON_USE_MIXED);
        ecore_con_ssl_server_verify_basic(e->svr);
        e->flags = ECORE_CON_USE_MIXED;
        return;
    case EMAIL_STATE_INIT:
        if (!email_op_ok(ev->data, ev->size))
        {
            ERR("Not a POP3 server!");
            ecore_con_server_del(ev->server);
            return;
        }
        if (ev->size > 20)
        {
            const unsigned char *end;

            end = memrchr(ev->data + 3, '>', ev->size - 3);
            if (end)
            {
                const unsigned char *start;

                start = memrchr(ev->data + 3, '<', end - (unsigned char*)ev->data);
                if (start)
                {
                    e->features.pop_features.apop = EINA_TRUE;
                    e->features.pop_features.apop_str = eina_binbuf_new();
                    eina_binbuf_append_length(e->features.pop_features.apop_str, start, end - start + 1);
                }
            }
        }
        if (e->secure && (!e->flags))
        {
            email_write(e, "STLS\r\n", sizeof("STLS\r\n") - 1);
            e->state++;
            return;
        }
        e->state = EMAIL_STATE_USER;
        ev = NULL;
    case EMAIL_STATE_USER:
        if (!ev)
        {
            unsigned char digest[16];
            char md5buf[33];

            if (!e->features.pop_features.apop)
            {
                INF("Beginning AUTH PLAIN");
                size = sizeof(char) * (sizeof("USER ") - 1 + sizeof("\r\n") - 1 + strlen(e->username)) + 1;
                buf = alloca(size);
                snprintf(buf, size, "USER %s\r\n", e->username);
                email_write(e, buf, size - 1);
                return;
            }
            INF("Beginning AUTH APOP");
            e->state++;
            eina_binbuf_append_length(e->features.pop_features.apop_str, (unsigned char*)e->password, strlen(e->password));

            md5_buffer((char*)eina_binbuf_string_get(e->features.pop_features.apop_str), eina_binbuf_length_get(e->features.pop_features.apop_str), digest);
            email_md5_digest_to_str(digest, md5buf);
            size = sizeof(char) * (sizeof("APOP ") - 1 + sizeof("\r\n") - 1 + strlen(e->username)) + sizeof(md5buf);
            buf = alloca(size);
            snprintf(buf, size, "APOP %s %s\r\n", e->username, md5buf);
            email_write(e, buf, size - 1);
            return;
        }
        if (!email_op_ok(ev->data, ev->size))
        {
            ERR("Username invalid!");
            ecore_con_server_del(e->svr);
            return;
        }
        size = sizeof(char) * (sizeof("PASS ") - 1 + sizeof("\r\n") - 1 + strlen(e->password)) + 1;
        buf = alloca(size);
        snprintf(buf, size, "PASS %s\r\n", e->password);
        DBG("Sending password");
        ecore_con_server_send(e->svr, buf, size - 1);
        e->state++;
        return;
    case EMAIL_STATE_PASS:
        if (!email_op_ok(ev->data, ev->size))
        {
            ERR("Credentials invalid!");
            ecore_con_server_del(e->svr);
            return;
        }
        INF("Logged in successfully!");
        e->state++;
        ecore_event_add(EMAIL_EVENT_CONNECTED, e, (Ecore_End_Cb)email_fake_free, NULL);
    default:
        break;
    }
}
Ejemplo n.º 27
0
/* Append md5sumed folder to path if path is a directory. */
static const char *
mutt_hcache_per_folder(const char *path, const char *folder,
                       hcache_namer_t namer)
{
  static char hcpath[_POSIX_PATH_MAX];
  struct stat sb;
  unsigned char md5sum[16];
  char* s;
  int ret, plen;
#ifndef HAVE_ICONV
  const char *chs = Charset && *Charset ? Charset : 
		    mutt_get_default_charset ();
#endif

  plen = mutt_strlen (path);

  ret = stat(path, &sb);
  if (ret < 0 && path[plen-1] != '/')
  {
#ifdef HAVE_ICONV
    return path;
#else
    snprintf (hcpath, _POSIX_PATH_MAX, "%s-%s", path, chs);
    return hcpath;
#endif
  }

  if (ret >= 0 && !S_ISDIR(sb.st_mode))
  {
#ifdef HAVE_ICONV
    return path;
#else
    snprintf (hcpath, _POSIX_PATH_MAX, "%s-%s", path, chs);
    return hcpath;
#endif
  }

  if (namer)
  {
    snprintf (hcpath, sizeof (hcpath), "%s%s", path,
              path[plen-1] == '/' ? "" : "/");
    if (path[plen-1] != '/')
      plen++;

    ret = namer (folder, hcpath + plen, sizeof (hcpath) - plen);
  }
  else
  {
    md5_buffer (folder, strlen (folder), &md5sum);

    /* On some systems (e.g. OS X), snprintf is defined as a macro.
     * Embedding directives inside macros is undefined, so we have to duplicate
     * the whole call:
     */
#ifndef HAVE_ICONV
    ret = snprintf(hcpath, _POSIX_PATH_MAX,
                   "%s/%02x%02x%02x%02x%02x%02x%02x%02x"
                   "%02x%02x%02x%02x%02x%02x%02x%02x"
		   "-%s"
		   ,
		   path, md5sum[0], md5sum[1], md5sum[2], md5sum[3],
                   md5sum[4], md5sum[5], md5sum[6], md5sum[7], md5sum[8],
                   md5sum[9], md5sum[10], md5sum[11], md5sum[12],
                   md5sum[13], md5sum[14], md5sum[15]
		   ,chs
		   );
#else
    ret = snprintf(hcpath, _POSIX_PATH_MAX,
                   "%s/%02x%02x%02x%02x%02x%02x%02x%02x"
                   "%02x%02x%02x%02x%02x%02x%02x%02x"
		   ,
		   path, md5sum[0], md5sum[1], md5sum[2], md5sum[3],
                   md5sum[4], md5sum[5], md5sum[6], md5sum[7], md5sum[8],
                   md5sum[9], md5sum[10], md5sum[11], md5sum[12],
                   md5sum[13], md5sum[14], md5sum[15]
		   );
#endif
  }
  
  if (ret <= 0)
    return path;

  if (stat (hcpath, &sb) >= 0)
    return hcpath;

  s = strchr (hcpath + 1, '/');
  while (s)
  {
    /* create missing path components */
    *s = '\0';
    if (stat (hcpath, &sb) < 0 && (errno != ENOENT || mkdir (hcpath, 0777) < 0))
      return path;
    *s = '/';
    s = strchr (s + 1, '/');
  }

  return hcpath;
}
Ejemplo n.º 28
0
Gc_rc
gc_md5 (const void *in, size_t inlen, void *resbuf)
{
  md5_buffer (in, inlen, resbuf);
  return GC_OK;
}
Ejemplo n.º 29
0
static virStoragePoolPtr
esxStoragePoolLookupByUUID(virConnectPtr conn,
                           const unsigned char *uuid)
{
    esxPrivate *priv = conn->privateData;
    esxVI_String *propertyNameList = NULL;
    esxVI_ObjectContent *datastoreList = NULL;
    esxVI_ObjectContent *datastore = NULL;
    esxVI_DatastoreHostMount *hostMount = NULL;
    /* MD5_DIGEST_SIZE = VIR_UUID_BUFLEN = 16 */
    unsigned char md5[MD5_DIGEST_SIZE];
    char *name = NULL;
    virStoragePoolPtr pool = NULL;


    if (esxVI_String_AppendValueToList(&propertyNameList, "summary.name") < 0 ||
        esxVI_LookupDatastoreList(priv->primary, propertyNameList,
                                  &datastoreList) < 0) {
        goto cleanup;
    }

    for (datastore = datastoreList; datastore;
         datastore = datastore->_next) {
        esxVI_DatastoreHostMount_Free(&hostMount);

        if (esxVI_LookupDatastoreHostMount(priv->primary, datastore->obj,
                                           &hostMount,
                                           esxVI_Occurrence_OptionalItem) < 0) {
            goto cleanup;
        }

        if (!hostMount) {
            /*
             * Storage pool is not of VMFS type, leave error reporting to the
             * base storage driver.
             */
            goto cleanup;
        }

        md5_buffer(hostMount->mountInfo->path,
                   strlen(hostMount->mountInfo->path), md5);

        if (memcmp(uuid, md5, VIR_UUID_BUFLEN) == 0)
            break;
    }

    if (!datastore) {
        /* Not found, let the base storage driver handle error reporting */
        goto cleanup;
    }

    if (esxVI_GetStringValue(datastore, "summary.name", &name,
                             esxVI_Occurrence_RequiredItem) < 0) {
        goto cleanup;
    }

    pool = virGetStoragePool(conn, name, uuid, &esxStorageBackendVMFS, NULL);

 cleanup:
    esxVI_String_Free(&propertyNameList);
    esxVI_ObjectContent_Free(&datastoreList);
    esxVI_DatastoreHostMount_Free(&hostMount);

    return pool;
}
Ejemplo n.º 30
0
static void cached_name(struct file_cache *c, const char *path, char *lpath)
{
	unsigned char digest[MD5_DIGEST_LENGTH];
	md5_buffer(path, strlen(path), digest);
	sprintf(lpath, "%s/%02x/%s", c->root, digest[0], md5_string(digest));
}