Example #1
0
 def test_2(self):
     jobj = self.read_file("java/testBytes.ser")
     pobj = javaobj.loads(jobj)
     print pobj
     self.assertEqual(pobj, 'HelloWorld')
     jobj_ = javaobj.dumps(pobj)
     self.assertEqual(jobj, jobj_)
Example #2
0
 def test_3(self):
     jobj = self.read_file("java/testBoolean.ser")
     pobj = javaobj.loads(jobj)
     print pobj
     self.assertEqual(pobj, chr(0))
     jobj_ = javaobj.dumps(pobj)
     self.assertEqual(jobj, jobj_)
Example #3
0
 def test_0_rw(self):
     jobj = self.read_file("java/testChar.ser")
     pobj = javaobj.loads(jobj)
     print pobj
     self.assertEqual(pobj, '\x00C')
     jobj_ = javaobj.dumps(pobj)
     self.assertEqual(jobj, jobj_)
Example #4
0
 def test_0_rw(self):
     jobj = self.read_file("java/testChar.ser")
     pobj = javaobj.loads(jobj)
     print pobj
     self.assertEqual(pobj, '\x00C')
     jobj_ = javaobj.dumps(pobj)
     self.assertEqual(jobj, jobj_)
Example #5
0
 def test_1(self):
     jobj = self.read_file("java/testDouble.ser")
     pobj = javaobj.loads(jobj)
     print pobj
     self.assertEqual(pobj, '\x7f\xef\xff\xff\xff\xff\xff\xff')
     jobj_ = javaobj.dumps(pobj)
     self.assertEqual(jobj, jobj_)
Example #6
0
 def test_2(self):
     jobj = self.read_file("java/testBytes.ser")
     pobj = javaobj.loads(jobj)
     print pobj
     self.assertEqual(pobj, 'HelloWorld')
     jobj_ = javaobj.dumps(pobj)
     self.assertEqual(jobj, jobj_)
Example #7
0
 def test_1(self):
     jobj = self.read_file("java/testDouble.ser")
     pobj = javaobj.loads(jobj)
     print pobj
     self.assertEqual(pobj, '\x7f\xef\xff\xff\xff\xff\xff\xff')
     jobj_ = javaobj.dumps(pobj)
     self.assertEqual(jobj, jobj_)
Example #8
0
 def installBusinessDataModel(self, zipFilename):
     rc, raw_session = self.getSession()
     session = json.loads(raw_session)
     xmlSession = self.xmlSessionFromSession(session)
     url = self.url + "/serverAPI/" + BonitaClient.API_BDM + \
         "/" + "installBusinessDataModel"
     headers = {}
     with open(zipFilename, 'rb') as zippedFile:
         zipDatas = zippedFile.read()
         javaarray = javaobj.JavaByteArray(
             zipDatas, classdesc=javaobj.ByteArrayDesc())
         datas = javaobj.dumps(javaarray)
         with open('/tmp/datas.ser', 'wb') as writefile:
             writefile.write(datas)
             writefile.close()
     files = {
         'binaryParameter0':
         ('binaryParameter0', open('/tmp/datas.ser',
                                   'rb'), 'application/octet-stream', {
                                       'Content-Transfer-Encoding': 'binary'
                                   })
     }
     payload = {
         "options": xmlSession,
         "classNameParameters": BonitaClient.CLASSNAME_BINARY_PARAMETER,
         "parametersValues": BonitaClient.VALUE_BINARY_PARAMETER
     }
     r = self.getInternalSession().post(url,
                                        data=payload,
                                        files=files,
                                        headers=headers)
     return self.formatResponse(r)
Example #9
0
 def test_3(self):
     jobj = self.read_file("java/testBoolean.ser")
     pobj = javaobj.loads(jobj)
     print pobj
     self.assertEqual(pobj, chr(0))
     jobj_ = javaobj.dumps(pobj)
     self.assertEqual(jobj, jobj_)
Example #10
0
    def test_4(self):
        jobj = self.read_file("obj4.ser")
        pobj = javaobj.loads(jobj)
        print pobj
        self.assertEqual(pobj, 127)

        jobj_ = javaobj.dumps(pobj)
        self.assertEqual(jobj, jobj_)
Example #11
0
 def test_char_rw(self):
     """
     Reads testChar.ser and checks the serialization process
     """
     jobj = self.read_file("testChar.ser")
     pobj = javaobj.loads(jobj)
     _logger.debug("Read char object: %s", pobj)
     self.assertEqual(pobj, '\x00C')
     jobj_ = javaobj.dumps(pobj)
     self.assertEqual(jobj, jobj_)
