package notify import ( "b612.me/starcrypto" "errors" "fmt" "math/rand" "time" ) // Deprecated: ExchangeKey drives the legacy RSA-based key exchange flow. // Prefer UseModernPSKClient. func (c *ClientCommon) ExchangeKey(newKey []byte) error { pubKey, err := starcrypto.DecodeRsaPublicKey(c.handshakeRsaPubKey) if err != nil { return err } newSendKey, err := starcrypto.RSAEncrypt(pubKey, newKey) if err != nil { return err } data, err := c.sendWait(TransferMsg{ ID: 19961127, Key: "sirius", Value: newSendKey, Type: MSG_KEY_CHANGE, }, time.Second*10) if err != nil { return err } if string(data.Value) != "success" { return errors.New("cannot exchange new aes-key") } c.SecretKey = newKey time.Sleep(time.Millisecond * 100) return nil } // Deprecated: aesRsaHello is the legacy RSA-based key exchange bootstrap. func aesRsaHello(c Client) error { newAesKey := []byte(fmt.Sprintf("%d%d%d%s", time.Now().UnixNano(), rand.Int63(), rand.Int63(), "b612.me")) newAesKey = []byte(starcrypto.Md5Str(newAesKey)) return c.ExchangeKey(newAesKey) }