Преглед на файлове

Merge pull request #2158 from slingamn/ircv3bearer.2

remove draft/bearer in favor of IRCV3BEARER
tags/v2.14.0-rc1
Shivaram Lingamneni преди 1 месец
родител
ревизия
54ca659e57
No account linked to committer's email address
променени са 6 файла, в които са добавени 30 реда и са изтрити 35 реда
  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 Целия файл

219
         url="https://github.com/ircv3/ircv3-specifications/pull/527",
219
         url="https://github.com/ircv3/ircv3-specifications/pull/527",
220
         standard="proposed IRCv3",
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
 def validate_defs():
224
 def validate_defs():

+ 5
- 6
irc/accounts.go Целия файл

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

+ 0
- 4
irc/caps/constants.go Целия файл

64
 	BotTagName = "bot"
64
 	BotTagName = "bot"
65
 	// https://ircv3.net/specs/extensions/chathistory
65
 	// https://ircv3.net/specs/extensions/chathistory
66
 	ChathistoryTargetsBatchType = "draft/chathistory-targets"
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
 func init() {
69
 func init() {

+ 1
- 6
irc/caps/defs.go Целия файл

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

+ 3
- 13
irc/config.go Целия файл

1402
 		if config.Accounts.OAuth2.Enabled {
1402
 		if config.Accounts.OAuth2.Enabled {
1403
 			saslCapValues = append(saslCapValues, "OAUTHBEARER")
1403
 			saslCapValues = append(saslCapValues, "OAUTHBEARER")
1404
 		}
1404
 		}
1405
+		if config.Accounts.OAuth2.Enabled || config.Accounts.JWTAuth.Enabled {
1406
+			saslCapValues = append(saslCapValues, "IRCV3BEARER")
1407
+		}
1405
 		config.Server.capValues[caps.SASL] = strings.Join(saslCapValues, ",")
1408
 		config.Server.capValues[caps.SASL] = strings.Join(saslCapValues, ",")
1406
 	} else {
1409
 	} else {
1407
 		config.Server.supportedCaps.Disable(caps.SASL)
1410
 		config.Server.supportedCaps.Disable(caps.SASL)
1419
 		return nil, fmt.Errorf("oauth2 is enabled with auth-script, but no auth-script is enabled")
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
 	if !config.Accounts.Registration.Enabled {
1425
 	if !config.Accounts.Registration.Enabled {
1436
 		config.Server.supportedCaps.Disable(caps.AccountRegistration)
1426
 		config.Server.supportedCaps.Disable(caps.AccountRegistration)
1437
 	} else {
1427
 	} else {

+ 21
- 0
irc/handlers.go Целия файл

306
 	return false
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.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
+
309
 func sendAuthErrorResponse(client *Client, rb *ResponseBuffer, err error) {
330
 func sendAuthErrorResponse(client *Client, rb *ResponseBuffer, err error) {
310
 	msg := authErrorToMessage(client.server, err)
331
 	msg := authErrorToMessage(client.server, err)
311
 	rb.Add(nil, client.server.name, ERR_SASLFAIL, client.nick, fmt.Sprintf("%s: %s", client.t("SASL authentication failed"), client.t(msg)))
332
 	rb.Add(nil, client.server.name, ERR_SASLFAIL, client.nick, fmt.Sprintf("%s: %s", client.t("SASL authentication failed"), client.t(msg)))

Loading…
Отказ
Запис