Exemplo n.º 1
0
void
soup_auth_digest_compute_hex_a1 (const char              *hex_urp,
				 SoupAuthDigestAlgorithm  algorithm,
				 const char              *nonce,
				 const char              *cnonce,
				 char                     hex_a1[33])
{
	if (algorithm == SOUP_AUTH_DIGEST_ALGORITHM_MD5) {
		/* In MD5, A1 is just user:realm:password, so hex_A1
		 * is just hex_urp.
		 */
		/* You'd think you could say "sizeof (hex_a1)" here,
		 * but you'd be wrong.
		 */
		memcpy (hex_a1, hex_urp, 33);
	} else {
		GChecksum *checksum;

		/* In MD5-sess, A1 is hex_urp:nonce:cnonce */

		checksum = g_checksum_new (G_CHECKSUM_MD5);
		g_checksum_update (checksum, (guchar *)hex_urp, strlen (hex_urp));
		g_checksum_update (checksum, (guchar *)":", 1);
		g_checksum_update (checksum, (guchar *)nonce, strlen (nonce));
		g_checksum_update (checksum, (guchar *)":", 1);
		g_checksum_update (checksum, (guchar *)cnonce, strlen (cnonce));
		strncpy (hex_a1, g_checksum_get_string (checksum), 33);
		g_checksum_free (checksum);
	}
}
Exemplo n.º 2
0
static char *
compute_accept_key (const char *key)
{
	gsize digest_len = FIXED_DIGEST_LEN;
	guchar digest[FIXED_DIGEST_LEN];
	GChecksum *checksum;

	if (!key)
		return NULL;

	checksum = g_checksum_new (G_CHECKSUM_SHA1);
	g_return_val_if_fail (checksum != NULL, NULL);

	g_checksum_update (checksum, (guchar *)key, -1);

	/* magic from: http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17 */
	g_checksum_update (checksum, (guchar *)"258EAFA5-E914-47DA-95CA-C5AB0DC85B11", -1);

	g_checksum_get_digest (checksum, digest, &digest_len);
	g_checksum_free (checksum);

	g_assert (digest_len == FIXED_DIGEST_LEN);

	return g_base64_encode (digest, digest_len);
}
Exemplo n.º 3
0
Arquivo: sms.c Projeto: AndriusA/ofono
/**
 * Generate a UUID from an SMS PDU List
 *
 * @param pdu Pointer to array of PDUs data to generate the ID from
 * @param pdus Number of entries in the \e pdu array
 * @return 0 in error (no memory or serious code inconsistency in the
 *     input data structures), otherwise the SMS UUID.
 *
 * @internal
 *
 * The current time is added to avoid the UUID being the same when the
 * same message is sent to the same destination repeatedly. Note we
 * need a high resolution time (not just seconds), otherwise resending
 * in the same second (not that rare) could yield the same UUID.
 */
static gboolean sms_uuid_from_pdus(const struct pending_pdu *pdu,
					unsigned char pdus,
					struct ofono_uuid *uuid)

{
	GChecksum *checksum;
	gsize uuid_size = sizeof(uuid->uuid);
	unsigned int cnt;
	struct timeval now;

	checksum = g_checksum_new(G_CHECKSUM_SHA1);
	if (checksum == NULL)
		return FALSE;

	for (cnt = 0; cnt < pdus; cnt++)
		g_checksum_update(checksum, pdu[cnt].pdu, pdu[cnt].pdu_len);

	gettimeofday(&now, NULL);
	g_checksum_update(checksum, (void *) &now, sizeof(now));

	g_checksum_get_digest(checksum, uuid->uuid, &uuid_size);
	g_checksum_free(checksum);

	return TRUE;
}
Exemplo n.º 4
0
/*
 * Get the check sum of password and verify code.
 *
 * First, compute check sum of password for three times.
 * Then, join the result with the capitalizaion of the verify code.
 * Compute the chekc sum of the new string.
 */
