Compare commits

...

2 Commits

Author SHA1 Message Date
HimbeerserverDE 90c4865b24
Remote media server support 6 months ago
HimbeerserverDE f632c108ae
Fix SRP identifier casing 6 months ago
  1. 37
      content.go
  2. 18
      process.go

37
content.go

@ -50,7 +50,8 @@ type contentConn struct {
nodeDefs []mt.NodeDef
media []mediaFile
media []mediaFile
remotes []string
}
func (cc *contentConn) state() clientState {
@ -173,7 +174,9 @@ func handleContent(cc *contentConn) {
NoSHA1: true,
})
case mt.FirstSRP:
salt, verifier, err := srp.NewClient([]byte(cc.userName), []byte{})
id := strings.ToLower(cc.userName)
salt, verifier, err := srp.NewClient([]byte(id), []byte{})
if err != nil {
cc.log("->", err)
break
@ -194,7 +197,9 @@ func handleContent(cc *contentConn) {
break
}
cc.auth.srpK, err = srp.CompleteHandshake(cc.auth.srpA, cc.auth.a, []byte(cc.userName), []byte{}, cmd.Salt, cmd.B)
id := strings.ToLower(cc.userName)
cc.auth.srpK, err = srp.CompleteHandshake(cc.auth.srpA, cc.auth.a, []byte(id), []byte{}, cmd.Salt, cmd.B)
if err != nil {
cc.log("->", err)
break
@ -247,6 +252,11 @@ func handleContent(cc *contentConn) {
})
}
cc.remotes = strings.Split(cmd.URL, ",")
for k, v := range cc.remotes {
cc.remotes[k] = strings.TrimSpace(v)
}
cc.SendCmd(&mt.ToSrvReqMedia{Filenames: filenames})
case *mt.ToCltMedia:
for _, f := range cmd.Files {
@ -464,7 +474,25 @@ func muxMedia(conns []*contentConn) []mediaFile {
return media
}
func muxContent(userName string) (itemDefs []mt.ItemDef, aliases []struct{ Alias, Orig string }, nodeDefs []mt.NodeDef, p0Map param0Map, p0SrvMap param0SrvMap, media []mediaFile, err error) {
func muxRemotes(conns []*contentConn) []string {
remotes := make(map[string]struct{})
for _, cc := range conns {
<-cc.done()
for _, v := range cc.remotes {
remotes[v] = struct{}{}
}
}
urls := make([]string, 0, len(remotes))
for remote := range remotes {
urls = append(urls, remote)
}
return urls
}
func muxContent(userName string) (itemDefs []mt.ItemDef, aliases []struct{ Alias, Orig string }, nodeDefs []mt.NodeDef, p0Map param0Map, p0SrvMap param0SrvMap, media []mediaFile, remotes []string, err error) {
var conns []*contentConn
for _, srv := range Conf().Servers {
var addr *net.UDPAddr
@ -492,6 +520,7 @@ func muxContent(userName string) (itemDefs []mt.ItemDef, aliases []struct{ Alias
itemDefs, aliases = muxItemDefs(conns)
nodeDefs, p0Map, p0SrvMap = muxNodeDefs(conns)
media = muxMedia(conns)
remotes = muxRemotes(conns)
return
}

18
process.go

@ -349,8 +349,9 @@ func (cc *ClientConn) process(pkt mt.Pkt) {
return
case *mt.ToSrvInit2:
var remotes []string
var err error
cc.itemDefs, cc.aliases, cc.nodeDefs, cc.p0Map, cc.p0SrvMap, cc.media, err = muxContent(cc.Name())
cc.itemDefs, cc.aliases, cc.nodeDefs, cc.p0Map, cc.p0SrvMap, cc.media, remotes, err = muxContent(cc.Name())
if err != nil {
cc.Log("<-", err.Error())
cc.Kick("Content multiplexing failed.")
@ -374,7 +375,10 @@ func (cc *ClientConn) process(pkt mt.Pkt) {
})
}
cc.SendCmd(&mt.ToCltAnnounceMedia{Files: files})
cc.SendCmd(&mt.ToCltAnnounceMedia{
Files: files,
URL: strings.Join(remotes, ","),
})
cc.lang = cmd.Lang
var csmrf mt.CSMRestrictionFlags
@ -487,7 +491,9 @@ func (sc *ServerConn) process(pkt mt.Pkt) {
NoSHA1: true,
})
case mt.FirstSRP:
salt, verifier, err := srp.NewClient([]byte(clt.name), []byte{})
id := strings.ToLower(clt.Name())
salt, verifier, err := srp.NewClient([]byte(id), []byte{})
if err != nil {
sc.Log("->", err)
return
@ -510,14 +516,16 @@ func (sc *ServerConn) process(pkt mt.Pkt) {
return
}
id := strings.ToLower(clt.Name())
var err error
sc.auth.srpK, err = srp.CompleteHandshake(sc.auth.srpA, sc.auth.a, []byte(clt.name), []byte{}, cmd.Salt, cmd.B)
sc.auth.srpK, err = srp.CompleteHandshake(sc.auth.srpA, sc.auth.a, []byte(id), []byte{}, cmd.Salt, cmd.B)
if err != nil {
sc.Log("->", err)
return
}
M := srp.ClientProof([]byte(clt.name), cmd.Salt, sc.auth.srpA, cmd.B, sc.auth.srpK)
M := srp.ClientProof([]byte(clt.Name()), cmd.Salt, sc.auth.srpA, cmd.B, sc.auth.srpK)
if M == nil {
sc.Log("<-", "SRP safety check fail")
return

Loading…
Cancel
Save