Subject: | ::SSH2 can't read ssh-keygen private key |
I'm new to Crypt::DSA::Key::SSH2, so I may be off base.
My ssh-keygen creates a key that looks like:
Show quoted text
-----BEGIN DSA PRIVATE KEY-----
<the key>
-----END DSA PRIVATE KEY-----
But the deserialize method of ::SSH2 says:
19: chomp($param{Content});
20: my($head, $object, $content, $tail) = $param{Content} =~
21 m:(---- BEGIN ([^\n\-]+) ----)\n(.+)(---- END .*? ----)$:s;
Clearly that space before BEGIN and END cause problems.
Would it be more general to change this re to something like:
m:(----*?\s*BEGIN ([^\n\-]+)\s*----*)\n(.+?)(-+\s*END.*?----)$:s
As a test, I tried this. The first was real data (my key removed), the
second was, well, you'll see. But I tried to make the second so it
looked like what the original re was supposed to match.
DB<78> x $param{Content}
0 '-----BEGIN DSA PRIVATE KEY-----
key goes here
-----END DSA PRIVATE KEY-----'
DB<79> x $foo
0 '---- BEGIN FOO PRIVATE KEY ----
foo here
more foo here
---- END FOO PRIVATE KEY ----'
DB<80> x ($head, $object, $content, $tail) = $param{Content}
=~m:(----*?\s*BEGIN ([^\n\-]+)\s*----*)\n(.+?)(-+\s*END.*?----)$:s
0 '-----BEGIN DSA PRIVATE KEY-----'
1 'DSA PRIVATE KEY'
2 'key goes here
'
3 '-----END DSA PRIVATE KEY-----'
DB<81> x ($head, $object, $content, $tail) = $foo =~m:(----*?\s*BEGIN
([^\n\-]+)\s*----*)\n(.+?)(-+\s*END.*?----)$:s
0 '---- BEGIN FOO PRIVATE KEY ----'
1 'FOO PRIVATE KEY '
2 'foo here
more foo here
'
3 '---- END FOO PRIVATE KEY ----'
DB<82>