Browse Source

Merge pull request #1148 from slingamn/issue1050_fingerprint

fix #1050
tags/v2.2.0-rc1
Shivaram Lingamneni 4 years ago
parent
commit
1c3e40b358
No account linked to committer's email address
6 changed files with 45 additions and 32 deletions
  1. 2
    2
      conventional.yaml
  2. 2
    2
      default.yaml
  3. 1
    1
      irc/client.go
  4. 17
    12
      irc/config.go
  5. 20
    12
      irc/gateways.go
  6. 3
    3
      irc/handlers.go

+ 2
- 2
conventional.yaml View File

149
         -
149
         -
150
             # SHA-256 fingerprint of the TLS certificate the gateway must use to connect
150
             # SHA-256 fingerprint of the TLS certificate the gateway must use to connect
151
             # (comment this out to use passwords only)
151
             # (comment this out to use passwords only)
152
-            fingerprint: "abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"
152
+            certfp: "abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"
153
 
153
 
154
             # password the gateway uses to connect, made with oragono genpasswd
154
             # password the gateway uses to connect, made with oragono genpasswd
155
             password: "$2a$04$abcdef0123456789abcdef0123456789abcdef0123456789abcde"
155
             password: "$2a$04$abcdef0123456789abcdef0123456789abcdef0123456789abcde"
574
         # if a SHA-256 certificate fingerprint is configured here, then it will be
574
         # if a SHA-256 certificate fingerprint is configured here, then it will be
575
         # required to /OPER. if you comment out the password hash above, then you can
575
         # required to /OPER. if you comment out the password hash above, then you can
576
         # /OPER without a password.
576
         # /OPER without a password.
577
-        #fingerprint: "abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"
577
+        #certfp: "abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"
578
         # if 'auto' is set (and no password hash is set), operator permissions will be
578
         # if 'auto' is set (and no password hash is set), operator permissions will be
579
         # granted automatically as soon as you connect with the right fingerprint.
579
         # granted automatically as soon as you connect with the right fingerprint.
580
         #auto: true
580
         #auto: true

+ 2
- 2
default.yaml View File

175
         -
175
         -
176
             # SHA-256 fingerprint of the TLS certificate the gateway must use to connect
176
             # SHA-256 fingerprint of the TLS certificate the gateway must use to connect
177
             # (comment this out to use passwords only)
177
             # (comment this out to use passwords only)
178
-            fingerprint: "abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"
178
+            certfp: "abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"
179
 
179
 
180
             # password the gateway uses to connect, made with oragono genpasswd
180
             # password the gateway uses to connect, made with oragono genpasswd
181
             password: "$2a$04$abcdef0123456789abcdef0123456789abcdef0123456789abcde"
181
             password: "$2a$04$abcdef0123456789abcdef0123456789abcdef0123456789abcde"
600
         # if a SHA-256 certificate fingerprint is configured here, then it will be
600
         # if a SHA-256 certificate fingerprint is configured here, then it will be
601
         # required to /OPER. if you comment out the password hash above, then you can
601
         # required to /OPER. if you comment out the password hash above, then you can
602
         # /OPER without a password.
602
         # /OPER without a password.
603
-        #fingerprint: "abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"
603
+        #certfp: "abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"
604
         # if 'auto' is set (and no password hash is set), operator permissions will be
604
         # if 'auto' is set (and no password hash is set), operator permissions will be
605
         # granted automatically as soon as you connect with the right fingerprint.
605
         # granted automatically as soon as you connect with the right fingerprint.
606
         #auto: true
606
         #auto: true

+ 1
- 1
irc/client.go View File

1646
 		return
1646
 		return
1647
 	}
1647
 	}
1648
 	for _, oper := range client.server.Config().operators {
1648
 	for _, oper := range client.server.Config().operators {
1649
-		if oper.Auto && oper.Pass == nil && oper.Fingerprint != "" && oper.Fingerprint == session.certfp {
1649
+		if oper.Auto && oper.Pass == nil && oper.Certfp != "" && oper.Certfp == session.certfp {
1650
 			rb := NewResponseBuffer(session)
1650
 			rb := NewResponseBuffer(session)
1651
 			applyOper(client, oper, rb)
1651
 			applyOper(client, oper, rb)
1652
 			rb.Send(true)
1652
 			rb.Send(true)

+ 17
- 12
irc/config.go View File

408
 	Vhost       string
408
 	Vhost       string
409
 	WhoisLine   string `yaml:"whois-line"`
409
 	WhoisLine   string `yaml:"whois-line"`
410
 	Password    string
410
 	Password    string
411
-	Fingerprint string
411
+	Fingerprint *string // legacy name for certfp, #1050
412
+	Certfp      string
412
 	Auto        bool
413
 	Auto        bool
413
 	Modes       string
414
 	Modes       string
414
 }
415
 }
695
 
696
 
696
 // Oper represents a single assembled operator's config.
697
 // Oper represents a single assembled operator's config.
697
 type Oper struct {
698
 type Oper struct {
698
-	Name        string
699
-	Class       *OperClass
700
-	WhoisLine   string
701
-	Vhost       string
702
-	Pass        []byte
703
-	Fingerprint string
704
-	Auto        bool
705
-	Modes       []modes.ModeChange
699
+	Name      string
700
+	Class     *OperClass
701
+	WhoisLine string
702
+	Vhost     string
703
+	Pass      []byte
704
+	Certfp    string
705
+	Auto      bool
706
+	Modes     []modes.ModeChange
706
 }
707
 }
707
 
708
 
708
 // Operators returns a map of operator configs from the given OperClass and config.
709
 // Operators returns a map of operator configs from the given OperClass and config.
724
 				return nil, fmt.Errorf("Oper %s has an invalid password hash: %s", oper.Name, err.Error())
725
 				return nil, fmt.Errorf("Oper %s has an invalid password hash: %s", oper.Name, err.Error())
725
 			}
726
 			}
