safely-serve 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,108 @@
1
+ [comment]: <> (SPDX-License-Identifier: AGPL-3.0)
2
+
3
+ [comment]: <> (-------------------------------------------------------------)
4
+ [comment]: <> (Copyright © 2024, 2025)
5
+ [comment]: <> ( Pellegrino Prevete)
6
+ [comment]: <> (All rights reserved)
7
+ [comment]: <> (-------------------------------------------------------------)
8
+ [comment]: <> (This program is free software: you can redistribute)
9
+ [comment]: <> (it and/or modify it under the terms of the GNU Affero)
10
+ [comment]: <> (General Public License as published by the Free)
11
+ [comment]: <> (Software Foundation, either version 3 of the License.)
12
+
13
+ [comment]: <> (This program is distributed in the hope that it will be useful,)
14
+ [comment]: <> (but WITHOUT ANY WARRANTY; without even the implied warranty of)
15
+ [comment]: <> (MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the)
16
+ [comment]: <> (GNU Affero General Public License for more details.)
17
+
18
+ [comment]: <> (You should have received a copy of the GNU Affero General)
19
+ [comment]: <> (Public License along with this program.)
20
+ [comment]: <> (If not, see <https://www.gnu.org/licenses/>.)
21
+
22
+
23
+ # Safely Serve (`safely-serve`)
24
+
25
+ A Serve extension which
26
+ auto-generate a new
27
+ self-signed certificate
28
+ when none is provided.
29
+
30
+ Certificates generation
31
+ is handled using
32
+ [Certificate Tools](
33
+ https://github.com/themartiancompany/cert-tools).
34
+
35
+ It works both in Node.js and in web browsers
36
+ using the
37
+ [Crash Javacript](
38
+ https://github.com/themartiancompany/crash-js)
39
+ module.
40
+
41
+ ### Installation
42
+
43
+ You can install and save an entry to your `package.json`
44
+ with the following command:
45
+
46
+ ```bash
47
+ npm \
48
+ install \
49
+ --save \
50
+ "safely-serve"
51
+ ```
52
+
53
+ You can then run the program with
54
+
55
+ ```bash
56
+ npx \
57
+ "safely-serve"
58
+ ```
59
+
60
+ or just with `safely-serve` if you install
61
+ the program system-wide using npm from this source
62
+ repository or from the
63
+ [NPM Registry](
64
+ https://www.npmjs.com/package/safely-serve)
65
+
66
+ ```
67
+ npm \
68
+ -g \
69
+ install \
70
+ "safely-serve"
71
+ ```
72
+
73
+ or if using GNU make in this repository
74
+
75
+ ```bash
76
+ make \
77
+ install
78
+ ```
79
+
80
+ **Note:** You may need admin rights (`sudo`,
81
+ `su -c` or on Windows `Run as administrator`).
82
+
83
+ or if you install it as a
84
+ [DogeOS](
85
+ https://github.com/themartiancompany/dogeos)
86
+ package from the
87
+ [Ur](
88
+ https://github.com/themartiancompany/ur)
89
+
90
+ ```bash
91
+ ur \
92
+ "safely-serve"
93
+ ```
94
+
95
+ ### Documentation
96
+
97
+ Upon installation the manual can be accessed with
98
+
99
+ ```bash
100
+ man \
101
+ "safely-serve"
102
+ ```
103
+
104
+ # License
105
+
106
+ This software by Pellegrino Prevete is released
107
+ under the terms of the GNU Affero General Public License
108
+ version 3.
@@ -0,0 +1,38 @@
1
+
2
+ // SPDX-License-Identifier: GPL-3.0-or-later
3
+
4
+ // ----------------------------------------------------------------------
5
+ // Copyright © 2024, 2025
6
+ // Jiang Jie
7
+ // Copyright © 2025
8
+ // Pellegrino Prevete
9
+ //
10
+ // All rights reserved
11
+ // ----------------------------------------------------------------------
12
+ //
13
+ // This program is free software: you can redistribute it and/or modify
14
+ // it under the terms of the GNU General Public License as published by
15
+ // the Free Software Foundation, either version 3 of the License, or
16
+ // (at your option) any later version.
17
+ //
18
+ // This program is distributed in the hope that it will be useful,
19
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ // GNU General Public License for more details.
22
+ //
23
+ // You should have received a copy of the GNU General Public License
24
+ // along with this program. If not, see <https://www.gnu.org/licenses/>.
25
+
26
+ import { defineConfig } from "eslint/config";
27
+
28
+ export default defineConfig([
29
+ { ignores: [
30
+ "build/**",
31
+ "eslint.config.js"
32
+ ],
33
+ rules:
34
+ { semi:
35
+ "error",
36
+ "prefer-const":
37
+ "error" } },
38
+ ]);
package/fs-worker.js ADDED
@@ -0,0 +1 @@
1
+ (()=>{var e={314:(e,o,n)=>{const t=n(816);_sync_agent=t.startSyncAgent,e.exports={_sync_agent},_sync_agent()},816:(e,o,n)=>{function t(){let e;return"undefined"==typeof window&&void 0!==n.g&&n.g.global===n.g&&"function"!=typeof n||(e=function(){let e;try{e=n(816)}catch(e){console.log(e);const o="Error importing the '@themartiancompany/opfs' module as 'opfs'. If you got this error while bundling a webpack for a project depending on this module double check its 'webpack.config.js' file or whether the 'opfs' module is listed in developer dependencies and install them.I'm sorry for this inconvenience but Node packagement system does not currently distinguish 'development' from 'build' dependencies.";throw console.error(o),e}return e}()),e}const r=t();e.exports=r,e.exports.getModule=function(e){let o;if(""==_module_name||"undefined"==typeof _module_name)o=t();else if("opfs"==_module_name)o=n(816);else{if("fs"!=_module_name){const e="Unknown file system module "+`'${_module_name}'.`.const;throw _error={msg:e},console.error(e),_error}o=n(816)}return o}}},o={};function n(t){var r=o[t];if(void 0!==r)return r.exports;var s=o[t]={exports:{}};return e[t](s,s.exports,n),s.exports}n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n(314)})();
@@ -0,0 +1,48 @@
1
+ const
2
+ _path =
3
+ require(
4
+ 'path');
5
+ const
6
+ _output_dir =
7
+ _path.resolve(
8
+ __dirname);
9
+ const
10
+ _input_file_name =
11
+ "fs-worker";
12
+ const
13
+ _input_file_path =
14
+ `./node_modules/opfs/${_input_file_name}`;
15
+ const
16
+ _output_file_name =
17
+ `${_input_file_name}.js`;
18
+ _output = {
19
+ path:
20
+ _output_dir,
21
+ filename:
22
+ _output_file_name
23
+ };
24
+ module.exports = {
25
+ entry:
26
+ _input_file_path,
27
+ output:
28
+ _output,
29
+ optimization: {
30
+ moduleIds: 'deterministic',
31
+ },
32
+ resolve: {
33
+ alias: {
34
+ "fs":
35
+ _path.resolve(
36
+ __dirname,
37
+ 'node_modules/fs/fs'),
38
+ "opfs":
39
+ _path.resolve(
40
+ __dirname,
41
+ 'node_modules/fs/fs'),
42
+ "path":
43
+ _path.resolve(
44
+ __dirname,
45
+ 'node_modules/path/mod.js'),
46
+ },
47
+ }
48
+ };
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env node
2
+
3
+ // SPDX-License-Identifier: AGPL-3.0-or-later
4
+
5
+ // ----------------------------------------------------------------------
6
+ // Copyright © 2024, 2025 Pellegrino Prevete
7
+ //
8
+ // All rights reserved
9
+ // ----------------------------------------------------------------------
10
+ //
11
+ // This program is free software: you can redistribute it and/or modify
12
+ // it under the terms of the GNU Affero General Public License as published by
13
+ // the Free Software Foundation, either version 3 of the License, or
14
+ // (at your option) any later version.
15
+ //
16
+ // This program is distributed in the hope that it will be useful,
17
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ // GNU Affero General Public License for more details.
20
+ //
21
+ // You should have received a copy of the GNU Affero General Public License
22
+ // along with this program. If not, see <https://www.gnu.org/licenses/>.
23
+
24
+ const
25
+ _serve_module =
26
+ require(
27
+ 'serve');
28
+ const
29
+ _cert_tools_module =
30
+ require(
31
+ 'cert-tools');
32
+ const
33
+ _libcrash =
34
+ require(
35
+ 'crash-js');
36
+ _error_display =
37
+ _libcrash._error_display;
38
+ _ext_rm =
39
+ _libcrash._ext_rm;
40
+ _file_exists =
41
+ _libcrash._file_exists;
42
+ _file_read =
43
+ _libcrash._file_read;
44
+ _file_write =
45
+ _libcrash._file_write;
46
+ _fs_worker_start =
47
+ _libcrash._fs_worker_start;
48
+ _json_read =
49
+ _libcrash._json_read;
50
+ _ls =
51
+ _libcrash._ls;
52
+ _mkdir =
53
+ _libcrash._mkdir;
54
+ _msg_info =
55
+ _libcrash._msg_info;
56
+ _msg_error =
57
+ _libcrash._msg_error;
58
+
59
+ async function
60
+ _safely_serve(
61
+ _key_private_path,
62
+ _keys_length,
63
+ _serial_number,
64
+ _validity_min,
65
+ _validity_max,
66
+ _domain_name,
67
+ _country_name,
68
+ _state_name,
69
+ _locality_name,
70
+ _organization_name,
71
+ _organization_unit,
72
+ _output_file) {
73
+ let
74
+ _alt_names,
75
+ _attrs,
76
+ _basic_constraints,
77
+ _cert,
78
+ _ext_key_usage,
79
+ _key_usage,
80
+ _key_pem,
81
+ _key_private,
82
+ _keys,
83
+ _keys_pem,
84
+ _ns_cert_type,
85
+ _pem,
86
+ _subject_alt_name,
87
+ _subject_key_identifier;
88
+ _keys_length =
89
+ Number(
90
+ _keys_length);
91
+ if ( _key_private_path == "" ||
92
+ ! _file_exists(
93
+ _key_private_path) ) {
94
+ _keys =
95
+ _rsa.generateKeyPair(
96
+ _keys_length);
97
+ _key_pem =
98
+ _pki.privateKeyToPem(
99
+ _keys.privateKey);
100
+ _file_write(
101
+ _key_private_path,
102
+ _key_pem);
103
+ _key_private =
104
+ _keys.privateKey;
105
+ }
106
+ else {
107
+ _key_pem =
108
+ _file_read(
109
+ _key_private_path);
110
+ _key_private =
111
+ _pki.privateKeyFromPem(
112
+ _key_pem);
113
+ _keys =
114
+ { privateKey:
115
+ _key_private };
116
+ }
117
+ if ( _log_file != "" ) {
118
+ if ( typeof window !== 'undefined') {
119
+ await _fs_worker_start(
120
+ "fs-worker.js");
121
+ }
122
+ _file_write(
123
+ _log_file,
124
+ _whatever_log);
125
+ }
126
+ return true;
127
+ }
128
+
129
+ module.exports = {
130
+ _safely_serve:
131
+ _safely_serve
132
+ };
@@ -0,0 +1,86 @@
1
+ const
2
+ _path =
3
+ require(
4
+ 'path');
5
+ const
6
+ _output_dir =
7
+ _path.resolve(
8
+ __dirname);
9
+ const
10
+ _input_file_name =
11
+ `libsafely-serve`;
12
+ const
13
+ _input_file_path =
14
+ `./${_input_file_name}`;
15
+ const
16
+ _output_file_name =
17
+ `${_input_file_name}.js`;
18
+ const
19
+ _yargs_ignore =
20
+ { resourceRegExp:
21
+ /^yargs$/ };
22
+ const
23
+ _yargs_helpers_ignore = {
24
+ resourceRegExp:
25
+ /^yargs\/helpers$/
26
+ };
27
+ const
28
+ _webpack =
29
+ require(
30
+ "webpack");
31
+ const
32
+ _ignore_plugin =
33
+ _webpack.IgnorePlugin;
34
+ const
35
+ _yargs_ignore_plugin =
36
+ new _ignore_plugin(
37
+ _yargs_ignore);
38
+ const
39
+ _yargs_helpers_ignore_plugin =
40
+ new _ignore_plugin(
41
+ _yargs_helpers_ignore);
42
+ const
43
+ _output = {
44
+ path:
45
+ _output_dir,
46
+ filename:
47
+ _output_file_name
48
+ };
49
+ module.exports = {
50
+ entry:
51
+ _input_file_path,
52
+ output:
53
+ _output,
54
+ optimization: {
55
+ moduleIds: 'deterministic',
56
+ },
57
+ resolve: {
58
+ alias: {
59
+ "fs":
60
+ _path.resolve(
61
+ __dirname,
62
+ 'node_modules/fs/fs'),
63
+ "path":
64
+ _path.resolve(
65
+ __dirname,
66
+ 'node_modules/path/mod.js'),
67
+ },
68
+ fallback: {
69
+ "utils":
70
+ false,
71
+ "web-worker":
72
+ false,
73
+ "yargs":
74
+ false,
75
+ "yargs/helpers":
76
+ false,
77
+ }
78
+ },
79
+ externals:
80
+ { yargs:
81
+ 'yargs' },
82
+ plugins: [
83
+ _yargs_ignore_plugin,
84
+ _yargs_helpers_ignore_plugin
85
+ ]
86
+ };
@@ -0,0 +1,112 @@
1
+ .\" Man page generated from reStructuredText
2
+ .\" by the Docutils 0.22.3 manpage writer.
3
+ .
4
+ .
5
+ .nr rst2man-indent-level 0
6
+ .
7
+ .de1 rstReportMargin
8
+ \\$1 \\n[an-margin]
9
+ level \\n[rst2man-indent-level]
10
+ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
11
+ -
12
+ \\n[rst2man-indent0]
13
+ \\n[rst2man-indent1]
14
+ \\n[rst2man-indent2]
15
+ ..
16
+ .de1 INDENT
17
+ .\" .rstReportMargin pre:
18
+ . RS \\$1
19
+ . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
20
+ . nr rst2man-indent-level +1
21
+ .\" .rstReportMargin post:
22
+ ..
23
+ .de UNINDENT
24
+ . RE
25
+ .\" indent \\n[an-margin]
26
+ .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
27
+ .nr rst2man-indent-level -1
28
+ .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
29
+ .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
30
+ ..
31
+ .TH "cert-gen" "1" "" "cert-gen insert.version.here"
32
+ .SH Name
33
+ cert-gen \- Certificate generator
34
+ .SH Synopsis
35
+ .sp
36
+ cert\-gen \fIoption\fP
37
+ .SH Description
38
+ .sp
39
+ Generates an X509 version 3
40
+ certificate using an existing private key
41
+ or generating one at runtime.
42
+ .sp
43
+ It depends on the Forge TLS
44
+ Javascript implementation
45
+ and on the Crash Javascript Library.
46
+ .sp
47
+ It runs both in Node as in
48
+ the browser.
49
+ .SH Options
50
+ .INDENT 0.0
51
+ .TP
52
+ .BI \-i\fP,\fB \-\-key\-private\fB= FILE
53
+ Use existing private key.
54
+ .TP
55
+ .BI \-l\fP,\fB \-\-keys\-length\fB= N
56
+ Keys pair length.
57
+ .TP
58
+ .BI \-o\fP,\fB \-\-output\-file\fB= FILE
59
+ Set output file.
60
+ .UNINDENT
61
+ .SH Validity options
62
+ .INDENT 0.0
63
+ .TP
64
+ .BI \-B\fP,\fB \-\-validity\-start\fB= DATE
65
+ Set activation date.
66
+ .TP
67
+ .BI \-E\fP,\fB \-\-validity\-end\fB= DATE
68
+ Set expiration date.
69
+ .UNINDENT
70
+ .SH Identity Options
71
+ .INDENT 0.0
72
+ .TP
73
+ .BI \-D\fP,\fB \-\-domain\-name\fB= DOMAIN
74
+ Set domain name.
75
+ .TP
76
+ .BI \-C\fP,\fB \-\-country\-name\fB= COUNTRY
77
+ Set country name.
78
+ .TP
79
+ .BI \-S\fP,\fB \-\-state\-name\fB= STATE
80
+ Set state name.
81
+ .TP
82
+ .BI \-L\fP,\fB \-\-locality\-name\fB= LOCALITY
83
+ Set locality name.
84
+ .TP
85
+ .BI \-O\fP,\fB \-\-organization\-name\fB= ORG
86
+ Set organization name.
87
+ .TP
88
+ .BI \-U\fP,\fB \-\-organization\-unit\fB= UNIT
89
+ Set organization unit.
90
+ .TP
91
+ .BI \-s\fP,\fB \-\-serial\-number\fB= SERIAL
92
+ Set serial number.
93
+ .UNINDENT
94
+ .sp
95
+ \-v \-\-verbose Enable verbose output.
96
+ \-h Display help.
97
+ .SH Bugs
98
+ .sp
99
+ \%<https://\:github\:.com/\:themartiancompany/\:cert-tools/\:-/\:issues>
100
+ .SH Copyright
101
+ .sp
102
+ Copyright Pellegrino Prevete. AGPL\-3.0.
103
+ .SH See also
104
+ .INDENT 0.0
105
+ .IP \(bu 2
106
+ node\-run
107
+ .IP \(bu 2
108
+ libcrash\-js
109
+ .IP \(bu 2
110
+ tmcfs
111
+ .UNINDENT
112
+ .\" End of generated man page.
package/package.json ADDED
@@ -0,0 +1,106 @@
1
+ {
2
+ "name":
3
+ "safely-serve",
4
+ "version":
5
+ "0.0.1",
6
+ "description":
7
+ "Serve extension which auto-generates self-signed OpenSSL certificates' at runtime",
8
+ "funding": {
9
+ "type":
10
+ "patreon",
11
+ "url":
12
+ "https://patreon.com/tallero"
13
+ },
14
+ "man":
15
+ "./man/safely-serve.1",
16
+ "files": [
17
+ "AUTHORS.rst",
18
+ "COPYING",
19
+ "README.md",
20
+ "eslint.config.mjs",
21
+ "package.json",
22
+ "safely-serve.js",
23
+ "safely-serve",
24
+ "fs-worker.js",
25
+ "fs-worker.webpack.config.cjs",
26
+ "index.html",
27
+ "libsafely-serve",
28
+ "libsafely-serve.webpack.config.cjs",
29
+ "man",
30
+ "serve.json",
31
+ "webpack.config.cjs"
32
+ ],
33
+ "keywords": [
34
+ "cert-tools",
35
+ "ur",
36
+ "themartiancompany",
37
+ "dogeos"
38
+ ],
39
+ "homepage":
40
+ "https://github.com/themartiancompany/safely-serve",
41
+ "bugs": {
42
+ "url":
43
+ "https://github.com/themartiancompany/safely-serve/issues"
44
+ },
45
+ "repository": {
46
+ "type":
47
+ "git",
48
+ "url":
49
+ "git+https://github.com/themartiancompany/safely-serve.git"
50
+ },
51
+ "license":
52
+ "AGPL-3.0-or-later",
53
+ "author": {
54
+ "name":
55
+ "Pellegrino Prevete",
56
+ "email":
57
+ "pellegrinoprevete@gmail.com",
58
+ "url":
59
+ "https://github.com/tallero"
60
+ },
61
+ "devDependencies": {
62
+ "crash-js-webpack":
63
+ "^0.0.3",
64
+ "eslint":
65
+ "^9.32.0",
66
+ "parcel":
67
+ "^2.16.0",
68
+ "webpack":
69
+ "^5.102.1",
70
+ "webpack-cli":
71
+ "^6.0.1"
72
+ },
73
+ "dependencies": {
74
+ "crash-js":
75
+ "^0.1.67",
76
+ "cert-tools":
77
+ "^0.0.7",
78
+ "serve":
79
+ "^14.2.5"
80
+ },
81
+ "type":
82
+ "commonjs",
83
+ "main":
84
+ "libsafely-serve",
85
+ "bin":
86
+ { "safely-serve":
87
+ "safely-serve" },
88
+ "scripts": {
89
+ "build-fs-worker":
90
+ "npx webpack --mode 'production' --config 'fs-worker.webpack.config.cjs' --stats-error-details",
91
+ "build-lib":
92
+ "npx webpack --mode 'production' --config 'libsafely-serve.webpack.config.cjs' --stats-error-details",
93
+ "build-bin":
94
+ "npx webpack --mode 'production' --config 'webpack.config.cjs' --stats-error-details",
95
+ "build":
96
+ "npm run lint && npm run build-fs-worker && npm run build-lib && npm run build-bin",
97
+ "lint":
98
+ "npx eslint .",
99
+ "publish-pnm":
100
+ "npm run build && npm publish --access public",
101
+ "start":
102
+ "npx parcel serve index.html --port 3000 --https --no-cache",
103
+ "test":
104
+ "echo \"Error: no test specified\" && exit 1"
105
+ }
106
+ }