Skip to content

Commit 2c78542

Browse files
committed
Merge pull request #395 from uProxy/trevj-utransformers-cleanup
remove remaining references to utransformers, shorten the interface
2 parents bad46c5 + fb2df92 commit 2c78542

11 files changed

Lines changed: 32 additions & 142 deletions

File tree

Gruntfile.coffee

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,7 @@ config =
298298
# Browserify freedom-modules in the library
299299
loggingProvider: Rule.browserify 'loggingprovider/freedom-module'
300300
echoFreedomModule: Rule.browserify 'echo/freedom-module'
301-
churnPipeFreedomModule: Rule.browserify(
302-
'churn-pipe/freedom-module',
303-
{
304-
# Emscripten, used to compile FTE and Rabbit to JS has unused
305-
# require statements for `ws` and for `path` that need to be
306-
# ignored.
307-
ignore: ['ws', 'path']
308-
browserifyOptions: { standalone: 'browserified_exports' }
309-
})
301+
churnPipeFreedomModule: Rule.browserify 'churn-pipe/freedom-module'
310302
# TODO: Make the browserified SSH stuff re-useable, e.g. freedomjs module.
311303
cloudInstallerFreedomModule: Rule.browserify('cloud/install/freedom-module', {
312304
alias : [

src/churn-pipe/churn-pipe.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import PassThrough = require('../transformers/passthrough');
1313
import promises = require('../promises/promises');
1414
import protean = require('../transformers/protean');
1515
import sequence = require('../transformers/byteSequenceShaper');
16+
import transformer = require('../transformers/transformer');
1617

1718
import Socket = freedom.UdpSocket.Socket;
1819

@@ -21,7 +22,7 @@ declare const freedom: freedom.FreedomInModuleEnv;
2122
var log :logging.Log = new logging.Log('churn-pipe');
2223

2324
// Maps transformer names to class constructors.
24-
var transformers :{[name:string] : new() => Transformer} = {
25+
var transformers :{[name:string] : new() => transformer.Transformer} = {
2526
'caesar': caesar.CaesarCipher,
2627
'decompressionShaper': decompression.DecompressionShaper,
2728
'encryptionShaper': encryption.EncryptionShaper,
@@ -88,7 +89,7 @@ class Pipe {
8889
{};
8990

9091
// Obfuscates and deobfuscates messages.
91-
private transformer_ :Transformer;
92+
private transformer_ :transformer.Transformer;
9293

9394
// Endpoint to which incoming obfuscated messages are forwarded on each
9495
// interface. The key is the interface, and the value is the port.

src/transformers/byteSequenceShaper.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
/// <reference path='../../../third_party/uTransformers/utransformers.d.ts' />
2-
31
import arraybuffers = require('../arraybuffers/arraybuffers');
42
import logging = require('../logging/logging');
53
import random = require('../crypto/random');
4+
import transformer = require('./transformer');
65

76
const log :logging.Log = new logging.Log('byte sequence shaper');
87

@@ -65,7 +64,7 @@ export var sampleConfig = () : SequenceConfig => {
6564
}
6665

6766
// An obfuscator that injects byte sequences.
68-
export class ByteSequenceShaper implements Transformer {
67+
export class ByteSequenceShaper implements transformer.Transformer {
6968
// Sequences that should be added to the outgoing packet stream.
7069
private addSequences_ :SequenceModel[];
7170

@@ -88,12 +87,6 @@ export class ByteSequenceShaper implements Transformer {
8887
this.configure(JSON.stringify(sampleConfig()));
8988
}
9089

91-
// This method is required to implement the Transformer API.
92-
// @param {ArrayBuffer} key Key to set, not used by this class.
93-
public setKey = (key:ArrayBuffer) :void => {
94-
throw new Error('setKey unimplemented');
95-
}
96-
9790
// Configure the transformer with the byte sequences to inject and the byte
9891
// sequences to remove.
9992
public configure = (json:string) :void => {
@@ -157,9 +150,6 @@ export class ByteSequenceShaper implements Transformer {
157150
}
158151
}
159152

160-
// No-op (we have no state or any resources to dispose).
161-
public dispose = () :void => {}
162-
163153
// Decode the byte sequences from strings in the config information
164154
static deserializeConfig(config :SequenceConfig)
165155
:[SequenceModel[], SequenceModel[]] {

src/transformers/caesar.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
/// <reference path='../../../third_party/uTransformers/utransformers.d.ts' />
2-
31
import logging = require('../logging/logging');
42
import random = require('../crypto/random');
3+
import transformer = require('./transformer');
54

65
var log :logging.Log = new logging.Log('caesar');
76

@@ -19,18 +18,14 @@ export var sampleConfig = () : Config => {
1918
}
2019

2120
// Caesar cipher.
22-
export class CaesarCipher implements Transformer {
21+
export class CaesarCipher implements transformer.Transformer {
2322
/** Value by which bytes' values are shifted. */
2423
private shift_ :number;
2524

2625
public constructor() {
2726
this.configure(JSON.stringify(sampleConfig()));
2827
}
2928

30-
public setKey = (key:ArrayBuffer) => {
31-
throw new Error('setKey unimplemented');
32-
}
33-
3429
public configure = (json:string) : void => {
3530
var config = <Config>JSON.parse(json);
3631
if (config.key === undefined) {
@@ -52,9 +47,6 @@ export class CaesarCipher implements Transformer {
5247
return [buffer];
5348
}
5449

55-
// No-op (we have no state or any resources to dispose).
56-
public dispose = () : void => {}
57-
5850
/** Applies mapper to each byte of buffer. */
5951
private map_ = (
6052
buffer:ArrayBuffer,

src/transformers/decompressionShaper.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
/// <reference path='../../../third_party/uTransformers/utransformers.d.ts' />
2-
31
import arithmetic = require('./arithmetic');
42
import arraybuffers = require('../arraybuffers/arraybuffers');
53
import decompression = require('./decompressionShaper');
64
import logging = require('../logging/logging');
5+
import transformer = require('./transformer');
76

87
const log :logging.Log = new logging.Log('decompression shaper');
98

@@ -51,7 +50,7 @@ export function sampleConfig() :decompression.DecompressionConfig {
5150
//
5251
// The important thing to realize is that the compression algorithm is being
5352
// run in reverse, contrary to normal expectations.
54-
export class DecompressionShaper implements Transformer {
53+
export class DecompressionShaper implements transformer.Transformer {
5554
private frequencies_ :number[];
5655

5756
private encoder_ :arithmetic.Encoder;
@@ -62,12 +61,6 @@ export class DecompressionShaper implements Transformer {
6261
this.configure(JSON.stringify(sampleConfig()));
6362
}
6463

65-
// This method is required to implement the Transformer API.
66-
// @param {ArrayBuffer} key Key to set, not used by this class.
67-
public setKey = (key :ArrayBuffer) :void => {
68-
throw new Error('setKey unimplemented');
69-
}
70-
7164
// Configure using the target byte frequencies.
7265
public configure = (json :string) :void => {
7366
let config = JSON.parse(json);
@@ -125,7 +118,4 @@ export class DecompressionShaper implements Transformer {
125118
// Slice off the extra bytes and only return the data.
126119
return [encoded.slice(1, -4)];
127120
}
128-
129-
// No-op (we have no state or any resources to dispose).
130-
public dispose = () :void => {}
131121
}

src/transformers/encryptionShaper.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/// <reference path='../../../third_party/uTransformers/utransformers.d.ts' />
21
/// <reference path='../../../third_party/aes-js/aes-js.d.ts' />
32

43
import aes = require('aes-js');
54
import arraybuffers = require('../arraybuffers/arraybuffers');
65
import logging = require('../logging/logging');
6+
import transformer = require('./transformer');
77

88
var log :logging.Log = new logging.Log('encryption shaper');
99

@@ -25,19 +25,13 @@ export var sampleConfig = () : EncryptionConfig => {
2525
}
2626

2727
// A packet shaper that encrypts the packets with AES CBC.
28-
export class EncryptionShaper implements Transformer {
28+
export class EncryptionShaper implements transformer.Transformer {
2929
private key_ :ArrayBuffer;
3030

3131
public constructor() {
3232
this.configure(JSON.stringify(sampleConfig()));
3333
}
3434

35-
// This method is required to implement the Transformer API.
36-
// @param {ArrayBuffer} key Key to set, not used by this class.
37-
public setKey = (key:ArrayBuffer) :void => {
38-
throw new Error('setKey unimplemented');
39-
}
40-
4135
public configure = (json:string) :void => {
4236
var config = JSON.parse(json);
4337

@@ -73,9 +67,6 @@ export class EncryptionShaper implements Transformer {
7367
return [this.decrypt_(iv, ciphertext)];
7468
}
7569

76-
// No-op (we have no state or any resources to dispose).
77-
public dispose = () :void => {}
78-
7970
static makeIV = () :ArrayBuffer => {
8071
var randomBytes = new Uint8Array(IV_SIZE);
8172
crypto.getRandomValues(randomBytes);

src/transformers/fragmentationShaper.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// <reference path='../../../third_party/uTransformers/utransformers.d.ts' />
2-
31
import arraybuffers = require('../arraybuffers/arraybuffers');
42
import defragmenter = require('./defragmenter');
53
import encryption = require('./encryptionShaper');
@@ -31,12 +29,6 @@ export class FragmentationShaper {
3129
this.configure(JSON.stringify(sampleConfig()));
3230
}
3331

34-
// This method is required to implement the Transformer API.
35-
// @param {ArrayBuffer} key Key to set, not used by this class.
36-
public setKey = (key :ArrayBuffer) :void => {
37-
throw new Error('setKey unimplemented');
38-
}
39-
4032
// Configure with the target length.
4133
public configure = (json :string) :void => {
4234
var config = JSON.parse(json);
@@ -82,9 +74,6 @@ export class FragmentationShaper {
8274
}
8375
}
8476

85-
// No-op (we have no state or any resources to dispose).
86-
public dispose = () :void => {}
87-
8877
// Perform the following steps:
8978
// - Break buffer into one or more fragments
9079
// - Add fragment headers to each fragment

src/transformers/passthrough.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
/// <reference path='../../../third_party/uTransformers/utransformers.d.ts' />
1+
import transformer = require('./transformer');
22

33
/** An obfuscator which does nothing. */
4-
class PassThrough implements Transformer {
4+
class PassThrough implements transformer.Transformer {
55

66
public constructor() {}
77

8-
public setKey = (key:ArrayBuffer) => {}
9-
108
public configure = (json:string) : void => {}
119

1210
public transform = (buffer:ArrayBuffer) : ArrayBuffer[] => {
@@ -16,8 +14,6 @@ class PassThrough implements Transformer {
1614
public restore = (buffer:ArrayBuffer) : ArrayBuffer[] => {
1715
return [buffer];
1816
}
19-
20-
public dispose = () : void => {}
2117
}
2218

2319
export = PassThrough;

src/transformers/protean.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/// <reference path='../../../third_party/uTransformers/utransformers.d.ts' />
21
/// <reference path='../../../third_party/aes-js/aes-js.d.ts' />
32

43
import arraybuffers = require('../arraybuffers/arraybuffers');
@@ -7,6 +6,7 @@ import encryption = require('./encryptionShaper');
76
import fragmentation = require('./fragmentationShaper');
87
import logging = require('../logging/logging');
98
import sequence = require('./byteSequenceShaper');
9+
import transformer = require('./transformer');
1010

1111
const log :logging.Log = new logging.Log('protean');
1212

@@ -40,7 +40,7 @@ function flatMap<T,E>(input :Array<T>, mappedFunction :(element :T) => Array<E>)
4040
// - AES encryption
4141
// - decompression using arithmetic coding
4242
// - byte sequence injection
43-
export class Protean implements Transformer {
43+
export class Protean implements transformer.Transformer {
4444
// Fragmentation transformer
4545
private fragmenter_ :fragmentation.FragmentationShaper;
4646

@@ -57,12 +57,6 @@ export class Protean implements Transformer {
5757
this.configure(JSON.stringify(sampleConfig()));
5858
}
5959

60-
// This method is required to implement the Transformer API.
61-
// @param {ArrayBuffer} key Key to set, not used by this class.
62-
public setKey = (key :ArrayBuffer) :void => {
63-
throw new Error('setKey unimplemented');
64-
}
65-
6660
public configure = (json :string) :void => {
6761
let config = JSON.parse(json);
6862

@@ -119,7 +113,4 @@ export class Protean implements Transformer {
119113
let defragmented = flatMap(decrypted, this.fragmenter_.restore);
120114
return defragmented;
121115
}
122-
123-
// No-op (we have no state or any resources to dispose).
124-
public dispose = () :void => {}
125116
}

src/transformers/transformer.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Transforms byte arrays for purposes of network traffic obfuscation.
2+
export interface Transformer {
3+
// Configures the transformer with an implementation-specific string.
4+
// Intended to be called once, immediately after creation and before any
5+
// packets are transformed or restored.
6+
// TODO: remove this, configure on construction
7+
configure(config: string): void;
8+
9+
// Returns the obfuscated form of p, as one or more (in the case of
10+
// fragmentation) ArrayBuffers.
11+
transform(p: ArrayBuffer): ArrayBuffer[];
12+
13+
// Returns a zero (if p is not the final or only fragment of a packet) or
14+
// one-length list of ArrayBuffers of the original, unobfuscated form of c.
15+
restore(c: ArrayBuffer): ArrayBuffer[];
16+
}

0 commit comments

Comments
 (0)