예제 #1
0
UT_Error ODc_Crypto::decrypt(GsfInput* pStream, const ODc_CryptoInfo& cryptInfo,
    const std::string& password, GsfInput** pDecryptedInput)
{
	UT_return_val_if_fail(pStream, UT_ERROR);
	UT_return_val_if_fail(pDecryptedInput, UT_ERROR);
	
	// check if we support the requested decryption method
	UT_return_val_if_fail(g_ascii_strcasecmp(cryptInfo.m_algorithm.c_str(), "Blowfish CFB") == 0, UT_ERROR);
	UT_return_val_if_fail(g_ascii_strcasecmp(cryptInfo.m_keyType.c_str(), "PBKDF2") == 0, UT_ERROR);
	
	// base64 decode the salt
	gsize salt_length;
	unsigned char* salt = g_base64_decode(cryptInfo.m_salt.c_str(), &salt_length);

	// base64 decode the initialization vector
	gsize ivec_length;
	unsigned char* ivec = g_base64_decode(cryptInfo.m_initVector.c_str(), &ivec_length);

	// decrypt the content
	UT_Error result = performDecrypt(pStream, salt, salt_length, cryptInfo.m_iterCount,  
			ivec, password, cryptInfo.m_decryptedSize, pDecryptedInput);

	// cleanup
	FREEP(salt);
	FREEP(ivec);

	return result;
}
예제 #2
0
파일: hashs.c 프로젝트: dupgit/sauvegarde
/**
 * makes a GSList of hash_data_t * element where 'hash' field is base64
 * decoded hashs from a string containning base64 * encoded hashs that
 * must be separated by commas.
 * @param the string containing base64 encoded hashs such as : *
 *        "cCoCVkt/AABf04jn2+rfDmqJaln6P2A9uKolBjEFJV4=", "0G8MaPZ/AADNyaPW7ZP2s0BI4hAdZZIE2xO1EwdOzhE="
 *        for instance.
 * @returns a GSList of hash_data_t * where each elements contains a
 *          base64 decoded hash (binary form).
 */
GList *make_hash_data_list_from_string(gchar *hash_string)
{
    guint i = 0;
    gchar **hashs = NULL;
    gchar *a_hash = NULL;
    hash_data_t *hash_data = NULL;
    GList *hash_list = NULL;
    gsize len = 0;

    if (hash_string != NULL)
        {
            /* hash list generation */
            hashs = g_strsplit(hash_string, ",", -1);

            while (hashs[i] != NULL)
                {
                    a_hash = g_strndup(g_strchug(hashs[i] + 1), strlen(g_strchug(hashs[i])) - 2);

                    /* we have to base64 decode it to insert it into the hash_data_t * structure
                     * and then into the meta_data one.
                     */
                    hash_data = new_hash_data_t_as_is(NULL, 0, g_base64_decode(a_hash, &len), COMPRESS_NONE_TYPE, 0);
                    hash_list = g_list_prepend(hash_list, hash_data);
                    free_variable(a_hash);
                    i = i + 1;
                }

            g_strfreev(hashs);

            hash_list = g_list_reverse(hash_list);
        }

    return hash_list;
}
예제 #3
0
static void keystore_load_aeskey(GKeyFile *keyfile, gchar *key,
                                 struct keystore_t *keystore)
{
	g_assert(NULL != keyfile);
	g_assert(NULL != key);
	g_assert(NULL != keystore);
	gsize length = 0;
	gchar **list = g_key_file_get_string_list(keyfile, "aes", key, &length, NULL);

	if (length == 2)
	{
		int key_index = atoi(key);
		int keylen = atoi(list[0]);
		gsize keybits_len = 0;
		guchar *keybits = g_base64_decode(list[1], &keybits_len);
		g_assert(keylen == keybits_len * 8);

		struct aes_key_t *aes_key = g_malloc(sizeof(struct aes_key_t));
		aes_key->keylen = keylen;
		memcpy(aes_key->key, keybits, keybits_len);

		keystore_key_replace(keystore->aes, aes_key, &key_index);

		g_free(keybits);
	}

