mtproto
mtproto copied to clipboard
fix: try all public keys
Updates #111.
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) {