/**
 * Method to search for a contact
 * @param aRequest [out] The request data to be sent to network
 * @param aContact contact to be searched
 * @param aPageNum The page to be extracted
 * @param aItemsPerPage Number of items per page
 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
 */
SmfPluginError FlickrContactFetcherPlugin::search( SmfPluginRequestData &aRequest,
		const SmfContact &aContact,
		const int aPageNum , 
		const int aItemsPerPage  )
	{
#ifndef TESTINGTHISFUNCTION
	Q_UNUSED(aRequest)
	Q_UNUSED(aContact)
	Q_UNUSED(aPageNum)
	Q_UNUSED(aItemsPerPage)
	qDebug()<<"Inside FlickrContactFetcherPlugin::search()";
	return SmfPluginErrServiceNotSupported; 
#else
	SmfPluginError error = SmfPluginErrInvalidArguments;
	
	// Get the key sets from SMF Plugin Utility class.
	QString apiKey;
	QString apiSecret;
	QString authToken;
	fetchKeys(apiKey, apiSecret, authToken );
	
	// Create the API signature string
	QString baseString;
	baseString.append(apiSecret);
	baseString.append("api_key"+apiKey);
	baseString.append("auth_token"+authToken);
	baseString.append("formatjson");
	baseString.append("methodflickr.people.findByUsername");
	//baseString.append("page"+QString::number(aPageNum));
	//baseString.append("per_page"+QString::number(aItemsPerPage));
	baseString.append("username"+(aContact.value("Name").value<QContactName>().firstName()));
	
	
	// Create the url
	QUrl url("http://api.flickr.com/services/rest/?");
	url.addQueryItem("api_key", apiKey);
	url.addQueryItem("auth_token", authToken);
	url.addQueryItem("format", "json");
	url.addQueryItem("method", "flickr.people.findByUsername");
	url.addQueryItem("username",aContact.value("Name").value<QContactName>().firstName());
	//url.addQueryItem("page", QString::number(10));
	//url.addQueryItem("per_page", QString::number(10));

	url.addQueryItem("api_sig", generateSignature(baseString));
	
	// Create the request, set the url
	aRequest.iNetworkRequest.setUrl(url);
	aRequest.iRequestType = SmfContactSearch;
	aRequest.iPostData = NULL;
	aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
	error = SmfPluginErrNone;
//	writeLog("Url string is :"+aRequest.iNetworkRequest.url().toString());
	return error; 

#endif
	}
Example #2
0
/**
 * Parses the method call within an expression
 */
int CodeParser::parseExpression_MethodCall( const char* methodName, Scope* scope, TokenStack* stack ) {
	int errorCode = 0;
	list<Parameter*> params;

	// parse the method parameters
	if( ( errorCode = parseMethodParameters( scope, stack, params ) ) ) {
		return errorCode;
	}

	// generate the method signature
	const char* signature = generateSignature( methodName, params );

	// lookup the method
	Method* method = lookupMethod( scope, signature );
	if( method == NULL ) {
		// generate the error message
		char* errorMessage = new char[256];
		sprintf( errorMessage, "Method '%s' could not be found", signature );

		// display the error message
		SYNTAX_ERROR( errorMessage, stack->last() );
		delete errorMessage;
		return -1;
	}
	else {
		printf( "CodeParser::parseExpression: Method call - [%s]\n", signature );

		// get the code buffer
		CodeBuffer* cb = scope->getCodeBuffer();

		// parse the method parameter


		// setup the method call
		// instruction: PARAMS methodParams
		// instruction: INVOKE methodSig
		OFFSET_T offset1 = cb->putInstruction( PARAMS << A_OP );
		OFFSET_T offset2 = cb->putInstruction( INVOKE << A_OP );

		// add the parameter and reference data
		scope->addParameterData( new ParameterData( state->nextParamId(), params, offset1 ) );
		scope->addReferenceData( new ReferenceData( state->nextDataRefId(), signature, offset2 ) );
		return 0;
	}
}
/**
 * Method to get the list of groups
 * @param aRequest [out] The request data to be sent to network
 * @param aPageNum The page to be extracted
 * @param aItemsPerPage Number of items per page
 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
 */