	g_strfreev(list);
}
예제 #4
0
파일: ui.c 프로젝트: collinmmccabe/lxdm
static gchar *greeter_param(char *str, char *name)
{
	char *temp, *p;
	char ret[128];
	int i;
	temp = g_strdup_printf(" %s=", name);
	p = strstr(str, temp);
	if( !p )
	{
		g_free(temp);
		return NULL;
	}
	p += strlen(temp);
	g_free(temp);
	for( i = 0; i < 127; i++ )
	{
		if( !p[i] || isspace(p[i]) )
			break;
		ret[i] = p[i];
	}
	ret[i] = 0;
	if(!strcmp(name,"pass"))
	{
		gsize outlen;
		temp=(char*)g_base64_decode(ret,&outlen);
		if(!temp) return NULL;
		p=g_malloc(outlen+1);
		memcpy(p,temp,outlen);
		p[outlen]=0;
		g_free(temp);
		return p;
	}
	return g_strdup(ret);
}
예제 #5
0
파일: password.c 프로젝트: Tux/claws-mail
static guchar *_make_key_deriv(const gchar *passphrase, guint rounds,
		guint length)
{
	guchar *kd, *salt;
	gchar *saltpref = prefs_common_get_prefs()->master_passphrase_salt;
	gsize saltlen;
	gint ret;

	/* Grab our salt, generating and saving a new random one if needed. */
	if (saltpref == NULL || strlen(saltpref) == 0) {
		_generate_salt();
		saltpref = prefs_common_get_prefs()->master_passphrase_salt;
	}
	salt = g_base64_decode(saltpref, &saltlen);
	kd = g_malloc0(length);

	START_TIMING("PBKDF2");
	ret = pkcs5_pbkdf2(passphrase, strlen(passphrase), salt, saltlen,
			kd, length, rounds);
	END_TIMING();

	g_free(salt);

	if (ret == 0) {
		return kd;
	}

	g_free(kd);
	return NULL;
}
static void
update_contact_inline (EBookClient *book,
                       const gchar *uid)
{
	EContact *contact = NULL;
	EContactPhoto *photo;
	guchar *data;
	gsize length = 0;
	GError *error = NULL;

	if (!e_book_client_get_contact_sync (book, uid, &contact, NULL, &error))
	  g_error ("Unable to get contact: %s", error->message);

	g_assert (contact);

	data = g_base64_decode (photo_data, &length);

	photo = g_new (EContactPhoto, 1);
	photo->type = E_CONTACT_PHOTO_TYPE_INLINED;
	photo->data.inlined.mime_type = NULL;
	photo->data.inlined.data = data;
	photo->data.inlined.length = length;

	/* set the photo */
	e_contact_set (contact, E_CONTACT_PHOTO, photo);

	if (!e_book_client_modify_contact_sync (book, contact, NULL, &error))
	    g_error ("Failed to modify contact with inline photo data: %s", error->message);
}
예제 #7
0
static void
soup_logger_print_basic_auth (SoupLogger *logger, const char *value)
{
	char *decoded, *decoded_utf8, *p;
	gsize len;

	decoded = (char *)g_base64_decode (value + 6, &len);
	if (decoded && !g_utf8_validate (decoded, -1, NULL)) {
		decoded_utf8 = g_convert_with_fallback (decoded, -1,
							"UTF-8", "ISO-8859-1",
							NULL, NULL, &len,
							NULL);
		if (decoded_utf8) {
			g_free (decoded);
			decoded = decoded_utf8;
		}
	}

	if (!decoded)
		decoded = g_strdup (value);
	p = strchr (decoded, ':');
	if (p) {
		while (++p < decoded + len)
			*p = '*';
	}
	soup_logger_print (logger, SOUP_LOGGER_LOG_HEADERS, '>',
			   "Authorization: Basic [%.*s]", len, decoded);
	g_free (decoded);
}
예제 #8
0
static GdkPixbuf*
decode_image (const char *val)
{
  int i;
  GError *error = NULL;
  GdkPixbuf *res = NULL;
  struct {
    const char *prefix;
    const char *mime_type;
  } formats[] = {
    { "data:image/x-icon;base64,", "image/x-icon" },
    { "data:image/png;base64,", "image/png" }
  };

  g_return_val_if_fail (val, NULL);

  for (i = 0; i < G_N_ELEMENTS (formats); i++)
    {
      if (g_str_has_prefix (val, formats[i].prefix))
        {
          gsize len;
          guchar *data = NULL;
          char *unescaped;

          unescaped = g_uri_unescape_string (val + strlen (formats[i].prefix), NULL);
          if (unescaped)
            {
              data = g_base64_decode (unescaped, &len);
              g_free (unescaped);
            }

          if (data)
            {
              GdkPixbufLoader *loader;

              loader = gdk_pixbuf_loader_new_with_mime_type (formats[i].mime_type, &error);
              if (loader &&
                  gdk_pixbuf_loader_write (loader, data, len, &error) &&
                  gdk_pixbuf_loader_close (loader, &error))
                {
                  res = gdk_pixbuf_loader_get_pixbuf (loader);
                  g_object_ref (res);
                }
              g_object_unref (loader);
              g_free (data);
            }
        }
    }
  if (!res)
    {
      if (error)
        {
          g_warning ("%s\n", error->message);
          g_error_free (error);
        }
      else
        g_warning ("incorrect data uri");
    }
  return res;
}
예제 #9
0
static GString *
getValue (gchar **src)
{
	GString *dest = g_string_new("");
	gchar *s = *src;
	gboolean need_base64 = (*s == ':');

 copy_line:
	while (*s != 0 && *s != '\n' && *s != '\r')
		dest = g_string_append_c (dest, *s++);

	if (*s == '\r') s++;
	if (*s == '\n')	s++;

	/* check for continuation here */
	if (*s == ' ') {
		s++;
		goto copy_line;
	}

	if (need_base64) {
		guchar *data;
		gsize length;

		/* XXX g_string_assign_len() would be nice here */
		data = g_base64_decode (dest->str + 2, &length);
		g_string_truncate (dest, 0);
		g_string_append_len (dest, (gchar *) data, length);
		g_free (data);
	}

	*src = s;

	return dest;
}
예제 #10
0
파일: base64.c 프로젝트: 01org/qemu-lite
uint8_t *qbase64_decode(const char *input,
                        size_t in_len,
                        size_t *out_len,
                        Error **errp)
{
    *out_len = 0;

    if (in_len != -1) {
        /* Lack of NUL terminator is an error */
        if (input[in_len] != '\0') {
            error_setg(errp, "Base64 data is not NUL terminated");
            return NULL;
        }
        /* Check there's no NULs embedded since we expect
         * this to be valid base64 data */
        if (memchr(input, '\0', in_len) != NULL) {
            error_setg(errp, "Base64 data contains embedded NUL characters");
            return NULL;
        }

        /* Now we know its a valid nul terminated string
         * strspn is safe to use... */
    } else {
        in_len = strlen(input);
    }

    if (strspn(input, base64_valid_chars) != in_len) {
        error_setg(errp, "Base64 data contains invalid characters");
        return NULL;
    }

    return g_base64_decode(input, out_len);
}
gboolean
vino_get_password (GValue   *value,
                   GVariant *variant,
                   gpointer  user_data)
{
  const gchar *setting;

  setting = g_variant_get_string (variant, NULL);

  if (strcmp (setting, "keyring") == 0)
    {
      /* "keyring" is the default value, even though vino doesn't support it at
       * the moment */

      g_value_set_static_string (value, "");
      return TRUE;
    }
  else
    {
      gchar *decoded;
      gsize length;
      gboolean ok;

      decoded = (gchar *) g_base64_decode (setting, &length);

      if ((ok = g_utf8_validate (decoded, length, NULL)))
        g_value_take_string (value, g_strndup (decoded, length));

      return ok;
    }
}
예제 #12
0
static gchar *
decode_string (const gchar *encoded)
{
	guchar *data, xval;
	gsize len = 0, ii;
	gchar *res;

	g_return_val_if_fail (encoded != NULL, NULL);
	g_return_val_if_fail (*encoded, NULL);

	data = g_base64_decode (encoded, &len);
	g_return_val_if_fail (data != NULL, NULL);
	g_return_val_if_fail (len > 0, NULL);

	xval = 17;
	for (ii = 0; ii < len; ii++) {
		data[ii] = data[ii] ^ xval;
		xval += 17;
	}

	res = g_strndup ((const gchar *) data, len);

	e_credentials_util_safe_free_string ((gchar *) data);

	return res;
}
예제 #13
0
파일: darxencli.c 프로젝트: darxen/Darxen
static void
poll_client_data_received(DarxenClient* client, DarxenClientDataPacket* data, gpointer user_data)
{
	printf("Data received from %s/%s\n", data->site, data->product);fflush(stdout);

	int len;
	guchar* fdata = g_base64_decode(data->data, &len);

	FILE* f = tmpfile();

	fwrite(fdata, 1, len, f);
	fseek(f, 0, SEEK_SET);

	ProductsLevel3Data* parsed;

	if (!(parsed = parser_lvl3_parse_file(f)))
	{
		g_critical("Failed to parse level 3 data");
		return;
	}

	printf("Header: %s\n", parsed->chrWmoHeader);

	fflush(stdout);
}
예제 #14
0
void b64_decode(gchar *data, gsize *len, unsigned char *raw_message) {
	guchar *out;

	out = g_base64_decode(data, len);
	memcpy(raw_message, out, *len);
	g_free(out);
}
/**
 * e_vcard_attribute_get_values_decoded:
 * @attr: an #EVCardAttribute
 *
 * Gets the list of values from @attr, decoding them if
 * necessary. The list and its contents are owned by @attr,
 * and must not be freed.
 *
 * Return value: A list of values of type #GString.
 **/
