}{c.r, c.w},
t.infoHash[:],
nil,
- func() uint32 {
+ func() mse.CryptoMethod {
switch {
case cl.config.ForceEncryption:
return mse.CryptoMethodRC4
r io.Reader
// True if the connection is operating over MSE obfuscation.
headerEncrypted bool
- cryptoMethod uint32
+ cryptoMethod mse.CryptoMethod
Discovery peerSource
uTP bool
closed missinggo.Event
) (
ret io.ReadWriter,
headerEncrypted bool,
- cryptoMethod uint32,
+ cryptoMethod mse.CryptoMethod,
err error,
) {
if !policy.ForceEncryption {
}
}
headerEncrypted = true
- ret, err = mse.ReceiveHandshake(rw, skeys, func(provides uint32) uint32 {
+ ret, err = mse.ReceiveHandshake(rw, skeys, func(provides mse.CryptoMethod) mse.CryptoMethod {
switch {
case policy.ForceEncryption:
return mse.CryptoMethodRC4
const (
maxPadLen = 512
- CryptoMethodPlaintext = 1
- CryptoMethodRC4 = 2
- AllSupportedCrypto = CryptoMethodPlaintext | CryptoMethodRC4
+ CryptoMethodPlaintext CryptoMethod = 1
+ CryptoMethodRC4 CryptoMethod = 2
+ AllSupportedCrypto = CryptoMethodPlaintext | CryptoMethodRC4
)
+type CryptoMethod uint32
+
var (
// Prime P according to the spec, and G, the generator.
p, g big.Int
skey []byte // Skey we're initiating with.
ia []byte // Initial payload. Only used by the initiator.
// Return the bit for the crypto method the receiver wants to use.
- chooseMethod func(supported uint32) uint32
+ chooseMethod CryptoSelector
// Sent to the receiver.
- cryptoProvides uint32
+ cryptoProvides CryptoMethod
writeMu sync.Mutex
writes [][]byte
return
}
r := newCipherReader(bC, h.conn)
- var method uint32
+ var method CryptoMethod
err = unmarshal(r, &method, &padLen)
if err != nil {
return
r := newCipherReader(newEncrypt(true, h.s[:], h.skey), h.conn)
var (
vc [8]byte
- provides uint32
+ provides CryptoMethod
padLen uint16
)
return
}
-func InitiateHandshake(rw io.ReadWriter, skey []byte, initialPayload []byte, cryptoProvides uint32) (ret io.ReadWriter, err error) {
+func InitiateHandshake(rw io.ReadWriter, skey []byte, initialPayload []byte, cryptoProvides CryptoMethod) (ret io.ReadWriter, err error) {
h := handshake{
conn: rw,
initer: true,
return h.Do()
}
-func ReceiveHandshake(rw io.ReadWriter, skeys SecretKeyIter, selectCrypto func(uint32) uint32) (ret io.ReadWriter, err error) {
+func ReceiveHandshake(rw io.ReadWriter, skeys SecretKeyIter, selectCrypto CryptoSelector) (ret io.ReadWriter, err error) {
h := handshake{
conn: rw,
initer: false,
// returns false or exhausted.
type SecretKeyIter func(callback func(skey []byte) (more bool))
-func DefaultCryptoSelector(provided uint32) uint32 {
+func DefaultCryptoSelector(provided CryptoMethod) CryptoMethod {
if provided&CryptoMethodPlaintext != 0 {
return CryptoMethodPlaintext
}
return CryptoMethodRC4
}
-type CryptoSelector func(uint32) uint32
+type CryptoSelector func(CryptoMethod) CryptoMethod
test("sup", "person", 1)
}
-func handshakeTest(t testing.TB, ia []byte, aData, bData string, cryptoProvides uint32, cryptoSelect func(uint32) uint32) {
+func handshakeTest(t testing.TB, ia []byte, aData, bData string, cryptoProvides CryptoMethod, cryptoSelect CryptoSelector) {
a, b := net.Pipe()
wg := sync.WaitGroup{}
wg.Add(2)
b.Close()
}
-func allHandshakeTests(t testing.TB, provides uint32, selector CryptoSelector) {
+func allHandshakeTests(t testing.TB, provides CryptoMethod, selector CryptoSelector) {
handshakeTest(t, []byte("jump the gun, "), "hello world", "yo dawg", provides, selector)
handshakeTest(t, nil, "hello world", "yo dawg", provides, selector)
handshakeTest(t, []byte{}, "hello world", "yo dawg", provides, selector)
}
func TestHandshakeSelectPlaintext(t *testing.T) {
- allHandshakeTests(t, AllSupportedCrypto, func(uint32) uint32 { return CryptoMethodPlaintext })
+ allHandshakeTests(t, AllSupportedCrypto, func(CryptoMethod) CryptoMethod { return CryptoMethodPlaintext })
}
func BenchmarkHandshakeDefault(b *testing.B) {
return wErr
}
-func benchmarkStream(t *testing.B, crypto uint32) {
+func benchmarkStream(t *testing.B, crypto CryptoMethod) {
ia := make([]byte, 0x1000)
a := make([]byte, 1<<20)
b := make([]byte, 1<<20)
}()
func() {
defer bc.Close()
- rw, err := ReceiveHandshake(bc, sliceIter([][]byte{[]byte("cats")}), func(uint32) uint32 { return crypto })
+ rw, err := ReceiveHandshake(bc, sliceIter([][]byte{[]byte("cats")}), func(CryptoMethod) CryptoMethod { return crypto })
require.NoError(t, err)
require.NoError(t, readAndWrite(rw, br, b))
}()