def New_Edit_Profile(args): # Get Root Element and PolicySet parser = etree.XMLParser(remove_blank_text=True) root_element = etree.parse(args.editprofile,parser) PolicySet = root_element.find('./PolicySets/PolicySet') if args.profilename: Profilename = root_element.find('name') Profilename.text = args.profilename if args.profiledescription: ProfileDescription = root_element.find('description') ProfileDescription.text = args.profiledescription if args.subjectNamePattern and args.subjectNameDefault is None: pkiprofilelib.Subject_Name_Default(root_element, PolicySet,args.subjectNamePattern,None) if args.subjectNamePattern is None and args.subjectNameDefault: pkiprofilelib.Subject_Name_Default(root_element, PolicySet,None,args.subjectNameDefault) if args.subjectNamePattern and args.subjectNameDefault: pkiprofilelib.Subject_Name_Default(root_element, PolicySet,args.subjectNamePattern,args.subjectNameDefault) if args.keyusageextensions: pkiprofilelib.Key_Usage_Default(root_element,PolicySet, args.keyusageextensions) if args.maxvalidity and args.validfor: pkiprofilelib.Validity_Default(root_element,PolicySet, args.validfor, args.maxvalidity) if args.notBefore and args.notAfter: pkiprofilelib.No_Default(root_element, PolicySet, args.notBefore , args.notAfter) if args.netscapeextensions: pkiprofilelib.Netscape_Certificate_Type_Extension_Default(root_element,PolicySet,args.netscapeextensions) if args.crlextension: pkiprofilelib.crl_Distribution_Points_Ext_Default(root_element,PolicySet,args.crlextension) if args.PathLength and args.isCA: pkiprofilelib.Basic_Constraints_Extension_Default(root_element,PolicySet,args.PathLength,args.isCA) if args.altType and args.altPattern: pkiprofilelib.Subject_Alt_Name_Constraint(root_element,PolicySet,args.altType, args.altPattern) if args.ExtOID: pkiprofilelib.User_Supplied_Extension_Default(root_element,PolicySet,args.ExtOID) root_element.write(args.outputfile, pretty_print=True)
def Add_Policies(root_element, PolicySet, Profile_Input_Dict): if Profile_Input_Dict['subjectNameDefault'] is None: pkiprofilelib.Subject_Name_Default(root_element,PolicySet, Profile_Input_Dict['Subject_Pattern'],None) else: pkiprofilelib.Subject_Name_Default(root_element,PolicySet, Profile_Input_Dict['Subject_Pattern'],Profile_Input_Dict['subjectNameDefault']) if not (Profile_Input_Dict.has_key('PathLength') and Profile_Input_Dict.has_key('isCA')): pkiprofilelib.No_Default(root_element, PolicySet, Profile_Input_Dict['NotBefore'],Profile_Input_Dict['NotAfter']) pkiprofilelib.Validity_Default(root_element,PolicySet, Profile_Input_Dict['Validity'],Profile_Input_Dict['MaxValidity']) pkiprofilelib.Extended_Key_Usage_Extension_Default(root_element,PolicySet) pkiprofilelib.Subject_Alt_Name_Constraint(root_element,PolicySet,Profile_Input_Dict['altType'],Profile_Input_Dict['altPattern']) if Profile_Input_Dict.has_key('ExtOID'): pkiprofilelib.User_Supplied_Extension_Default(root_element,PolicySet,Profile_Input_Dict['ExtOID']) pkiprofilelib.Key_Default(root_element, PolicySet) pkiprofilelib.Authority_Key_Identifier_Default(root_element,PolicySet) pkiprofilelib.AIA_Extension_Default(root_element,PolicySet) pkiprofilelib.Key_Usage_Default(root_element, PolicySet,Profile_Input_Dict['Key_List']) pkiprofilelib.Signing_Alg(root_element,PolicySet) if Profile_Input_Dict.has_key('Generic_extensions'): pkiprofilelib.Generic_Extension(root_element,PolicySet) if Profile_Input_Dict.has_key('NetscapeExtensions'): pkiprofilelib.Netscape_Certificate_Type_Extension_Default(root_element,PolicySet, Profile_Input_Dict['NetscapeExtensions']) if Profile_Input_Dict.has_key('crlurl'): pkiprofilelib.crl_Distribution_Points_Ext_Default(root_element,PolicySet,Profile_Input_Dict['crlurl']) if Profile_Input_Dict.has_key('PathLength') and Profile_Input_Dict.has_key('isCA'): pkiprofilelib.Basic_Constraints_Extension_Default(root_element,PolicySet,Profile_Input_Dict['PathLength'], Profile_Input_Dict['isCA']) pkiprofilelib.CA_Certificate_Validity_Default(root_element,PolicySet) pkiprofilelib.Subject_Key_Identifier_Extension_Default(root_element,PolicySet) et = etree.ElementTree(root_element) return et