GString* get_pwvc_md5(const gchar *pwd, const gchar *vc, GError **err)
{
	guint8 buf[100];
	gsize bsize = 100;
	
	GChecksum *cs = g_checksum_new(G_CHECKSUM_MD5);
	g_checksum_update(cs, (const guchar*)pwd, strlen(pwd));
	g_checksum_get_digest(cs, buf, &bsize);
	g_checksum_free(cs);
	
	cs = g_checksum_new(G_CHECKSUM_MD5);
	g_checksum_update(cs, buf, bsize);
	g_checksum_get_digest(cs, buf, &bsize);
	g_checksum_free(cs);
	
	cs = g_checksum_new(G_CHECKSUM_MD5);
	g_checksum_update(cs, buf, bsize);
	const gchar * md5_3 = g_checksum_get_string(cs);
	md5_3 = g_ascii_strup(md5_3, strlen(md5_3));
	gchar buf2[100];
	g_sprintf(buf2, "%s%s", md5_3, vc);
	g_checksum_free(cs);

	gchar *tmp1;
	tmp1 = g_ascii_strup(buf2, strlen(buf2));
	tmp1 = g_compute_checksum_for_string(G_CHECKSUM_MD5
						, tmp1, -1);
	tmp1 = g_ascii_strup(tmp1, strlen(tmp1));
	GString *re = g_string_new(tmp1);
	g_free(tmp1);

	return re;
}
Exemplo n.º 5
0
static void chap_process_challenge(struct ppp_chap *chap, const guint8 *packet)
{
	const struct chap_header *header = (const struct chap_header *) packet;
	struct chap_header *response;
	GChecksum *checksum;
	const char *secret = g_at_ppp_get_password(chap->ppp);
	const char *username = g_at_ppp_get_username(chap->ppp);
	guint16 response_length;
	struct ppp_header *ppp_packet;
	gsize digest_len;

	/* create a checksum over id, secret, and challenge */
	checksum = g_checksum_new(chap->method);
	if (checksum == NULL)
		return;

	g_checksum_update(checksum, &header->identifier, 1);

	if (secret)
		g_checksum_update(checksum, (guchar *) secret, strlen(secret));

	g_checksum_update(checksum, &header->data[1], header->data[0]);

	/* transmit a response packet */
	/*
	 * allocate space for the header, the checksum, and the ppp header,
	 * and the value size byte
	 */
	digest_len = g_checksum_type_get_length(chap->method);
	response_length = digest_len + sizeof(*header) + 1;

	if (username != NULL)
		response_length += strlen(username);

	ppp_packet = ppp_packet_new(response_length, CHAP_PROTOCOL);
	if (ppp_packet == NULL)
		goto challenge_out;

	response = (struct chap_header *) &ppp_packet->info;
	if (response) {
		response->code = RESPONSE;
		response->identifier = header->identifier;
		response->length = htons(response_length);
		g_checksum_get_digest(checksum, response->data + 1,
							&digest_len);
		response->data[0] = digest_len;
		/* leave the name empty? */
	}

	if (username != NULL)
		memcpy(response->data + digest_len + 1, username,
				strlen(username));

	/* transmit the packet */
	ppp_transmit(chap->ppp, (guint8 *) ppp_packet, response_length);
	g_free(ppp_packet);

challenge_out:
	g_checksum_free(checksum);
}
Exemplo n.º 6
0
/**
 * CacheUtilHashPassword:
 * @algorithm: Hash algorithm.
 * @salt: Random data, usually stored with the hash.
 * @password: Secret value to hash.
 *
 * Returns: (allow-none): Hash value of concatenated @salt and @password, or
 * #NULL if an argument was invalid.
 */
