tcalmant / python-javaobj

Extended fork of python-javaobj from http://code.google.com/p/python-javaobj/
Apache License 2.0
81 stars 19 forks source link

Oops state dump + 'JavaArray' object has no attribute 'name' #5

Closed voetsjoeba closed 8 years ago

voetsjoeba commented 8 years ago

While parsing a serialized com.sun.crypto.provider.SealedObjectForKeyProtector instance embedded in a JCEKS keystore, I received the output below. Used to work in v0.1.1.

I deliberately left ignore_remaining_data to False because the output shows that it seems to think half or so of the actual object is remaining data.

This is on Python 2.7.5 on CentOS 7:

ERROR:javaobj:==Oops state dump=============
ERROR:javaobj:References: [[com.sun.crypto.provider.SealedObjectForKeyProtector:0x-32A835A618CF44AD], [javax.crypto.SealedObject:0x3E363DA6C3B75470], '[B', 'Ljava/lang/String;', [[B:0x-530CE807F9F7AB20], [48, 13, 4, 8, 91, -81, 16, 100, -33, 73, -100, -99, 2, 1, 20], []]
ERROR:javaobj:Stream seeking back at -16 byte (2nd line is an actual position!):
ERROR:javaobj:Warning!!!!: Stream still has 230 bytes left.
ERROR:javaobj:00ED   49 9C 9D 02 01 14 75 71 00 7E 00 05 00 00 00 90   I.....uq.~......
00FD   F0 2C CE F1 EB 76 CF 35 5A A6 3E 55 3B 24 37 44   .,...v.5Z.>U;$7D
010D   7F 25 45 D5 E2 3F 22 89 5B 1F DA 8F 8C 1D 8E 7A   .%E..?".[......z
011D   DC 36 D6 B5 D9 52 35 21 48 12 15 D3 85 D1 71 97   .6...R5!H.....q.
012D   10 3E 34 45 C9 0F 63 16 0C 53 6B 5B 3B 98 D7 D4   .>4E..c..Sk[;...
013D   04 0D 96 28 F1 09 E2 45 2B 16 69 0B B2 DC DB E3   ...(...E+.i.....
014D   F8 1D CA 55 A1 D0 F2 C3 2F 6A 98 40 5F 62 0F 92   ...U..../j.@_b..
015D   88 92 3D 31 80 39 46 86 16 26 DA 7C 3B 2E 0B D8   ..=1.9F..&.|;...
016D   F2 A8 C2 C3 42 7F 56 74 B0 06 A2 99 A7 6F 6E A1   ....B.Vt.....on.
017D   1B 6E 74 62 09 C5 49 41 0D 21 59 C2 5D 4F BE 5C   .ntb..IA.!Y.]O..
018D   74 00 16 50 42 45 57 69 74 68 4D 44 35 41 6E 64   t..PBEWithMD5And
019D   54 72 69 70 6C 65 44 45 53 74 00 16 50 42 45 57   TripleDESt..PBEW
01AD   69 74 68 4D 44 35 41 6E 64 54 72 69 70 6C 65 44   ithMD5AndTripleD
01BD   45 53 EF 22 FC 75 BF F0 16 B1 B1 C2 5A 20 13 D5   ES.".u......Z ..
01CD   BF E2 48 B2 AC 1F                                 ..H...

ERROR:javaobj:==============================
Traceback (most recent call last):
  File "main.py", line 20, in <module>
    ks = jks.KeyStore.load(args.keystore_file, args.keystore_password)
  File "/home/vmuser/pyjks/jks/jks.py", line 43, in load
    return cls.loads(file.read(), password)
  File "/home/vmuser/pyjks/jks/jks.py", line 146, in loads
    sealed_obj, pos = _read_java_obj(data, pos, ignore_remaining_data=True)
  File "/home/vmuser/pyjks/jks/jks.py", line 244, in _read_java_obj
    obj = javaobj.load(data_stream)
  File "/home/vmuser/.local/lib/python2.7/site-packages/javaobj.py", line 168, in load
    return marshaller.readObject(ignore_remaining_data=ignore_remaining_data)
  File "/home/vmuser/.local/lib/python2.7/site-packages/javaobj.py", line 495, in readObject
    _, res = self._read_and_exec_opcode(ident=0)
  File "/home/vmuser/.local/lib/python2.7/site-packages/javaobj.py", line 560, in _read_and_exec_opcode
    return opid, handler(ident=ident)
  File "/home/vmuser/.local/lib/python2.7/site-packages/javaobj.py", line 799, in do_object
    res = self._read_value(field_type, ident, name=field_name)
  File "/home/vmuser/.local/lib/python2.7/site-packages/javaobj.py", line 1002, in _read_value
    _, res = self._read_and_exec_opcode(ident=ident + 1)
  File "/home/vmuser/.local/lib/python2.7/site-packages/javaobj.py", line 560, in _read_and_exec_opcode
    return opid, handler(ident=ident)
  File "/home/vmuser/.local/lib/python2.7/site-packages/javaobj.py", line 883, in do_array
    type_char = classdesc.name[0]
AttributeError: 'JavaArray' object has no attribute 'name'

Here's the input serialized object (run it through xxd -r to produce the binary file):

0000000: aced 0005 7372 0033 636f 6d2e 7375 6e2e  ....sr.3com.sun.
0000010: 6372 7970 746f 2e70 726f 7669 6465 722e  crypto.provider.
0000020: 5365 616c 6564 4f62 6a65 6374 466f 724b  SealedObjectForK
0000030: 6579 5072 6f74 6563 746f 72cd 57ca 59e7  eyProtector.W.Y.
0000040: 30bb 5302 0000 7872 0019 6a61 7661 782e  0.S...xr..javax.
0000050: 6372 7970 746f 2e53 6561 6c65 644f 626a  crypto.SealedObj
0000060: 6563 743e 363d a6c3 b754 7002 0004 5b00  ect>6=...Tp...[.
0000070: 0d65 6e63 6f64 6564 5061 7261 6d73 7400  .encodedParamst.
0000080: 025b 425b 0010 656e 6372 7970 7465 6443  .[B[..encryptedC
0000090: 6f6e 7465 6e74 7100 7e00 024c 0009 7061  ontentq.~..L..pa
00000a0: 7261 6d73 416c 6774 0012 4c6a 6176 612f  ramsAlgt..Ljava/
00000b0: 6c61 6e67 2f53 7472 696e 673b 4c00 0773  lang/String;L..s
00000c0: 6561 6c41 6c67 7100 7e00 0378 7075 7200  ealAlgq.~..xpur.
00000d0: 025b 42ac f317 f806 0854 e002 0000 7870  .[B......T....xp
00000e0: 0000 000f 300d 0408 5baf 1064 df49 9c9d  ....0...[..d.I..
00000f0: 0201 1475 7100 7e00 0500 0000 90f0 2cce  ...uq.~.......,.
0000100: f1eb 76cf 355a a63e 553b 2437 447f 2545  ..v.5Z.>U;$7D.%E
0000110: d5e2 3f22 895b 1fda 8f8c 1d8e 7adc 36d6  ..?".[......z.6.
0000120: b5d9 5235 2148 1215 d385 d171 9710 3e34  ..R5!H.....q..>4
0000130: 45c9 0f63 160c 536b 5b3b 98d7 d404 0d96  E..c..Sk[;......
0000140: 28f1 09e2 452b 1669 0bb2 dcdb e3f8 1dca  (...E+.i........
0000150: 55a1 d0f2 c32f 6a98 405f 620f 9288 923d  U..../j.@_b....=
0000160: 3180 3946 8616 26da 7c3b 2e0b d8f2 a8c2  1.9F..&.|;......
0000170: c342 7f56 74b0 06a2 99a7 6f6e a11b 6e74  .B.Vt.....on..nt
0000180: 6209 c549 410d 2159 c25d 4fbe 5c74 0016  b..IA.!Y.]O.\t..
0000190: 5042 4557 6974 684d 4435 416e 6454 7269  PBEWithMD5AndTri
00001a0: 706c 6544 4553 7400 1650 4245 5769 7468  pleDESt..PBEWith
00001b0: 4d44 3541 6e64 5472 6970 6c65 4445 53    MD5AndTripleDES