Skip to content

Commit dd5c246

Browse files
Merge pull request #29 from jrconlin/draft/python
feat: Add int "aes128gcm" content-type handling to python.
2 parents 95fadef + fc8cc61 commit dd5c246

12 files changed

Lines changed: 771 additions & 253 deletions

File tree

nodejs/test.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ var crypto = require('crypto');
44
var ece = require('./ece.js');
55
var base64 = require('urlsafe-base64');
66
var assert = require('assert');
7+
var fs = require('fs');
8+
79

810
// Usage: node test.js [args]
911
// If args contains a version (e.g., aes128gcm), filter on versions.
@@ -35,6 +37,7 @@ if (process.argv.length >= 3) {
3537
} else {
3638
plaintext = new Buffer(process.argv[2], 'ascii');
3739
}
40+
dump = ( process.argv.indexOf('dump') != -1)
3841
}
3942
function filterTests(fullList) {
4043
var filtered = fullList.filter(function(t) {
@@ -59,12 +62,16 @@ function logbuf(msg, buf) {
5962
}
6063
}
6164

65+
// Validate that the encryption function only accepts Buffers
6266
function validate() {
6367
['hello', null, 1, NaN, [], {}].forEach(function(v) {
6468
try {
65-
encrypt('hello', {});
66-
throw new Error('should insist on a buffer');
67-
} catch (e) {}
69+
ece.encrypt(v, {});
70+
} catch (e) {
71+
if (e.toString() != "Error: buffer argument must be a Buffer") {
72+
throw new Error("encrypt failed to reject " + JSON.stringify(v));
73+
}
74+
}
6875
});
6976
}
7077

@@ -104,6 +111,21 @@ function encryptDecrypt(input, encryptParams, decryptParams) {
104111
logbuf('Encrypted', encrypted);
105112
var decrypted = ece.decrypt(encrypted, decryptParams);
106113
logbuf('Decrypted', decrypted);
114+
if (dump) {
115+
var data = {
116+
version: version,
117+
input: base64.encode(input),
118+
encrypted: base64.encode(encrypted),
119+
params: {
120+
encrypted: encryptParams,
121+
decrypt: decryptParams,
122+
}
123+
};
124+
if (keyData) {
125+
data.keys = keyData;
126+
}
127+
dumpData(data);
128+
}
107129
assert.equal(Buffer.compare(input, decrypted), 0);
108130
log('----- OK');
109131
}
@@ -155,7 +177,7 @@ function detectTruncation(version) {
155177
logbuf('Encrypted', encrypted);
156178
var ok = false;
157179
try {
158-
ece.decrypt(encrypted, params);
180+
ece.decrypt(encrypted, params, params, version);
159181
} catch (e) {
160182
log('----- OK: ' + e);
161183
ok = true;
@@ -282,4 +304,4 @@ filterTests([ 'aesgcm128', 'aesgcm', 'aes128gcm' ])
282304
});
283305
checkExamples();
284306

285-
log('All tests passed.');
307+
log('All tests passed.');

python/.coveragerc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[report]
2+
omit =
3+
*noseplugin*
4+
show_missing = true

python/.noserc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# this file's explicitly loaded from setup.cfg (.noserc isn't a
2+
# standard config path), separated out due to '%(...)s'
3+
[nosetests]
4+
verbose=True
5+
verbosity=1
6+
detailed-errors=True
7+
with-coverage=True
8+
cover-erase=True
9+
cover-package=http_ece
10+
cover-tests=True
11+
logging-format=%(asctime)s,%(msecs)03d %(name)s: %(levelname)s: %(message)s
12+
logging-datefmt=%H:%M:%S

python/.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: python
2+
python:
3+
- "2.7"
4+
install:
5+
- pip install -r test-requirements.txt
6+
script:
7+
- nosetests
8+
- flake8 http-ece
9+
after_success:
10+
- codecov

python/VERSION_DIFFERENCES.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Major Differences Between the Various HTTP ECE Versions
2+
3+
## aes128gcm
4+
* Most current version as of 2016/11
5+
* `salt`, `rs`, and `key_id` now all contained as preamble for the encrypted content.
6+
* Sender's public DH key value is sent as the `dh` parameter of the `Crypto-Key` header
7+
* The `Encryption` header is no longer required.
8+
* The context string `WebPush: info\x00` + Receiver's raw public key + Sender's raw public key
9+
* `keyinfo` string set to `Content-Encoding: aes128gcm\x00`
10+
* `nonceinfo` string set to `Content-Encoding: nonce\x00`
11+
12+
## aesgcm
13+
* `salt` contained as 'salt' parameter of the `Encryption` header
14+
* `key_id` contained as `keyid` parameter of the `Crypto-Key` header
15+
* Sender's public DH key value is sent as the `dh` parameter of the `Crypto-Key` header
16+
* The context string is: `P-256\x00\x00\x41` + Receiver's raw public key + `\x00\x41` + Sender's raw public key
17+
* `keyinfo` string set to `Content-Encoding: aesgcm\x00` + context_string
18+
* `nonceinfo` string set to `Content-Encoding: nonce` + context_string
19+
20+
## aesgcm128
21+
* Most obsolete version
22+
* `salt` contained as 'salt' parameter of the `Encryption` header
23+
* `key_id` contained as `keyid` parameter of the `Encryption-Key` header
24+
* Sender's public DH key value is sent as the `dh` parameter of the `Encryption-Key` header
25+
* The context string is: `P-256\x00\x00\x41` + Receiver's raw public key + `\x00\x41` + Sender's raw public key
26+
* `keyinfo` string set to `Content-Encoding: aesgcm128`
27+
* `nonceinfo` string set to `Content-Encoding: nonce`
28+
* padding between chunks is only 1 octet.

0 commit comments

Comments
 (0)