Example #1
0
void sipe_core_ft_incoming_init(struct sipe_file_transfer *ft)
{
	struct sipe_file_transfer_private *ft_private = SIPE_FILE_TRANSFER_PRIVATE;
	gchar *b64_encryption_key = g_base64_encode(ft_private->encryption_key,
						    SIPE_FT_KEY_LENGTH);
	gchar *b64_hash_key = g_base64_encode(ft_private->hash_key,
					      SIPE_FT_KEY_LENGTH);

	gchar *body = g_strdup_printf("Invitation-Command: ACCEPT\r\n"
				      "Request-Data: IP-Address:\r\n"
				      "Invitation-Cookie: %s\r\n"
				      "Encryption-Key: %s\r\n"
				      "Hash-Key: %s\r\n"
				      /*"IP-Address: %s\r\n"
					"Port: 6900\r\n"
					"PortX: 11178\r\n"
					"Auth-Cookie: 11111111\r\n"
					"Sender-Connect: TRUE\r\n"*/,
				      ft_private->invitation_cookie,
				      b64_encryption_key,
				      b64_hash_key
                                      /*,sipe_backend_network_ip_address()*/
		);
	sipe_ft_request(ft_private, body);

	g_free(body);
	g_free(b64_hash_key);
	g_free(b64_encryption_key);
}
Example #2
0
static
void priv_generate_candidate_credentials (NiceAgent *agent,
    NiceCandidate *candidate)
{

  if (agent->compatibility == NICE_COMPATIBILITY_MSN ||
      agent->compatibility == NICE_COMPATIBILITY_OC2007) {
    guchar username[32];
    guchar password[16];

    g_free (candidate->username);
    g_free (candidate->password);

    nice_rng_generate_bytes (agent->rng, 32, (gchar *)username);
    nice_rng_generate_bytes (agent->rng, 16, (gchar *)password);

    candidate->username = g_base64_encode (username, 32);
    candidate->password = g_base64_encode (password, 16);

  } else if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
    gchar username[16];

    g_free (candidate->username);
    g_free (candidate->password);
    candidate->password = NULL;

    nice_rng_generate_bytes_print (agent->rng, 16, (gchar *)username);

    candidate->username = g_strndup (username, 16);
  }


}
Example #3
0
File: reg.c Project: 52M/megatools
static gchar* serialize_reg_state(mega_reg_state* state)
{
  gc_free gchar* pk = g_base64_encode(state->password_key, 16);
  gc_free gchar* ch = g_base64_encode(state->challenge, 16);

  return g_strdup_printf("%s:%s:%s", pk, ch, state->user_handle);
}
void AuthYahooCommand::WriteCommand()
{
	MojLogTrace(m_log);
	if (m_state == State_SendingYCookie) {
		MojLogInfo(m_log, "Sending AUTH XYMCOOKIE command with YCookie");
	
		std::string command = COMMAND_STRING;
	
		std::string cookie = m_yCookie.data();
		cookie.erase(0,2); // erase 'Y='

		command += ' ';

		MojLogInfo(m_log, "Pre-encoded command: {%s}", cookie.c_str());
		
		gchar * encodedPayload = g_base64_encode((unsigned guchar*)cookie.c_str(), cookie.length());
		try {
			command += encodedPayload;
		} catch (...) {
			g_free(encodedPayload);
			throw;
		}
		g_free(encodedPayload);


		MojLogInfo(m_log, "Post-encoded command: {%s}", command.c_str());
	
		SendCommand(command);
		
	} else if (m_state == State_SendingTCookie) {
		MojLogInfo(m_log, "Sending TCookie");
	
		std::string cookie = m_tCookie.data();
		cookie.erase(0,2); // erase 'T='
		
		cookie += " ts=";
		cookie += boost::lexical_cast<std::string>(timeMillis() / 1000);
		
		cookie += " src=";
		cookie += m_partnerId.data();
		cookie += " GUID=";
		cookie += m_deviceId.data();
		
		MojLogInfo(m_log, "Pre-encoded cookie: {%s}", cookie.c_str());

		gchar * encodedPayload = g_base64_encode((unsigned guchar*)cookie.c_str(), cookie.length());
		try {
			cookie = encodedPayload;
		} catch (...) {
			g_free(encodedPayload);
			throw;
		}
		g_free(encodedPayload);

		MojLogInfo(m_log, "Post-encoded cookie: {%s}", cookie.c_str());
		
		SendCommand(cookie);
	}
}
Example #5
0
static char *encode_avc1_header(uint8_t *p, unsigned int len, int packet_mode)
{
    int i, cnt, nalsize;
    uint8_t *q = p;
    char *sprop = NULL;
    cnt = *(p+5) & 0x1f; // Number of sps
    p += 6;

    for (i = 0; i < cnt; i++) {
        if (p > q + len)
            goto err_alloc;
        nalsize = RB16(p); //buf_size
        p += 2;
        fnc_log(FNC_LOG_VERBOSE, "[h264] nalsize %d", nalsize);
        if (i == 0) {
            gchar *out = g_strdup_printf("profile-level-id=%02x%02x%02x; "
                                  "packetization-mode=%d; ",
                                  p[0], p[1], p[2], packet_mode);
	    gchar *buf = g_base64_encode(p, nalsize);
            sprop = g_strdup_printf("%ssprop-parameter-sets=%s", out, buf);
	    g_free(buf);
            g_free(out);
        } else {
            gchar *buf = g_base64_encode(p, nalsize);
            gchar *out = g_strdup_printf("%s,%s", sprop, buf);
            g_free(sprop);
	    g_free(buf);
            sprop = out;
        }
        p += nalsize;
    }
    // Decode pps from avcC
    cnt = *(p++); // Number of pps
    fnc_log(FNC_LOG_VERBOSE, "[h264] pps %d", cnt);

    for (i = 0; i < cnt; i++) {
        gchar *out, *buf;

        if (p > q + len)
            goto err_alloc;
        nalsize = RB16(p);
        p += 2;
        fnc_log(FNC_LOG_VERBOSE, "[h264] nalsize %d", nalsize);
	buf = g_base64_encode(p, nalsize);
        out = g_strdup_printf("%s,%s",sprop, buf);
        g_free(sprop);
	g_free(buf);
        sprop = out;
        p += nalsize;
    }

    return sprop;

    err_alloc:
        if (sprop) g_free(sprop);
    return NULL;
}
Example #6
0
void DtlsSocketContext::handshakeCompleted()
{
    char fprint[100];
    SRTP_PROTECTION_PROFILE* srtp_profile;

    if (mSocket->getRemoteFingerprint(fprint)) {
        ELOG_TRACE("Remote fingerprint == %s", fprint);

        bool check = mSocket->checkFingerprint(fprint, strlen(fprint));
        ELOG_DEBUG("Fingerprint check == %d", check);

        SrtpSessionKeys* keys = mSocket->getSrtpSessionKeys();

        unsigned char* cKey = (unsigned char*)malloc(keys->clientMasterKeyLen + keys->clientMasterSaltLen);
        unsigned char* sKey = (unsigned char*)malloc(keys->serverMasterKeyLen + keys->serverMasterSaltLen);

        memcpy(cKey, keys->clientMasterKey, keys->clientMasterKeyLen);
        memcpy(cKey + keys->clientMasterKeyLen, keys->clientMasterSalt, keys->clientMasterSaltLen);

        memcpy(sKey, keys->serverMasterKey, keys->serverMasterKeyLen);
        memcpy(sKey + keys->serverMasterKeyLen, keys->serverMasterSalt, keys->serverMasterSaltLen);

        // g_base64_encode must be free'd with g_free.  Also, std::string's assignment operator does *not* take
        // ownership of the passed in ptr; under the hood it copies up to the first nullptr character.
        gchar* temp = g_base64_encode((const guchar*)cKey, keys->clientMasterKeyLen + keys->clientMasterSaltLen);
        std::string clientKey = temp;
        g_free(temp);
        temp = nullptr;

        temp = g_base64_encode((const guchar*)sKey, keys->serverMasterKeyLen + keys->serverMasterSaltLen);
        std::string serverKey = temp;
        g_free(temp);
        temp = nullptr;

        ELOG_DEBUG("ClientKey: %s", clientKey.c_str());
        ELOG_DEBUG("ServerKey: %s", serverKey.c_str());

        free(cKey);
        free(sKey);
        delete keys;

        srtp_profile = mSocket->getSrtpProfile();

        if (srtp_profile) {
            ELOG_DEBUG("SRTP Extension negotiated profile=%s", srtp_profile->name);
        }

        if (receiver != nullptr) {
            receiver->onHandshakeCompleted(this, clientKey, serverKey, srtp_profile->name);
        }
    } else {
        ELOG_DEBUG("Peer did not authenticate");
    }
}
Example #7
0
static char *encode_header(uint8_t *p, unsigned int len, int packet_mode)
{
    uint8_t *q, *end = p + len;
    char *sprop = NULL, *out, *buf = NULL;

    for (q = p; q < end - 3; q++) {
        if (q[0] == 0 && q[1] == 0 && q[2] == 1) {
            break;
        }
    }

    if (q >= end - 3)
        return NULL;

    p = q; // sps start;

    for (; q < end - 3; q++) {
        if (q[0] == 0 && q[1] == 0 && q[2] == 1) {
            // sps end;
            break;
        }
    }

    //FIXME I'm abusing memory
    // profile-level-id aka the first 3 bytes from sps
    out = g_strdup_printf("profile-level-id=%02x%02x%02x; "
                          "packetization-mode=%d; ",
                            p[0], p[1], p[2], packet_mode);

    buf = g_base64_encode(p, q-p);

    sprop = g_strdup_printf("%ssprop-parameter-sets=%s", out, buf);
    g_free(out);
    g_free(buf);
    p = q;

    while (p < end - 3) {
        //seek to the next startcode [0 0 1]
        for (q = p; q < end; q++)
            if (end - q <= 3) continue; // last nal
            if (q[0] == 0 && q[1] == 0 && q[2] == 1) {
                break;
            }
        buf = g_base64_encode(p, q - p);
        out = g_strdup_printf("%s,%s",sprop, buf);
        g_free(sprop);
	g_free(buf);
        sprop = out;
        p = q;
    }

    return sprop;
}
static gchar *
g_value_to_string (const GValue * val)
{
  if (G_VALUE_TYPE (val) == GST_TYPE_BUFFER) {
    GstBuffer *buf = gst_value_get_buffer (val);
    GstMapInfo map;
    gchar *ret;

    gst_buffer_map (buf, &map, GST_MAP_READ);
    ret = g_base64_encode (map.data, map.size);
    gst_buffer_unmap (buf, &map);

    return ret;
  } else {
    GValue s = { 0, };
    gchar *ret;

    g_value_init (&s, G_TYPE_STRING);

    if (!g_value_transform (val, &s)) {
      return NULL;
    }

    ret = g_value_dup_string (&s);
    g_value_unset (&s);

    return ret;
  }
}
Example #9
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);
}
Example #10
0
static void
on_key_received (GstDtlsConnection * connection, gpointer key, guint cipher,
    guint auth, GstDtlsDec * self)
{
  gpointer key_dup;
  gchar *key_str;

  g_return_if_fail (GST_IS_DTLS_DEC (self));

  self->srtp_cipher = cipher;
  self->srtp_auth = auth;

  key_dup = g_memdup (key, GST_DTLS_SRTP_MASTER_KEY_LENGTH);

  if (self->decoder_key) {
    gst_buffer_unref (self->decoder_key);
    self->decoder_key = NULL;
  }

  self->decoder_key =
      gst_buffer_new_wrapped (key_dup, GST_DTLS_SRTP_MASTER_KEY_LENGTH);

  key_str = g_base64_encode (key, GST_DTLS_SRTP_MASTER_KEY_LENGTH);
  GST_INFO_OBJECT (self, "received key: %s", key_str);
  g_free (key_str);

  g_signal_emit (self, signals[SIGNAL_ON_KEY_RECEIVED], 0);
}
Example #11
0
static gchar *
g_value_to_string (const GValue * val)
{
    if (G_VALUE_TYPE (val) == GST_TYPE_BUFFER) {
#if GLIB_CHECK_VERSION (2,16,0)
        const GstBuffer *buf = gst_value_get_buffer (val);
        gchar *ret = g_base64_encode (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
#else
        gchar *ret = gst_value_serialize (val);
#endif

        return ret;
    } else {
        GValue s = { 0, };
        gchar *ret;

        g_value_init (&s, G_TYPE_STRING);

        if (!g_value_transform (val, &s)) {
            return NULL;
        }

        ret = g_value_dup_string (&s);
        g_value_unset (&s);

        return ret;
    }
}
Example #12
0
static gboolean
save_image_png (const gchar *filename, GdkPixbuf *pixbuf, GError **error)
{
	gchar *contents = NULL;
	gchar *contents_encode = NULL;
	gsize length;
	gboolean ret;
	gint len;

	/* get icc file */
	ret = g_file_get_contents (ICC_PROFILE, &contents, &length, error);
	if (!ret)
		goto out;
	contents_encode = g_base64_encode ((const guchar *) contents, length);
	ret = gdk_pixbuf_save (pixbuf, filename, "png", error,
			       "tEXt::Software", "Hello my name is dave",
			       "icc-profile", contents_encode,
			       NULL);
	len = strlen (contents_encode);
	g_debug ("ICC profile was %i bytes", len);
out:
	g_free (contents);
	g_free (contents_encode);
	return ret;
}
Example #13
0
static gboolean
builder_source_file_update (BuilderSource *source,
                            BuilderContext *context,
                            GError **error)
{
  BuilderSourceFile *self = BUILDER_SOURCE_FILE (source);
  g_autoptr(GFile) src = NULL;
  gboolean is_local, is_inline;

  src = get_source_file (self, context, &is_local, &is_inline, error);
  if (src == NULL)
    return FALSE;

  if (is_local)
    {
      g_autofree char *data = NULL;
      g_autofree char *base64 = NULL;
      gsize len;

      if (!g_file_load_contents (src, NULL, &data, &len, NULL, error))
        return FALSE;

      base64 = g_base64_encode ((const guchar *)data, len);
      g_free (self->url);
      self->url = g_strdup_printf ("data:text/plain;charset=utf8;base64,%s", base64);
      if (self->dest_filename == NULL || *self->dest_filename == 0)
        {
          g_free (self->dest_filename);
          self->dest_filename = g_file_get_basename (src);
        }
    }

  return TRUE;
}
Example #14
0
static gchar *
TicketGenerateTicket(const gchar *userName)
{
#define RAND_BUF_SIZE   8
   guchar rndBuf[RAND_BUF_SIZE];
   gchar *newTicket;
   gchar *b64rnd;
   VGAuthError err;

   err = ServiceRandomBytes(RAND_BUF_SIZE, rndBuf);
   if (VGAUTH_E_OK != err) {
      return NULL;
   }

   b64rnd = g_base64_encode(rndBuf, RAND_BUF_SIZE);

   /*
    * Use a constant string, the username, and a 256 bits
    * of base64'd random data.
    */
   newTicket = g_strdup_printf("Ticket-%s-%s", userName, b64rnd);

   g_free(b64rnd);

   return newTicket;
}
Example #15
0
static void do_sending(void *unused)
{
    static char outbuf[(BLKSIZE + 2) / 3 * 4 + 2];
    static char inbuf[BLKSIZE];
    int nbytes_read;

    nbytes_read = fread(inbuf, 1, BLKSIZE, fp);
    nbytes_remain -= nbytes_read;
    nblk_sent++;

    {
        char buf[100];
	sprintf(buf, "%d / %d", nblk_sent, nblk_total);
	gtk_label_set_text(lb_progress, buf);
    }

    char *blk_base64 = g_base64_encode((guchar *) inbuf, nbytes_read);
    sprintf(outbuf, "d%s", blk_base64);
    g_free(blk_base64);

    if (nbytes_remain > 0) 
        dtp_transfer(outbuf, do_sending, NULL);
    else
        dtp_transfer(outbuf, transfer_ended, NULL);
}
Example #16
0
int
ns__get_radar_data(soap* soap, int sessionID, char* site, char* product, struct DateTime time, struct RadarData* result)
{
	DarxendClient* client = client_manager_get_client(sessionID);
	if (!client)
		return die_bad_client(soap);

	unsigned int length = 0;

	gchar* psite = g_ascii_strdown(site, -1);
	gchar* pproduct = g_ascii_strup(product, -1);

	char* data = radar_data_manager_read_data(psite, pproduct, time, &length);

	g_free(psite);
	g_free(pproduct);

	if (!data)
		return soap_receiver_fault(soap, "Data not found", NULL);

	gchar* b64data = g_base64_encode((guchar*)data, length);
	free(data);
	result->data = (char*)soap_malloc(soap, strlen(b64data));
	strcpy(result->data, b64data);
	g_free(b64data);

	return SOAP_OK;
}
Example #17
0
/**
 * irc_sasl_encode_plain:
 * @username: Username of user
 * @password: Password of user
 *
 * Encodes @username and @password according to RFC 4616
 *
 * Returns: Newly allocated string
 */
char *
irc_sasl_encode_plain (const char *username, const char *password)
{
	const gsize authlen = (strlen (username) * 2) + 2 + strlen (password);
	g_autofree char *buffer = g_strdup_printf ("%s%c%s%c%s", username, '\0', username, '\0', password);
	return g_base64_encode ((guchar*)buffer, authlen);
}
Example #18
0
static void vncws_send_handshake_response(VncState *vs, const char* key)
{
    char combined_key[WS_CLIENT_KEY_LEN + WS_GUID_LEN + 1];
    unsigned char hash[SHA1_DIGEST_LEN];
    size_t hash_size = sizeof(hash);
    char *accept = NULL, *response = NULL;
    gnutls_datum_t in;
    int ret;

    g_strlcpy(combined_key, key, WS_CLIENT_KEY_LEN + 1);
    g_strlcat(combined_key, WS_GUID, WS_CLIENT_KEY_LEN + WS_GUID_LEN + 1);

    /* hash and encode it */
    in.data = (void *)combined_key;
    in.size = WS_CLIENT_KEY_LEN + WS_GUID_LEN;
    ret = gnutls_fingerprint(GNUTLS_DIG_SHA1, &in, hash, &hash_size);
    if (ret == GNUTLS_E_SUCCESS && hash_size <= SHA1_DIGEST_LEN) {
        accept = g_base64_encode(hash, hash_size);
    }
    if (accept == NULL) {
        VNC_DEBUG("Hashing Websocket combined key failed\n");
        vnc_client_error(vs);
        return;
    }

    response = g_strdup_printf(WS_HANDSHAKE, accept);
    vnc_client_write_buf(vs, (const uint8_t *)response, strlen(response));

    g_free(accept);
    g_free(response);

    vs->encode_ws = 1;
    vnc_init_state(vs);
}
Example #19
0
static void
remmina_pref_gen_secret (void)
{
    guchar s[32];
    gint i;
    GTimeVal gtime;
    GKeyFile *gkeyfile;
    gchar *content;
    gsize length;

    g_get_current_time (&gtime);
    srand (gtime.tv_sec);

    for (i = 0; i < 32; i++)
    {
        s[i] = (guchar) (rand () % 256);
    }
    remmina_pref.secret = g_base64_encode (s, 32);

    gkeyfile = g_key_file_new ();
    g_key_file_load_from_file (gkeyfile, remmina_pref_file, G_KEY_FILE_NONE, NULL);
    g_key_file_set_string (gkeyfile, "remmina_pref", "secret", remmina_pref.secret);
    content = g_key_file_to_data (gkeyfile, &length, NULL);
    g_file_set_contents (remmina_pref_file, content, length, NULL);

    g_key_file_free (gkeyfile);
    g_free (content);
}
Example #20
0
static gint sieve_auth_login_user_recv(SieveSession *session, const gchar *msg)
{
	gchar *tmp, *tmp2;

	session->state = SIEVE_AUTH_LOGIN_PASS;
	
	if (strstr(msg, "UGFzc3dvcmQ6")) {
		tmp2 = g_base64_encode(session->pass, strlen(session->pass));
		tmp = g_strdup_printf("\"%s\"", tmp2);
		g_free(tmp2);
	} else {
		/* Server rejects AUTH */
		tmp = g_strdup("\"*\"");
	}

	if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL, tmp) < 0) {
		g_free(tmp);
		return SE_ERROR;
	}
	g_free(tmp);

	log_print(LOG_PROTOCOL, "Sieve> [PASSWORD]\n");

	return SE_OK;
}
Example #21
0
static gint sieve_auth_plain(SieveSession *session)
{
	gchar buf[MESSAGEBUFSIZE], *b64buf, *out;
	gint len;

	session->state = SIEVE_AUTH_PLAIN;
	session->auth_type = SIEVEAUTH_PLAIN;

	memset(buf, 0, sizeof buf);

	/* "\0user\0password" */
	len = sprintf(buf, "%c%s%c%s", '\0', session->user, '\0', session->pass);
	b64buf = g_base64_encode(buf, len);
	out = g_strconcat("Authenticate \"PLAIN\" \"", b64buf, "\"", NULL);
	g_free(b64buf);

	if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL, out) < 0) {
		g_free(out);
		return SE_ERROR;
	}

	g_free(out);

	log_print(LOG_PROTOCOL, "Sieve> [Authenticate PLAIN]\n");

	return SE_OK;
}
Example #22
0
std::string SrtpChannel::generateBase64Key() {

    unsigned char key[30];
    crypto_get_random(key, 30);
    gchar* base64key = g_base64_encode((guchar*) key, 30);
    return std::string(base64key);
}
Example #23
0
CockpitCreds *
cockpit_auth_login_finish (CockpitAuth *self,
                           GAsyncResult *result,
                           gboolean force_secure,
                           GHashTable *out_headers,
                           GError **error)
{
  CockpitAuthClass *klass = COCKPIT_AUTH_GET_CLASS (self);
  CockpitCreds *creds;
  gs_free char *cookie = NULL;
  gs_free gchar *cookie_b64 = NULL;
  gchar *header;

  g_return_val_if_fail (klass->login_finish != NULL, FALSE);
  creds = klass->login_finish (self, result, error);

  if (creds && out_headers)
    {
      cookie = creds_to_cookie (self, creds);
      cookie_b64 = g_base64_encode ((guint8 *)cookie, strlen (cookie));
      header = g_strdup_printf ("CockpitAuth=%s; Path=/; Expires=Wed, 13-Jan-2021 22:23:01 GMT;%s HttpOnly",
                                cookie_b64, force_secure ? " Secure;" : "");

      g_hash_table_insert (out_headers, g_strdup ("Set-Cookie"), header);
    }

  return creds;
}
Example #24
0
static void
soup_auth_digest_authenticate (SoupAuth *auth, const char *username,
			       const char *password)
{
	SoupAuthDigestPrivate *priv = SOUP_AUTH_DIGEST_GET_PRIVATE (auth);
	char *bgen;

	g_clear_pointer (&priv->cnonce, g_free);
	g_clear_pointer (&priv->user, g_free);

	/* Create client nonce */
	bgen = g_strdup_printf ("%p:%lu:%lu",
				auth,
				(unsigned long) getpid (),
				(unsigned long) time (0));
	priv->cnonce = g_base64_encode ((guchar *)bgen, strlen (bgen));
	g_free (bgen);

	priv->user = g_strdup (username);

	/* compute "URP" (user:realm:password) */
	soup_auth_digest_compute_hex_urp (username, auth->realm,
					  password ? password : "",
					  priv->hex_urp);

	/* And compute A1 from that */
	recompute_hex_a1 (priv);
}
Example #25
0
static void
run (int format, gboolean alpha)
{
  guint8 data[2000] = { 0, };
  guint8 compressed[2000] = { 0, };
  gsize len; 
  gulong clen;
  int ret;
  char *s;

  switch (format) {
    case 3:
      len = create_palletized (data, alpha);
      g_print ("%u\n", len);
      break;
    default:
      g_assert_not_reached ();
      return;
  }
  
  if (alpha) {
    clen = sizeof (compressed);
    ret = compress2 (compressed, &clen, data, len, 9);
  } else {
    clen = sizeof (compressed) - 1;
    ret = compress2 (compressed + 1, &clen, data + 1, len - 1, 9);
    compressed[0] = data[0];
  }
  g_assert (ret == Z_OK);

  s = g_base64_encode (compressed, clen + 1);
  g_print ("%s\n\n", s);
  g_free (s);
}
Example #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;
}
Example #27
0
GList*
kolab_util_kconv_kconvmail_data_base64_encode (const Kolab_conv_mail *kconvmail)
{
	GList *kconvbase64 = NULL;
	guint ii = 0;

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

	/* iterate over kconvmail parts */
	for (ii = 0; ii < kconvmail->length; ii++) {
		Kolab_conv_mail_part *kconvmailpart = NULL;
		gchar *base64str = NULL;

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

		g_assert (kconvmailpart != NULL);
		g_assert (kconvmailpart->data != NULL);
		g_assert (kconvmailpart->length > 0);

		base64str = g_base64_encode ((guchar *) kconvmailpart->data,
		                             (gsize) kconvmailpart->length);
		kconvbase64 = g_list_append (kconvbase64, base64str);
	}

	return kconvbase64;
}
Example #28
0
static gboolean
handle_get_icon_data_url (CockpitAccount *object,
                          GDBusMethodInvocation *invocation)
{
  Account *acc = ACCOUNT (object);
  gs_free gchar *raw_data = NULL;
  gsize raw_size;
  gs_free gchar *base64_data = NULL;
  gs_free gchar *data = NULL;

  if (acc->u == NULL)
    goto out;

  const gchar *icon_file = act_user_get_icon_file (acc->u);
  if (icon_file == NULL)
    goto out;

  if (!g_file_get_contents (icon_file, &raw_data, &raw_size, NULL))
    goto out;

  base64_data = g_base64_encode ((guchar *)raw_data, raw_size);
  data = g_strdup_printf ("data:image/png;base64,%s", base64_data);

out:
  cockpit_account_complete_get_icon_data_url (object, invocation, data? data : "");
  return TRUE;
}
Example #29
0
static void keystore_save_rsakey(gpointer key, gpointer value,
                                 gpointer user_data)
{
	const int key_index = GPOINTER_TO_INT(key);
	const struct rsa_key_t *rsa_key = (const struct rsa_key_t *)value;
	GKeyFile *key_file = (GKeyFile *)user_data;

	g_assert(rsa_key != NULL);
	g_assert(key_file != NULL);

	gchar *index = g_strdup_printf("%d", key_index);
	int pkcs_len = i2d_RSAPrivateKey(rsa_key->rsa, NULL);
	unsigned char *pkcs_buf = malloc(pkcs_len);
	unsigned char *tmp = pkcs_buf;
	i2d_RSAPrivateKey(rsa_key->rsa, &tmp);

	const gchar *const list[] =
	{
		g_strdup_printf("%d", rsa_key->keylen),
		g_base64_encode(pkcs_buf, pkcs_len),
	};

	g_key_file_set_string_list(key_file, "rsa", index, list, 2);

	g_free(index);
	free(pkcs_buf);
	g_free((gpointer)list[0]);
	g_free((gpointer)list[1]);
}
Example #30
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;
}