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

fix: Try all public keys #115

Merged
merged 1 commit into from
Oct 12, 2022
Merged

Conversation

tdakkota
Copy link

Updates #111.

@waybackarchiver
Copy link
Contributor

I got an error after running this patch:

$ go run examples/auth/main.go 1001101111
Downloading public keys from https://git.io/JtImk, this can be insecure
panic: key can't be nil

goroutine 1 [running]:
github.com/xelaj/go-dry.PanicIf(...)
	/usr/local/src/go/pkg/mod/github.com/xelaj/[email protected]/errors.go:25
github.com/xelaj/mtproto/internal/keys.RSAFingerprint(0xc000453b60)
	/usr/local/src/go/src/github.com/replaced/mtproto/internal/keys/keys.go:27 +0x325
github.com/xelaj/mtproto.(*MTProto).makeAuthKey(0xc0000cd320)
	/usr/local/src/go/src/github.com/replaced/mtproto/handshake.go:42 +0x1a7
github.com/xelaj/mtproto.(*MTProto).CreateConnection(0xc0000cd320)
	/usr/local/src/go/src/github.com/replaced/mtproto/mtproto.go:153 +0x95
github.com/xelaj/mtproto/telegram.NewClient({{0xc00003e340, 0x38}, {0x76eb0b, 0x12}, {0xc00003e380, 0x3e}, {0x0, 0x0}, {0x0, 0x0}, ...})
	/usr/local/src/go/src/github.com/replaced/mtproto/telegram/common.go:85 +0x325
main.main()
	/usr/local/src/go/src/github.com/replaced/mtproto/examples/auth/main.go:33 +0x218
exit status 2

Maybe we can skip if publicKey is nil.

diff --git a/handshake.go b/handshake.go
index fe31a43..00cb3e6 100644
--- a/handshake.go
+++ b/handshake.go
@@ -39,6 +39,9 @@ func (m *MTProto) makeAuthKey() error { // nolint don't know how to make method
 
        var key *rsa.PublicKey
        for _, publicKey := range m.publicKeys {
+               if publicKey == nil {
+                       continue
+               }
                fp := keys.RSAFingerprint(publicKey)
                for _, b := range res.Fingerprints {
                        if uint64(b) == binary.LittleEndian.Uint64(fp) {

Copy link
Member

@quenbyako quenbyako left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks!

@quenbyako quenbyako changed the base branch from main to dev October 12, 2022 19:18
@quenbyako quenbyako changed the title fix: try all public keys ✨ Try all public keys Oct 12, 2022
@quenbyako quenbyako changed the title ✨ Try all public keys fix: Try all public keys Oct 12, 2022
@quenbyako quenbyako merged commit 95c4542 into xelaj:dev Oct 12, 2022
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

Successfully merging this pull request may close these issues.

3 participants