示例#1
0
static void to_dbus_iter_from_variant(DBusMessageIter* parent_it, const EdbusData& data) {
	E_ASSERT(data.is_variant());

	EdbusVariant var = data.to_variant();
	/* hm... really needed ? */
	if(!var.value.is_valid())
		return;

	const char* value_sig;
	String ss;

	if(!EdbusData::basic_type(var.value)) {
		build_signature(var.value, ss);
		value_sig = ss.c_str();
	} else
		value_sig = from_edbusdata_type_to_dbus_type_string(var.value.type());

	/* printf("variant entry is %s\n", value_sig); */

	DBusMessageIter sub;
	dbus_message_iter_open_container(parent_it, DBUS_TYPE_VARIANT, value_sig, &sub);

	to_dbus_iter_from_edbusdata_type(&sub, var.value);

	dbus_message_iter_close_container(parent_it, &sub);
}
示例#2
0
文件: blame.c 项目: carlosmn/pygit2
PyObject *
BlameHunk_orig_committer__get__(BlameHunk *self)
{
    if (!self->orig_signature)
        Py_RETURN_NONE;

    return build_signature((Object*) self, self->orig_signature, "utf-8");
}
示例#3
0
文件: tag.c 项目: cboos/pygit2
PyObject *
Tag_tagger__get__(Tag *self)
{
    const git_signature *signature = git_tag_tagger(self->tag);
    if (!signature)
        Py_RETURN_NONE;

    return build_signature((Object*)self, signature, "utf-8");
}
示例#4
0
PyObject *
Repository_default_signature__get__(Repository *self)
{
    git_signature *sig;
    int err;

    if ((err = git_signature_default(&sig, self->repo)) < 0)
        return Error_set(err);

    return build_signature(NULL, sig, "utf-8");
}
示例#5
0
PyObject *
Commit_committer__get__(Commit *self)
{
    const git_signature *signature;
    const char *encoding;

    signature = git_commit_committer(self->commit);
    encoding = git_commit_message_encoding(self->commit);

    return build_signature((Object*)self, signature, encoding);
}
示例#6
0
文件: hmac.c 项目: WinnowTag/winnow
struct curl_slist * hmac_sign(const char * method, const char * path, struct curl_slist *headers, const Credentials * credentials) {
  if (valid_credentials(credentials)) {
    headers = add_date_header_if_missing(headers);
    char * signature = build_signature(method, path, headers, credentials->secret_key);
    char * auth_header = build_auth_header(credentials->access_id, signature);  

    curl_slist_append(headers, auth_header);

    free(signature);
    free(auth_header);
  }
  
  return headers;
}
示例#7
0
文件: hmac.c 项目: WinnowTag/winnow
int hmac_auth(const char * method, const char * path, struct curl_slist *headers, const Credentials * credentials) {
  int authenticated = 0;
  struct auth_data auth = {NULL, NULL};
  memset(&auth, 0, sizeof(auth));
    
  if (extract_authentication_data(headers, &auth)) {
    char * computed_signature = build_signature(method, path, headers, credentials->secret_key);
    debug("computed = '%s'", computed_signature);
    authenticated = strcmp(auth.access_id, credentials->access_id) == 0 && strcmp(auth.signature, computed_signature) == 0;    
    free(computed_signature);
  } else {
    debug("No authentication data");
  }

  if (auth.access_id) free(auth.access_id);
  if (auth.signature) free(auth.signature);
  
  return authenticated;
}
示例#8
0
static void to_dbus_iter_from_array(DBusMessageIter* parent_it, const EdbusData& data) {
	E_ASSERT(data.is_array());

	/*
	 * Marshalling arrays is much simpler than e.g. dict; we already know all elements
	 * are the same type. The only tricky case is when array elements are another array, dict
	 * or struct so signature, where build_signature() comes in
	 */
	EdbusList arr = data.to_array();

	/* TODO: allow empty containers ??? */
	if(arr.size() < 1)
		return;

	EdbusList::const_iterator it = arr.begin(), it_end = arr.end();

	const char* value_sig;
	String ss;

	if(arr.value_type_is_container()) {
		build_signature(*it, ss);
		value_sig = ss.c_str();
	} else
		value_sig = from_edbusdata_type_to_dbus_type_string(arr.value_type());


	/* printf("Array entry signature: %s\n", value_sig); */

	/* 
	 * dbus_message_iter_open_container() will by default append container
	 * signature (at the start of signature array)
	 */
	DBusMessageIter sub;
	dbus_message_iter_open_container(parent_it, DBUS_TYPE_ARRAY, value_sig, &sub);

	while(it != it_end) {
		to_dbus_iter_from_edbusdata_type(&sub, *it);
		++it;
	}

	dbus_message_iter_close_container(parent_it, &sub);
}
示例#9
0
PyObject *
RefLogEntry_committer__get__(RefLogEntry *self)
{
    return build_signature((Object*) self, self->signature, "utf-8");
}
示例#10
0
/* 
 * Builds a signature for subtypes, e.g. array, struct or dict elements.
 * This function will be called on container subtypes, not container itself
 */
