Commit Graph

1552 Commits

Author SHA1 Message Date
Daniel Huigens
d844b8b06c Add minimum AEAD buffer size
This enables parallelism for streaming AEAD chunked encryption.

The reason we can't do so at the very end of the pipe chain
(e.g., in `readToEnd`) is because requests for increased
buffering (i.e. `desiredSize > 1`) do not propagate backwards,
only requests for backpressure (i.e. `desiredSize <= 0`) do.
2018-08-14 16:35:39 +02:00
Daniel Huigens
54d5bd7d39 Add testcase for verifying messages without one-pass-signatures 2018-08-14 16:35:39 +02:00
Daniel Huigens
ca537e439d Comments & code style 2018-08-14 16:35:38 +02:00
Daniel Huigens
1101a05b10 Don't return streams inside unarmored generated keys and signatures
When not requested, we convert the streams to Uint8Arrays.

This makes the generated key safe to pass to a Worker more than once.

Partially reverts 735aa1da.
2018-08-14 16:35:36 +02:00
Daniel Huigens
85223093a4 Switch to fork of asmcrypto.js
Fixes performance issues in Firefox.
2018-08-10 14:46:30 +02:00
Daniel Huigens
d489f3369f Update to asmcrypto.js 2 2018-08-10 14:46:30 +02:00
Daniel Huigens
e66d44e42d Rename config.unsafe_stream to allow_unauthenticated_stream 2018-08-10 14:46:29 +02:00
Daniel Huigens
2b30ab9c8f Replace data with message parameter in encrypt() and sign()
When encrypting/signing a stream, this allows you to indicate whether it's a
stream of Strings or Uint8Arrays (using message.fromText or message.fromBinary,
respectively.)

When signing text, this allows you to control whether to create a cleartext
message or a regular armored text message.

When creating a detached signature, it allows you to control whether it's "meant
for" (verifying against) a cleartext message. A cleartext message has trailing
whitespace trimmed before signing. This fixes the case of passing a detached
signature from sign() to encrypt(). Since encrypt() doesn't create a cleartext
message, the signature would be invalid if the text contained lines with
trailing whitespace.
2018-08-10 14:46:29 +02:00
Daniel Huigens
95413cc6ed Fix signatures of messages with leading/trailing whitespace 2018-08-10 14:46:29 +02:00
Daniel Huigens
160b03451f Fix key generation in Firefox
Previously broken by daa0188e.
2018-08-10 14:46:29 +02:00
Daniel Huigens
9f0f00e087 Make signature.verified a Promise instead of result.signatures
Also, fix verifying detached signatures
2018-08-10 14:46:28 +02:00
Daniel Huigens
0db32bea39 Backpressure and cancellation in sign/verify 2018-08-10 14:46:28 +02:00
Daniel Huigens
d2ba6b3c6c Wait for data to be read before resolving signatures 2018-08-10 14:46:28 +02:00
Daniel Huigens
3113976dd2 Don't throw in result.signatures
- The caller might not await them, in which case you get an "unhandled rejection"
- The caller might await them but only after reading the data, in which case you
  get an unhandled rejection if there's an error before the end of the data
2018-08-10 14:46:27 +02:00
Daniel Huigens
b6e988b6a6 Convert result.signatures to a Promise
Also, throw armor checksum errors inside the data stream
2018-08-10 14:46:27 +02:00
Daniel Huigens
0cabf72682 Add TextDecoder polyfill 2018-08-10 14:46:27 +02:00
Daniel Huigens
ad92ac7c3a Fix signature type of one-pass signatures when passing a signature
If the type of the signature passed to openpgp.encrypt() did not
match the "expected" type (text for literal text packets, etc)
the signature type would be set incorrectly.
2018-08-10 14:46:26 +02:00
Daniel Huigens
4d82d25559 Pass more tests
We now use streams internally in more places.
2018-08-10 14:46:26 +02:00
Daniel Huigens
4e749965f2 Remove support for V3 keys and signatures 2018-08-10 14:46:26 +02:00
Daniel Huigens
eb72d4dd63 Don't use asmcrypto's streaming API when not necessary
Optimization for Firefox
2018-08-10 14:46:26 +02:00
Daniel Huigens
e1a8b17753 Fix literalPacket.getText()
We now close streams after reading them, so we can no longer use
stream.locked for a proxy for "has been read". What we want is the
internal [[disturbed]] property, but we can't access it for native
streams.

