From 0066cfc3932c50323fa596981f18ef5b0e862742 Mon Sep 17 00:00:00 2001 From: Yawning Angel Date: Tue, 17 Feb 2015 11:33:29 +0000 Subject: Add support for acting as a ScrambleSuit client. This allows obfs4proxy to be used as a ScrambleSuit client that is wire compatible with the obfs4proxy implementation, including session ticket support, and length obfuscation. The current implementation has the following limitations: * IAT obfuscation is not supported (and is disabled in all other ScrambleSuit implementations by default). * The length distribution and probabilites are different from those generated by obfsproxy and obfsclient due to a different DRBG. * Server support is missing and is unlikely to be implemented. --- common/probdist/weighted_dist.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'common') diff --git a/common/probdist/weighted_dist.go b/common/probdist/weighted_dist.go index 2386bbe..811a8a0 100644 --- a/common/probdist/weighted_dist.go +++ b/common/probdist/weighted_dist.go @@ -31,9 +31,11 @@ package probdist import ( + "bytes" "container/list" "fmt" "math/rand" + "sync" "git.torproject.org/pluggable-transports/obfs4.git/common/csrand" "git.torproject.org/pluggable-transports/obfs4.git/common/drbg" @@ -46,6 +48,8 @@ const ( // WeightedDist is a weighted distribution. type WeightedDist struct { + sync.Mutex + minValue int maxValue int biased bool @@ -192,6 +196,9 @@ func (w *WeightedDist) Reset(seed *drbg.Seed) { drbg, _ := drbg.NewHashDrbg(seed) rng := rand.New(drbg) + w.Lock() + defer w.Unlock() + w.genValues(rng) if w.biased { w.genBiasedWeights(rng) @@ -205,6 +212,9 @@ func (w *WeightedDist) Reset(seed *drbg.Seed) { func (w *WeightedDist) Sample() int { var idx int + w.Lock() + defer w.Unlock() + // Generate a fair die roll from an $n$-sided die; call the side $i$. i := csrand.Intn(len(w.values)) // Flip a biased coin that comes up heads with probability $Prob[i]$. @@ -218,3 +228,18 @@ func (w *WeightedDist) Sample() int { return w.minValue + w.values[idx] } + +// String returns a dump of the distribution table. +func (w *WeightedDist) String() string { + var buf bytes.Buffer + + buf.WriteString("[ ") + for i, v := range w.values { + p := w.weights[i] + if p > 0.01 { // Squelch tiny probabilities. + buf.WriteString(fmt.Sprintf("%d: %f ", v, p)) + } + } + buf.WriteString("]") + return buf.String() +} -- cgit v1.2.3