Example #12
0
    def test_class(self):
        """
        Reads the serialized String class
        """
        jobj = self.read_file("testClass.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug("Read object: %s", pobj)
        self.assertEqual(pobj.name, 'java.lang.String')

        jobj_ = javaobj.dumps(pobj)
        self.assertEqual(jobj, jobj_)
Example #13
0
    def test_bytes_rw(self):
        """
        Reads testBytes.ser and checks the serialization process
        """
        jobj = self.read_file("testBytes.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug("Read bytes: %s", pobj)

        self.assertEqual(pobj, 'HelloWorld')

        jobj_ = javaobj.dumps(pobj)
        self.assertEqual(jobj, jobj_)
Example #14
0
    def test_boolean(self):
        """
        Reads testBoolean.ser and checks the serialization process
        """
        jobj = self.read_file("testBoolean.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug("Read boolean object: %s", pobj)

        self.assertEqual(pobj, chr(0))

        jobj_ = javaobj.dumps(pobj)
        self.assertEqual(jobj, jobj_)
Example #15
0
    def test_double_rw(self):
        """
        Reads testDouble.ser and checks the serialization process
        """
        jobj = self.read_file("testDouble.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug("Read double object: %s", pobj)

        self.assertEqual(pobj, '\x7f\xef\xff\xff\xff\xff\xff\xff')

        jobj_ = javaobj.dumps(pobj)
        self.assertEqual(jobj, jobj_)
Example #16
0
    def test_byte(self):
        """
        Reads testByte.ser

        The result from javaobj is a single-character string.
        """
        jobj = self.read_file("testByte.ser")
        pobj = javaobj.loads(jobj)
        _logger.debug("Read Byte: %r", pobj)

        self.assertEqual(pobj, chr(127))

        jobj_ = javaobj.dumps(pobj)
        self.assertEqual(jobj, jobj_)
Example #17
0
 def _try_marshalling(self, original_stream, original_object):
     """
     Tries to marshall an object and compares it to the original stream
     """
     marshalled_stream = javaobj.dumps(original_object)
     # Reloading the new dump allows to compare the decoding sequence
     try:
         javaobj.loads(marshalled_stream)
         self.assertEqual(original_stream, marshalled_stream)
     except:
         print("-" * 80)
         print("=" * 30, "Original", "=" * 30)
         print(
             javaobj.JavaObjectUnmarshaller._create_hexdump(
                 original_stream))
         print("*" * 30, "Marshalled", "*" * 30)
         print(
             javaobj.JavaObjectUnmarshaller._create_hexdump(
                 marshalled_stream))
         print("-" * 80)
         raise
Example #18
0
    def _encrypt_for(self, store_type, key_password):
        if not self.is_decrypted():
            return self._encrypted

        # build a plaintext Java object to hold the key and some metadata
        plaintext_obj = None
        if "DES" in self.algorithm:
            plaintext_obj = self._java_KeyRep(self.algorithm, self.key, "RAW", "SECRET")
        else:
            plaintext_obj = self._java_SecretKeySpec(self.algorithm, self.key)

        plaintext = javaobj.dumps(plaintext_obj)

        # now encrypt the serialized plaintext object, and store the result in a SealedObjectForKeyProtector object
        ciphertext, salt, iteration_count = sun_crypto.jce_pbe_encrypt(plaintext, key_password)

        params = rfc2898.PBEParameter()
        params.setComponentByName('salt', salt)
        params.setComponentByName('iterationCount', iteration_count)
        params = encoder.encode(params)

        sealed_obj = self._java_SealedObjectForKeyProtector(ciphertext, params, "PBEWithMD5AndTripleDES", "PBEWithMD5AndTripleDES")
        return sealed_obj
Example #19
0
 def _try_marshalling(self, original_stream, original_object):
     """
     Tries to marshall an object and compares it to the original stream
     """
     marshalled_stream = javaobj.dumps(original_object)
     # Reloading the new dump allows to compare the decoding sequence
     try:
         javaobj.loads(marshalled_stream)
         self.assertEqual(original_stream, marshalled_stream)
     except Exception:
         print("-" * 80)
         print("=" * 30, "Original", "=" * 30)
         print(
             javaobj.JavaObjectUnmarshaller._create_hexdump(original_stream)
         )
         print("*" * 30, "Marshalled", "*" * 30)
         print(
             javaobj.JavaObjectUnmarshaller._create_hexdump(
                 marshalled_stream
             )
         )
         print("-" * 80)
         raise
Example #20
0
 def _write_secret_key_entry(cls, alias, item, encrypted_form):
     result = b4.pack(cls.ENTRY_TYPE_SECRET_KEY)
     result += cls._write_utf(alias)
     result += b8.pack(item.timestamp)
     result += javaobj.dumps(encrypted_form)
     return result
Example #21
0
import sys
import javaobj

with open(sys.argv[1], "rb") as f:
    obj = javaobj.loads(f.read())

print(obj.testCodeStructure.globalUserCode.userCode)
# obj.testCodeStructure.globalUserCode.userCode = "tests() ;"

print(len(javaobj.dumps(obj)))
# with open(sys.argv[1], "wb") as f :
# f.write(javaobj.dumps(obj))
 def python2java(pobj):
     try:
         jobj = javaobj.dumps(pobj)
         return jobj
     except Exception as e:
         raise e