Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using existing CSR - Error - Can not read key length from csr #614

Closed
TomFreudenberg opened this issue Feb 13, 2017 · 8 comments
Closed

Comments

@TomFreudenberg
Copy link

Hi, thanks for your tool!

I run in an issue when using existing CSR files. This occurs when using --signcsr or --showcsr. Those will stop with message:

Can not read key length from csr: file.csr

Code L3434

I have done some debug and found you regex was too sharp.

in function _readKeyLengthFromCSR() Code L980

You are grepping for "^ *Public-Key:.*" but the resulting output (in my case, openssl 0.9.8zh, Mac OSX) is RSA Public Key: (4096 bit) without a minus between Public Key and there can be tabs as well as spaces in front.

I changed you regex in Code L993 to:

echo "$_outcsr" | _egrep_o "^.*Public(-| )Key:.*" | cut -d '(' -f 2 | cut -d ' ' -f 1

Maybe you are interested in this.

Cheers
Tom

Neilpang pushed a commit that referenced this issue Feb 15, 2017
@Neilpang
Copy link
Member

fixed thank you.

@TomFreudenberg
Copy link
Author

Hi Neil @Neilpang please check my additional comment on your commit at 72af092#commitcomment-20894340

@Neilpang
Copy link
Member

@TomFreudenberg
Thanks, I saw your comment.

I will think about it later.

@Neilpang Neilpang reopened this Feb 15, 2017
Neilpang pushed a commit that referenced this issue Feb 20, 2017
@TomFreudenberg
Copy link
Author

Hi @Neilpang

thanks, that works for me.

Cheers
Tom

@TomFreudenberg
Copy link
Author

@Neilpang sorry did not work ... I hadn't updated your script first time test.

You Regex needs to be like

"^ *(RSA )?Public.Key:.*"

@JackWindows
Copy link

I think there is a mistake in the code right now:
In Code L1141

echo "$_outcsr" | tr "\t" " " | (_egrep_o "^ *Public.Key:.*" || _egrep_o "RSA Public.Key:.*") | cut -d '(' -f 2 | cut -d ' ' -f 1

The || operator here is wrong, you cannot re-read the piped text twice, so the latter part _egrep_o "RSA Public.Key:.*" will never return a match.
The right way to do this is changing

(_egrep_o "^ *Public.Key:.*" || _egrep_o "RSA Public.Key:.*")

to

while read line ; do ( ! ( echo $line |  _egrep_o "^ *Public.Key:.*" ) || ! ( echo $line | _egrep_o "RSA Public Key: .*")) ; done

@Neilpang
Copy link
Member

@JackWindows Thank you.
I will fix it soon.

@Neilpang
Copy link
Member

@JackWindows
fixed. please try again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants