#!/usr/bin/env python # genkey.py - generate a certifate request, based upon genkey.py as shipped # with pyme in examples/ : # # $Id: genkey.py,v 1.5 2005/03/18 19:09:28 belyi Exp $ # Copyright (C) 2004 Igor Belyi # Copyright (C) 2002 John Goerzen # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA from pyme import core, callbacks # for GPGME_PROTOCOL_CMS from pyme import constants, errors import pyme.constants.validity # for the public arg in op_genkey from pyme.core import Data # Initialize our context. c = core.Context() c.set_armor(1) ### c.set_progress_cb(callbacks.progress_stdout, None) c.set_protocol(pyme.util.gpgme.GPGME_PROTOCOL_CMS) # This example from the GPGME manual # use this when using PGP gpg_parms = """ Key-Type: DSA Key-Length: 1024 Subkey-Type: ELG-E Subkey-Length: 1024 Name-Real: Joe Tester Name-Comment: with stupid passphrase Name-Email: joe@foo.bar Passphrase: abcdabcdfs Expire-Date: 2010-08-15 """ # make sure you _have_ C=NL,O=SURFnet in your certificates! parms = """ Key-Type: RSA Key-Length: 1024 Name-DN: C=NL,O=SURFnet,CN=Joe 2 Tester Name-Email: joe@foo.bar """ data = Data() # c.op_genkey(parms, None, None) # for gnupg try: c.op_genkey(parms, data, None) except pyme.errors.GPGMEError, exc: print exc.getstring() # not defined in CMS-case print c.op_genkey_result().fpr # data holds certificate request in CMS-case # should rewind! data.seek(0,0) print data.read() print "done"