726
 		}
727
 		}
727
-		if opConf.Fingerprint != "" {
728
-			oper.Fingerprint, err = utils.NormalizeCertfp(opConf.Fingerprint)
728
+		certfp := opConf.Certfp
729
+		if certfp == "" && opConf.Fingerprint != nil {
730
+			certfp = *opConf.Fingerprint
731
+		}
732
+		if certfp != "" {
733
+			oper.Certfp, err = utils.NormalizeCertfp(certfp)
729
 			if err != nil {
734
 			if err != nil {
730
 				return nil, fmt.Errorf("Oper %s has an invalid fingerprint: %s", oper.Name, err.Error())
735
 				return nil, fmt.Errorf("Oper %s has an invalid fingerprint: %s", oper.Name, err.Error())
731
 			}
736
 			}
732
 		}
737
 		}
733
 		oper.Auto = opConf.Auto
738
 		oper.Auto = opConf.Auto
734
 
739
 
735
-		if oper.Pass == nil && oper.Fingerprint == "" {
740
+		if oper.Pass == nil && oper.Certfp == "" {
736
 			return nil, fmt.Errorf("Oper %s has neither a password nor a fingerprint", name)
741
 			return nil, fmt.Errorf("Oper %s has neither a password nor a fingerprint", name)
737
 		}
742
 		}
738
 
743
 

+ 20
- 12
irc/gateways.go View File

26
 )
26
 )
27
 
27
 
28
 type webircConfig struct {
28
 type webircConfig struct {
29
-	PasswordString string `yaml:"password"`
30
-	Password       []byte `yaml:"password-bytes"`
31
-	Fingerprint    string
29
+	PasswordString string  `yaml:"password"`
30
+	Password       []byte  `yaml:"password-bytes"`
31
+	Fingerprint    *string // legacy name for certfp, #1050
32
+	Certfp         string
32
 	Hosts          []string
33
 	Hosts          []string
33
 	allowedNets    []net.IPNet
34
 	allowedNets    []net.IPNet
34
 }
35
 }
35
 
36
 
36
 // Populate fills out our password or fingerprint.
37
 // Populate fills out our password or fingerprint.
37
 func (wc *webircConfig) Populate() (err error) {
38
 func (wc *webircConfig) Populate() (err error) {
38
-	if wc.Fingerprint == "" && wc.PasswordString == "" {
39
-		err = ErrNoFingerprintOrPassword
40
-	}
41
-
42
-	if err == nil && wc.PasswordString != "" {
39
+	if wc.PasswordString != "" {
43
 		wc.Password, err = decodeLegacyPasswordHash(wc.PasswordString)
40
 		wc.Password, err = decodeLegacyPasswordHash(wc.PasswordString)
41
+		if err != nil {
42
+			return
43
+		}
44
 	}
44
 	}
45
 
45
 
46
-	if err == nil && wc.Fingerprint != "" {
47
-		wc.Fingerprint, err = utils.NormalizeCertfp(wc.Fingerprint)
46
+	certfp := wc.Certfp
47
+	if certfp == "" && wc.Fingerprint != nil {
48
+		certfp = *wc.Fingerprint
49
+	}
50
+	if certfp != "" {
51
+		wc.Certfp, err = utils.NormalizeCertfp(certfp)
52
+	}
53
+	if err != nil {
54
+		return
48
 	}
55
 	}
49
 
56
 
50
-	if err == nil {
51
-		wc.allowedNets, err = utils.ParseNetList(wc.Hosts)
57
+	if wc.Certfp == "" && wc.PasswordString == "" {
58
+		return ErrNoFingerprintOrPassword
52
 	}
59
 	}
53
 
60
 
61
+	wc.allowedNets, err = utils.ParseNetList(wc.Hosts)
54
 	return err
62
 	return err
55
 }
63
 }
56
 
64
 

+ 3
- 3
irc/handlers.go View File

2164
 	var checkPassed, checkFailed, passwordFailed bool
2164
 	var checkPassed, checkFailed, passwordFailed bool
2165
 	oper := server.GetOperator(msg.Params[0])
2165
 	oper := server.GetOperator(msg.Params[0])
2166
 	if oper != nil {
2166
 	if oper != nil {
2167
-		if oper.Fingerprint != "" {
2168
-			if oper.Fingerprint == rb.session.certfp {
2167
+		if oper.Certfp != "" {
2168
+			if oper.Certfp == rb.session.certfp {
2169
 				checkPassed = true
2169
 				checkPassed = true
2170
 			} else {
2170
 			} else {
2171
 				checkFailed = true
2171
 				checkFailed = true
2737
 			if 0 < len(info.Password) && bcrypt.CompareHashAndPassword(info.Password, givenPassword) != nil {
2737
 			if 0 < len(info.Password) && bcrypt.CompareHashAndPassword(info.Password, givenPassword) != nil {
2738
 				continue
2738
 				continue
2739
 			}
2739
 			}
2740
-			if info.Fingerprint != "" && info.Fingerprint != rb.session.certfp {
2740
+			if info.Certfp != "" && info.Certfp != rb.session.certfp {
2741
 				continue
2741
 				continue
2742
 			}
2742
 			}
2743
 
2743
 

Loading…
Cancel
Save