Menu

#10 IllegalArgumentException in HmacSha.verify

open
nobody
J2SSH (18)
5
2003-10-20
2003-10-20
No

Hello there.

The following exception will be raised in
Sun JDK 1.4.2_01 + Red Hat 2.1AS Japanese:

ERROR
com.sshtools.j2ssh.transport.TransportProtocolCommon -
The Transport Protocol thread failed
java.lang.IllegalArgumentException
at java.nio.Buffer.position(Buffer.java:218)
at java.nio.charset.CharsetDecoder.decode
(CharsetDecoder.java:575)
at java.lang.StringCoding$CharsetSD.decode
(StringCoding.java:186)
at java.lang.StringCoding.decode
(StringCoding.java:224)
at java.lang.StringCoding.decode
(StringCoding.java:230)
at java.lang.String.<init>(String.java:371)
at java.lang.String.<init>(String.java:390)
at
com.sshtools.j2ssh.transport.hmac.HmacSha.verify
(Unknown Source)
at
com.sshtools.j2ssh.transport.TransportProtocolInputStre
am.readMessage(Unknown Source)
at
com.sshtools.j2ssh.transport.TransportProtocolCommon.p
rocessMessages(Unknown Source)
at
com.sshtools.j2ssh.transport.TransportProtocolCommon.s
tartBinaryPacketProtocol(Unknown Source)
at
com.sshtools.j2ssh.transport.TransportProtocolCommon.r
un(Unknown Source)
at java.lang.Thread.run(Thread.java:534)

This problem doesn't happen in Windows XP Japanese.
However, I moved my little program that uses sftp
to Red Hat and this exception started to occur
when I try to transfer files.
This exception will be raised most of the time,
but not always.

It seems to me that the problem lies within
String initialization code of Sun's JDK.
I read somewhere on the Internet
that setting LANG to be C solves this problem
(not confirmed by me).

I looked at the portion of HmacSha.verify(),
and found out that:
1) it basically compares two binary arrays
2) but it instanciates a String instance
for both the operands
and realized that I could eliminate
the use of String class without
altering the functionality.

So, I replaced
String compare1 = new String(generated);
String compare2 = new String(data, data.length -
len, len);
boolean result = compare1.equals(compare2);
with
boolean result = true;
for (int i = 0; i < len; i++) {
if (generated[i] != data[data.length -
len + i]) {
result = false;
break;
}
}
and the problem has went away as far as I could tell.

By the way, since we are just comparing
two binary arrays here, I think
we just need to compare each byte from them
without creating unnecessary String instances.

Discussion

  • Kenichi Masuko

    Kenichi Masuko - 2003-10-20

    java file replacement

     
  • Kenichi Masuko

    Kenichi Masuko - 2003-10-20

    Logged In: YES
    user_id=890414

    I forgot to add that I first thought this problem could be the
    ssh server, and I tried my program with openssh-3.1p1-
    14.i386 and openssh-3.7.1p2 from www.openssh.org, but the
    exception occurred whichever version I try.

    And I doubt this problem happens in English versions of Linux.

     
  • Kenichi Masuko

    Kenichi Masuko - 2003-10-20

    Logged In: YES
    user_id=890414

    I forgot to add that I first thought this problem could be the
    ssh server, and I tried my program with openssh-3.1p1-
    14.i386 and openssh-3.7.1p2 from www.openssh.org, but the
    exception occurred whichever version I try.

    And I doubt this problem happens in English versions of Linux.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.