Since we always read the stream when calling getText(), it's not
an issue.
2018-08-10 14:46:25 +02:00
Daniel Huigens
411b626149 Work around timing difference between Chrome and polyfill
When piping a stream to a writable stream and erroring that,
the input (readable) stream only gets cancelled after pipeTo()
returns in Chrome.
2018-08-10 14:46:25 +02:00
Daniel Huigens
55fd292fba Fix armor errors
Also, fix error handling in transformPair()
2018-08-10 14:46:25 +02:00
Daniel Huigens
304cbf4783 Fix backpressure 2018-08-10 14:46:25 +02:00
Daniel Huigens
589b666ac7 Don't clone stream in packet.parse() 2018-08-10 14:46:24 +02:00
Daniel Huigens
ddda6a0b16 Implement cancellation by manually linking together input and output streams 2018-08-10 14:46:24 +02:00
Daniel Huigens
de2971d84a Use TransformStreams 2018-08-10 14:46:24 +02:00
Daniel Huigens
51c897b073 Cancelling 2018-08-10 14:46:23 +02:00
Daniel Huigens
a6a701df7f Streaming signing 2018-08-10 14:46:23 +02:00
Daniel Huigens
9c1c28bc59 Add option to read unauthenticated data from stream 2018-08-10 14:46:23 +02:00
Daniel Huigens
1effe19c1d Allow simultaneously reading data and waiting for signature verification
This makes openpgp.{decrypt,verify}().signatures a Promise when passing a
stream or when asStream=true
2018-08-10 14:46:22 +02:00
Daniel Huigens
4bbbdaee9f Rename stream.subarray() to stream.slice()
Also, support ReadableStream[String] in stream.* and reader.* functions
2018-08-10 14:46:22 +02:00
Daniel Huigens
56ec5b3a8d Don't keep extra copies of streams in memory 2018-08-10 14:46:22 +02:00
Daniel Huigens
78a0ca937e Cache browserified modules
Adding asmcrypto's SHA1 and SHA512 made browserify a lot slower,
this makes it a lot faster on the second run at least.
2018-08-10 14:46:21 +02:00
Daniel Huigens
f79a3f718d Fix streaming UTF8 decoding 2018-08-10 14:44:01 +02:00
Daniel Huigens
f0633f00ea Don't repeatedly decrypt the same key in unit tests 2018-08-10 14:44:01 +02:00
Daniel Huigens
253e1c572b Switch to asmcrypto for hashing where available 2018-08-10 14:44:01 +02:00
Daniel Huigens
ade2627bca Streaming verify one-pass signatures 2018-08-10 14:44:01 +02:00
Daniel Huigens
ead3ddd706 Streaming decrypt old-format packets 2018-08-10 14:44:01 +02:00
Daniel Huigens
9fcc075f0b Streaming decrypt non-partial-length-encoded packets 2018-08-10 14:44:01 +02:00
Daniel Huigens
fb155ffae0 Streaming support on Node 2018-08-10 14:44:01 +02:00
Daniel Huigens
8658816b90 Add Web Streams polyfill 2018-08-10 14:44:01 +02:00
Daniel Huigens
802e1b8d94 Transfer Streams to Workers
Also, add a "asStream" parameter to high-level functions to control
whether the return value is a Stream; defaulting to whether the
parameter passed was a Stream.
2018-08-10 14:44:01 +02:00
Daniel Huigens
58eca571bf Fix integrity_protect = false 2018-08-10 14:44:01 +02:00
Daniel Huigens
d67526338e Streaming (de)compression (Web)
compressjs has a streaming API, but it is synchronous, so we can't use it
(at least in the browser).
2018-08-10 14:44:01 +02:00
Daniel Huigens
37014ecf30 Pass more tests
- Allow leading spaces in headers (since we were already accepting
leading spaces everywhere else in the armored text).
- Read ReadableStreams before passing them to a Worker
2018-08-10 14:44:01 +02:00
Daniel Huigens
05479e6e6b Don't warn about await in loops 2018-08-10 14:44:01 +02:00
Daniel Huigens
db39e616ca Replace stream.tee() with stream.clone()
Also some other fixes to pass more tests.
2018-08-10 14:44:01 +02:00
Daniel Huigens
3475843d82 Don't hack util.concatUint8Array() to handle Streams
Use util.concat() instead.
2018-08-10 14:44:01 +02:00
Daniel Huigens
16ba26c298 Streaming AEAD 2018-08-10 14:44:01 +02:00