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

+ 2
- 2
default.yaml View File

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

+ 1
- 1
irc/client.go View File

@@ -1646,7 +1646,7 @@ func (client *Client) attemptAutoOper(session *Session) {
1646 1646
 		return
1647 1647
 	}
1648 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 1650
 			rb := NewResponseBuffer(session)
1651 1651
 			applyOper(client, oper, rb)
1652 1652
 			rb.Send(true)

+ 17
- 12
irc/config.go View File

@@ -408,7 +408,8 @@ type OperConfig struct {
408 408
 	Vhost       string
409 409
 	WhoisLine   string `yaml:"whois-line"`
410 410
 	Password    string
411
-	Fingerprint string
411
+	Fingerprint *string // legacy name for certfp, #1050
412
+	Certfp      string
412 413
 	Auto        bool
413 414
 	Modes       string
414 415
 }
@@ -695,14 +696,14 @@ func (conf *Config) OperatorClasses() (map[string]*OperClass, error) {
695 696
 
696 697
 // Oper represents a single assembled operator's config.
697 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 709
 // Operators returns a map of operator configs from the given OperClass and config.
@@ -724,15 +725,19 @@ func (conf *Config) Operators(oc map[string]*OperClass) (map[string]*Oper, error
724 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 734
 			if err != nil {
730 735
 				return nil, fmt.Errorf("Oper %s has an invalid fingerprint: %s", oper.Name, err.Error())
731 736
 			}
732 737
 		}
733 738
 		oper.Auto = opConf.Auto
734 739
 
735
-		if oper.Pass == nil && oper.Fingerprint == "" {
740
+		if oper.Pass == nil && oper.Certfp == "" {
736 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,31 +26,39 @@ const (
26 26
 )
27 27
 
28 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 33
 	Hosts          []string
33 34
 	allowedNets    []net.IPNet
34 35
 }
35 36
 
36 37
 // Populate fills out our password or fingerprint.
37 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 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 62
 	return err
55 63
 }
56 64
 

+ 3
- 3
irc/handlers.go View File

@@ -2164,8 +2164,8 @@ func operHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp
2164 2164
 	var checkPassed, checkFailed, passwordFailed bool
2165 2165
 	oper := server.GetOperator(msg.Params[0])
2166 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 2169
 				checkPassed = true
2170 2170
 			} else {
2171 2171
 				checkFailed = true
@@ -2737,7 +2737,7 @@ func webircHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Re
2737 2737
 			if 0 < len(info.Password) && bcrypt.CompareHashAndPassword(info.Password, givenPassword) != nil {
2738 2738
 				continue
2739 2739
 			}
2740
-			if info.Fingerprint != "" && info.Fingerprint != rb.session.certfp {
2740
+			if info.Certfp != "" && info.Certfp != rb.session.certfp {
2741 2741
 				continue
2742 2742
 			}
2743 2743
 

Loading…
Cancel
Save