This module is designed to authorize users (based upon their public keys) before allowing execution of applications.

Installation:

This module may be built by typing:
make
make install

I assumed a couple things here.  First, I assume that you will have python installed.  Second, I assume that your python libraries directory is located at /usr/lib/pythonX.X/site-packages (where X's are the version).  I further assume that you will have the python development package installed which should contain Python.h as located in /usr/include/pythonX.X

If any of these assumptions are incorrect, then you will want to modify the Makefile accordingly.

Usage:

**** DO NOT DO THE FOLLOWING AS ROOT ****
Keep in mind that in order to use this module, you will need to have a pre-defined list of keys (RSA or DSA) that you would like to authorize in your application.  How you maintain that particular list of public keys is outside of the scope of this document (whether they're stored in a db or in a file or simply hard-coded).  A sample key will look something like this:

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAsJ/wAmYRIFhof47rIyUyB7ZN+MbVjW1WiiY7CJ/rX0k2z23l+LT0m0F2KmNHGu6sbuXCzlMT9sM7umWeegVokEQn7SFCmvrUYDAetmEGsz2Cili5rNkDNJqupEO9xz23iPol8ayJvT0hhpDXy8eOBPk+zgCEMfD3TOB5Q1MHX7TygEDTf2tJco02HlHL5nOSSv7+hyCjHIzjWwzkTUzVXh3VP19YIoK867Adpcs2v6jiGCZWgfm0erJLMPpjsMZaSgzzO3NrQKZa7v5Koyycfef5poqlDFvICQxXUQteAaCWY/D2y3FOdwfRgYzWh8XVkGBF2FFgoeEj9+iNBFjZ4w== sam@localhost.localdomain

To get something like this simply run ssh-keygen -t [rsa|dsa] -b (number of bytes i.e. 2048) and be sure to set a passphrase on the identity.

Before this identity can actually be authorized, it must be added to the ssh agent.  Do that by the following:
ssh-add /path/to/your/.ssh/id_rsa

(or, if you only have one identity to add, then simply: ssh-add)
you should then be prompted for your passphrase which you must enter before the agent can add your identity.

Now you should be able to type ssh-add -l and see the agent spit out the fingerprint for the key you just added.

To use this module, you will want to import agentValidate into your python application as follows:
	from agentValidate import AgentValidate

Build up a list of authorized keys (we'll use the one shown above as an example).
	authorizedKeys = ["ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAsJ/wAmYRIFhof47rIyUyB7ZN+MbVjW1WiiY7CJ/rX0k2z23l+LT0m0F2KmNHGu6sbuXCzlMT9sM7umWeegVokEQn7SFCmvrUYDAetmEGsz2Cili5rNkDNJqupEO9xz23iPol8ayJvT0hhpDXy8eOBPk+zgCEMfD3TOB5Q1MHX7TygEDTf2tJco02HlHL5nOSSv7+hyCjHIzjWwzkTUzVXh3VP19YIoK867Adpcs2v6jiGCZWgfm0erJLMPpjsMZaSgzzO3NrQKZa7v5Koyycfef5poqlDFvICQxXUQteAaCWY/D2y3FOdwfRgYzWh8XVkGBF2FFgoeEj9+iNBFjZ4w== sam@localhost.localdomain",]

now you're ready to ask the agent to sign the data and have it verified.
	myValidator = AgentValidate()

	if myValidator.signData("foobar", authorizedKeys):
		print "congrats you may continue executing this application"
	else:
		print "sorry, you are not permitted access to this application"

Keep in mind that the string data passed to signData must not contain any spaces or other odd characters as that will prevent the verification routine from succeeding.

Here's the example in a neat format for grabbing.

from agentValidate import AgentValidate

authorizedKeys = ["ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAsJ/wAmYRIFhof47rIyUyB7ZN+MbVjW1WiiY7CJ/rX0k2z23l+LT0m0F2KmNHGu6sbuXCzlMT9sM7umWeegVokEQn7SFCmvrUYDAetmEGsz2Cili5rNkDNJqupEO9xz23iPol8ayJvT0hhpDXy8eOBPk+zgCEMfD3TOB5Q1MHX7TygEDTf2tJco02HlHL5nOSSv7+hyCjHIzjWwzkTUzVXh3VP19YIoK867Adpcs2v6jiGCZWgfm0erJLMPpjsMZaSgzzO3NrQKZa7v5Koyycfef5poqlDFvICQxXUQteAaCWY/D2y3FOdwfRgYzWh8XVkGBF2FFgoeEj9+iNBFjZ4w== sam@localhost.localdomain",]

myValidator = AgentValidate()
if myValidator.signData("foobar", authorizedKeys):
	print "congrats you may continue executing this application"
else:
	print "sorry, you are not permitted access to this application"
