Skip to content

Commit

Permalink
Log auth attempts. (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc authored Dec 10, 2024
1 parent 4b11887 commit bd3de27
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/sip/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (c *Client) newCall(ctx context.Context, conf *config.Config, log logger.Lo
call := &outboundCall{
c: c,
log: log,
cc: c.newOutbound(id, URI{
cc: c.newOutbound(log, id, URI{
User: sipConf.from,
Host: sipConf.host,
Addr: contact.Addr,
Expand Down Expand Up @@ -516,7 +516,7 @@ func (c *outboundCall) transferCall(ctx context.Context, transferTo string, dial
return nil
}

func (c *Client) newOutbound(id LocalTag, from, contact URI) *sipOutbound {
func (c *Client) newOutbound(log logger.Logger, id LocalTag, from, contact URI) *sipOutbound {
from = from.Normalize()
fromHeader := &sip.FromHeader{
DisplayName: from.User,
Expand All @@ -528,6 +528,7 @@ func (c *Client) newOutbound(id LocalTag, from, contact URI) *sipOutbound {
}
fromHeader.Params.Add("tag", string(id))
return &sipOutbound{
log: log,
c: c,
id: id,
from: fromHeader,
Expand All @@ -537,6 +538,7 @@ func (c *Client) newOutbound(id LocalTag, from, contact URI) *sipOutbound {
}

type sipOutbound struct {
log logger.Logger
c *Client
id LocalTag
from *sip.FromHeader
Expand Down Expand Up @@ -648,6 +650,11 @@ authLoop:
authHeaderName = "Proxy-Authenticate"
authHeaderRespName = "Proxy-Authorization"
}
cid := ""
if h := resp.CallID(); h != nil {
cid = h.Value()
}
c.log.Infow("auth requested", "sipCallID", cid, "status", resp.StatusCode, "body", string(resp.Body()))
// auth required
if user == "" || pass == "" {
return nil, errors.New("server required auth, but no username or password was provided")
Expand Down
3 changes: 3 additions & 0 deletions pkg/sip/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ func LoggerWithParams(log logger.Logger, c Signaling) logger.Logger {
if tag := c.Tag(); tag != "" {
log = log.WithValues("sipTag", tag)
}
if cid := c.CallID(); cid != "" {
log = log.WithValues("sipCallID", cid)
}
return log
}

Expand Down

0 comments on commit bd3de27

Please sign in to comment.