Skip to content

Commit adfd225

Browse files
authored
Merge pull request #397 from fancycode/turn_username_password
Support fixed username/password TURN credentials.
2 parents 3645248 + d0d3348 commit adfd225

File tree

4 files changed

+39
-20
lines changed

4 files changed

+39
-20
lines changed

go/channelling/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ type Config struct {
1414
Renegotiation bool // Renegotiation flag
1515
StunURIs []string // STUN server URIs
1616
TurnURIs []string // TURN server URIs
17+
TurnUsername string // Username for TURN server
18+
TurnPassword string // Password for TURN server
1719
Tokens bool // True when we got a tokens file
1820
Version string // Server version number
1921
UsersEnabled bool // Flag if users are enabled

go/channelling/hub.go

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,29 +92,38 @@ func (h *hub) ClientInfo(details bool) (clientCount int, sessions map[string]*Da
9292
}
9393

9494
func (h *hub) CreateTurnData(sender Sender, session *Session) *DataTurn {
95-
// Create turn data credentials for shared secret auth with TURN
96-
// server. See http://tools.ietf.org/html/draft-uberti-behave-turn-rest-00
97-
// and https://code.google.com/p/rfc5766-turn-server/ REST API auth
98-
// and set shared secret in TURN server with static-auth-secret.
99-
if len(h.turnSecret) == 0 {
100-
return &DataTurn{}
95+
if len(h.turnSecret) > 0 {
96+
// Create turn data credentials for shared secret auth with TURN
97+
// server. See http://tools.ietf.org/html/draft-uberti-behave-turn-rest-00
98+
// and https://code.google.com/p/rfc5766-turn-server/ REST API auth
99+
// and set shared secret in TURN server with static-auth-secret.
100+
id := session.Id
101+
bar := sha256.New()
102+
bar.Write([]byte(id))
103+
id = base64.StdEncoding.EncodeToString(bar.Sum(nil))
104+
foo := hmac.New(sha1.New, h.turnSecret)
105+
expiration := int32(time.Now().Unix()) + turnTTL
106+
user := fmt.Sprintf("%d:%s", expiration, id)
107+
foo.Write([]byte(user))
108+
password := base64.StdEncoding.EncodeToString(foo.Sum(nil))
109+
110+
return &DataTurn{
111+
Username: user,
112+
Password: password,
113+
Ttl: turnTTL,
114+
Urls: h.config.TurnURIs,
115+
}
101116
}
102-
id := session.Id
103-
bar := sha256.New()
104-
bar.Write([]byte(id))
105-
id = base64.StdEncoding.EncodeToString(bar.Sum(nil))
106-
foo := hmac.New(sha1.New, h.turnSecret)
107-
expiration := int32(time.Now().Unix()) + turnTTL
108-
user := fmt.Sprintf("%d:%s", expiration, id)
109-
foo.Write([]byte(user))
110-
password := base64.StdEncoding.EncodeToString(foo.Sum(nil))
111117

112-
return &DataTurn{
113-
Username: user,
114-
Password: password,
115-
Ttl: turnTTL,
116-
Urls: h.config.TurnURIs,
118+
if h.config.TurnUsername != "" && h.config.TurnPassword != "" {
119+
return &DataTurn{
120+
Username: h.config.TurnUsername,
121+
Password: h.config.TurnPassword,
122+
Urls: h.config.TurnURIs,
123+
}
117124
}
125+
126+
return &DataTurn{}
118127
}
119128

120129
func (h *hub) GetSession(id string) (session *Session, ok bool) {

go/channelling/server/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ func NewConfig(container phoenix.Container, tokens bool) (*channelling.Config, e
128128
Renegotiation: container.GetBoolDefault("app", "renegotiation", false),
129129
StunURIs: stunURIs,
130130
TurnURIs: turnURIs,
131+
TurnUsername: container.GetStringDefault("app", "turnUsername", ""),
132+
TurnPassword: container.GetStringDefault("app", "turnPassword", ""),
131133
Tokens: tokens,
132134
Version: version,
133135
UsersEnabled: container.GetBoolDefault("users", "enabled", false),

server.conf.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ listen = 127.0.0.1:8080
5757
; See http://tools.ietf.org/html/draft-uberti-behave-turn-rest-00 for details.
5858
; A supported TURN server is https://code.google.com/p/rfc5766-turn-server/.
5959
;turnSecret = the-default-turn-shared-secret-do-not-keep
60+
; Fixed username/password credentials to be used for the TURN server.
61+
; IMPORTANT: This will give all users connected to the spreed-webrtc service
62+
; access to the credentials, so in almost all cases the shared secret mode
63+
; should be used instead!!
64+
;turnUsername = the-turn-username
65+
;turnPassword = the-turn-secret
6066
; Enable renegotiation support. Set to true to tell clients that they can
6167
; renegotiate peer connections when required. Firefox support is not complete,
6268
; so do not enable if you want compatibility with Firefox clients.

0 commit comments

Comments
 (0)