GList*
e_vcard_attribute_get_values_decoded (EVCardAttribute *attr)
{
	g_return_val_if_fail (attr != NULL, NULL);

	if (!attr->decoded_values) {
		GList *l;
		switch (attr->encoding) {
		case EVC_ENCODING_RAW:
			for (l = attr->values; l; l = l->next)
				attr->decoded_values = g_list_prepend (attr->decoded_values, g_string_new ((char*)l->data));
			attr->decoded_values = g_list_reverse (attr->decoded_values);
			break;
		case EVC_ENCODING_BASE64:
			for (l = attr->values; l; l = l->next) {
				guchar *decoded;
				gsize len = 0;

				decoded = g_base64_decode (l->data, &len);
				attr->decoded_values = g_list_prepend (attr->decoded_values, g_string_new_len (decoded, len));
				g_free (decoded);
			}
			attr->decoded_values = g_list_reverse (attr->decoded_values);
			break;
		case EVC_ENCODING_QP:
			g_warning ("need to implement quoted printable decoding");
			break;
		}
	}

	return attr->decoded_values;
}
예제 #16
0
static gboolean parseDataUrl(gpointer callback_data)
{
    ResourceHandle* handle = static_cast<ResourceHandle*>(callback_data);
    String data = handle->request().url().string();

    ASSERT(data.startsWith("data:", false));

    String header;
    bool base64 = false;

    int index = data.find(',');
    if (index != -1) {
        header = data.substring(5, index - 5).lower();
        data = data.substring(index + 1);

        if (header.endsWith(";base64")) {
            base64 = true;
            header = header.left(header.length() - 7);
        }
    } else
        data = String();

    data = decodeURLEscapeSequences(data);

    size_t outLength = 0;
    char* outData = 0;
    if (base64 && !data.isEmpty()) {
        // Use the GLib Base64 if available, since WebCore's decoder isn't
        // general-purpose and fails on Acid3 test 97 (whitespace).
        outData = reinterpret_cast<char*>(g_base64_decode(data.utf8().data(), &outLength));
    }

    if (header.isEmpty())
        header = "text/plain;charset=US-ASCII";

    ResourceHandleClient* client = handle->getInternal()->client();

    ResourceResponse response;

    response.setMimeType(extractMIMETypeFromMediaType(header));
    response.setTextEncodingName(extractCharsetFromMediaType(header));
    if (outData)
        response.setExpectedContentLength(outLength);
    else
        response.setExpectedContentLength(data.length());
    response.setHTTPStatusCode(200);

    client->didReceiveResponse(handle, response);

    if (outData)
        client->didReceiveData(handle, outData, outLength, 0);
    else
        client->didReceiveData(handle, data.latin1().data(), data.length(), 0);

    g_free(outData);

    client->didFinishLoading(handle);

    return FALSE;
}
예제 #17
0
static void
test_full (gint length)
{
  char *text;
  guchar *data2;
  gsize len;

  text = g_base64_encode (data, length);
  data2 = g_base64_decode (text, &len);
  g_free (text);

  if (len != length)
    {
      g_print ("Wrong decoded length: got %d, expected %d\n",
	       len, length);
      exit (1);
    }

  if (memcmp (data, data2, length) != 0)
    {
      g_print ("Wrong decoded base64 data\n");
      exit (1);
    }

  g_free (data2);
}
예제 #18
0
/**
 * Function that gets the argument corresponding to the key 'key' in the
 * url (from connection)
 * @param connection is the connection in MHD
 * @param key the key to look for into the url
 * @param encoded is a boolean that is TRUE if value is base64 encoded
 * @returns a gchar * string that may be freed when no longer needed
 */