GBytes *CacheUtilHashPassword(GChecksumType algorithm, GBytes *salt,
                               const char *password) {
  GChecksum *checksum = NULL;
  gssize checksum_len = -1;
  guint8 *result = NULL;
  gsize result_len = 0;

  if (!salt || !password)
    return NULL;

  checksum_len = g_checksum_type_get_length(algorithm);
  if (checksum_len <= 0)
    return NULL;

  checksum = g_checksum_new(algorithm);
  if (!checksum)
    return NULL;

  g_checksum_update(
      checksum, g_bytes_get_data(salt, NULL), g_bytes_get_size(salt));
  g_checksum_update(checksum, (guint8 *) password, strlen(password));

  result = g_malloc(checksum_len);
  result_len = checksum_len;

  g_checksum_get_digest(checksum, result, &result_len);
  g_assert(checksum_len == result_len);

  g_checksum_free(checksum);
  return g_bytes_new_take(result, result_len);
}
Exemplo n.º 7
0
static RejillaBurnResult
rejilla_checksum_files_get_file_checksum (RejillaChecksumFiles *self,
					  GChecksumType type,
					  const gchar *path,
					  gchar **checksum_string,
					  GError **error)
{
	RejillaChecksumFilesPrivate *priv;
	guchar buffer [BLOCK_SIZE];
	GChecksum *checksum;
	gint read_bytes;
	FILE *file;

	priv = REJILLA_CHECKSUM_FILES_PRIVATE (self);

	file = fopen (path, "r");
	if (!file) {
                int errsv;
		gchar *name = NULL;

		/* If the file doesn't exist carry on with next */
		if (errno == ENOENT)
			return REJILLA_BURN_RETRY;

		name = g_path_get_basename (path);

                errsv = errno;
		g_set_error (error,
			     REJILLA_BURN_ERROR,
			     REJILLA_BURN_ERROR_GENERAL,
			     _("File \"%s\" could not be opened (%s)"),
			     name,
			     g_strerror (errsv));
		g_free (name);

		return REJILLA_BURN_ERR;
	}

	checksum = g_checksum_new (type);

	read_bytes = fread (buffer, 1, BLOCK_SIZE, file);
	g_checksum_update (checksum, buffer, read_bytes);

	while (read_bytes == BLOCK_SIZE) {
		if (priv->cancel) {
			fclose (file);
			g_checksum_free (checksum);
			return REJILLA_BURN_CANCEL;
		}

		read_bytes = fread (buffer, 1, BLOCK_SIZE, file);
		g_checksum_update (checksum, buffer, read_bytes);
	}

	*checksum_string = g_strdup (g_checksum_get_string (checksum));
	g_checksum_free (checksum);
	fclose (file);

	return REJILLA_BURN_OK;
}
Exemplo n.º 8
0
void
hmac_sha1 ( guint8 *hmac, const guint8 *key, guint lk, const guint8 *data, guint ld )
{
  GChecksum *sha1;
  guint i;
  gsize dl;
  guint8 k_buf[SHA_DIGESTSIZE];
  guint8 buf[SHA_BLOCKSIZE];
  guint8 isha[SHA_DIGESTSIZE];
  const guint8 *k;


  sha1 = g_checksum_new ( G_CHECKSUM_SHA1 );

  /* make sure key isn't too long */
  if ( lk > SHA_BLOCKSIZE ) {
    g_checksum_reset ( sha1 );
    g_checksum_update ( sha1, key, lk );
    dl = SHA_DIGESTSIZE;
    g_checksum_get_digest ( sha1, k_buf, &dl);
    lk = SHA_DIGESTSIZE;
    k = k_buf;
  } else {
    k = key;
  }

  /**** Inner digest ****/

  g_checksum_reset ( sha1 );

   /* Pad the key for inner digest */
  for ( i=0; i < lk; ++i ) buf[i] = k[i] ^ 0x36;
  for ( i=lk; i < SHA_BLOCKSIZE; ++i ) buf[i] = 0x36;

  g_checksum_update ( sha1, buf, SHA_BLOCKSIZE );
  g_checksum_update ( sha1, data, ld );
  dl = SHA_DIGESTSIZE;
  g_checksum_get_digest ( sha1, isha, &dl);

  /**** Outer digest ****/

  g_checksum_reset ( sha1 );

  /* Pad the key for outer digest */
  for ( i=0; i < lk; ++i ) buf[i] = k[i] ^ 0x5C;
  for ( i=lk; i < SHA_BLOCKSIZE; ++i ) buf[i] = 0x5C;

  g_checksum_update ( sha1, buf, SHA_BLOCKSIZE );
  g_checksum_update ( sha1, isha, SHA_DIGESTSIZE );

  /* copy over the final result */
  dl = SHA_DIGESTSIZE;
  g_checksum_get_digest ( sha1, hmac, &dl);

   /* cleanup */
  g_checksum_free ( sha1 );
  
}
Exemplo n.º 9
0
void
nm_ip4_config_hash (NMIP4Config *config, GChecksum *sum, gboolean dns_only)
{
	guint32 i, n;
	const char *s;

	g_return_if_fail (config != NULL);
	g_return_if_fail (sum != NULL);

	if (dns_only == FALSE) {
		for (i = 0; i < nm_ip4_config_get_num_addresses (config); i++) {
			NMIP4Address *a = nm_ip4_config_get_address (config, i);

			hash_u32 (sum, nm_ip4_address_get_address (a));
			hash_u32 (sum, nm_ip4_address_get_prefix (a));
			hash_u32 (sum, nm_ip4_address_get_gateway (a));
		}

		for (i = 0; i < nm_ip4_config_get_num_routes (config); i++) {
			NMIP4Route *r = nm_ip4_config_get_route (config, i);

			hash_u32 (sum, nm_ip4_route_get_dest (r));
			hash_u32 (sum, nm_ip4_route_get_prefix (r));
			hash_u32 (sum, nm_ip4_route_get_next_hop (r));
			hash_u32 (sum, nm_ip4_route_get_metric (r));
		}

		n = nm_ip4_config_get_ptp_address (config);
		if (n)
			hash_u32 (sum, n);

		for (i = 0; i < nm_ip4_config_get_num_nis_servers (config); i++)
			hash_u32 (sum, nm_ip4_config_get_nis_server (config, i));

		s = nm_ip4_config_get_nis_domain (config);
		if (s)
			g_checksum_update (sum, (const guint8 *) s, strlen (s));
	}

	for (i = 0; i < nm_ip4_config_get_num_nameservers (config); i++)
		hash_u32 (sum, nm_ip4_config_get_nameserver (config, i));

	for (i = 0; i < nm_ip4_config_get_num_wins (config); i++)
		hash_u32 (sum, nm_ip4_config_get_wins (config, i));

	for (i = 0; i < nm_ip4_config_get_num_domains (config); i++) {
		s = nm_ip4_config_get_domain (config, i);
		g_checksum_update (sum, (const guint8 *) s, strlen (s));
	}

	for (i = 0; i < nm_ip4_config_get_num_searches (config); i++) {
		s = nm_ip4_config_get_search (config, i);
		g_checksum_update (sum, (const guint8 *) s, strlen (s));
	}
}
Exemplo n.º 10
0
void fs_emu_netplay_init() {
    const char *value;

    g_send_mutex = fs_mutex_create();
    g_connection_mutex = fs_mutex_create();
    g_input_event_mutex = fs_mutex_create();
    g_input_event_queue = g_queue_new();
    g_wait_for_frame_cond = fs_condition_create();
    g_wait_for_frame_mutex = fs_mutex_create();

    value = fs_config_get_const_string("netplay_server");
    if (value) {
        g_fs_emu_netplay_server = g_strdup(value);
    }
    if (!fs_emu_netplay_enabled()) {
        return;
    }

    value = fs_config_get_const_string("netplay_tag");
    if (value) {
        strncpy(g_fs_emu_netplay_tag, value, 4);
    }
    else {
        g_fs_emu_netplay_tag[0] = 'U';
        g_fs_emu_netplay_tag[1] = 'N';
        g_fs_emu_netplay_tag[2] = 'K';
    }
    g_fs_emu_netplay_tag[3] = '\0';

    value = fs_config_get_const_string("netplay_port");
    if (value) {
        g_fs_emu_netplay_port = g_strdup(value);
    }

    char *password_value = fs_config_get_string("netplay_password");
    if (password_value) {
        GChecksum *cs = g_checksum_new(G_CHECKSUM_SHA1);
        g_checksum_update(cs, (unsigned char *) "FSNP", 4);
        int len = strlen(password_value);
        for (int i = 0; i < len; i++) {
            unsigned char c = password_value[i];
            // only include ASCII characters
            if (c < 128) {
                g_checksum_update(cs, &c, 1);
            }
        }
        gsize digest_len = 20;
        g_checksum_get_digest(cs, g_fs_emu_netplay_password, &digest_len);
        free(password_value);
        g_checksum_free(cs);
    }

}
Exemplo n.º 11
0
static void
_same_hash (const char *p0)
{
	static gchar* memory[65536];

	GString *prefix = g_string_new(p0);

	gint64 counter;
	GChecksum *c;
	gchar num[64];
	union {
		guint8 b[32];
		guint16 prefix;
	} bin;
	gsize binsize;

	memset(&bin, 0, sizeof(bin));
	counter = 0;
	c = g_checksum_new(G_CHECKSUM_SHA256);

	if (prefix && prefix->len > 0) {
		/* pre-loads the memory with the prefix only */
		g_checksum_update(c, (guint8*) prefix->str, prefix->len);
		binsize = sizeof(bin.b);
		g_checksum_get_digest(c, bin.b, &binsize);
		memory[bin.prefix] = g_strdup(prefix->str);
	}

	for (;;) {

		GString *gstr = g_string_new("");
		if (prefix && prefix->len > 0)
			g_string_append_len(gstr, prefix->str, prefix->len);
		g_snprintf(num, sizeof(num), "%"G_GINT64_FORMAT, counter++);
		g_string_append(gstr, num);

		g_checksum_reset(c);
		g_checksum_update(c, (guint8*) gstr->str, gstr->len);
		binsize = sizeof(bin.b);
		g_checksum_get_digest(c, bin.b, &binsize);

		if (memory[bin.prefix]) {
			g_print("%02X%02X %s %s\n", bin.b[0], bin.b[1],
					memory[bin.prefix], gstr->str);
			g_free(memory[bin.prefix]);
		}

		memory[bin.prefix] = g_string_free(gstr, FALSE);
	}

	g_checksum_free(c);
}
Exemplo n.º 12
0
static gboolean auth_backend_htdigest(liVRequest *vr, const GString *username, const GString *password, AuthBasicData *bdata, gboolean debug) {
	const char *pass, *realm;
	AuthFileData *afd = auth_file_get_data(vr->wrk, bdata->data);
	GChecksum *md5sum;
	gboolean res = FALSE;

	if (NULL == afd) return FALSE;

	/* unknown user? */
	if (!(pass = g_hash_table_lookup(afd->users, username->str))) {
		if (debug) {
			VR_DEBUG(vr, "User \"%s\" not found", username->str);
		}
		goto out;
	}

	realm = pass;
	pass = strchr(pass, ':');

	/* no realm/wrong realm? */
	if (NULL == pass || 0 != strncmp(realm, bdata->realm->str, bdata->realm->len)) {
		if (debug) {
			VR_DEBUG(vr, "Realm for user \"%s\" doesn't match", username->str);
		}
		goto out;
	}
	pass++;

	md5sum = g_checksum_new(G_CHECKSUM_MD5);
	g_checksum_update(md5sum, GUSTR_LEN(username));
	g_checksum_update(md5sum, CONST_USTR_LEN(":"));
	g_checksum_update(md5sum, GUSTR_LEN(bdata->realm));
	g_checksum_update(md5sum, CONST_USTR_LEN(":"));
	g_checksum_update(md5sum, GUSTR_LEN(password));

	/* wrong password? */
	if (g_str_equal(pass, g_checksum_get_string(md5sum))) {
		res = TRUE;
	} else {
		if (debug) {
			VR_DEBUG(vr, "Password digest \"%s\" doesn't match \"%s\" for user \"%s\"", g_checksum_get_string(md5sum), pass, username->str);
		}
	}

	g_checksum_free(md5sum);

out:
	auth_file_data_release(afd);

	return res;
}
Exemplo n.º 13
0
gchar*
kolab_util_kconv_kconvmail_checksum (const Kolab_conv_mail *kconvmail)
{
	GChecksum *checksum = NULL;
	gchar *checksum_str = NULL;
	guint ii = 0;

	/* we need to do checksumming over all members of the
	 * Kolab_conv_mail_parts, which includes the part
	 * name and mimetype (we do need to catch changes in
	 * these parts since it also means "changed data set,
	 * even if the actual payload data did not change)
	 */

	g_assert (kconvmail != NULL);
	g_assert (kconvmail->length > 0);
	g_assert (kconvmail->mail_parts != NULL);

	/* We can use the simplest checksumming algorithm available
	 * here, since we do not need the checksum for crypto purposes
	 * but just for telling whether or not a data blob has changed
	 */

	checksum = g_checksum_new (G_CHECKSUM_SHA1);

	for (ii = 0; ii < kconvmail->length; ii++) {
		Kolab_conv_mail_part *kconvmailpart = NULL;

		kconvmailpart = &(kconvmail->mail_parts[ii]);

		/* mime part (file)name */
		g_checksum_update (checksum,
		                   (const guchar *) kconvmailpart->name,
		                   (gssize) strlen (kconvmailpart->name));
		/* mime part type */
		g_checksum_update (checksum,
		                   (const guchar *) kconvmailpart->mime_type,
		                   (gssize) strlen (kconvmailpart->mime_type));
		/*mime part payload data */
		g_checksum_update (checksum,
		                   (const guchar *) kconvmailpart->data,
		                   (gssize) kconvmailpart->length);
	}

	checksum_str = g_strdup (g_checksum_get_string (checksum));

	g_checksum_free (checksum);

	return checksum_str;
}
Exemplo n.º 14
0
void
_gcr_display_view_append_fingerprint (GcrDisplayView *self, GcrRenderer *renderer, const guchar *data,
                                      gsize n_data, const gchar *name, GChecksumType type)
{
	GChecksum *checksum;
	guint8 *buffer;
	gsize n_buffer;
	gchar *display;

	g_return_if_fail (GCR_IS_DISPLAY_VIEW (self));

	checksum = g_checksum_new (type);
	g_return_if_fail (checksum);
	g_checksum_update (checksum, data, n_data);

	n_buffer = g_checksum_type_get_length (type);
	g_return_if_fail (n_buffer);
	buffer = g_malloc0 (n_buffer);

	g_checksum_get_digest (checksum, buffer, &n_buffer);
	g_checksum_free (checksum);

	display = egg_hex_encode_full (buffer, n_buffer, TRUE, ' ', 1);
	_gcr_display_view_append_value (self, renderer, name, display, TRUE);
	g_free (display);

	g_free (buffer);
}
Exemplo n.º 15
0
static void
wep128_passphrase_hash (const char *input,
                        size_t input_len,
                        guint8 *out_digest,
                        size_t *out_digest_len)
{
	GChecksum *sum;
	guint8 data[64];
	int i;

	g_return_if_fail (out_digest != NULL);
	g_return_if_fail (out_digest_len != NULL);
	g_return_if_fail (*out_digest_len >= 16);

	/* Get at least 64 bytes by repeating the passphrase into the buffer */
	for (i = 0; i < sizeof (data); i++)
		data[i] = input[i % input_len];

	sum = g_checksum_new (G_CHECKSUM_MD5);
	g_assert (sum);
	g_checksum_update (sum, data, sizeof (data));
	g_checksum_get_digest (sum, out_digest, out_digest_len);
	g_checksum_free (sum);

	g_assert (*out_digest_len == 16);
	/* WEP104 keys are 13 bytes in length (26 hex characters) */
	*out_digest_len = 13;
}
Exemplo n.º 16
0
Arquivo: http.c Projeto: Amelos/moloch
int
moloch_hp_cb_on_body (http_parser *parser, const char *at, size_t length)
{
    HTTPInfo_t            *http = parser->data;
    MolochSession_t       *session = http->session;

#ifdef HTTPDEBUG
    LOG("HTTPDEBUG: which: %d", http->which);
#endif

    if (!(http->inBody & (1 << http->which))) {
        if (moloch_memstr(at, length, "password="******"http:password");
        }

        moloch_parsers_magic_tag(session, magicField, "http:content", at, length);
        http->inBody |= (1 << http->which);
    }

    g_checksum_update(http->checksum[http->which], (guchar *)at, length);

    if (pluginsCbs & MOLOCH_PLUGIN_HP_OB)
        moloch_plugins_cb_hp_ob(session, parser, at, length);

    return 0;
}
Exemplo n.º 17
0
/**
 * gcr_fingerprint_from_subject_public_key_info:
 * @key_info: (array length=n_key_info): DER encoded subjectPublicKeyInfo structure
 * @n_key_info: length of DER encoded structure
 * @checksum_type: the type of fingerprint to create
 * @n_fingerprint: the length of fingerprint returned
 *
 * Create a key fingerprint for a DER encoded subjectPublicKeyInfo.
 *
 * Returns: (transfer full) (allow-none) (array length=n_fingerprint): the
 *          fingerprint or %NULL if the input was invalid.
 */