SmfPluginError FlickrContactFetcherPlugin::groups( SmfPluginRequestData &aRequest,
		const int aPageNum , 
		const int aItemsPerPage  )
	{
	qDebug()<<"Inside FlickrContactFetcherPlugin::groups()";

	SmfPluginError error = SmfPluginErrInvalidArguments;

	// invalid arguments
		/*if( aPageNum < 0 || aItemsPerPage < 0 )
			{
			qDebug()<<"Invalid arguments";
			return error;
			}*/
	// Get the key sets from SMF Plugin Utility class.
	QString apiKey;
	QString apiSecret;
	QString authToken;
	fetchKeys(apiKey, apiSecret, authToken );
	
	// Create the API signature string
	QString baseString;
	baseString.append(apiSecret);
	baseString.append("api_key"+apiKey);
	baseString.append("auth_token"+authToken);
	baseString.append("formatjson");
	baseString.append("methodflickr.groups.pools.getGroups");
	
	// Create the url
	QUrl url("http://api.flickr.com/services/rest/?");
	url.addQueryItem("api_key", apiKey);
	url.addQueryItem("auth_token", authToken);
	url.addQueryItem("format", "json");
	url.addQueryItem("method","flickr.groups.pools.getGroups");
	url.addQueryItem("api_sig", generateSignature(baseString));
		
	// Create the request, set the url
	aRequest.iNetworkRequest.setUrl(url);
	aRequest.iRequestType = SmfContactGetGroups;
	aRequest.iPostData = NULL;
	aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
	error = SmfPluginErrNone;
//	writeLog("Url string is : "+aRequest.iNetworkRequest.url().toString());
	return error; 
	}
Example #4
0
/**
 * Parses a method definition
 */
int CodeParser::parseMethod( Scope* scope, const char* name, TypeReference* type, TokenStack* stack ) {
	int errorCode = 0;
	const char* signature;
	list<Parameter*> params;
	Method *method;

	// step through the tokens ...
	int step = 0;
	bool done = false;
	while( !errorCode && !done && stack->hasNext() ) {
		switch( ++step ) {
			// step 1: create the method
			case 1:
				// get the method parameters
				if( !( errorCode = parseMethodParameters( scope, stack, params ) ) ) {
					// create the method signature
					signature = generateSignature( name, params );

					// create the method
					printf( "CodeParser::parseMethod - method '%s' signature = '%s' modifiers = %s\n", name, signature, toBinary( this->modifiers ) );
					method = new Method( scope, name, signature, type, this->modifiers );
				}

				// reset the modifier for the current scope
				this->modifiers = 0;
				break;

			// step 2: process the method code block
			case 2:
				// must be a code block
				if( stack->peek()->getType() != tok::CODE_BLOCK ) {
					SYNTAX_ERROR( "symbol '{' expected", stack->next() );
					return NULL;
				}

				// process the method code block
				errorCode = parse( method, ((ComplexToken*)stack->next())->getChildren() );
				method->getCodeBuffer()->putInstruction( RET << A_OP ); // RET
				done = true;
				break;
		}
	}

	// is there already an error code?
	if( errorCode ) {
		return errorCode;
	}

	// did it complete?
	if( !done ) {
		SYNTAX_ERROR( "unexpected end of statement", stack->last() );
		return -1;
	}

	// add the method to the scope
	if( scope->getScopeType() != CLASS_SCOPE ) {
		SYNTAX_ERROR( "method cannot be defined here", stack->last() );
		return -1;
	}

	// add the method to the scope
	ScopeContainer* container = (ScopeContainer*)scope;
	container->addMethod( method );
	return 0;
}
/**
 * Method to get the list of friends
 * @param aRequest [out] The request data to be sent to network
 * @param aPageNum The page to be extracted
 * @param aItemsPerPage Number of items per page
 * @return SmfPluginError Plugin error if any, else SmfPluginErrNone
 */
