(jad, jar, use_j2me_endpoint=False)
return jad.render()
run jadTool on the newly created JAR
run jadTool on the newly created JAR
run jadTool on the newly created JAR
def sign_jar(jad, jar, use_j2me_endpoint=False):
    if not (hasattr(jad, 'update') and hasattr(jad, 'render')):
        jad = JadDict.from_jad(jad, use_j2me_endpoint=use_j2me_endpoint)

    ''' run jadTool on the newly created JAR '''
    key_store   = settings.JAR_SIGN['key_store']
    key_alias   = settings.JAR_SIGN['key_alias']
    store_pass  = settings.JAR_SIGN['store_pass']
    key_pass    = settings.JAR_SIGN['key_pass']
    jad_tool    = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'JadTool.jar')
    # remove traces of former jar signings, if any
    jad.update({
        "MIDlet-Certificate-1-1" : None,
        "MIDlet-Certificate-1-2" : None,
        "MIDlet-Certificate-1-3" : None,
        "MIDlet-Jar-RSA-SHA1" : None,
        "MIDlet-Permissions" : None
    })
    line_ending = jad.line_ending
    # save jad and jar to actual files
    with NamedTemporaryFile('w', suffix='.jad', delete=False) as jad_file:
        with NamedTemporaryFile('wb', suffix='.jar', delete=False) as jar_file:

            jad_file.write(jad.render())
            jar_file.write(jar)

            jad_file.flush()
            jar_file.flush()

            step_one = (
                f'java -jar "{jad_tool}" -addjarsig -jarfile "{jar_file.name}"'
                f' -alias {key_alias} -keystore "{key_store}"'
                f' -storepass {store_pass} -keypass {key_pass}'
                f' -inputjad "{jad_file.name}" -outputjad "{jad_file.name}"'
            )

            step_two = (
                f'java -jar "{jad_tool}" -addcert -alias {key_alias}'
                f' -keystore "{key_store}" -storepass {store_pass}'
                f' -inputjad "{jad_file.name}" -outputjad "{jad_file.name}"'
            )

            for step in (step_one, step_two):
                p = Popen(shlex.split(step), stdout=PIPE, stderr=PIPE, shell=False)
                _, stderr = p.communicate()
                if stderr.strip():
                    raise Exception(stderr)

            with open(jad_file.name, encoding='utf-8') as f:
                txt = f.read()
                jad = JadDict.from_jad(txt, use_j2me_endpoint=use_j2me_endpoint)

            try:
                os.unlink(jad_file.name)
                os.unlink(jar_file.name)
            except Exception:
                pass

    jad.update({
        "MIDlet-Permissions":
            "javax.microedition.io.Connector.file.read,"
            "javax.microedition.io.Connector.ssl,"
            "javax.microedition.io.Connector.file.write,"
            "javax.microedition.io.Connector.comm,"
            "javax.microedition.io.Connector.http,"
            "javax.microedition.io.Connector.https,"
            "javax.microedition.io.Connector.sms,"
            "javax.wireless.messaging.sms.send,"
            "javax.microedition.media.control.VideoControl.getSnapshot"
    })
    jad.line_ending = line_ending

    return jad.render()
def sign_jar ( jad , jar , use_j2me_endpoint = False ) : if not ( hasattr ( jad , 'update' ) and hasattr ( jad , 'render' ) ) : jad = JadDict . from_jad ( jad , use_j2me_endpoint = use_j2me_endpoint ) key_store = settings . JAR_SIGN [ 'key_store' ] key_alias = settings . JAR_SIGN [ 'key_alias' ] store_pass = settings . JAR_SIGN [ 'store_pass' ] key_pass = settings . JAR_SIGN [ 'key_pass' ] jad_tool = os . path . join ( os . path . abspath ( os . path . dirname ( __file__ ) ) , 'JadTool.jar' ) # remove traces of former jar signings, if any jad . update ( { "MIDlet-Certificate-1-1" : None , "MIDlet-Certificate-1-2" : None , "MIDlet-Certificate-1-3" : None , "MIDlet-Jar-RSA-SHA1" : None , "MIDlet-Permissions" : None } ) line_ending = jad . line_ending # save jad and jar to actual files with NamedTemporaryFile ( 'w' , suffix = '.jad' , delete = False ) as jad_file : with NamedTemporaryFile ( 'wb' , suffix = '.jar' , delete = False ) as jar_file : jad_file . write ( jad . render ( ) ) jar_file . write ( jar ) jad_file . flush ( ) jar_file . flush ( ) step_one = ( f'java -jar "{jad_tool}" -addjarsig -jarfile "{jar_file.name}"' f' -alias {key_alias} -keystore "{key_store}"' f' -storepass {store_pass} -keypass {key_pass}' f' -inputjad "{jad_file.name}" -outputjad "{jad_file.name}"' ) step_two = ( f'java -jar "{jad_tool}" -addcert -alias {key_alias}' f' -keystore "{key_store}" -storepass {store_pass}' f' -inputjad "{jad_file.name}" -outputjad "{jad_file.name}"' ) for step in ( step_one , step_two ) : p = Popen ( shlex . split ( step ) , stdout = PIPE , stderr = PIPE , shell = False ) _ , stderr = p . communicate ( ) if stderr . strip ( ) : raise Exception ( stderr ) with open ( jad_file . name , encoding = 'utf-8' ) as f : txt = f . read ( ) jad = JadDict . from_jad ( txt , use_j2me_endpoint = use_j2me_endpoint ) try : os . unlink ( jad_file . name ) os . unlink ( jar_file . name ) except Exception : pass jad . update ( { "MIDlet-Permissions" : "javax.microedition.io.Connector.file.read," "javax.microedition.io.Connector.ssl," "javax.microedition.io.Connector.file.write," "javax.microedition.io.Connector.comm," "javax.microedition.io.Connector.http," "javax.microedition.io.Connector.https," "javax.microedition.io.Connector.sms," "javax.wireless.messaging.sms.send," "javax.microedition.media.control.VideoControl.getSnapshot" } ) jad . line_ending = line_ending return jad . render ( )