static gchar *get_argument_value_from_key(struct MHD_Connection *connection, gchar *key, gboolean encoded)
{
    const char *value = NULL;
    gchar *value_dup = NULL;
    gsize len = 0;

    if (connection != NULL && key != NULL)
        {
            value = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, key);

            if (value != NULL)
                {
                    if (encoded == TRUE)
                        {
                            value_dup = (gchar *) g_base64_decode(value, &len);
                        }
                    else
                        {
                            value_dup = g_strdup(value);
                        }
                }
        }

    return value_dup;
}
예제 #19
0
static gboolean
parse_basic (SoupMessage *msg, const char *header,
	     char **username, char **password)
{
	char *decoded, *colon;
	gsize len, plen;

	if (!header || (strncmp (header, "Basic ", 6) != 0))
		return FALSE;

	decoded = (char *)g_base64_decode (header + 6, &len);
	if (!decoded)
		return FALSE;

	colon = memchr (decoded, ':', len);
	if (!colon) {
		pw_free (decoded);
		return FALSE;
	}
	*colon = '\0';
	plen = len - (colon - decoded) - 1;

	*password = g_strndup (colon + 1, plen);
	memset (colon + 1, 0, plen);
	*username = decoded;
	return TRUE;
}
static gboolean _cd_do_fill_bookmark_entry (CDEntry *pEntry)
{
	if (pEntry->pIconSurface != NULL || pEntry->cIconName == NULL)
		return FALSE;
	
	gsize out_len = 0;
	//g_print ("icon : %s\n", pEntry->cIconName);
	guchar *icon = g_base64_decode (pEntry->cIconName, &out_len);
	//g_print ("-> out_len : %d\n", out_len);
	g_return_val_if_fail (icon != NULL, FALSE);
	//g_print ("-> data : %d\n", icon);
	
	GInputStream * is = g_memory_input_stream_new_from_data (icon,
		out_len,
		NULL);
	GdkPixbuf *pixbuf = gdk_pixbuf_new_from_stream (is,
		NULL,
		NULL);
	g_object_unref (is);
	double fImageWidth=0, fImageHeight=0;
	double fZoomX=0, fZoomY=0;
	pEntry->pIconSurface = cairo_dock_create_surface_from_pixbuf (pixbuf,
		1.,
		myDialogsParam.dialogTextDescription.iSize, myDialogsParam.dialogTextDescription.iSize,
		0,
		&fImageWidth, &fImageHeight,
		&fZoomX, &fZoomY);
	g_object_unref (pixbuf);
	g_free (icon);
	
	return TRUE;
}
예제 #21
0
static int
identify_auth (SoupMessage *msg)
{
	const char *header;
	int num;

	header = soup_message_headers_get_one (msg->request_headers,
					       "Authorization");
	if (!header)
		return 0;

	if (!g_ascii_strncasecmp (header, "Basic ", 6)) {
		char *token;
		gsize len;

		token = (char *)g_base64_decode (header + 6, &len);
		num = token[len - 1] - '0';
		g_free (token);
	} else {
		const char *user;

		user = strstr (header, "username=\"user");
		if (user)
			num = user[14] - '0';
		else
			num = 0;
	}

	g_assert (num >= 0 && num <= 4);

	return num;
}
예제 #22
0
bool SrtpChannel::configureSrtpSession(srtp_t *session, const char* key,
        enum TransmissionType type) {
    srtp_policy_t policy;
    memset(&policy, 0, sizeof(policy));
    crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtp);
    crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp);
    if (type == SENDING) {
        policy.ssrc.type = ssrc_any_outbound;
    } else {

        policy.ssrc.type = ssrc_any_inbound;
    }

    policy.ssrc.value = 0;
    policy.window_size = 1024;
    policy.allow_repeat_tx = 1;
    policy.next = NULL;
    //ELOG_DEBUG("auth_tag_len %d", policy.rtp.auth_tag_len);

    gsize len = 0;
    uint8_t *akey = (uint8_t*) g_base64_decode((gchar*) key, &len);
    ELOG_DEBUG("set master key/salt to %s/", octet_string_hex_string(akey, 16));
    // allocate and initialize the SRTP session
    policy.key = akey;
    int res = srtp_create(session, &policy);
    if (res!=0){
      ELOG_ERROR("Failed to create srtp session with %s, %d", octet_string_hex_string(akey, 16), res);
    }
    return res!=0? false:true;
}
static void
add_contact_inline (EBookClient *book)
{
	EContact *contact;
	EContactPhoto *photo;
	guchar *data;
	gsize length = 0;

	contact = e_contact_new ();

	data = g_base64_decode (photo_data, &length);

	photo = g_new (EContactPhoto, 1);
	photo->type = E_CONTACT_PHOTO_TYPE_INLINED;
	photo->data.inlined.mime_type = NULL;
	photo->data.inlined.data = data;
	photo->data.inlined.length = length;

	/* set the photo */
	e_contact_set (contact, E_CONTACT_PHOTO, photo);
	e_contact_set (contact, E_CONTACT_FULL_NAME, "Micheal Jackson");

	if (!add_contact_verify  (book, contact))
		g_error ("Failed to add contact");

	micheal_jackson_uid = e_contact_get (contact, E_CONTACT_UID);
}
예제 #24
0
char *
ccnet_rpc_pubkey_encrypt (const char *msg_base64, const char *peer_id, GError **error)
{
    unsigned char *msg;
    gsize msg_len;
    CcnetPeer *peer;
    unsigned char *enc_msg;
    int enc_msg_len;
    char *ret;

    peer = ccnet_peer_manager_get_peer (session->peer_mgr, peer_id);
    if (!peer) {
        g_warning ("Cannot find peer %s.\n", peer_id);
        return NULL;
    }

    msg = g_base64_decode (msg_base64, &msg_len);

    enc_msg = public_key_encrypt (peer->pubkey, msg, (int)msg_len, &enc_msg_len);

    ret = g_base64_encode (enc_msg, enc_msg_len);

    g_free (msg);
    g_free (enc_msg);
    g_object_unref (peer);
    return ret;
}
예제 #25
0
gchar* remmina_crypt_decrypt(const gchar *str)
{
	guchar* buf;
	gsize buf_len;
	gcry_error_t err;
	gcry_cipher_hd_t hd;

	if (!str || str[0] == '\0')
		return NULL;

	if (!remmina_crypt_init(&hd))
		return NULL;

	buf = g_base64_decode(str, &buf_len);

	err = gcry_cipher_decrypt(hd, buf, buf_len, NULL, 0);

	if (err)
	{
		g_print("gcry_cipher_decrypt failure: %s\n", gcry_strerror(err));
		g_free(buf);
		gcry_cipher_close(hd);
		return NULL;
	}

	gcry_cipher_close(hd);

	/* Just in case */
	buf[buf_len - 1] = '\0';

	return (gchar*) buf;
}
예제 #26
0
char *
ccnet_rpc_privkey_decrypt (const char *msg_base64, GError **error)
{
    unsigned char *msg;
    gsize msg_len;
    unsigned char *dec_msg;
    int dec_msg_len;
    char *ret;

    msg = g_base64_decode (msg_base64, &msg_len);

    dec_msg = private_key_decrypt (session->privkey, msg, (int)msg_len, &dec_msg_len);

    if (dec_msg_len < 0) {
        g_warning ("Failed to decrypt message with RSA priv key.\n");
        g_set_error (error, CCNET_DOMAIN, CCNET_ERR_INTERNAL, "Failed to decrypt");
        g_free (msg);
        return NULL;
    }

    ret = g_base64_encode (dec_msg, dec_msg_len);

    g_free (msg);
    g_free (dec_msg);
    return ret;
}
예제 #27
0
파일: gtlm-nfc.c 프로젝트: 01org/libtlm-nfc
static void _decode_username_password(GTlmNfc* self, const gchar* data)
{
    gsize variant_s_size = 0;
    guchar* variant_s = g_base64_decode(data, &variant_s_size);
    
    GVariantType* v_t = g_variant_type_new("(msms)");
    GVariant* v = g_variant_new_from_data(v_t, variant_s, variant_s_size, FALSE, NULL, NULL);
    
    if (v == NULL) {
        g_debug("Couldn't decode Payload data to variant");
        g_variant_type_free(v_t);
        g_free(variant_s);
        g_signal_emit(self, signals[SIG_NO_RECORD_FOUND], 0);
        return;
    }
    
    gchar* username = NULL;
    gchar* password = NULL;
    g_variant_get(v, "(msms)", &username, &password);
    
    g_signal_emit(self, signals[SIG_RECORD_FOUND], 0, username, password);
    
    g_free(username);
    g_free(password);
    g_variant_unref(v);
    g_variant_type_free(v_t);
    g_free(variant_s);
}
예제 #28
0
int
ccnet_rpc_verify_message (const char *message,
                          const char *sig_base64,
                          const char *peer_id,
                          GError **error)
{
    unsigned char *sig;
    gsize sig_len;
    CcnetPeer *peer;

    sig = g_base64_decode (sig_base64, &sig_len);

    peer = ccnet_peer_manager_get_peer (session->peer_mgr, peer_id);
    if (!peer) {
        g_warning ("Cannot find peer %s.\n", peer_id);
        return -1;
    }

    if (!RSA_verify (NID_sha1, (const unsigned char *)message, strlen(message),
                     sig, (guint)sig_len, peer->pubkey)) {
        g_object_unref (peer);
        return -1;
    }

    g_object_unref (peer);
    return 0;
}
예제 #29
0
static void keystore_load_rsakey(GKeyFile *keyfile, gchar *key,
                                 struct keystore_t *keystore)
{
	g_assert(NULL != keyfile);
	g_assert(NULL != key);
	g_assert(NULL != keystore);
	gsize length = 0;
	gchar **list = g_key_file_get_string_list(keyfile, "rsa", key, &length, NULL);

