MiniDNS / minidns

DNS library for Android and Java SE
Other
226 stars 61 forks source link

Fix DSA ASN.1 encoding #118

Closed Flowdalic closed 2 years ago

Flowdalic commented 3 years ago

Marvin suggests the following untested code

         byte[] r = new byte[LENGTH + 1];
         dis.readFully(r, 1, LENGTH);
         int roff = 0;
         while(roff < LENGTH && r[roff] == 0 && r[roff + 1] < 0) roff++;

         byte[] s = new byte[LENGTH + 1];
         dis.readFully(s, 1, LENGTH);
         int soff = 0;
         while(soff < LENGTH && s[soff] == 0 && r[soff + 1] < 0) soff++;

         dos.writeByte(0x30);         dos.writeByte(r.length - roff + s.length - soff + 4);

         dos.writeByte(0x2);
         dos.writeByte(r.length - roff);
         dos.write(r, roff, r.length - roff);

         dos.writeByte(0x2);
         dos.writeByte(s.length - soff);
         dos.write(s, soff, s.length - soff);