2 from OpenSSL import crypto
3 from M2Crypto import X509
4 sys.path.append('../../util/sec')
5 sys.path.append('../../util')
14 hrn = raw_input('Enter the hrn of the object: ')
16 #generate certificate and the private key
18 create_self_cert(name)
20 #extract the public key from the certificate and input to the database
21 cert = X509.load_cert(name+'.cert')
22 pubkey_pem = cert.get_pubkey().as_pem(cipher=None)
25 tablename = obtain_authority(hrn).replace('.','$')
26 t1 = tablename+SUFFIX1
27 t2 = tablename+SUFFIX2
29 querystr = "SELECT * FROM "+t1+" WHERE hrn='"+name+"';"
30 res = cnx.query(querystr)
32 querystr = "UPDATE "+t1+" SET pubkey = '"+pubkey_pem+"' WHERE hrn = '"+name+"';"
35 querystr = "SELECT * FROM "+t2+" WHERE hrn='"+name+"';"
36 res = cnx.query(querystr)
38 querystr = "UPDATE "+t2+" SET pubkey = '"+pubkey_pem+"' WHERE hrn = '"+name+"';"
41 print 'The record with name:'+hrn+"' does not exist in the system.\n"
44 print "Public key is successfully added to '"+hrn+"' record.\nThe certificate and key are generated.\n"