jschauma/jass

panic index out of range

Closed this issue · 4 comments

I'm not sure how I managed to make a jass file, it looked right, but produced:

rindge$ ./bin/jass -d <  /tmp/test.jass 
Enter pass phrase for /Users/seph/.ssh/id_rsa: 
panic: runtime error: index out of range

goroutine 1 [running]:
main.identifyCorrectSessionKeyData(0xc82014f650, 0x2f, 0xc82014f740, 0x0, 0x0, 0x0)
    /Users/seph/checkouts/secrets-jass-gpg/bin/jass.go:801 +0x35f
main.decrypt()
    /Users/seph/checkouts/secrets-jass-gpg/bin/jass.go:228 +0x1e3
main.main()
    /Users/seph/checkouts/secrets-jass-gpg/bin/jass.go:129 +0xc0

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    /usr/local/Cellar/go/1.5.1/libexec/src/runtime/asm_amd64.s:1696 +0x1

goroutine 20 [syscall]:
os/signal.loop()
    /usr/local/Cellar/go/1.5.1/libexec/src/os/signal/signal_unix.go:22 +0x18
created by os/signal.init.1
    /usr/local/Cellar/go/1.5.1/libexec/src/os/signal/signal_unix.go:28 +0x37

goroutine 21 [select, locked to thread]:
runtime.gopark(0x422a40, 0xc820023f28, 0x392068, 0x6, 0x3f418, 0x2)
    /usr/local/Cellar/go/1.5.1/libexec/src/runtime/proc.go:185 +0x163
runtime.selectgoImpl(0xc820023f28, 0x0, 0x18)
    /usr/local/Cellar/go/1.5.1/libexec/src/runtime/select.go:392 +0xa64
runtime.selectgo(0xc820023f28)
    /usr/local/Cellar/go/1.5.1/libexec/src/runtime/select.go:212 +0x12
runtime.ensureSigM.func1()
    /usr/local/Cellar/go/1.5.1/libexec/src/runtime/signal1_unix.go:227 +0x323
runtime.goexit()
    /usr/local/Cellar/go/1.5.1/libexec/src/runtime/asm_amd64.s:1696 +0x1

goroutine 22 [chan receive]:
main.getpassFromUser.func1(0xc82006e0c0)
    /Users/seph/checkouts/secrets-jass-gpg/bin/jass.go:775 +0x36
created by main.getpassFromUser
    /Users/seph/checkouts/secrets-jass-gpg/bin/jass.go:778 +0x3af

I will try to reproduce.

For reference:

rindge:bin seph$ cat /tmp/broken.jass
begin-base64 600 message
U2FsdGVkX19CSlNMQ7DzERUnUxgNHHX0YTBJumFfDw0=
====
begin-base64 600 ssh-keys/seph/id_rsa.pub-49:84:63:1e:ce:c7:87:99:4d:0f:fb:66:1c:6f:30:da
cPQNk3wKceAkx+QosYmiGWLEJf1AUW0qZcOlaAMPC0t5SdY3JJWlIBvnrvDOPlKjlGm7CzWOAh9u
0SMv5JBE23fH/Kjx2RPWzjnZM4bKzhXWHBHz6ATkBUp1CHoxJ0zS9T/TAcnv//ANB+zP4x8c9ozW
ldsWvsKk6u/7mty73Zdje5xubyzstKM6K2PJtD42QdWUwS92LdSftI6BoWZy07B5dl33vslMAkGq
IdjDuoFaz/kGBcBuaI/tfnbje3+1VSeSleOLEXH7n3xyC0pK5qSJpxFZTDg3HMn7lkUQspXvtGq0
sTQxTi9SCKq1TsYTlCCNdaRKyb7Lz8wREfm1EEc1C16BlnxXY57y/KWmJPFpCnjePw+1Ik7B8Oxq
5MvC5mOd0zLt7YtqVdx1sbrn+yx7RrrJoiGZKAqYMuBZCkHdflryKfM7y9n5Xm94d3s+8rWUN0VB
EYkHvww2qKalao2J4NZ5FmzOxRsiKo26Ps3Epbnzrif74qEn7L57PrJmSYz5cutesC5kq7CPjcyY
Jhic5Mxl47HbDiQqEoKyFa6hkbLimb6Ai7pzOx+K4TFalcccay74mkQsqV6GB/DW06MrpFreo0td
iHCEuNWDG67iukLGZTmp+veKPL+/VpuXNbrmUEri+xc0FvR92QuH/XwkN+P6ccJqjvIiWIVigDs=
====
begin-base64 600 version
VkVSU0lPTjogNC4wCg==
====

The issue is this part in the code:

        /* fingerprints may be "user-fi:ng:er:pr:in:t" or "fi:ng:er:pr:in:t" */
        fp_pattern := regexp.MustCompile("^([^-]+-)?(?P<fp>[a-f0-9:]+)")

        for r, key := range keys {
                fp := fp_pattern.FindStringSubmatch(r)[2]

That is, it's looking for "user-fi:ng:er:pr:in:t", but your line is:

begin-base64 600 ssh-keys/seph/id_rsa.pub-49:84:63:1e:ce:c7:87:99:4d:0f:fb:66:1c:6f:30:da

ie, the first dash is in "ssh-keys".

I'll need to make it more flexible in the 'name' portion of the key. I'll try to make time this weekend to fix this.

Awesome, glad you found it. Gotta love serialization bugs.

Well, if the fingerprint is a fixed length, it's not too hard. Variable length fingerprints would have a much gnarlier regex.

Resolved by PR#12. Version bumped, changelog updated.