	if (length == 2)
	{
		int key_index = atoi(key);
		int keylen = atoi(list[0]);
		gsize keybits_len = 0;
		guchar *keybits = g_base64_decode(list[1], &keybits_len);
		const guchar *tmp = keybits;

		struct rsa_key_t *rsa_key = g_malloc(sizeof(struct rsa_key_t));
		rsa_key->keylen = keylen;
		rsa_key->rsa = d2i_RSAPrivateKey(NULL, (const unsigned char **)&tmp,
		                                 keybits_len);

		if (NULL != rsa_key->rsa)
		{
			keystore_key_replace(keystore->rsa, rsa_key, &key_index);
		}

		g_free(keybits);
	}

	g_strfreev(list);
}
예제 #30
0
Glib::ustring base64decode(Glib::ustring url)
{
	if (url.empty())
		return url ;

	guchar* decoded = NULL ;

	try
	{
		gsize size ;
		decoded = g_base64_decode(url.c_str(), &size) ;

		if (!decoded)
			return "" ;

		std::string result ;

		Log::out() << "base64decode ~~~> decoded size = " << size << std::endl ;
		result.assign((gchar*)decoded, size) ;
		g_free(decoded) ;
		return result ;
	}
	catch (...)
	{
		Log::err() << "base64decode: error." << std::endl ;
		if (decoded)
			g_free(decoded) ;
		return "" ;
	}
}