guchar *
gcr_fingerprint_from_subject_public_key_info (const guchar *key_info,
                                              gsize n_key_info,
                                              GChecksumType checksum_type,
                                              gsize *n_fingerprint)
{
	GChecksum *check;
	guint8 *fingerprint;

	g_return_val_if_fail (key_info, NULL);
	g_return_val_if_fail (n_key_info, NULL);
	g_return_val_if_fail (n_fingerprint, NULL);

	check = g_checksum_new (checksum_type);
	g_return_val_if_fail (check, NULL);

	g_checksum_update (check, key_info, n_key_info);

	*n_fingerprint = g_checksum_type_get_length (checksum_type);
	fingerprint = g_malloc (*n_fingerprint);
	g_checksum_get_digest (check, fingerprint, n_fingerprint);

	g_checksum_free (check);
	return fingerprint;
}
Exemplo n.º 18
0
void SHA1SKey(char *x)
{
        GChecksum *checksum;
        guint8 digest[20];
        gsize digest_len = sizeof (digest);
	guint32 *results;

        checksum = g_checksum_new (G_CHECKSUM_SHA1);
        g_checksum_update (checksum, (const guchar *) x, SKEY_SIZE);
        g_checksum_get_digest (checksum, digest, &digest_len);
        g_assert (digest_len == 20);

        results = (guint32 *) digest;
#ifndef WORDS_BIGENDIAN
	HTONDIGEST(results);
#else
	byteReverse((unsigned char *)digest, 5);
#endif

	results[0] ^= results[2];
	results[1] ^= results[3];
	results[0] ^= results[4];

	memcpy((void *)x, (void *)results, SKEY_SIZE);

        g_checksum_free (checksum);
}
Exemplo n.º 19
0
gboolean
ot_gio_write_update_checksum (GOutputStream  *out,
                              gconstpointer   data,
                              gsize           len,
                              gsize          *out_bytes_written,
                              GChecksum      *checksum,
                              GCancellable   *cancellable,
                              GError        **error)
{
  gboolean ret = FALSE;

  if (out)
    {
      if (!g_output_stream_write_all (out, data, len, out_bytes_written,
                                      cancellable, error))
        goto out;
    }
  else if (out_bytes_written)
    {
      *out_bytes_written = len;
    }

  if (checksum)
    g_checksum_update (checksum, data, len);
  
  ret = TRUE;
 out:
  return ret;
}
Exemplo n.º 20
0
const char *
oio_str_autocontainer_name (const char *path, gchar *dst,
		const struct oio_str_autocontainer_config_s *cfg)
{
	guint8 bin[64];

	g_assert (path != NULL);
	g_assert (dst != NULL);
	g_assert (cfg != NULL);

	gsize len = strlen (path);
	gsize src_offset = cfg->src_offset;
	gsize src_size = cfg->src_size;
	if (src_offset + src_size > len)
		return NULL;
	/* TODO check the sum doesn't cause an overflow... */

	if (!src_size)
		src_size = len - src_offset;

	GChecksum *checksum = g_checksum_new (G_CHECKSUM_SHA256);
	g_checksum_update (checksum, (guint8*)(path+src_offset), src_size);
	len = sizeof(bin);
	g_checksum_get_digest (checksum, bin, &len);
	g_checksum_free (checksum);

	return oio_str_autocontainer_hash (bin, 64, dst, cfg);
}
Exemplo n.º 21
0
static void
do_md5sum (SoupMessage *msg, SoupXMLRPCParams *params)
{
	GVariant *args;
	GVariant *child;
	GChecksum *checksum;
	GByteArray *digest;
	gsize digest_len = 16;

	if (!(args = parse_params (msg, params, "(ay)")))
		return;

	child = g_variant_get_child_value (args, 0);

	checksum = g_checksum_new (G_CHECKSUM_MD5);
	g_checksum_update (checksum,
			   g_variant_get_data (child),
			   g_variant_get_size (child));
	digest = g_byte_array_new ();
	g_byte_array_set_size (digest, digest_len);
	g_checksum_get_digest (checksum, digest->data, &digest_len);
	g_checksum_free (checksum);

	soup_xmlrpc_message_set_response (msg,
					  g_variant_new_from_data (G_VARIANT_TYPE_BYTESTRING,
								   digest->data, digest_len,
								   TRUE, NULL, NULL),
					  NULL);
	g_byte_array_free (digest, TRUE);
	g_variant_unref (child);
	g_variant_unref (args);
}
Exemplo n.º 22
0
static void
do_md5sum (SoupMessage *msg, GValueArray *params)
{
	GChecksum *checksum;
	GByteArray *data, *digest;
	gsize digest_len = 16;

	if (params->n_values != 1) {
		args_error (msg, params, 1);
		return;
	}

	if (!soup_value_array_get_nth (params, 0, SOUP_TYPE_BYTE_ARRAY, &data)) {
		type_error (msg, SOUP_TYPE_BYTE_ARRAY, params, 0);
		return;
	}
	checksum = g_checksum_new (G_CHECKSUM_MD5);
	g_checksum_update (checksum, data->data, data->len);
	digest = g_byte_array_new ();
	g_byte_array_set_size (digest, digest_len);
	g_checksum_get_digest (checksum, digest->data, &digest_len);
	g_checksum_free (checksum);

	soup_xmlrpc_set_response (msg, SOUP_TYPE_BYTE_ARRAY, digest);
	g_byte_array_free (digest, TRUE);
}
Exemplo n.º 23
0
/**
 * gum_validate_generate_username:
 * @str: (transfer none): the string to be validated
 * @error: (transfer none): the #GError to be set in case of error
 *
 * Generate username based on the string @str and then validate the generated
 * user name against #GUM_NAME_PATTERN pattern.
 *
 * Returns: (transfer full): string if successful, NULL otherwise.
 */
