Skip to content

Commit e45a9a1

Browse files
committed
Implementing multipart/msigned
1 parent 7f3a4bf commit e45a9a1

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ module.exports = function sign(signFunction) {
2626
, end = res.end
2727
, stream
2828
, method
29-
, doSign = req.headers['accept'] == 'multipart/signed'
30-
, boundary = 'foo';
29+
, doSign = req.headers['accept'] == 'multipart/msigned';
3130

3231
// see compress.js #724
3332
req.on('close', function(){
@@ -71,10 +70,8 @@ module.exports = function sign(signFunction) {
7170
stream = new SigningStream(signFunction, boundary);
7271

7372
// header fields
74-
var contentType = 'multipart/signed;';
73+
var contentType = 'multipart/msigned;';
7574
contentType += ' boundary='+boundary+';';
76-
//contentType += ' micalg=pgp-sha1;';
77-
contentType += ' protocol="application/pgp-signature"';
7875
res.setHeader('Content-Type', contentType);
7976
res.removeHeader('Content-Length');
8077

signingstream.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,17 @@ SigningStream.prototype.end = function(data) {
2323
SigningStream.prototype.sign = function(callback) {
2424
var that = this;
2525
process.nextTick(function () {
26-
var body = that.buffer.replace(/\r\n/g, '\n').replace(/\n/g, '\r\n');
27-
var text = body;
28-
// var start = Date.now();
29-
that.doSign(body, function (err, ciphertext) {
30-
// var end = Date.now();
31-
// console.log("Duration: %sms", (end-start));
26+
var text = that.buffer.replace(/\r\n/g, '\n').replace(/\n/g, '\r\n');
27+
that.doSign(text, function (err, signature) {
3228
var body = '';
3329
body += '--' + that.boundary + '\n';
34-
body += text + '\n\n';
30+
body += 'Content-Type: octet-stream\r\n\r\n';
31+
body += text + '\r\n';
3532
if(!err){
36-
ciphertext = ciphertext.substring(ciphertext.lastIndexOf('-----BEGIN PGP SIGNATURE-----'));
33+
signature = signature.substring(signature.lastIndexOf('-----BEGIN PGP SIGNATURE-----'));
3734
body += '--' + that.boundary + '\n';
3835
body += 'Content-Type: application/pgp-signature\n\n';
39-
body += ciphertext + '\n';
36+
body += signature + '\n';
4037
}
4138
body += '--' + that.boundary + '--\n';
4239
callback(body);

0 commit comments

Comments
 (0)