def sign_envelope(envelope, key_file):
doc = etree.fromstring(envelope)<EOL>body = get_body(doc)<EOL>queue = SignQueue()<EOL>queue.push_and_mark(body)<EOL>security_node = ensure_security_header(doc, queue)<EOL>security_token_node = create_binary_security_token(key_file)<EOL>signature_node = Signature(<EOL>xmlsec.TransformExclC14N, xmlsec.TransformRsaSha1)<EOL>security_node.append(security_token_node)<EOL>security_node.append(signature_node)<EOL>queue.insert_references(signature_node)<EOL>key_info = create_key_info_node(security_token_node)<EOL>signature_node.append(key_info)<EOL>xmlsec.addIDs(doc, ['<STR_LIT>'])<EOL>dsigCtx = xmlsec.DSigCtx()<EOL>dsigCtx.signKey = xmlsec.Key.load(key_file, xmlsec.KeyDataFormatPem, None)<EOL>dsigCtx.sign(signature_node)<EOL>return etree.tostring(doc)<EOL>
Sign the given soap request with the given key