owpengram-server/internal/rpc/phone_dh.go

39 lines
1.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package rpc
import (
"context"
"github.com/iamxvbaba/td/tg"
appphone "telesrv/internal/app/phone"
)
// onMessagesGetDhConfig 下发私聊通话(及未来 secret chat的 DH 参数。
//
// 契约TDesktop calls_instance.cpp updateDhConfig
// - p/g 必须过 MTP::IsPrimeAndGood——用官方 2048-bit prime + g=3 走白名单快速路径;
// - random 字节数必须与请求的 random_length 一致;
// - 客户端缓存命中version 相同)时返回 dhConfigNotModified只补新随机数。
func (r *Router) onMessagesGetDhConfig(ctx context.Context, req *tg.MessagesGetDhConfigRequest) (tg.MessagesDhConfigClass, error) {
if req == nil {
return nil, inputRequestInvalidErr()
}
if _, ok, err := r.currentUserID(ctx); err != nil {
return nil, internalErr()
} else if !ok {
return nil, authKeyUnregisteredErr()
}
random, err := appphone.DHRandom(req.RandomLength)
if err != nil {
return nil, internalErr()
}
if req.Version == appphone.DHConfigVersion {
return &tg.MessagesDhConfigNotModified{Random: random}, nil
}
return &tg.MessagesDhConfig{
G: appphone.DHG,
P: appphone.DHPrime(),
Version: appphone.DHConfigVersion,
Random: random,
}, nil
}