Ticket #216: koji_passwd_cache.patch

File koji_passwd_cache.patch, 1.4 KB (added by bbockelm, 3 years ago)
  • (a) /tmp/SSLCommon.py.orig vs. (b) ssl/SSLCommon.py

    a b  
    2020import httplib 
    2121import socket 
    2222import SocketServer 
     23import getpass 
    2324 
    2425def our_verify(connection, x509, errNum, errDepth, preverifyOK): 
    2526    # print "Verify: errNum = %s, errDepth = %s, preverifyOK = %s" % (errNum, errDepth, preverifyOK) 
     
    2829    # correctly authenticates against the CA chain 
    2930    return preverifyOK 
    3031 
     32cached_passwd = None 
     33def passwd_callback(max_length, ask_twice, userdata): 
     34    cpass = globals()['cached_passwd'] 
     35    if cpass: 
     36        return cpass 
     37 
     38    typed_pass = getpass.getpass("Enter PEM pass phrase: ") 
     39    if len(typed_pass) > max_length: 
     40        print "Password is longer than what OpenSSL is able to handle" 
     41        return False 
     42 
     43    if ask_twice: 
     44        typed_pass2 = getpass.getpass("Please enter password again for verification: ") 
     45        if typed_pass != typed_pass2: 
     46            return False 
     47 
     48    globals()['cached_passwd'] = typed_pass 
     49    return typed_pass 
    3150 
    3251def CreateSSLContext(certs): 
    3352    key_and_cert = certs['key_and_cert'] 
     
    3857            raise StandardError, "%s does not exist or is not readable" % f 
    3958 
    4059    ctx = SSL.Context(SSL.SSLv3_METHOD)   # SSLv3 only 
     60    ctx.set_passwd_cb(passwd_callback, None) 
    4161    ctx.use_certificate_file(key_and_cert) 
    4262    ctx.use_privatekey_file(key_and_cert) 
    4363    ctx.load_client_ca(ca_cert)