Skip to content

Commit

Permalink
WSAA: agrego callback para passphrase opcional
Browse files Browse the repository at this point in the history
  • Loading branch information
reingart committed May 15, 2014
1 parent b6b2262 commit be86370
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions wsaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
__author__ = "Mariano Reingart (reingart@gmail.com)"
__copyright__ = "Copyright (C) 2008-2011 Mariano Reingart"
__license__ = "GPL 3.0"
__version__ = "2.07d"
__version__ = "2.08a"

import hashlib, datetime, email, os, sys, time, traceback
from php import date
Expand Down Expand Up @@ -71,20 +71,23 @@ def create_tra(service=SERVICE,ttl=2400):
tra.add_child('service',service)
return tra.as_xml()

def sign_tra(tra,cert=CERT,privatekey=PRIVATEKEY):
def sign_tra(tra,cert=CERT,privatekey=PRIVATEKEY,passphrase=""):
"Firmar PKCS#7 el TRA y devolver CMS (recortando los headers SMIME)"

if BIO:
# Firmar el texto (tra) usando m2crypto (openssl bindings para python)
buf = BIO.MemoryBuffer(tra) # Crear un buffer desde el texto
#Rand.load_file('randpool.dat', -1) # Alimentar el PRNG
s = SMIME.SMIME() # Instanciar un SMIME
# soporte de contraseña de encriptación (clave privada, opcional)
callback = lambda *args, **kwarg: passphrase
# Cargar clave privada y certificado
if privatekey.startswith("-----BEGIN RSA PRIVATE KEY-----"):
key_bio = BIO.MemoryBuffer(privatekey)
crt_bio = BIO.MemoryBuffer(cert)
s.load_key_bio(key_bio, crt_bio) # Cargar certificados (buffer)
s.load_key_bio(key_bio, crt_bio) # (desde buffer)
elif os.path.exists(privatekey) and os.path.exists(cert):
s.load_key(privatekey, cert) # Cargar certificados (archivo)
s.load_key(privatekey, cert, callback) # (desde archivo)
else:
raise RuntimeError("Archivos no encontrados: %s, %s" % (privatekey, cert))
p7 = s.sign(buf,0) # Firmar el buffer
Expand Down

0 comments on commit be86370

Please sign in to comment.