gchar *
gum_validate_generate_username (
        const gchar *str,
        GError **error)
{
    gchar *gen_name = NULL;
    GChecksum *hid = NULL;
    gsize len = 0;
    if (!str || (len = strlen (str)) == 0) {
        GUM_RETURN_WITH_ERROR (GUM_ERROR_INVALID_NAME,
                "Unable to generate name for 0 len str", error, NULL);
    }

    hid = g_checksum_new (G_CHECKSUM_MD5);
    g_checksum_update (hid, (const guchar*)str, len);

    gen_name = g_strdup (g_checksum_get_string (hid));
    g_checksum_free (hid);
    if (!g_ascii_isalpha ((gchar)gen_name[0])) {
        gen_name[0] = 'U';
        DBG ("First character changed to alpha in %s",gen_name);
    }
    if (!gum_validate_name (gen_name, error)) {
        g_free (gen_name);
        gen_name = NULL;
    }

    return gen_name;
}
Exemplo n.º 24
0
char *
rpmhdrs_rpmdbv (struct RpmHeaders *l1,
                GCancellable   *cancellable,
                GError        **error)
{
  GChecksum *checksum = g_checksum_new (G_CHECKSUM_SHA1);
  g_autofree char *checksum_cstr = NULL;
  char *ret = NULL;
  int num = 0;

  while (num < l1->hs->len)
    {
      Header pkg = l1->hs->pdata[num++];
      g_autofree char *envra = pkg_envra_strdup (pkg);

      g_checksum_update (checksum, (guint8*)envra, strlen(envra));
    }

  checksum_cstr = g_strdup (g_checksum_get_string (checksum));

  ret = g_strdup_printf ("%u:%s", num, checksum_cstr);

  g_checksum_free (checksum);

  return ret;
}
Exemplo n.º 25
0
static void
uuid_randomize(gchar *d, gsize dl)
{
    static guint32 seq = 0;

    struct {
        int pid, ppid;
        GTimeVal now;
        guint32 seq;
        gpointer p0, p1, p2;
        gchar h[512];
    } bulk;

    memset(&bulk, 0, sizeof(bulk));
    bulk.pid = getpid();
    bulk.ppid = getppid();
    g_get_current_time(&(bulk.now));
    bulk.seq = ++seq;
    bulk.p0 = &bulk;
    bulk.p1 = d;
    bulk.p2 = &d;
    gethostname(bulk.h, sizeof(bulk.h));

    GChecksum *cs = g_checksum_new(G_CHECKSUM_SHA256);
    g_checksum_update(cs, (guint8*) &bulk, sizeof(bulk));
    g_strlcpy(d, g_checksum_get_string(cs), dl);
    g_checksum_free(cs);

    for (; dl ;--dl)
        d[dl-1] = g_ascii_toupper(d[dl-1]);
}
Exemplo n.º 26
0
static uint8_t *digest_cert(const char *cert, int length)
{
	GChecksum *checksum;
	uint8_t *hash;
	gsize digest_len;

	if (cert == NULL || length < 0)
		return NULL;

	digest_len = g_checksum_type_get_length(G_CHECKSUM_SHA1);
	hash = g_try_malloc(digest_len);
	if (hash == NULL)
		return NULL;

	checksum = g_checksum_new(G_CHECKSUM_SHA1);
	if (checksum == NULL) {
		g_free(hash);
		return NULL;
	}

	g_checksum_update(checksum, cert, length);

	g_checksum_get_digest(checksum, hash, &digest_len);

	DBG("Digest is: ");
	__seel_apdu_dump(hash, digest_len);

	g_checksum_free(checksum);

	return hash;
}
Exemplo n.º 27
0
Arquivo: sms.c Projeto: AndriusA/ofono
static gboolean compute_incoming_msgid(GSList *sms_list,
						struct ofono_uuid *uuid)
{
	GChecksum *checksum;
	GSList *l;
	const struct sms *s;
	unsigned char buf[176];
	gsize uuid_size = sizeof(uuid->uuid);
	int len;