static void build_signature(const EdbusData& data, String& sig) {
	if(data.is_dict()) {
		EdbusDict dd = data.to_dict();

		if(dd.size() < 1)
			return;

		sig += DBUS_TYPE_ARRAY_AS_STRING;
		sig += DBUS_DICT_ENTRY_BEGIN_CHAR;

		EdbusDict::const_iterator it = dd.begin();
		/* always basic */
		sig += from_edbusdata_type_to_dbus_type_string((*it).key.type());

		if(EdbusData::basic_type((*it).value))
			sig += from_edbusdata_type_to_dbus_type_string((*it).value.type());
		else {
			/* recurse for more */
			build_signature((*it).value, sig);
		}

		sig += DBUS_DICT_ENTRY_END_CHAR;
	} else if(data.is_array()) {
		EdbusList arr = data.to_array();

		if(arr.size() < 1)
			return;

		sig += DBUS_TYPE_ARRAY_AS_STRING;
		EdbusList::const_iterator it = arr.begin();
		
		if(EdbusData::basic_type(*it))
			sig += from_edbusdata_type_to_dbus_type_string((*it).type());
		else {
			/* recurse for more */
			build_signature((*it), sig);
		}
	} else if(data.is_struct()) {
		EdbusList s = data.to_struct();

		if(s.size() < 1)
			return;

		sig += DBUS_STRUCT_BEGIN_CHAR;
		EdbusList::const_iterator it = s.begin(), it_end = s.end();

		for(; it != it_end; ++it) {
			if(EdbusData::basic_type(*it))
				sig += from_edbusdata_type_to_dbus_type_string((*it).type());
			else {
				/* recurse for more */
				build_signature((*it), sig);
			}
		}

		sig += DBUS_STRUCT_END_CHAR;
	} else {
		/* here can be any other basic type and/or variant */
		sig += from_edbusdata_type_to_dbus_type_string(data.type());
	}
}
示例#11
0
static void to_dbus_iter_from_dict(DBusMessageIter* parent_it, const EdbusData& data) {
	E_ASSERT(data.is_dict());

	EdbusDict dict = data.to_dict();

	/* TODO: allow empty containers ??? */
	if(dict.size() < 1)
		return;

	/*
	 * TODO: check signature size in DBus spec (or use edelib::String here)
	 *
	 * Also, this part needs a better code, especially in case when value signature
	 * is needed. Value can be another dict, struct or array of dicts, struct, variants
	 * and etc. so I need better singature builder.
	 */
	char sig[256];
	const char* key_sig = from_edbusdata_type_to_dbus_type_string(dict.key_type());
	//const char* value_sig = from_edbusdata_type_to_dbus_type_string(dict.value_type());
#if 0	
	const char* value_sig;
	if(dict.value_type() == EDBUS_TYPE_DICT)
		value_sig = "a{ss}";
	else
		value_sig = from_edbusdata_type_to_dbus_type_string(dict.value_type());
#endif
	const char* value_sig;
	String ss;

	if(dict.value_type_is_container()) {
		/*
		 * We already have correct header that represents dict array. Now
		 * go and recurse into dict value container
		 */
		EdbusDict::const_iterator first = dict.begin();

		build_signature((*first).value, ss);
		value_sig = ss.c_str();
	} else
		value_sig = from_edbusdata_type_to_dbus_type_string(dict.value_type());


	/*
	 * Dicts are serialized as array of dict entries. We first build signature for array
	 * elements, then iterate over EdbusDict entries and from key/value pairs construct a 
	 * DBus dict entry then append that entry to the array
	 *
	 * A signature for dictionary will be 'a{TYPE TYPE}'. dbus_message_iter_open_container() will
	 * append 'a' to the signature.
	 */
	snprintf(sig, sizeof(sig), "%c%s%s%c", 
			DBUS_DICT_ENTRY_BEGIN_CHAR,
			key_sig,
			value_sig,
			DBUS_DICT_ENTRY_END_CHAR);

	/* printf("Dict entry signature: %s\n", sig); */

	DBusMessageIter sub;
	dbus_message_iter_open_container(parent_it, DBUS_TYPE_ARRAY, sig, &sub);

	EdbusDict::const_iterator it = dict.begin(), it_end = dict.end();
	for(; it != it_end; ++it) {
		DBusMessageIter dict_entry_iter;

		dbus_message_iter_open_container(&sub, DBUS_TYPE_DICT_ENTRY, 0, &dict_entry_iter);

		/* 
		 * append key; it is always basic type
		 * TODO: here should be assertion check
		 */
		to_dbus_iter_from_basic_type(&dict_entry_iter, (*it).key);

		/* append value, can be any type */
		to_dbus_iter_from_edbusdata_type(&dict_entry_iter, (*it).value);

		dbus_message_iter_close_container(&sub, &dict_entry_iter);
	}

	dbus_message_iter_close_container(parent_it, &sub);
}
示例#12
0
文件: Oauth.c 项目: bomma/io
void oauth_signandappend_oauth_header(const char *reqMethod, struct url_props *url, const char *consumerKey, const char *consumerSecret, const char *authToken, const char *authTokenSecret, const time_t now, const char *postContent, const size_t postContentLen, const char *oauthCallback, const char *oauthVerifier, const char *oauthScope, struct string *out)
{
	struct signctx senv;
	char _tb[256];
	const size_t _tbLen = sprintf(_tb, "%u", (unsigned)now);
	struct timeval tv;
	struct md5_context md5Ctx;

	signctx_init(&senv);
	init_signature_seed(&senv, reqMethod, url);

	if (postContentLen)
		append_signature_params(&senv, postContent, postContent + postContentLen);


	string_append(out, "Authorization: OAuth ", 21);

	append_signature_param(&senv, "oauth_consumer_key", 18, consumerKey, strlen(consumerKey));
	string_appendfmt(out, "oauth_consumer_key=\"%s\"", consumerKey);

	append_signature_param(&senv, "oauth_signature_method", 22, "HMAC-SHA1", 9);
	string_append(out, ",oauth_signature_method=\"HMAC-SHA1\"", 35);


        string_appendfmt(out,",oauth_timestamp=\"%u\"", (uint32_t)now);
        append_signature_param(&senv, "oauth_timestamp", 15, _tb, _tbLen);
                
        gettimeofday(&tv, NULL);
                        
        uint8_t digest[16];
        char digestAlpha[33];

	md5_init(&md5Ctx);
        md5_update(&md5Ctx, (uint8_t *)&tv.tv_sec, sizeof(tv.tv_sec));
        md5_update(&md5Ctx, (uint8_t *)&tv.tv_usec, sizeof(tv.tv_usec));
        md5_update(&md5Ctx, (uint8_t *)consumerKey, strlen(consumerKey));
        md5_update(&md5Ctx, (uint8_t *)"io.language", 11);
	md5_finalize(&md5Ctx, digest);
                
        md5_string((char *)digest, digestAlpha);
        const size_t digestAlphaLen = strlen(digestAlpha);      // 32
                
	string_appendfmt(out, ",oauth_nonce=\"%.*s\"",  digestAlphaLen, digestAlpha);
        append_signature_param(&senv, "oauth_nonce", 11, digestAlpha, digestAlphaLen);

        string_appendfmt(out, ",oauth_version=\"1.0\"", 20);
        append_signature_param(&senv, "oauth_version", 13, "1.0", 3);
                
        if (authToken && *authToken != '\0')
        {
                string_appendfmt(out, ",oauth_token=\"%s\"", authToken);
                append_signature_param(&senv, "oauth_token", 11, authToken, strlen(authToken));
        }       

        if (oauthCallback && *oauthCallback != '\0')
        {
                string_appendfmt(out, ",oauth_callback=\"%s\"", oauthCallback);
                append_signature_param(&senv, "oauth_callback", 14, oauthCallback, strlen(oauthCallback));
        }
                
        if (oauthVerifier && *oauthVerifier != '\0')
        {
                string_appendfmt(out, ",oauth_verifier=\"%s\"", oauthVerifier);
                append_signature_param(&senv, "oauth_verifier", 14, oauthVerifier, strlen(oauthVerifier));
        }

        if (oauthScope && *oauthScope != '\0')
        {
                string_appendfmt(out, ",scope=\"%s\"", oauthScope);
                append_signature_param(&senv, "scope", 5, oauthScope, strlen(oauthScope));
        }
	
        build_signature(&senv, "HMAC-SHA1", consumerSecret, authTokenSecret ? authTokenSecret : "");

        string_append(out, ",oauth_signature=\"", 18);
	string_append_urlencoded_rfc3986(out, string_data(&senv.signatureParamsBuf), string_len(&senv.signatureParamsBuf));
	string_append(out, "\"\r\n", 3);

	signctx_dealloc(&senv);
}