Browse Source

remove draft/bearer in favor of IRCV3BEARER

tags/v2.14.0-rc1
Shivaram Lingamneni 1 month ago
parent
commit
ed683bff79
6 changed files with 30 additions and 35 deletions
  1. 0
    6
      gencapdefs.py
  2. 5
    6
      irc/accounts.go
  3. 0
    4
      irc/caps/constants.go
  4. 1
    6
      irc/caps/defs.go
  5. 3
    13
      irc/config.go
  6. 21
    0
      irc/handlers.go

+ 0
- 6
gencapdefs.py View File

@@ -219,12 +219,6 @@ CAPDEFS = [
219 219
         url="https://github.com/ircv3/ircv3-specifications/pull/527",
220 220
         standard="proposed IRCv3",
221 221
     ),
222
-   CapDef(
223
-        identifier="Bearer",
224
-        name="draft/bearer",
225
-        url="https://gist.github.com/slingamn/4fabc7a3d5f335da7bb313a7f0648f37",
226
-        standard="proposed IRCv3",
227
-    ),
228 222
 ]
229 223
 
230 224
 def validate_defs():

+ 5
- 6
irc/accounts.go View File

@@ -20,7 +20,6 @@ import (
20 20
 	"github.com/tidwall/buntdb"
21 21
 	"github.com/xdg-go/scram"
22 22
 
23
-	"github.com/ergochat/ergo/irc/caps"
24 23
 	"github.com/ergochat/ergo/irc/connection_limits"
25 24
 	"github.com/ergochat/ergo/irc/email"
26 25
 	"github.com/ergochat/ergo/irc/migrations"
@@ -1398,10 +1397,6 @@ func (am *AccountManager) AuthenticateByPassphrase(client *Client, accountName s
1398 1397
 		}
1399 1398
 	}
1400 1399
 
1401
-	if strings.HasPrefix(accountName, caps.BearerTokenPrefix) {
1402
-		return am.AuthenticateByBearerToken(client, strings.TrimPrefix(accountName, caps.BearerTokenPrefix), passphrase)
1403
-	}
1404
-
1405 1400
 	if throttled, remainingTime := client.checkLoginThrottle(); throttled {
1406 1401
 		return &ThrottleError{remainingTime}
1407 1402
 	}
@@ -1448,11 +1443,14 @@ func (am *AccountManager) AuthenticateByBearerToken(client *Client, tokenType, t
1448 1443
 func (am *AccountManager) AuthenticateByOAuthBearer(client *Client, opts oauth2.OAuthBearerOptions) (err error) {
1449 1444
 	config := am.server.Config()
1450 1445
 
1451
-	// we need to check this here since we can get here via SASL PLAIN:
1452 1446
 	if !config.Accounts.OAuth2.Enabled {
1453 1447
 		return errFeatureDisabled
1454 1448
 	}
1455 1449
 
1450
+	if throttled, remainingTime := client.checkLoginThrottle(); throttled {
1451
+		return &ThrottleError{remainingTime}
1452
+	}
1453
+
1456 1454
 	var username string
1457 1455
 	if config.Accounts.AuthScript.Enabled && config.Accounts.OAuth2.AuthScript {
1458 1456
 		username, err = am.authenticateByOAuthBearerScript(client, config, opts)
@@ -2220,6 +2218,7 @@ var (
2220 2218
 		"EXTERNAL":      authExternalHandler,
2221 2219
 		"SCRAM-SHA-256": authScramHandler,
2222 2220
 		"OAUTHBEARER":   authOauthBearerHandler,
2221
+		"IRCV3BEARER":   authIRCv3BearerHandler,
2223 2222
 	}
2224 2223
 )
2225 2224
 

+ 0
- 4
irc/caps/constants.go View File

@@ -64,10 +64,6 @@ const (
64 64
 	BotTagName = "bot"
65 65
 	// https://ircv3.net/specs/extensions/chathistory
66 66
 	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*"
71 67
 )
72 68
 
73 69
 func init() {

+ 1
- 6
irc/caps/defs.go View File

@@ -7,7 +7,7 @@ package caps
7 7
 
8 8
 const (
9 9
 	// number of recognized capabilities:
10
-	numCapabs = 35
10
+	numCapabs = 34
11 11
 	// length of the uint32 array that represents the bitset:
12 12
 	bitsetLen = 2
13 13
 )
@@ -41,10 +41,6 @@ const (
41 41
 	// https://github.com/ircv3/ircv3-specifications/pull/435
42 42
 	AccountRegistration Capability = iota
43 43
 
44
-	// Bearer is the proposed IRCv3 capability named "draft/bearer":
45
-	// https://gist.github.com/slingamn/4fabc7a3d5f335da7bb313a7f0648f37
46
-	Bearer Capability = iota
47
-
48 44
 	// ChannelRename is the draft IRCv3 capability named "draft/channel-rename":
49 45
 	// https://ircv3.net/specs/extensions/channel-rename
50 46
 	ChannelRename Capability = iota
@@ -164,7 +160,6 @@ var (
164 160
 		"cap-notify",
165 161
 		"chghost",
166 162
 		"draft/account-registration",
167
-		"draft/bearer",
168 163
 		"draft/channel-rename",
169 164
 		"draft/chathistory",
170 165
 		"draft/event-playback",

+ 3
- 13
irc/config.go View File

@@ -1402,6 +1402,9 @@ func LoadConfig(filename string) (config *Config, err error) {
1402 1402
 		if config.Accounts.OAuth2.Enabled {
1403 1403
 			saslCapValues = append(saslCapValues, "OAUTHBEARER")
1404 1404
 		}
1405
+		if config.Accounts.OAuth2.Enabled || config.Accounts.JWTAuth.Enabled {
1406
+			saslCapValues = append(saslCapValues, "IRCV3BEARER")
1407
+		}
1405 1408
 		config.Server.capValues[caps.SASL] = strings.Join(saslCapValues, ",")
1406 1409
 	} else {
1407 1410
 		config.Server.supportedCaps.Disable(caps.SASL)
@@ -1419,19 +1422,6 @@ func LoadConfig(filename string) (config *Config, err error) {
1419 1422
 		return nil, fmt.Errorf("oauth2 is enabled with auth-script, but no auth-script is enabled")
1420 1423
 	}
1421 1424
 
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
-
1435 1425
 	if !config.Accounts.Registration.Enabled {
1436 1426
 		config.Server.supportedCaps.Disable(caps.AccountRegistration)
1437 1427
 	} else {

+ 21
- 0
irc/handlers.go View File

@@ -306,6 +306,27 @@ func authPlainHandler(server *Server, client *Client, session *Session, value []
306 306
 	return false
307 307
 }
308 308
 
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.Split(value, []byte{'\000'})
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
+
309 330
 func sendAuthErrorResponse(client *Client, rb *ResponseBuffer, err error) {
310 331
 	msg := authErrorToMessage(client.server, err)
311 332
 	rb.Add(nil, client.server.name, ERR_SASLFAIL, client.nick, fmt.Sprintf("%s: %s", client.t("SASL authentication failed"), client.t(msg)))

Loading…
Cancel
Save