SmfPluginError FlickrContactFetcherPlugin::friends( SmfPluginRequestData &aRequest,
		const int aPageNum, 
		const int aItemsPerPage )
	{
	qDebug()<<"Inside FlickrContactFetcherPlugin::friends()";
	
	SmfPluginError error = SmfPluginErrInvalidArguments;

	// invalid arguments
	if( aPageNum < 0 || aItemsPerPage < 0 )
		{
		qDebug()<<"Invalid arguments";
		return error;
		}
	
	qDebug()<<"Valid arguments";
	
	// Get the key sets from SMF Plugin Utility class.
	QString apiKey;
	QString apiSecret;
	QString authToken;
	fetchKeys(apiKey, apiSecret, authToken );
	
	// Create the API signature string
	QString baseString;
	baseString.append(apiSecret);
	baseString.append("api_key"+apiKey);
	baseString.append("auth_token"+authToken);
	baseString.append("filterfriends");
#ifdef SMF_XMLPARSING
	baseString.append("formatxml");
#else
	baseString.append("formatjson");
#endif
	baseString.append("methodflickr.contacts.getList");
	baseString.append("page"+QString::number(aPageNum));
	baseString.append("per_page"+QString::number(aItemsPerPage));
	
	// Create the url
	QUrl url("http://api.flickr.com/services/rest/?");
	url.addQueryItem("api_key", apiKey);
	url.addQueryItem("auth_token", authToken);
	url.addQueryItem("filter", "friends");
#ifdef SMF_XMLPARSING
	url.addQueryItem("format", "x");
#else
	url.addQueryItem("format", "json");
#endif
	url.addQueryItem("method", "flickr.contacts.getList");
	url.addQueryItem("page", QString::number(aPageNum));
	url.addQueryItem("per_page", QString::number(aItemsPerPage));
	url.addQueryItem("api_sig", generateSignature(baseString));
	
	// Create the request, set the url
	aRequest.iNetworkRequest.setUrl(url);
	aRequest.iRequestType = SmfContactGetFriends;
	aRequest.iPostData = NULL;
	aRequest.iHttpOperationType = QNetworkAccessManager::GetOperation;
	error = SmfPluginErrNone;

	qDebug()<<"Url string is : "<<aRequest.iNetworkRequest.url().toString();
	return error; 
	}
Example #6
0
int main( int argc, char *argv[]) {

	PKCS7 *p7;
	PKCS7_SIGNER_INFO *si;
	X509_STORE_CTX cert_ctx;
	X509_STORE *cert_store=NULL;

	BIO *data = NULL, *p7bio=NULL;
	BIO *signature = NULL;

	int cmd=-1;
        char *infile=NULL;
        /* char *outfile=NULL; */
        char *certfile=NULL;
        char *keyfile=NULL;
        char *key=NULL;
	int nodetach=0;

	char *datafile = NULL;
	char *outfile = NULL;
	char *signaturefile = NULL;

	char buf[1024*4];
	char **pp = NULL;
	int badops=0, outdata=0, err=0, version=0, i;

	 /* default certificates dir */
	 /* char *certsdir="/usr/local/OpenCA/certs"; */

	 /* default certificates file */
	 /* char *certsfile="/usr/local/OpenCA/cacert.pem"; */

	char *certsdir = NULL;
	char *certsfile = NULL;

	STACK_OF(PKCS7_SIGNER_INFO) *sk;

	if ((bio_err=BIO_new(BIO_s_file())) != NULL)
		BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);

	bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
	bio_out=BIO_new_fp(stdout,BIO_NOCLOSE);

#ifndef NO_MD5
        EVP_add_digest(EVP_md5());
#endif
#ifndef NO_SHA1
        EVP_add_digest(EVP_sha1());
#endif

	if( argc <= 1 ) {
		printVersion( bio_err, INFO );
		printf("ERROR: needed command and arguments missing\n\n");
		badops=1;
		goto badops;
	}

	if( ( cmd = getCommand( argc, argv ) ) == -1 ) {
		printVersion( bio_err, INFO );
		printf("ERROR: unknown command %s\n\n", argv[1] );
		badops=1;
		goto badops;
	}

	if( argc >= 1 ) {
		argc--;
		argv++;

		if( argc <= 1 )
		{
			printVersion( bio_err, INFO );
			printf("ERROR: needed at least one argument!\n\n" );
	                badops=1;
        	        goto badops;
		}
	}

	while (argc > 1) {
		argc--;
		argv++;
		if (strcmp(*argv,"-verbose") == 0)
                        {
			verbose=1;
			}
		else if (strcmp(*argv,"-print_data") == 0)
                        {
			outdata=1;
			}
		else if (strcmp(*argv,"-no_chain") == 0)
                        {
			chainVerify=0;
			}
		else if (strcmp(*argv,"-data") == 0)
			{
                        if (--argc < 1) goto bad;
			datafile= *( ++argv );
			}
		else if (strcmp(*argv,"-d") == 0)
			{
			/* Present for compatibility reasons ... */
                        if (--argc < 1) goto bad;
			datafile= *( ++argv );
			}
		else if (strcmp(*argv,"-in") == 0)
			{
                        if (--argc < 1) goto bad;
			infile= *( ++argv );
			}
		else if (strcmp(*argv,"-out") == 0)
			{
                        if (--argc < 1) goto bad;
			outfile= *( ++argv );
			}
		else if (strcmp(*argv,"-cd") == 0)
			{
                        if (--argc < 1) goto bad;
                        certsdir = *(++argv);
			}
		else if (strcmp(*argv,"-cf") == 0)
			{
                        if (--argc < 1) goto bad;
                        certsfile = *( ++argv );
			}
		else if (strcmp(*argv,"-cert") == 0)
			{
                        if (--argc < 1) goto bad;
                        certfile = *( ++argv );
			}
		else if (strcmp(*argv,"-keyfile") == 0)
			{
                        if (--argc < 1) goto bad;
                        keyfile = *( ++argv );
			}
		else if (strcmp(*argv,"-key") == 0)
			{
                        if (--argc < 1) goto bad;
                        key = *( ++argv );
			}
		else if (strcmp(*argv,"-nd") == 0)
                        {
			nodetach=1;
			}
		else if (strcmp(*argv,"-h") == 0)
			{
			   badops=1;
			   break;
			}
		else
			{
			if( argc == 2 ) {
				datafile = *argv;
				argc--;
				continue;
			}
bad:
			printVersion( bio_err, INFO );
                        BIO_printf(bio_err,"ERROR: unknown option %s\n\n",*argv);
                        badops=1;
                        break;
			}
	}

