mirror of https://github.com/keeweb/keeweb.git
sign html
This commit is contained in:
parent
68a51a27c5
commit
be2699f2d1
11
Gruntfile.js
11
Gruntfile.js
|
@ -445,6 +445,14 @@ module.exports = function(grunt) {
|
|||
publicKey: 'app/resources/public-key.pem'
|
||||
}
|
||||
}
|
||||
},
|
||||
'sign-html': {
|
||||
'app': {
|
||||
options: {
|
||||
file: 'dist/index.html',
|
||||
privateKey: 'keys/private-key.pem'
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -464,7 +472,8 @@ module.exports = function(grunt) {
|
|||
'inline',
|
||||
'htmlmin',
|
||||
'string-replace:manifest_html',
|
||||
'string-replace:manifest'
|
||||
'string-replace:manifest',
|
||||
'sign-html'
|
||||
]);
|
||||
|
||||
grunt.registerTask('desktop', [
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<head lang="en">
|
||||
<meta charset="UTF-8">
|
||||
<title>KeeWeb</title>
|
||||
<meta name="signature" content="">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<link rel="shortcut icon" href="favicon.png?__inline=true" />
|
||||
<link rel="apple-touch-icon" sizes="192x192" href="touchicon.png?__inline=true">
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = function (grunt) {
|
||||
grunt.registerMultiTask('sign-html', 'Signs html page with a private key', function () {
|
||||
var fs = require('fs');
|
||||
var crypto = require('crypto');
|
||||
if (!fs.existsSync(this.options().privateKey)) {
|
||||
grunt.log.warn('Private key is missing, app html will not be signed.');
|
||||
return;
|
||||
}
|
||||
var file = fs.readFileSync(this.options().file).toString('utf8');
|
||||
var marker = '<meta name="signature" content="';
|
||||
var ix = file.indexOf(marker);
|
||||
if (ix < 0) {
|
||||
grunt.warn('Signature placeholder not found');
|
||||
return;
|
||||
}
|
||||
var sign = crypto.createSign('RSA-SHA256');
|
||||
sign.write(file);
|
||||
sign.end();
|
||||
var privateKey = fs.readFileSync(this.options().privateKey, 'binary');
|
||||
var signature = sign.sign(privateKey).toString('base64');
|
||||
file = file.replace(marker, marker + signature);
|
||||
fs.writeFileSync(this.options().file, file, 'utf8');
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue