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

asn1: structure error: tags don't match #11

Closed
lancechentw opened this issue May 11, 2015 · 16 comments
Closed

asn1: structure error: tags don't match #11

lancechentw opened this issue May 11, 2015 · 16 comments

Comments

@lancechentw
Copy link

Below is what I got, I think it is different from #4

rtop: asn1: structure error: tags don't match (16 vs {class:0 tag:0 length:28 isCompound:false}) {optional:false explicit:false application:false defaultValue:<nil> tag:<nil> stringType:0 set:false omitEmpty:false} pkcs1PrivateKey @2
Background info

Commit hash: ed16e84
uname: Linux foobar 4.0.1-1-ARCH #1 SMP PREEMPT Wed Apr 29 12:00:26 CEST 2015 x86_64 GNU/Linux
openssh: 6.8p1
openssl: 1.0.2a

@mdevan
Copy link
Contributor

mdevan commented May 11, 2015

Same as #13. Repeating what I posted there, could you try this?


Hmm, maybe it is picking up the key file auth method first, before the ssh-agent method. Can you try an experiment please?

  • comment out line 118 in sshhelper.go: auths = addPasswordAuth(auths)
  • recompile (make)
  • try again?

@peterbe
Copy link

peterbe commented May 11, 2015

I have the same error. I tried commenting out line 118 and recompiled and it didn't solve the problem.

I'm on OSX.

@peterbe
Copy link

peterbe commented May 11, 2015

By the way, I encountered that error with and without the -i flag.

@lancechentw
Copy link
Author

Commenting out line 118 does not work for me, either running rtop without ssh-agent.

I think it fails at ans1.Unmarshal() in ParsePKCS1PrivateKey
https://golang.org/src/crypto/x509/pkcs1.go?h=ParsePKCS1PrivateKey#L41

@lancechentw
Copy link
Author

I found that 512-bit RSA works, while 2048-bit RSA fails.

@lancechentw
Copy link
Author

#11 (comment) is not correct. It is not 2048-bit RSA that fails, it is a key-pair with passphrase that fails.

@lancechentw
Copy link
Author

Do DecryptPEMBlock() like this after pem.Decode()
https://golang.org/src/crypto/x509/pem_decrypt_test.go#L15

Also, use IsEncryptedPEMBlock() to determine if decryption is needed.

@mdevan
Copy link
Contributor

mdevan commented May 13, 2015

Please check with commit f753d19. With this rtop will natively support encrypted private keys, and also support auth via ssh-agent correctly.

@peterbe
Copy link

peterbe commented May 13, 2015

Building this version, now I no longer get that same error @Lance0312 got. But instead I get a "Key passphrase:" prompt

:~/dev/GO/rtop (master=)$ ./rtop [email protected]
Key passphrase:
^C

This works though without prompting me for a passphrase:

:~/dev/GO/rtop (master=)$ ssh [email protected]

@mdevan
Copy link
Contributor

mdevan commented May 13, 2015

@peterbe is your ~/.ssh/id_rsa encrypted?

@peterbe
Copy link

peterbe commented May 13, 2015

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,4AD650ED3EC480B5....

........

@peterbe
Copy link

peterbe commented May 13, 2015

so, plain text I guess

@lancechentw
Copy link
Author

@mdevan, f753d19 works great. I was working on to build something like getpass(), didn't know passwordCallback() could simply do the job ;D

I think @peterbe uses ssh-agent, am I correct? The auth order changed in f753d19 breaks how it should work. If ssh-agent has credentials cached, it should be used for auth first. Then asks user for passphrase if there's no credential cached.

@mdevan
Copy link
Contributor

mdevan commented May 14, 2015

@Lance0312 There is a catch in the auth order. The code in golang.org/x/crypto/ssh/client_auth.go#clientAuthenticate assumes that there is only one callback per auth type (e.g. "publickey"). So as it stands, either the agent or the key would work, but not both (as a superset). Will fix soon.

@lancechentw
Copy link
Author

@mdevan, got it. I am closing this issue since we have encrypted key pair support now. @peterbe, would you please open another issue for your problem?

@mdevan
Copy link
Contributor

mdevan commented May 20, 2015

Try with the latest commit ba5b35e. This improves the auth method handling.

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