badops:
        if (badops) {
                for (pp=usage; (*pp != NULL); pp++)
                        BIO_printf(bio_err,*pp);
                        exit(1);
        }

	if( cmd == 1 ) {
		generateSignature( verbose, infile, outfile, certfile, keyfile, key, nodetach );
	} else if ( cmd == 2 )
		{
		verifySignature( verbose, infile, outfile, outdata, 
				chainVerify, datafile, certsdir, certsfile);
		}
	else if ( cmd == 3 )
		{
		sign2nd( verbose, infile, outfile, datafile, outdata );
		}
	exit(0);
}
Example #7
0
QByteArray Token::signRequest(const QUrl& requestUrl, Token::AuthMethod authMethod, Token::HttpMethod method, const QMultiMap<QString, QString>& parameters) const
{
	QString timestamp;
	QString nonce;

	if (d->consumerKey == "test_token") { // Set known values for unit-testing
		timestamp = "1234567890";	//Feb 13, 2009, 23:31:30 GMT
		nonce = "ABCDEF";
	} else {
#if QT_VERSION >= 0x040700
		timestamp = QString::number(QDateTime::currentDateTimeUtc().toTime_t());
#else
		timestamp = QString::number(QDateTime::currentDateTime().toUTC().toTime_t());
#endif
		nonce = QString::number(qrand());
	}

	if (!requestUrl.isValid()) {
		qWarning() << "OAuth::Token: Invalid url. The request will probably be invalid";
	}

	// Step 1. Get all the oauth params for this request

	QMultiMap<QString, QString> oauthParams;

	oauthParams.insert("oauth_consumer_key", d->consumerKey);
    if(d->serviceType == "dbox")
        oauthParams.insert("oauth_signature_method", "PLAINTEXT");
    else
        oauthParams.insert("oauth_signature_method", "HMAC-SHA1");
	oauthParams.insert("oauth_timestamp", timestamp);
	oauthParams.insert("oauth_nonce", nonce);
	oauthParams.insert("oauth_version", "1.0");

	switch (d->tokenType) {
	case Token::InvalidToken:
		oauthParams.insert("oauth_callback", d->callbackUrl.toString());
		break;

	case Token::RequestToken:
		oauthParams.insert("oauth_token", d->oauthToken);
		oauthParams.insert("oauth_verifier", d->oauthVerifier);
		break;

	case Token::AccessToken:
		oauthParams.insert("oauth_token", d->oauthToken);
		break;
	}

	// Step 2. Take the parameters from the url, and add the oauth params to them

	QMultiMap<QString, QString> allParams = oauthParams;
	QList<QPair<QString, QString> > queryItems = requestUrl.queryItems();
	for(int i = 0; i < queryItems.count(); ++i) {
		allParams.insert(queryItems[i].first, queryItems[i].second);
	}

	allParams.unite(parameters);

	// Step 3. Calculate the signature from those params, and append the signature to the oauth params

	QString signature = generateSignature(requestUrl, allParams, method);
	oauthParams.insert("oauth_signature", signature);

	// Step 4. Concatenate all oauth params into one comma-separated string

	QByteArray authHeader;

	if (authMethod == Sasl) {
		authHeader = "GET ";
		authHeader.append(requestUrl.toString() + " ");
	} else {
		authHeader = "OAuth ";
	}

	QMultiMap<QString, QString>::const_iterator p = oauthParams.constBegin();
	while (p != oauthParams.constEnd()) {
		authHeader += QString("%1=\"%2\",").arg(p.key()).arg(encode(p.value()));
		++p;
	}
	authHeader.chop(1); // remove the last character (the trailing ",")

	return authHeader;
}