소스 검색

Allow custom JWT service expiry times

tags/v2.2.0-rc1
Daniel Oaks 4 년 전
부모
커밋
9b998a7582
4개의 변경된 파일36개의 추가작업 그리고 14개의 파일을 삭제
  1. 7
    3
      conventional.yaml
  2. 7
    3
      default.yaml
  3. 15
    3
      irc/config.go
  4. 7
    5
      irc/handlers.go

+ 7
- 3
conventional.yaml 파일 보기

@@ -164,9 +164,13 @@ server:
164 164
     # these services can integrate with the ircd using JSON Web Tokens (https://jwt.io)
165 165
     # sometimes referred to with 'EXTJWT'
166 166
     jwt-services:
167
-        # # service name -> secret string the service uses to verify our tokens
168
-        # call-host: call-hosting-secret-token
169
-        # image-host: image-hosting-secret-token
167
+        # # service name
168
+        # call-host:
169
+        #     # custom expiry length, default is 30s
170
+        #     expiry-in-seconds: 45
171
+
172
+        #     # secret string to verify the generated tokens
173
+        #     secret: call-hosting-secret-token
170 174
 
171 175
     # allow use of the RESUME extension over plaintext connections:
172 176
     # do not enable this unless the ircd is only accessible over internal networks

+ 7
- 3
default.yaml 파일 보기

@@ -190,9 +190,13 @@ server:
190 190
     # these services can integrate with the ircd using JSON Web Tokens (https://jwt.io)
191 191
     # sometimes referred to with 'EXTJWT'
192 192
     jwt-services:
193
-        # # service name -> secret string the service uses to verify our tokens
194
-        # call-host: call-hosting-secret-token
195
-        # image-host: image-hosting-secret-token
193
+        # # service name
194
+        # call-host:
195
+        #     # custom expiry length, default is 30s
196
+        #     expiry-in-seconds: 45
197
+
198
+        #     # secret string to verify the generated tokens
199
+        #     secret: call-hosting-secret-token
196 200
 
197 201
     # allow use of the RESUME extension over plaintext connections:
198 202
     # do not enable this unless the ircd is only accessible over internal networks

+ 15
- 3
irc/config.go 파일 보기

@@ -471,6 +471,11 @@ type TorListenersConfig struct {
471 471
 	MaxConnectionsPerDuration int           `yaml:"max-connections-per-duration"`
472 472
 }
473 473
 
474
+type JwtServiceConfig struct {
475
+	ExpiryInSeconds int64 `yaml:"expiry-in-seconds"`
476
+	Secret          string
477
+}
478
+
474 479
 // Config defines the overall configuration.
475 480
 type Config struct {
476 481
 	Network struct {
@@ -502,9 +507,9 @@ type Config struct {
502 507
 		MOTDFormatting          bool     `yaml:"motd-formatting"`
503 508
 		ProxyAllowedFrom        []string `yaml:"proxy-allowed-from"`
504 509
 		proxyAllowedFromNets    []net.IPNet
505
-		WebIRC                  []webircConfig    `yaml:"webirc"`
506
-		JwtServices             map[string]string `yaml:"jwt-services"`
507
-		MaxSendQString          string            `yaml:"max-sendq"`
510
+		WebIRC                  []webircConfig              `yaml:"webirc"`
511
+		JwtServices             map[string]JwtServiceConfig `yaml:"jwt-services"`
512
+		MaxSendQString          string                      `yaml:"max-sendq"`
508 513
 		MaxSendQBytes           int
509 514
 		AllowPlaintextResume    bool `yaml:"allow-plaintext-resume"`
510 515
 		Compatibility           struct {
@@ -922,6 +927,13 @@ func LoadConfig(filename string) (config *Config, err error) {
922 927
 		config.Server.capValues[caps.Multiline] = multilineCapValue
923 928
 	}
924 929
 
930
+	// confirm jwt config
931
+	for name, info := range config.Server.JwtServices {
932
+		if info.Secret == "" {
933
+			return nil, fmt.Errorf("Could not parse jwt-services config, %s service has no secret set", name)
934
+		}
935
+	}
936
+
925 937
 	// handle legacy name 'bouncer' for 'multiclient' section:
926 938
 	if config.Accounts.Bouncer != nil {
927 939
 		config.Accounts.Multiclient = *config.Accounts.Bouncer

+ 7
- 5
irc/handlers.go 파일 보기

@@ -922,7 +922,6 @@ func extjwtHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
922 922
 	}
923 923
 
924 924
 	claims := jwt.MapClaims{
925
-		"exp":     time.Now().Unix() + expireInSeconds,
926 925
 		"iss":     server.name,
927 926
 		"sub":     client.Nick(),
928 927
 		"account": accountName,
@@ -945,8 +944,6 @@ func extjwtHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
945 944
 		}
946 945
 	}
947 946
 
948
-	token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
949
-
950 947
 	// we default to a secret of `*`. if you want a real secret setup a service in the config~
951 948
 	service := "*"
952 949
 	secret := "*"
@@ -954,14 +951,19 @@ func extjwtHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
954 951
 		service = strings.ToLower(msg.Params[1])
955 952
 
956 953
 		c := server.Config()
957
-		var exists bool
958
-		secret, exists = c.Server.JwtServices[service]
954
+		info, exists := c.Server.JwtServices[service]
959 955
 		if !exists {
960 956
 			rb.Add(nil, server.name, "FAIL", "EXTJWT", "NO_SUCH_SERVICE", client.t("No such service"))
961 957
 			return false
962 958
 		}
959
+		secret = info.Secret
960
+		if info.ExpiryInSeconds != 0 {
961
+			expireInSeconds = info.ExpiryInSeconds
962
+		}
963 963
 	}
964
+	claims["exp"] = time.Now().Unix() + expireInSeconds
964 965
 
966
+	token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
965 967
 	tokenString, err := token.SignedString([]byte(secret))
966 968
 
967 969
 	if err == nil {

Loading…
취소
저장