	checksum = g_checksum_new(G_CHECKSUM_SHA1);
	if (checksum == NULL)
		return FALSE;

	for (l = sms_list; l; l = l->next) {
		s = l->data;

		if (sms_encode(s, &len, NULL, buf) == FALSE) {
			g_checksum_free(checksum);
			return FALSE;
		}

		g_checksum_update(checksum, buf, len);
	}

	g_checksum_get_digest(checksum, uuid->uuid, &uuid_size);
	g_checksum_free(checksum);

	return TRUE;
}
static void
append_fingerprint (GcrCertificateDetailsWidget *self, const guchar *data, 
                    gsize n_data, const gchar *name, GChecksumType type)
{
	GChecksum *checksum;
	guint8 *buffer;
	gsize n_buffer;
	gchar *display;
	
	checksum = g_checksum_new (type);
	g_return_if_fail (checksum);
	g_checksum_update (checksum, data, n_data);
	
	n_buffer = g_checksum_type_get_length (type);
	g_return_if_fail (n_buffer);
	buffer = g_malloc0 (n_buffer);
	
	g_checksum_get_digest (checksum, buffer, &n_buffer);
	g_checksum_free (checksum);
	
	display = egg_hex_encode_full (buffer, n_buffer, TRUE, ' ', 1);
	append_field_and_value (self, name, display, TRUE);
	g_free (display);
	
	g_free (buffer);		
}
Exemplo n.º 29
0
static void _tgentransfer_writePayload(TGenTransfer* transfer) {
    TGEN_ASSERT(transfer);

    gboolean firstByte = transfer->bytes.payloadWrite == 0 ? TRUE : FALSE;

    /* try to flush any leftover bytes */
    transfer->bytes.payloadWrite += _tgentransfer_flushOut(transfer);

    /* keep writing until blocked */
    while(!transfer->writeBuffer) {
        gsize length = MIN(16384, (transfer->size - transfer->bytes.payloadWrite));

        if(length > 0) {
            /* we need to send more payload */
            transfer->writeBuffer = _tgentransfer_getRandomString(length);
            g_checksum_update(transfer->payloadChecksum, (guchar*)transfer->writeBuffer->str,
                    (gssize)transfer->writeBuffer->len);

            transfer->bytes.payloadWrite += _tgentransfer_flushOut(transfer);

            if(firstByte && transfer->bytes.payloadWrite > 0) {
                firstByte = FALSE;
                transfer->time.firstPayloadByte = g_get_monotonic_time();
            }
        } else {
            /* payload done, send the checksum next */
            _tgentransfer_changeState(transfer, TGEN_XFER_CHECKSUM);
            transfer->time.lastPayloadByte = g_get_monotonic_time();
            break;
        }
    }
}
Exemplo n.º 30
0
gboolean
_rpmostree_util_update_checksum_from_file (GChecksum    *checksum,
                                           GFile        *src,
                                           GCancellable *cancellable,
                                           GError      **error)
{
  gboolean ret = FALSE;
  gsize bytes_read;
  char buf[4096];
  gs_unref_object GInputStream *filein = NULL;

  filein = (GInputStream*)g_file_read (src, cancellable, error);
  if (!filein)
    goto out;

  do
    {
      if (!g_input_stream_read_all (filein, buf, sizeof(buf), &bytes_read,
                                    cancellable, error))
        goto out;

      g_checksum_update (checksum, (guint8*)buf, bytes_read);
    }
  while (bytes_read > 0);

  ret = TRUE;
 out:
  return ret;
}