Skip to content

Commit 54ca659

Browse files
authored
Merge pull request #2158 from slingamn/ircv3bearer.2
remove draft/bearer in favor of IRCV3BEARER
2 parents 5ee32cd + 794b4a2 commit 54ca659

File tree

6 files changed

+30
-35
lines changed

6 files changed

+30
-35
lines changed

gencapdefs.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,6 @@
219219
url="https://github.com/ircv3/ircv3-specifications/pull/527",
220220
standard="proposed IRCv3",
221221
),
222-
CapDef(
223-
identifier="Bearer",
224-
name="draft/bearer",
225-
url="https://gist.github.com/slingamn/4fabc7a3d5f335da7bb313a7f0648f37",
226-
standard="proposed IRCv3",
227-
),
228222
]
229223

230224
def validate_defs():

irc/accounts.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/tidwall/buntdb"
2121
"github.com/xdg-go/scram"
2222

23-
"github.com/ergochat/ergo/irc/caps"
2423
"github.com/ergochat/ergo/irc/connection_limits"
2524
"github.com/ergochat/ergo/irc/email"
2625
"github.com/ergochat/ergo/irc/migrations"
@@ -1398,10 +1397,6 @@ func (am *AccountManager) AuthenticateByPassphrase(client *Client, accountName s
13981397
}
13991398
}
14001399

1401-
if strings.HasPrefix(accountName, caps.BearerTokenPrefix) {
1402-
return am.AuthenticateByBearerToken(client, strings.TrimPrefix(accountName, caps.BearerTokenPrefix), passphrase)
1403-
}
1404-
14051400
if throttled, remainingTime := client.checkLoginThrottle(); throttled {
14061401
return &ThrottleError{remainingTime}
14071402
}
@@ -1448,11 +1443,14 @@ func (am *AccountManager) AuthenticateByBearerToken(client *Client, tokenType, t
14481443
func (am *AccountManager) AuthenticateByOAuthBearer(client *Client, opts oauth2.OAuthBearerOptions) (err error) {
14491444
config := am.server.Config()
14501445

1451-
// we need to check this here since we can get here via SASL PLAIN:
14521446
if !config.Accounts.OAuth2.Enabled {
14531447
return errFeatureDisabled
14541448
}
14551449

1450+
if throttled, remainingTime := client.checkLoginThrottle(); throttled {
1451+
return &ThrottleError{remainingTime}
1452+
}
1453+
14561454
var username string
14571455
if config.Accounts.AuthScript.Enabled && config.Accounts.OAuth2.AuthScript {
14581456
username, err = am.authenticateByOAuthBearerScript(client, config, opts)
@@ -2220,6 +2218,7 @@ var (
22202218
"EXTERNAL": authExternalHandler,
22212219
"SCRAM-SHA-256": authScramHandler,
22222220
"OAUTHBEARER": authOauthBearerHandler,
2221+
"IRCV3BEARER": authIRCv3BearerHandler,
22232222
}
22242223
)
22252224

irc/caps/constants.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ const (
6464
BotTagName = "bot"
6565
// https://ircv3.net/specs/extensions/chathistory
6666
ChathistoryTargetsBatchType = "draft/chathistory-targets"
67-
68-
// draft/bearer defines this prefix namespace for authcids, enabling tunneling bearer tokens
69-
// in SASL PLAIN:
70-
BearerTokenPrefix = "*bearer*"
7167
)
7268

7369
func init() {

irc/caps/defs.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package caps
77

88
const (
99
// number of recognized capabilities:
10-
numCapabs = 35
10+
numCapabs = 34
1111
// length of the uint32 array that represents the bitset:
1212
bitsetLen = 2
1313
)
@@ -41,10 +41,6 @@ const (
4141
// https://github.com/ircv3/ircv3-specifications/pull/435
4242
AccountRegistration Capability = iota
4343

44-
// Bearer is the proposed IRCv3 capability named "draft/bearer":
45-
// https://gist.github.com/slingamn/4fabc7a3d5f335da7bb313a7f0648f37
46-
Bearer Capability = iota
47-
4844
// ChannelRename is the draft IRCv3 capability named "draft/channel-rename":
4945
// https://ircv3.net/specs/extensions/channel-rename
5046
ChannelRename Capability = iota
@@ -164,7 +160,6 @@ var (
164160
"cap-notify",
165161
"chghost",
166162
"draft/account-registration",
167-
"draft/bearer",
168163
"draft/channel-rename",
169164
"draft/chathistory",
170165
"draft/event-playback",

irc/config.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,9 @@ func LoadConfig(filename string) (config *Config, err error) {
14021402
if config.Accounts.OAuth2.Enabled {
14031403
saslCapValues = append(saslCapValues, "OAUTHBEARER")
14041404
}
1405+
if config.Accounts.OAuth2.Enabled || config.Accounts.JWTAuth.Enabled {
1406+
saslCapValues = append(saslCapValues, "IRCV3BEARER")
1407+
}
14051408
config.Server.capValues[caps.SASL] = strings.Join(saslCapValues, ",")
14061409
} else {
14071410
config.Server.supportedCaps.Disable(caps.SASL)
@@ -1419,19 +1422,6 @@ func LoadConfig(filename string) (config *Config, err error) {
14191422
return nil, fmt.Errorf("oauth2 is enabled with auth-script, but no auth-script is enabled")
14201423
}
14211424

1422-
var bearerCapValues []string
1423-
if config.Accounts.OAuth2.Enabled {
1424-
bearerCapValues = append(bearerCapValues, "oauth2")
1425-
}
1426-
if config.Accounts.JWTAuth.Enabled {
1427-
bearerCapValues = append(bearerCapValues, "jwt")
1428-
}
1429-
if len(bearerCapValues) != 0 {
1430-
config.Server.capValues[caps.Bearer] = strings.Join(bearerCapValues, ",")
1431-
} else {
1432-
config.Server.supportedCaps.Disable(caps.Bearer)
1433-
}
1434-
14351425
if !config.Accounts.Registration.Enabled {
14361426
config.Server.supportedCaps.Disable(caps.AccountRegistration)
14371427
} else {

irc/handlers.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,27 @@ func authPlainHandler(server *Server, client *Client, session *Session, value []
306306
return false
307307
}
308308

309+
// AUTHENTICATE IRCV3BEARER
310+
func authIRCv3BearerHandler(server *Server, client *Client, session *Session, value []byte, rb *ResponseBuffer) bool {
311+
defer session.sasl.Clear()
312+
313+
// <authzid> \x00 <type> \x00 <token>
314+
splitValue := bytes.SplitN(value, []byte{'\000'}, 3)
315+
if len(splitValue) != 3 {
316+
rb.Add(nil, server.name, ERR_SASLFAIL, client.Nick(), client.t("SASL authentication failed: Invalid auth blob"))
317+
return false
318+
}
319+
320+
err := server.accounts.AuthenticateByBearerToken(client, string(splitValue[1]), string(splitValue[2]))
321+
if err != nil {
322+
sendAuthErrorResponse(client, rb, err)
323+
return false
324+
}
325+
326+
sendSuccessfulAccountAuth(nil, client, rb, true)
327+
return false
328+
}
329+
309330
func sendAuthErrorResponse(client *Client, rb *ResponseBuffer, err error) {
310331
msg := authErrorToMessage(client.server, err)
311332
rb.Add(nil, client.server.name, ERR_SASLFAIL, client.nick, fmt.Sprintf("%s: %s", client.t("SASL authentication failed"), client.t(msg)))

0 commit comments

Comments
 (0)