@@ -4,10 +4,10 @@ import (
4
4
"bytes"
5
5
"encoding/binary"
6
6
"errors"
7
- "log"
8
7
"strings"
9
8
"time"
10
9
10
+ "github.com/golang/glog"
11
11
"github.com/jedisct1/xsecretbox"
12
12
"github.com/miekg/dns"
13
13
"golang.org/x/crypto/ed25519"
@@ -41,15 +41,15 @@ func FetchCurrentCert(proxy *Proxy, proto string, pk ed25519.PublicKey, serverAd
41
41
for _ , answerRr := range in .Answer {
42
42
binCert , err := packTxtString (strings .Join (answerRr .(* dns.TXT ).Txt , "" ))
43
43
if err != nil {
44
- log . Printf ("[%v] Unable to unpack the certificate\n " , providerName )
44
+ glog . Warningf ("[%v] Unable to unpack the certificate" , providerName )
45
45
continue
46
46
}
47
47
if len (binCert ) < 124 {
48
- log . Printf ("[%v] Certificate too short\n " , providerName )
48
+ glog . Warningf ("[%v] Certificate too short" , providerName )
49
49
continue
50
50
}
51
51
if ! bytes .Equal (binCert [:4 ], CertMagic [:4 ]) {
52
- log . Printf ("[%v] Invalid cert magic\n " , providerName )
52
+ glog . Warningf ("[%v] Invalid cert magic" , providerName )
53
53
continue
54
54
}
55
55
cryptoConstruction := CryptoConstruction (0 )
@@ -59,36 +59,36 @@ func FetchCurrentCert(proxy *Proxy, proto string, pk ed25519.PublicKey, serverAd
59
59
case 0x0002 :
60
60
cryptoConstruction = XChacha20Poly1305
61
61
default :
62
- log . Printf ("[%v] Unsupported crypto construction\n " , providerName )
62
+ glog . Infof ("[%v] Unsupported crypto construction" , providerName )
63
63
continue
64
64
}
65
65
signature := binCert [8 :72 ]
66
66
signed := binCert [72 :]
67
67
if ! ed25519 .Verify (pk , signed , signature ) {
68
- log . Printf ("[%v] Incorrect signature\n " , providerName )
68
+ glog . Warningf ("[%v] Incorrect signature" , providerName )
69
69
continue
70
70
}
71
71
serial := binary .BigEndian .Uint32 (binCert [112 :116 ])
72
72
tsBegin := binary .BigEndian .Uint32 (binCert [116 :120 ])
73
73
tsEnd := binary .BigEndian .Uint32 (binCert [120 :124 ])
74
74
if now > tsEnd || now < tsBegin {
75
- log . Printf ("[%v] Certificate not valid at the current date\n " , providerName )
75
+ glog . Infof ("[%v] Certificate not valid at the current date" , providerName )
76
76
continue
77
77
}
78
78
if serial < highestSerial {
79
- log . Printf ("[%v] Superseded by a previous certificate\n " , providerName )
79
+ glog . Infof ("[%v] Superseded by a previous certificate" , providerName )
80
80
continue
81
81
}
82
82
if serial == highestSerial {
83
83
if cryptoConstruction < certInfo .CryptoConstruction {
84
- log . Printf ("[%v] Keeping the previous, preferred crypto construction" , providerName )
84
+ glog . Infof ("[%v] Keeping the previous, preferred crypto construction" , providerName )
85
85
continue
86
86
} else {
87
- log . Printf ("[%v] Upgrading the construction from %v to %v\n " , providerName , certInfo .CryptoConstruction , cryptoConstruction )
87
+ glog . Infof ("[%v] Upgrading the construction from %v to %v" , providerName , certInfo .CryptoConstruction , cryptoConstruction )
88
88
}
89
89
}
90
90
if cryptoConstruction != XChacha20Poly1305 && cryptoConstruction != XSalsa20Poly1305 {
91
- log . Printf ("[%v] Cryptographic construction %v not supported\n " , providerName , cryptoConstruction )
91
+ glog . Warningf ("[%v] Cryptographic construction %v not supported" , providerName , cryptoConstruction )
92
92
continue
93
93
}
94
94
var serverPk [32 ]byte
@@ -97,7 +97,7 @@ func FetchCurrentCert(proxy *Proxy, proto string, pk ed25519.PublicKey, serverAd
97
97
if cryptoConstruction == XChacha20Poly1305 {
98
98
sharedKey , err = xsecretbox .SharedKey (proxy .proxySecretKey , serverPk )
99
99
if err != nil {
100
- log . Printf ("[%v] Weak public key\n " , providerName )
100
+ glog . Warningf ("[%v] Weak public key" , providerName )
101
101
continue
102
102
}
103
103
} else {
@@ -108,7 +108,7 @@ func FetchCurrentCert(proxy *Proxy, proto string, pk ed25519.PublicKey, serverAd
108
108
certInfo .CryptoConstruction = cryptoConstruction
109
109
copy (certInfo .ServerPk [:], serverPk [:])
110
110
copy (certInfo .MagicQuery [:], binCert [104 :112 ])
111
- log . Printf ("[%v] Valid cert found: %x \n " , providerName , certInfo .ServerPk )
111
+ glog . Infof ("[%v] Valid cert found: [%x] " , providerName , certInfo .ServerPk )
112
112
}
113
113
if certInfo .CryptoConstruction == UndefinedConstruction {
114
114
return certInfo , errors .New ("No useable certificate found" )
0 commit comments