@ethernity-cloud/sdk-js 1.1.0
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/LICENSE +661 -0
- package/README.md +185 -0
- package/build.js +22 -0
- package/init.js +301 -0
- package/nodenithy/build/las/Dockerfile +5 -0
- package/nodenithy/build/securelock/Dockerfile.tmpl +65 -0
- package/nodenithy/build/securelock/scripts/binary-fs-build.sh +28 -0
- package/nodenithy/build/securelock/src/.env +3 -0
- package/nodenithy/build/securelock/src/etny_crypto.js +201 -0
- package/nodenithy/build/securelock/src/etny_exec.js +65 -0
- package/nodenithy/build/securelock/src/image_registry_abi.js +808 -0
- package/nodenithy/build/securelock/src/models.js +261 -0
- package/nodenithy/build/securelock/src/package.json +40 -0
- package/nodenithy/build/securelock/src/pox_abi.js +1491 -0
- package/nodenithy/build/securelock/src/securelock.js.tmpl +421 -0
- package/nodenithy/build/securelock/src/swift_stream_service.js +147 -0
- package/nodenithy/build/securelock/src/task_status.js +15 -0
- package/nodenithy/build/securelock/src/wallet.js +29 -0
- package/nodenithy/build/squash/Dockerfile +7 -0
- package/nodenithy/build/trustedzone/Dockerfile.tmpl +57 -0
- package/nodenithy/build/trustedzone/scripts/binary-fs-build.sh +22 -0
- package/nodenithy/build/trustedzone/src/.env +3 -0
- package/nodenithy/build/trustedzone/src/etny_crypto.js +202 -0
- package/nodenithy/build/trustedzone/src/etny_exec.js +54 -0
- package/nodenithy/build/trustedzone/src/image_registry_abi.js +808 -0
- package/nodenithy/build/trustedzone/src/models.js +261 -0
- package/nodenithy/build/trustedzone/src/package.json +40 -0
- package/nodenithy/build/trustedzone/src/pox_abi.js +1491 -0
- package/nodenithy/build/trustedzone/src/swift_stream_service.js +147 -0
- package/nodenithy/build/trustedzone/src/task_status.js +15 -0
- package/nodenithy/build/trustedzone/src/test.js +44 -0
- package/nodenithy/build/trustedzone/src/trustedzone.js.tmpl +508 -0
- package/nodenithy/build/trustedzone/src/wallet.js +28 -0
- package/nodenithy/build/validator/Dockerfile +58 -0
- package/nodenithy/build/validator/package-lock.json +6 -0
- package/nodenithy/build/validator/scripts/binary-fs-build.sh +19 -0
- package/nodenithy/build/validator/src/.env +3 -0
- package/nodenithy/build/validator/src/cert.pem +5 -0
- package/nodenithy/build/validator/src/etny_crypto.js +204 -0
- package/nodenithy/build/validator/src/etny_exec.js +52 -0
- package/nodenithy/build/validator/src/image_registry_abi.js +808 -0
- package/nodenithy/build/validator/src/key.pem +6 -0
- package/nodenithy/build/validator/src/models.js +261 -0
- package/nodenithy/build/validator/src/package-lock.json +2498 -0
- package/nodenithy/build/validator/src/package.json +40 -0
- package/nodenithy/build/validator/src/pox_abi.js +1491 -0
- package/nodenithy/build/validator/src/swift_stream_service.js +147 -0
- package/nodenithy/build/validator/src/task_status.js +15 -0
- package/nodenithy/build/validator/src/test.js +44 -0
- package/nodenithy/build/validator/src/trustedzone.js +613 -0
- package/nodenithy/build/validator/src/validator_abi.js +834 -0
- package/nodenithy/build/validator/src/wallet.js +28 -0
- package/nodenithy/build.js +184 -0
- package/nodenithy/build.mjs +179 -0
- package/nodenithy/build.sh +161 -0
- package/nodenithy/ipfs.js +135 -0
- package/nodenithy/ipfs.mjs +551 -0
- package/nodenithy/public/favicon.ico +0 -0
- package/nodenithy/public/index.html +43 -0
- package/nodenithy/public/logo192.png +0 -0
- package/nodenithy/public/logo512.png +0 -0
- package/nodenithy/public/manifest.json +25 -0
- package/nodenithy/public/robots.txt +3 -0
- package/nodenithy/run/__pycache__/swift_stream_service.cpython-312.pyc +0 -0
- package/nodenithy/run/app/input.txt +4 -0
- package/nodenithy/run/app/payload.js +4 -0
- package/nodenithy/run/docker-compose-final.yml.tmpl +65 -0
- package/nodenithy/run/docker-compose-swift-stream.yml +17 -0
- package/nodenithy/run/docker-compose.yml.tmpl +76 -0
- package/nodenithy/run/etny-securelock-test.yaml.tpl +46 -0
- package/nodenithy/run/etny-trustedzone-test.yaml.tpl +45 -0
- package/nodenithy/run/git.sh +22 -0
- package/nodenithy/run/image_registry.abi +1 -0
- package/nodenithy/run/image_registry.js +372 -0
- package/nodenithy/run/image_registry.py +327 -0
- package/nodenithy/run/image_registry_runner.py +71 -0
- package/nodenithy/run/ipfs.sh +58 -0
- package/nodenithy/run/ipfs_pre.sh +75 -0
- package/nodenithy/run/public_key_service.js +90 -0
- package/nodenithy/run/public_key_service.py +107 -0
- package/nodenithy/run/swift_stream_service.py +212 -0
- package/nodenithy/run/swiftstream.py +37 -0
- package/nodenithy/run/swiftstream1.py +27 -0
- package/nodenithy/run.js +538 -0
- package/nodenithy/run.sh +277 -0
- package/nodenithy/scripts/build-ipfs-upload.sh +23 -0
- package/nodenithy/scripts/build.sh +40 -0
- package/nodenithy/scripts/ipfs-daemon.sh +7 -0
- package/nodenithy/scripts/run.sh +50 -0
- package/nodenithy/src/App.css +57 -0
- package/nodenithy/src/ec_helloworld_example.js +64 -0
- package/nodenithy/src/index.css +13 -0
- package/nodenithy/src/index.js +17 -0
- package/nodenithy/src/preStart.js +45 -0
- package/nodenithy/src/preStart.mjs +57 -0
- package/nodenithy/src/reportWebVitals.js +13 -0
- package/nodenithy/src/serverless/backend.js +5 -0
- package/package.json +48 -0
- package/postinstall.js +34 -0
- package/publish.js +126 -0
- package/pynithy/build/docker-compose.yml +68 -0
- package/pynithy/build/las/Dockerfile +11 -0
- package/pynithy/build/las/src/etny_entrypoint.sh +6 -0
- package/pynithy/build/las/src/las_entrypoint.sh +26 -0
- package/pynithy/build/scripts/binary-fs-build.sh +28 -0
- package/pynithy/build/securelock/Dockerfile.tmpl +78 -0
- package/pynithy/build/securelock/scripts/binary-fs-build.sh +41 -0
- package/pynithy/build/securelock/src/app/.env +5 -0
- package/pynithy/build/securelock/src/app/cert1-ca1-clean.crt +10 -0
- package/pynithy/build/securelock/src/app/cert1-ca1-clean.key +6 -0
- package/pynithy/build/securelock/src/app/enclave_pub_cert.pem +10 -0
- package/pynithy/build/securelock/src/app/input.txt +1 -0
- package/pynithy/build/securelock/src/app/payload.py +25 -0
- package/pynithy/build/securelock/src/app/public-cert-clean.pem +10 -0
- package/pynithy/build/securelock/src/app/result.txt +1 -0
- package/pynithy/build/securelock/src/app/transaction.txt +1 -0
- package/pynithy/build/securelock/src/etny_crypto.py +167 -0
- package/pynithy/build/securelock/src/etny_exec.py +79 -0
- package/pynithy/build/securelock/src/image_registry.abi +1 -0
- package/pynithy/build/securelock/src/key_generation.py +17 -0
- package/pynithy/build/securelock/src/models.py +176 -0
- package/pynithy/build/securelock/src/pox.abi +1489 -0
- package/pynithy/build/securelock/src/securelock.py.tmpl +411 -0
- package/pynithy/build/securelock/src/swift_stream_service.py +186 -0
- package/pynithy/build/trustedzone/Dockerfile.tmpl +56 -0
- package/pynithy/build/trustedzone/scripts/binary-fs-build.sh +32 -0
- package/pynithy/build/trustedzone/src/app/.env +5 -0
- package/pynithy/build/trustedzone/src/app/cert1-ca1-clean.crt +10 -0
- package/pynithy/build/trustedzone/src/app/cert1-ca1-clean.key +6 -0
- package/pynithy/build/trustedzone/src/app/enclave_pub_cert.pem +10 -0
- package/pynithy/build/trustedzone/src/app/input.txt +1 -0
- package/pynithy/build/trustedzone/src/app/payload.py +25 -0
- package/pynithy/build/trustedzone/src/app/public-cert-clean.pem +10 -0
- package/pynithy/build/trustedzone/src/app/result.txt +1 -0
- package/pynithy/build/trustedzone/src/app/securelock.crt +10 -0
- package/pynithy/build/trustedzone/src/app/transaction.txt +1 -0
- package/pynithy/build/trustedzone/src/app/trustedzone.crt +10 -0
- package/pynithy/build/trustedzone/src/etny_crypto.py +188 -0
- package/pynithy/build/trustedzone/src/etny_exec.py +56 -0
- package/pynithy/build/trustedzone/src/formatter.py +42 -0
- package/pynithy/build/trustedzone/src/image_registry.abi +1 -0
- package/pynithy/build/trustedzone/src/key_generation.py +17 -0
- package/pynithy/build/trustedzone/src/models.py +176 -0
- package/pynithy/build/trustedzone/src/pox.abi +1489 -0
- package/pynithy/build/trustedzone/src/swift_stream_service.py +186 -0
- package/pynithy/build/trustedzone/src/trustedzone.py.tmpl +460 -0
- package/pynithy/build.mjs +179 -0
- package/pynithy/docker-compose.yml +0 -0
- package/pynithy/ipfs.mjs +244 -0
- package/pynithy/public/favicon.ico +0 -0
- package/pynithy/public/index.html +43 -0
- package/pynithy/public/logo192.png +0 -0
- package/pynithy/public/logo512.png +0 -0
- package/pynithy/public/manifest.json +25 -0
- package/pynithy/public/robots.txt +3 -0
- package/pynithy/run/certs/cert.pem +31 -0
- package/pynithy/run/certs/challenge.crt +10 -0
- package/pynithy/run/certs/key.pem +52 -0
- package/pynithy/run/docker-compose-final.yml +59 -0
- package/pynithy/run/docker-compose-final.yml.tmpl +59 -0
- package/pynithy/run/docker-compose-swift-stream.yml +27 -0
- package/pynithy/run/docker-compose-swift-stream.yml.tmpl +27 -0
- package/pynithy/run/docker-compose.yml +55 -0
- package/pynithy/run/docker-compose.yml.tmpl +55 -0
- package/pynithy/run/etny-pynity-test.yaml.tpl +46 -0
- package/pynithy/run/etny-securelock-test.yaml.tpl +46 -0
- package/pynithy/run/etny-trustedzone-test.yaml.tpl +46 -0
- package/pynithy/run/git.sh +22 -0
- package/pynithy/run/image_registry.abi +1 -0
- package/pynithy/run/image_registry.js +372 -0
- package/pynithy/run/image_registry.py +139 -0
- package/pynithy/run/image_registry_runner.py +45 -0
- package/pynithy/run/ipfs.sh +89 -0
- package/pynithy/run/public_key_service.js +90 -0
- package/pynithy/run/swiftstream.py +28 -0
- package/pynithy/run.js +538 -0
- package/pynithy/src/App.css +57 -0
- package/pynithy/src/ec_helloworld_example.js +64 -0
- package/pynithy/src/index.css +13 -0
- package/pynithy/src/index.js +17 -0
- package/pynithy/src/preStart.mjs +57 -0
- package/pynithy/src/reportWebVitals.js +13 -0
- package/pynithy/src/serverless/__init__.py +0 -0
- package/pynithy/src/serverless/backend.py +2 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const { Command } = require('commander');
|
|
4
|
+
const program = new Command();
|
|
5
|
+
|
|
6
|
+
const BASE_URL = "https://publickey.ethernity.cloud";
|
|
7
|
+
|
|
8
|
+
async function submitIpfsHash(hash, enclaveName, protocolVersion, network, templateVersion, dockerComposerHash) {
|
|
9
|
+
const url = `${BASE_URL}/api/addHash`;
|
|
10
|
+
const payload = {
|
|
11
|
+
hash: hash,
|
|
12
|
+
enclave_name: enclaveName,
|
|
13
|
+
protocol_version: protocolVersion,
|
|
14
|
+
network: network,
|
|
15
|
+
template_version: templateVersion,
|
|
16
|
+
docker_composer_hash: dockerComposerHash,
|
|
17
|
+
};
|
|
18
|
+
try {
|
|
19
|
+
const response = await axios.post(url, payload);
|
|
20
|
+
// console.log(`response: ${response}`);
|
|
21
|
+
return response.data;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.error("Error:", error.response ? error.response.data : error.message);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function checkIpfsHashStatus(hash) {
|
|
29
|
+
const url = `${BASE_URL}/api/checkHash/${hash}`;
|
|
30
|
+
try {
|
|
31
|
+
const response = await axios.get(url);
|
|
32
|
+
return response.data;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error("Error:", error.response ? error.response.data : error.message);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
program
|
|
40
|
+
.requiredOption('--enclave_name <enclaveName>', 'Enclave name')
|
|
41
|
+
.requiredOption('--protocol_version <protocolVersion>', 'Protocol version')
|
|
42
|
+
.requiredOption('--network <network>', 'Network')
|
|
43
|
+
.requiredOption('--template_version <templateVersion>', 'Template version');
|
|
44
|
+
|
|
45
|
+
program.parse(process.argv);
|
|
46
|
+
|
|
47
|
+
const options = program.opts();
|
|
48
|
+
const enclaveName = options.enclave_name;
|
|
49
|
+
const protocolVersion = options.protocol_version;
|
|
50
|
+
const network = options.network.toLowerCase().split("_")[1];
|
|
51
|
+
const templateVersion = options.template_version;
|
|
52
|
+
|
|
53
|
+
const hhash = fs.readFileSync('IPFS_HASH.ipfs', 'utf8').trim();
|
|
54
|
+
const dockerComposerHash = fs.readFileSync('IPFS_DOCKER_COMPOSE_HASH.ipfs', 'utf8').trim();
|
|
55
|
+
|
|
56
|
+
console.log("IPFS Hash:", hhash);
|
|
57
|
+
console.log("Enclave Name:", enclaveName);
|
|
58
|
+
console.log("Protocol Version:", protocolVersion);
|
|
59
|
+
console.log("Network:", network);
|
|
60
|
+
console.log("Template Version:", templateVersion);
|
|
61
|
+
console.log("Docker Composer Hash:", dockerComposerHash);
|
|
62
|
+
|
|
63
|
+
(async () => {
|
|
64
|
+
// Submit IPFS Hash
|
|
65
|
+
const submitResponse = await submitIpfsHash(hhash, enclaveName, protocolVersion, network, templateVersion, dockerComposerHash);
|
|
66
|
+
console.log("Submit IPFS Hash Response:", submitResponse);
|
|
67
|
+
|
|
68
|
+
// Check IPFS Hash Status
|
|
69
|
+
while (true) {
|
|
70
|
+
const checkResponse = await checkIpfsHashStatus(hhash);
|
|
71
|
+
if ("publicKey" in checkResponse) {
|
|
72
|
+
if (checkResponse.publicKey === 0) {
|
|
73
|
+
console.log(`Public key not available yet. Queue position: ${checkResponse.queuePosition || 'Unknown'}`);
|
|
74
|
+
} else if (checkResponse.publicKey === -1) {
|
|
75
|
+
console.log("Hash is not derived from Eternity Cloud SDK.");
|
|
76
|
+
process.exit(1);
|
|
77
|
+
} else {
|
|
78
|
+
console.log("Public Key:", checkResponse.publicKey);
|
|
79
|
+
// Save public key to file
|
|
80
|
+
fs.writeFileSync('PUBLIC_KEY.txt', checkResponse.publicKey);
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
console.log("Unexpected response:", checkResponse);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
await new Promise(resolve => setTimeout(resolve, 10000)); // Wait for 10 seconds before checking again
|
|
89
|
+
}
|
|
90
|
+
})();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/local/bin/python
|
|
2
|
+
|
|
3
|
+
from minio import Minio
|
|
4
|
+
from minio.error import S3Error
|
|
5
|
+
from swift_stream_service import SwiftStreamService
|
|
6
|
+
|
|
7
|
+
swiftStreamClient = SwiftStreamService("docker:9000", "swiftstreamadmin", "swiftstreamadmin")
|
|
8
|
+
|
|
9
|
+
swiftStreamClient.create_bucket("etny-pynithy-v2")
|
|
10
|
+
|
|
11
|
+
swiftStreamClient.upload_file("etny-pynithy-v2", ".env", "./.env")
|
|
12
|
+
|
|
13
|
+
print(swiftStreamClient.is_object_in_bucket("etny-pynithy-v2", ".env"))
|
|
14
|
+
|
|
15
|
+
status, content = swiftStreamClient.get_file_content("etny-pynithy-v2", ".env")
|
|
16
|
+
|
|
17
|
+
print("************************")
|
|
18
|
+
print("Status %s" % status )
|
|
19
|
+
print("Content %s" % content)
|
|
20
|
+
print("************************")
|
|
21
|
+
|
|
22
|
+
status, content = swiftStreamClient.get_file_content_bytes("etny-pynithy-v2", ".env")
|
|
23
|
+
|
|
24
|
+
print("************************")
|
|
25
|
+
print("Status %s" % status )
|
|
26
|
+
print("Content %s" % content)
|
|
27
|
+
print("************************")
|
|
28
|
+
|
package/pynithy/run.js
ADDED
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const { execSync } = require('child_process');
|
|
3
|
+
require('dotenv').config();
|
|
4
|
+
const readline = require('readline');
|
|
5
|
+
const forge = require('node-forge');
|
|
6
|
+
const axios = require('axios');
|
|
7
|
+
const https = require('https');
|
|
8
|
+
|
|
9
|
+
if (!fs.existsSync('.env')) {
|
|
10
|
+
console.error("Error: .env file not found");
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const rl = readline.createInterface({
|
|
15
|
+
input: process.stdin,
|
|
16
|
+
output: process.stdout
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const promptOptions = (message, options, defaultOption) => {
|
|
20
|
+
return new Promise((resolve) => {
|
|
21
|
+
const askOption = () => {
|
|
22
|
+
rl.question(message, (answer) => {
|
|
23
|
+
const reply = answer.trim().toLowerCase();
|
|
24
|
+
if (reply === '') {
|
|
25
|
+
console.log(`No option selected. Defaulting to ${defaultOption}.`);
|
|
26
|
+
resolve(defaultOption);
|
|
27
|
+
} else if (options.includes(reply)) {
|
|
28
|
+
resolve(reply);
|
|
29
|
+
} else {
|
|
30
|
+
console.log(`Invalid option "${reply}". Please enter "yes" or "no".`);
|
|
31
|
+
askOption();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
askOption();
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const writeEnv = (key, value) => {
|
|
40
|
+
const envFile = `${currentDir}/.env`;
|
|
41
|
+
let envContent = '';
|
|
42
|
+
|
|
43
|
+
if (fs.existsSync(envFile)) {
|
|
44
|
+
envContent = fs.readFileSync(envFile, 'utf8');
|
|
45
|
+
const regex = new RegExp(`^${key}=.*`, 'm');
|
|
46
|
+
if (regex.test(envContent)) {
|
|
47
|
+
envContent = envContent.replace(regex, `${key}=${value}`);
|
|
48
|
+
} else {
|
|
49
|
+
envContent += `\n${key}=${value}`;
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
envContent = `${key}=${value}`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
fs.writeFileSync(envFile, envContent);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
let templateName = process.env.TRUSTED_ZONE_IMAGE || 'etny-pynithy-testnet';
|
|
59
|
+
|
|
60
|
+
const isMainnet = !templateName.includes('testnet');
|
|
61
|
+
|
|
62
|
+
const currentDir = process.cwd();
|
|
63
|
+
console.log(`currentDir: ${currentDir}`);
|
|
64
|
+
const runDir = `${currentDir}/node_modules/@ethernity-cloud/sdk-js/pynithy/run`;
|
|
65
|
+
process.chdir(runDir);
|
|
66
|
+
process.env.REGISTRY_PATH = `${currentDir}/registry`;
|
|
67
|
+
const registryPath = process.env.REGISTRY_PATH;
|
|
68
|
+
|
|
69
|
+
const runDockerCommand = (service) => {
|
|
70
|
+
const command = `docker-compose run -e SCONE_LOG=INFO -e SCONE_HASH=1 ${service}`;
|
|
71
|
+
const output = execSync(command).toString().trim();
|
|
72
|
+
console.log(`Output of ${command}: ${output}`);
|
|
73
|
+
return output.split('\n').filter(line => !/Creating|Pulling|latest|Digest/.test(line)).join('');
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const main = async () => {
|
|
77
|
+
process.env.NODE_NO_WARNINGS = 1
|
|
78
|
+
const backupFiles = ['docker-compose.yml.tmpl', 'docker-compose-final.yml.tmpl'];
|
|
79
|
+
backupFiles.forEach(file => {
|
|
80
|
+
if (!fs.existsSync(file)) {
|
|
81
|
+
console.error(`Error: ${file} not found!`);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const backupContent = fs.readFileSync(file, 'utf8');
|
|
85
|
+
fs.writeFileSync(file.replace('.tmpl', ''), backupContent, 'utf8');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
process.env.MRENCLAVE_SECURELOCK = runDockerCommand('etny-securelock');
|
|
90
|
+
console.log(`MRENCLAVE_SECURELOCK: ${process.env.MRENCLAVE_SECURELOCK}`);
|
|
91
|
+
// process.env.MRENCLAVE_TRUSTEDZONE = runDockerCommand('etny-trustedzone');
|
|
92
|
+
// console.log(`MRENCLAVE_TRUSTEDZONE: ${process.env.MRENCLAVE_TRUSTEDZONE}`);
|
|
93
|
+
// process.env.MRENCLAVE_VALIDATOR = runDockerCommand('etny-validator');
|
|
94
|
+
// console.log(`MRENCLAVE_VALIDATOR: ${process.env.MRENCLAVE_VALIDATOR}`);
|
|
95
|
+
|
|
96
|
+
writeEnv('MRENCLAVE_SECURELOCK', process.env.MRENCLAVE_SECURELOCK);
|
|
97
|
+
// writeEnv('MRENCLAVE_TRUSTEDZONE', process.env.MRENCLAVE_TRUSTEDZONE);
|
|
98
|
+
// writeEnv('MRENCLAVE_VALIDATOR', process.env.MRENCLAVE_VALIDATOR);
|
|
99
|
+
|
|
100
|
+
const generateEnclaveName = (name) => {
|
|
101
|
+
return name.toUpperCase().replace(/\//g, '_').replace(/-/g, '_');
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const processYamlTemplate = (templateFile, outputFile, replacements) => {
|
|
105
|
+
if (!fs.existsSync(templateFile)) {
|
|
106
|
+
console.error(`Error: Template file ${templateFile} not found!`);
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let content = fs.readFileSync(templateFile, 'utf8');
|
|
111
|
+
for (const [key, value] of Object.entries(replacements)) {
|
|
112
|
+
const regex = new RegExp(`__${key}__`, 'g');
|
|
113
|
+
content = content.replace(regex, value);
|
|
114
|
+
}
|
|
115
|
+
if (isMainnet) {
|
|
116
|
+
content = content.replace(", debug-mode", "");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
fs.writeFileSync(outputFile, content);
|
|
120
|
+
// console.log(`Contents of ${outputFile}:`);
|
|
121
|
+
// console.log(content);
|
|
122
|
+
|
|
123
|
+
console.log("Checking for remaining placeholders:");
|
|
124
|
+
const remainingPlaceholders = content.match(/__.*__/g);
|
|
125
|
+
if (remainingPlaceholders) {
|
|
126
|
+
console.log(remainingPlaceholders.join('\n'));
|
|
127
|
+
} else {
|
|
128
|
+
console.log("No placeholders found.");
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// const ENCLAVE_NAME_SECURELOCK = generateEnclaveName(process.env.ENCLAVE_NAME_SECURELOCK);
|
|
133
|
+
const ENCLAVE_NAME_SECURELOCK = process.env.ENCLAVE_NAME_SECURELOCK;
|
|
134
|
+
// const PREDECESSOR_NAME_SECURELOCK = generateEnclaveName(`PREDECESSOR_SECURELOCK_${process.env.VERSION}_${process.env.PROJECT_NAME}`);
|
|
135
|
+
|
|
136
|
+
console.log(`\nENCLAVE_NAME_SECURELOCK: ${ENCLAVE_NAME_SECURELOCK}`);
|
|
137
|
+
// console.log(`PREDECESSOR_NAME_SECURELOCK: ${PREDECESSOR_NAME_SECURELOCK}`);
|
|
138
|
+
// writeEnv('PREDECESSOR_NAME_SECURELOCK', PREDECESSOR_NAME_SECURELOCK);
|
|
139
|
+
|
|
140
|
+
process.env.ENCLAVE_NAME_SECURELOCK = ENCLAVE_NAME_SECURELOCK;
|
|
141
|
+
const envPredecessor = process.env.PREDECESSOR_HASH_SECURELOCK || 'EMPTY';
|
|
142
|
+
let PREDECESSOR_HASH_SECURELOCK = 'EMPTY';
|
|
143
|
+
let PREDECESSOR_PROJECT_NAME = 'EMPTY';
|
|
144
|
+
let PREDECESSOR_VERSION = 'EMPTY';
|
|
145
|
+
if (envPredecessor !== 'EMPTY') {
|
|
146
|
+
PREDECESSOR_HASH_SECURELOCK = envPredecessor.split("$$$%$")[0];
|
|
147
|
+
PREDECESSOR_PROJECT_NAME = process.env.PREDECESSOR_HASH_SECURELOCK.split("$$$%$")[1];
|
|
148
|
+
PREDECESSOR_VERSION = process.env.PREDECESSOR_HASH_SECURELOCK.split("$$$%$")[2];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
console.log(`PREDECESSOR_HASH_SECURELOCK: ${PREDECESSOR_HASH_SECURELOCK}`);
|
|
152
|
+
console.log(`PREDECESSOR_PROJECT_NAME: ${PREDECESSOR_PROJECT_NAME}`);
|
|
153
|
+
console.log(`PREDECESSOR_VERSION: ${PREDECESSOR_VERSION}`);
|
|
154
|
+
console.log(`MRENCLAVE_SECURELOCK: ${process.env.MRENCLAVE_SECURELOCK}`);
|
|
155
|
+
console.log(`ENCLAVE_NAME_SECURELOCK: ${ENCLAVE_NAME_SECURELOCK}`);
|
|
156
|
+
|
|
157
|
+
if (PREDECESSOR_HASH_SECURELOCK !== 'EMPTY' && PREDECESSOR_PROJECT_NAME !== process.env.PROJECT_NAME && PREDECESSOR_VERSION !== process.env.VERSION) {
|
|
158
|
+
PREDECESSOR_HASH_SECURELOCK = 'EMPTY';
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const replacementsSecurelock = {
|
|
162
|
+
PREDECESSOR: PREDECESSOR_HASH_SECURELOCK === 'EMPTY' ? `# predecessor: ${PREDECESSOR_HASH_SECURELOCK}` : `predecessor: ${PREDECESSOR_HASH_SECURELOCK}`,
|
|
163
|
+
MRENCLAVE: process.env.MRENCLAVE_SECURELOCK,
|
|
164
|
+
ENCLAVE_NAME: ENCLAVE_NAME_SECURELOCK
|
|
165
|
+
};
|
|
166
|
+
processYamlTemplate('etny-securelock-test.yaml.tpl', 'etny-securelock-test.yaml', replacementsSecurelock);
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
// don't generate new keys if PREDECESSOR_HASH_SECURELOCK is not empty and the key.pem and cert.pem files exist
|
|
170
|
+
if (PREDECESSOR_HASH_SECURELOCK !== 'EMPTY' && fs.existsSync('key.pem') && fs.existsSync('cert.pem')) {
|
|
171
|
+
console.log("Skipping key pair generation and certificate creation.");
|
|
172
|
+
console.log("Using existing key.pem and cert.pem files.");
|
|
173
|
+
} else {
|
|
174
|
+
// Generate a keypair and create an X.509v3 certificate
|
|
175
|
+
const pki = forge.pki;
|
|
176
|
+
const keys = pki.rsa.generateKeyPair(4096);
|
|
177
|
+
const cert = pki.createCertificate();
|
|
178
|
+
|
|
179
|
+
cert.publicKey = keys.publicKey;
|
|
180
|
+
cert.serialNumber = '01';
|
|
181
|
+
cert.validity.notBefore = new Date();
|
|
182
|
+
cert.validity.notBefore.setFullYear(cert.validity.notBefore.getFullYear() - 1);
|
|
183
|
+
cert.validity.notAfter = new Date();
|
|
184
|
+
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 2);
|
|
185
|
+
|
|
186
|
+
const attrs = [
|
|
187
|
+
{
|
|
188
|
+
name: 'countryName',
|
|
189
|
+
value: 'AU'
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
shortName: 'ST',
|
|
193
|
+
value: 'Some-State'
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
name: 'organizationName',
|
|
197
|
+
value: process.env.ENCLAVE_NAME_SECURELOCK || 'Internet Widgits Pty Ltd'
|
|
198
|
+
}
|
|
199
|
+
];
|
|
200
|
+
cert.setSubject(attrs);
|
|
201
|
+
cert.setIssuer(attrs);
|
|
202
|
+
|
|
203
|
+
cert.setExtensions([
|
|
204
|
+
{
|
|
205
|
+
name: 'subjectKeyIdentifier'
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
name: 'authorityKeyIdentifier',
|
|
209
|
+
keyIdentifier: true
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
name: 'basicConstraints',
|
|
213
|
+
cA: true,
|
|
214
|
+
critical: true
|
|
215
|
+
}
|
|
216
|
+
]);
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
// TOdo: use same certificate for future entryes
|
|
220
|
+
// Self-sign certificate
|
|
221
|
+
cert.sign(keys.privateKey, forge.md.sha256.create());
|
|
222
|
+
|
|
223
|
+
// PEM-format keys and cert
|
|
224
|
+
const privateKeyPem = pki.privateKeyToPem(keys.privateKey, 72, { type: 'pkcs8' });
|
|
225
|
+
const certPem = pki.certificateToPem(cert);
|
|
226
|
+
|
|
227
|
+
// Write to files
|
|
228
|
+
fs.writeFileSync('key.pem', privateKeyPem);
|
|
229
|
+
fs.writeFileSync('cert.pem', certPem);
|
|
230
|
+
|
|
231
|
+
console.log("# Generated cert.pem and key.pem files");
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
}
|
|
235
|
+
// Read the certificate and key files
|
|
236
|
+
const certFile = fs.readFileSync('cert.pem');
|
|
237
|
+
const keyFile = fs.readFileSync('key.pem');
|
|
238
|
+
const data = fs.readFileSync('etny-securelock-test.yaml');
|
|
239
|
+
|
|
240
|
+
// Create an HTTPS agent with the certificate and key
|
|
241
|
+
const agent = new https.Agent({
|
|
242
|
+
cert: certFile,
|
|
243
|
+
key: keyFile,
|
|
244
|
+
rejectUnauthorized: false, // This is equivalent to the `-k` option in curl
|
|
245
|
+
secureProtocol: 'TLSv1_2_method' // Ensure using TLSv1.2
|
|
246
|
+
});
|
|
247
|
+
// Perform the POST request
|
|
248
|
+
await axios.post('https://scone-cas.cf:8081/session', data, {
|
|
249
|
+
httpsAgent: agent,
|
|
250
|
+
headers: {
|
|
251
|
+
'Content-Type': 'application/octet-stream'
|
|
252
|
+
}
|
|
253
|
+
})
|
|
254
|
+
.then(response => {
|
|
255
|
+
fs.writeFileSync('predecessor.json', JSON.stringify(response.data, null, 2));
|
|
256
|
+
console.log("# Updated session file for securelock and saved to predecessor.json");
|
|
257
|
+
// console.log("predecessor.json:"+JSON.stringify(response.data, null, 2));
|
|
258
|
+
const pred = response.data.hash || 'EMPTY';
|
|
259
|
+
if (pred !== 'EMPTY') {
|
|
260
|
+
process.env.PREDECESSOR_HASH_SECURELOCK = `${pred}$$$%$${process.env.PROJECT_NAME}$$$%$${process.env.VERSION}` || 'EMPTY';
|
|
261
|
+
writeEnv('PREDECESSOR_HASH_SECURELOCK', process.env.PREDECESSOR_HASH_SECURELOCK);
|
|
262
|
+
} else {
|
|
263
|
+
process.env.PREDECESSOR_HASH_SECURELOCK = 'EMPTY';
|
|
264
|
+
writeEnv('PREDECESSOR_HASH_SECURELOCK', process.env.PREDECESSOR_HASH_SECURELOCK);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (process.env.PREDECESSOR_HASH_SECURELOCK === 'EMPTY') {
|
|
268
|
+
console.log("Error: Could not update session file for securelock");
|
|
269
|
+
console.log("Please change the name/version of your project (using ecld-init or by editing .env file) and run the scripts again. Exiting.");
|
|
270
|
+
process.exit(1);
|
|
271
|
+
}
|
|
272
|
+
console.log()
|
|
273
|
+
console.log("Scone CAS registration successful.");
|
|
274
|
+
console.log()
|
|
275
|
+
})
|
|
276
|
+
.catch(error => {
|
|
277
|
+
console.log("Scone CAS error: ", error);
|
|
278
|
+
console.log("Error: Could not update session file for securelock");
|
|
279
|
+
console.log("Please change the name/version of your project (using ecld-init or by editing .env file) and run the scripts again. Exiting.");
|
|
280
|
+
process.exit(1);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
// const ENCLAVE_NAME_TRUSTEDZONE = generateEnclaveName(process.env.ENCLAVE_NAME_TRUSTEDZONE);
|
|
285
|
+
// const PREDECESSOR_NAME_TRUSTEDZONE = generateEnclaveName(`PREDECESSOR_TRUSTEDZONE_${process.env.VERSION}_${process.env.PROJECT_NAME}`);
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
// console.log(`\ENCLAVE_NAME_TRUSTEDZONE: ${ENCLAVE_NAME_TRUSTEDZONE}`);
|
|
290
|
+
// console.log(`PREDECESSOR_NAME_TRUSTEDZONE: ${PREDECESSOR_NAME_TRUSTEDZONE}`);
|
|
291
|
+
// writeEnv('PREDECESSOR_NAME_TRUSTEDZONE', PREDECESSOR_NAME_TRUSTEDZONE);
|
|
292
|
+
|
|
293
|
+
// process.env.ENCLAVE_NAME_TRUSTEDZONE = ENCLAVE_NAME_TRUSTEDZONE;
|
|
294
|
+
|
|
295
|
+
// const PREDECESSOR_HASH_TRUSTEDZONE = process.env[PREDECESSOR_NAME_TRUSTEDZONE] || 'EMPTY';
|
|
296
|
+
|
|
297
|
+
// console.log(`PREDECESSOR_HASH_TRUSTEDZONE: ${PREDECESSOR_HASH_TRUSTEDZONE}`);
|
|
298
|
+
// console.log(`MRENCLAVE_TRUSTEDZONE: ${process.env.MRENCLAVE_TRUSTEDZONE}`);
|
|
299
|
+
// console.log(`ENCLAVE_NAME_TRUSTEDZONE: ${ENCLAVE_NAME_TRUSTEDZONE}`);
|
|
300
|
+
|
|
301
|
+
// const replacementsTrustedzone = {
|
|
302
|
+
// PREDECESSOR: PREDECESSOR_HASH_TRUSTEDZONE === 'EMPTY' ? `# predecessor: ${PREDECESSOR_HASH_TRUSTEDZONE}` : `predecessor: ${PREDECESSOR_HASH_TRUSTEDZONE}`,
|
|
303
|
+
// MRENCLAVE: process.env.MRENCLAVE_TRUSTEDZONE,
|
|
304
|
+
// ENCLAVE_NAME: ENCLAVE_NAME_TRUSTEDZONE,
|
|
305
|
+
// MRENCLAVE_VALIDATOR: process.env.MRENCLAVE_VALIDATOR
|
|
306
|
+
// };
|
|
307
|
+
|
|
308
|
+
// processYamlTemplate('etny-trustedzone-test.yaml.tpl', 'etny-trustedzone-test.yaml', replacementsTrustedzone);
|
|
309
|
+
|
|
310
|
+
// revert 'docker-compose.yml', 'docker-compose-final.yml' to the backed up ones from 'docker-compose.yml.tmpl', 'docker-compose-final.yml.tmpl'
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
console.log("# Update docker-compose files");
|
|
315
|
+
|
|
316
|
+
const files = ['docker-compose.yml', 'docker-compose-final.yml'];
|
|
317
|
+
|
|
318
|
+
files.forEach(file => {
|
|
319
|
+
if (!fs.existsSync(file)) {
|
|
320
|
+
console.error(`Error: ${file} not found!`);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
console.log(`Processing ${file}`);
|
|
325
|
+
console.log(`ENCLAVE_NAME_SECURELOCK: ${ENCLAVE_NAME_SECURELOCK}`);
|
|
326
|
+
// console.log(`ENCLAVE_NAME_TRUSTEDZONE: ${ENCLAVE_NAME_TRUSTEDZONE}`);
|
|
327
|
+
|
|
328
|
+
console.log("Checking for placeholders before replacement:");
|
|
329
|
+
const fileContentBefore = fs.readFileSync(file, 'utf8');
|
|
330
|
+
if (fileContentBefore.includes('__ENCLAVE_NAME_SECURELOCK__')) {
|
|
331
|
+
console.log(`__ENCLAVE_NAME_SECURELOCK__ found in ${file}`);
|
|
332
|
+
} else {
|
|
333
|
+
console.log(`Ok, No __ENCLAVE_NAME_SECURELOCK__ found in ${file}`);
|
|
334
|
+
}
|
|
335
|
+
if (fileContentBefore.includes('__ENCLAVE_NAME_TRUSTEDZONE__')) {
|
|
336
|
+
console.log(`__ENCLAVE_NAME_TRUSTEDZONE__ found in ${file}`);
|
|
337
|
+
} else {
|
|
338
|
+
console.log(`No __ENCLAVE_NAME_TRUSTEDZONE__ found in ${file}`);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
let ENCLAVE_NAME_TRUSTEDZONE = 'etny-pynithy-trustedzone-v3-testnet-0.1.12'
|
|
342
|
+
if (isMainnet) {
|
|
343
|
+
ENCLAVE_NAME_TRUSTEDZONE = 'ecld-pynithy-trustedzone-v3-3.0.0'
|
|
344
|
+
}
|
|
345
|
+
const updatedContent = fileContentBefore
|
|
346
|
+
.replace(/__ENCLAVE_NAME_SECURELOCK__/g, ENCLAVE_NAME_SECURELOCK)
|
|
347
|
+
.replace(/__ENCLAVE_NAME_TRUSTEDZONE__/g, ENCLAVE_NAME_TRUSTEDZONE);
|
|
348
|
+
|
|
349
|
+
fs.writeFileSync(file, updatedContent, 'utf8');
|
|
350
|
+
|
|
351
|
+
console.log("Checking for placeholders after replacement:");
|
|
352
|
+
const fileContentAfter = fs.readFileSync(file, 'utf8');
|
|
353
|
+
if (fileContentAfter.includes('__ENCLAVE_NAME_SECURELOCK__')) {
|
|
354
|
+
console.log(`__ENCLAVE_NAME_SECURELOCK__ still found in ${file}`);
|
|
355
|
+
} else {
|
|
356
|
+
console.log(`Ok, No __ENCLAVE_NAME_SECURELOCK__ found in ${file}`);
|
|
357
|
+
}
|
|
358
|
+
if (fileContentAfter.includes('__ENCLAVE_NAME_TRUSTEDZONE__')) {
|
|
359
|
+
console.log(`__ENCLAVE_NAME_TRUSTEDZONE__ still found in ${file}`);
|
|
360
|
+
} else {
|
|
361
|
+
console.log(`No __ENCLAVE_NAME_TRUSTEDZONE__ found in ${file}`);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
console.log();
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
// let PUBLIC_KEY_SECURELOCK_RES = execSync(`docker-compose run etny-securelock 2>/dev/null | grep -v Creating | grep -v Pulling | grep -v latest | grep -v Digest | sed 's/.*PUBLIC_KEY:\\s*//' | tr -d '\\r'`).toString().trim();
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
// TODO: calculate hash of the files localy, and query the public key service, if the hash is already there it means we dont have to do the below.
|
|
371
|
+
|
|
372
|
+
if (fs.existsSync('certificate.securelock.crt')) {
|
|
373
|
+
// delete it
|
|
374
|
+
fs.unlinkSync('certificate.securelock.crt');
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
let PUBLIC_KEY_SECURELOCK_RES = '';
|
|
378
|
+
try {
|
|
379
|
+
const output = execSync(`docker-compose run etny-securelock`, { cwd: runDir }).toString();
|
|
380
|
+
console.log("Output of docker-compose run etny-securelock:");
|
|
381
|
+
// Extract the WHOLE multi-line PEM certificate block from the enclave
|
|
382
|
+
// output. A previous version grabbed only the single line containing
|
|
383
|
+
// "PUBLIC_KEY:" -- but the certificate is multi-line, so that captured just
|
|
384
|
+
// the "-----BEGIN CERTIFICATE-----" line (or a fragment), and any log noise
|
|
385
|
+
// interleaved with it (e.g. an IPFS "Saving file(s) to Qm..." line) could be
|
|
386
|
+
// stored as the key. Match the full BEGIN..END block instead, tolerating a
|
|
387
|
+
// "PUBLIC_KEY:"/"PUBLIC_CERT:" marker prefix on the BEGIN line.
|
|
388
|
+
const certMatch = output.match(/-----BEGIN CERTIFICATE-----[\s\S]*?-----END CERTIFICATE-----/);
|
|
389
|
+
PUBLIC_KEY_SECURELOCK_RES = certMatch ? certMatch[0].trim() : '';
|
|
390
|
+
} catch (error) {
|
|
391
|
+
console.log("Error: Could not fetch PUBLIC_KEY_SECURELOCK" + error);
|
|
392
|
+
// console.error("Error: Could not fetch PUBLIC_KEY_SECURELOCK");
|
|
393
|
+
PUBLIC_KEY_SECURELOCK_RES = '';
|
|
394
|
+
console.log("");
|
|
395
|
+
}
|
|
396
|
+
console.log(`PUBLIC_KEY_SECURELOCK_RES: ${PUBLIC_KEY_SECURELOCK_RES}`);
|
|
397
|
+
|
|
398
|
+
// v3:QmPwv3JfYdfkBMDJK8mTFMMdQgrbSCgqRbPQi5qfRUqKgy:etny-nodenithy-testnet:QmNk58xU3f74NFcGmEpUz6KM8eMKiySdwyXgb33QwCaxCc:QmPFVaY5M2esayqCkLEFC5ivF2GWxRp8BZXTFjasPP5cVH:bad1ba9aae6bc1ad314435d5a4843abe1449f261feaf32ccaaac7aad68c95702
|
|
399
|
+
|
|
400
|
+
if (!PUBLIC_KEY_SECURELOCK_RES) {
|
|
401
|
+
console.log("\n\nIt seems that your machine is not SGX compatible.\n");
|
|
402
|
+
console.log("");
|
|
403
|
+
|
|
404
|
+
const opt = ["yes", "no"];
|
|
405
|
+
const choice = await promptOptions("Do you want to continue by generating the necessary certificates using the Ethernity Cloud public certificate extraction services? (yes/no) (default: no): ", opt, "no");
|
|
406
|
+
|
|
407
|
+
if (choice.toLowerCase() !== 'yes') {
|
|
408
|
+
console.log("Exiting.");
|
|
409
|
+
process.exit(0);
|
|
410
|
+
} else {
|
|
411
|
+
console.log("\nGenerating certificates using the Ethernity Cloud signing service...\n");
|
|
412
|
+
console.log("**** Started ipfs initial pining ****");
|
|
413
|
+
if (fs.existsSync('IPFS_HASH.ipfs')) {
|
|
414
|
+
fs.unlinkSync('IPFS_HASH.ipfs');
|
|
415
|
+
}
|
|
416
|
+
if (fs.existsSync('IPFS_DOCKER_COMPOSE_HASH.ipfs')) {
|
|
417
|
+
fs.unlinkSync('IPFS_DOCKER_COMPOSE_HASH.ipfs');
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
console.log('Upload docker-compose-final.yml to IPFS');
|
|
422
|
+
const dockerHash = execSync(`node ../ipfs.mjs --host "${process.env.IPFS_ENDPOINT}" --action upload --filePath docker-compose-final.yml`, { stdio: "inherit" });
|
|
423
|
+
if (!fs.existsSync('IPFS_DOCKER_COMPOSE_HASH.ipfs')) {
|
|
424
|
+
console.error("Error: Could not upload docker-compose-final.yml to IPFS, please try again!");
|
|
425
|
+
process.exit(1);
|
|
426
|
+
}
|
|
427
|
+
process.env.IPFS_DOCKER_COMPOSE_HASH = fs.readFileSync('IPFS_DOCKER_COMPOSE_HASH.ipfs', 'utf8').trim();
|
|
428
|
+
console.log("IPFS_DOCKER_COMPOSE_HASH: ", process.env.IPFS_DOCKER_COMPOSE_HASH);
|
|
429
|
+
writeEnv('IPFS_DOCKER_COMPOSE_HASH', process.env.IPFS_DOCKER_COMPOSE_HASH);
|
|
430
|
+
console.log()
|
|
431
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
432
|
+
|
|
433
|
+
console.log('Upload docker registry to IPFS');
|
|
434
|
+
const repositoryHash = execSync(`node ../ipfs.mjs --host "${process.env.IPFS_ENDPOINT}" --action upload --folderPath ${registryPath}`, { stdio: "inherit" });
|
|
435
|
+
if (!fs.existsSync(`./IPFS_HASH.ipfs`)) {
|
|
436
|
+
console.error("Error: Could not upload registry to IPFS, please try again!");
|
|
437
|
+
process.exit(1);
|
|
438
|
+
}
|
|
439
|
+
process.env.IPFS_HASH = fs.readFileSync(`./IPFS_HASH.ipfs`, 'utf8').trim();
|
|
440
|
+
console.log("IPFS_HASH: ", process.env.IPFS_HASH);
|
|
441
|
+
writeEnv('IPFS_HASH', process.env.IPFS_HASH);
|
|
442
|
+
|
|
443
|
+
console.log()
|
|
444
|
+
|
|
445
|
+
console.log("**** Finished ipfs initial pining ****");
|
|
446
|
+
console.log()
|
|
447
|
+
console.log()
|
|
448
|
+
|
|
449
|
+
console.log(`ENCLAVE_NAME_SECURELOCK: ${ENCLAVE_NAME_SECURELOCK}`);
|
|
450
|
+
execSync(`node ./public_key_service.js --enclave_name "${process.env.PROJECT_NAME}" --protocol_version "v3" --network "${process.env.BLOCKCHAIN_NETWORK}" --template_version "${process.env.VERSION}"`, { stdio: 'inherit' });
|
|
451
|
+
PUBLIC_KEY_SECURELOCK_RES = fs.readFileSync('PUBLIC_KEY.txt', 'utf8').trim();
|
|
452
|
+
console.log(`PUBLIC_KEY_SECURELOCK_RES: ${PUBLIC_KEY_SECURELOCK_RES}`);
|
|
453
|
+
if (!PUBLIC_KEY_SECURELOCK_RES || PUBLIC_KEY_SECURELOCK_RES === '-1') {
|
|
454
|
+
console.error("Error: Could not fetch PUBLIC_KEY_SECURELOCK");
|
|
455
|
+
process.exit(1);
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// Validate we actually have a certificate before registering it on-chain.
|
|
461
|
+
// (Guard the match so a missing/garbage value fails loudly instead of throwing
|
|
462
|
+
// "Cannot read properties of null".) On-chain registrations are effectively
|
|
463
|
+
// permanent per version, so refuse to register anything that isn't a PEM cert.
|
|
464
|
+
const certContentMatch = PUBLIC_KEY_SECURELOCK_RES.match(/-----BEGIN CERTIFICATE-----([\s\S]*?)-----END CERTIFICATE-----/);
|
|
465
|
+
const CERTIFICATE_CONTENT_SECURELOCK = certContentMatch ? certContentMatch[1].trim() : '';
|
|
466
|
+
if (!CERTIFICATE_CONTENT_SECURELOCK) {
|
|
467
|
+
console.error("ERROR! PUBLIC_KEY_SECURELOCK not a valid certificate; refusing to register.");
|
|
468
|
+
console.error(` got: ${JSON.stringify((PUBLIC_KEY_SECURELOCK_RES || '').slice(0, 120))}`);
|
|
469
|
+
process.exit(1);
|
|
470
|
+
} else {
|
|
471
|
+
console.log("FOUND PUBLIC_KEY_SECURELOCK");
|
|
472
|
+
}
|
|
473
|
+
fs.writeFileSync('certificate.securelock.crt', PUBLIC_KEY_SECURELOCK_RES);
|
|
474
|
+
console.log("Listing certificate PUBLIC_KEY_SECURELOCK:");
|
|
475
|
+
console.log(fs.readFileSync('certificate.securelock.crt', 'utf8'));
|
|
476
|
+
|
|
477
|
+
if (fs.existsSync('certificate.trustedzone.crt')) {
|
|
478
|
+
// delete it
|
|
479
|
+
fs.unlinkSync('certificate.trustedzone.crt');
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// const scriptPath = path.resolve(__dirname, '/image_registry.js');
|
|
483
|
+
const trustedZoneCert = execSync(`node ./image_registry.js "${process.env.BLOCKCHAIN_NETWORK}" ${templateName} "v3" "" "getTrustedZoneCert"`).toString().trim();
|
|
484
|
+
|
|
485
|
+
console.log("trustedZoneCert: ", trustedZoneCert);
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
const tzMatch = trustedZoneCert.match(/-----BEGIN CERTIFICATE-----([\s\S]*?)-----END CERTIFICATE-----/);
|
|
489
|
+
if (!tzMatch) {
|
|
490
|
+
console.error("ERROR! Could not read a valid trustedzone certificate from the image registry.");
|
|
491
|
+
console.error(` got: ${JSON.stringify((trustedZoneCert || '').slice(0, 120))}`);
|
|
492
|
+
process.exit(1);
|
|
493
|
+
}
|
|
494
|
+
const CERTIFICATE_CONTENT_TRUSTEDZONE = tzMatch[1].trim();
|
|
495
|
+
const PUBLIC_KEY_TRUSTEDZONE = `-----BEGIN CERTIFICATE-----\n${CERTIFICATE_CONTENT_TRUSTEDZONE}\n-----END CERTIFICATE-----`;
|
|
496
|
+
fs.writeFileSync('certificate.trustedzone.crt', PUBLIC_KEY_TRUSTEDZONE);
|
|
497
|
+
console.log("Listing certificate PUBLIC_KEY_TRUSTEDZONE:");
|
|
498
|
+
console.log(fs.readFileSync('certificate.trustedzone.crt', 'utf8'));
|
|
499
|
+
|
|
500
|
+
fs.copyFileSync('certificate.securelock.crt', `${registryPath}/certificate.securelock.crt`);
|
|
501
|
+
fs.copyFileSync('certificate.trustedzone.crt', `${registryPath}/certificate.trustedzone.crt`);
|
|
502
|
+
|
|
503
|
+
if (fs.existsSync('IPFS_HASH.ipfs')) {
|
|
504
|
+
fs.unlinkSync('IPFS_HASH.ipfs');
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
console.log('Upload docker registry to IPFS');
|
|
508
|
+
execSync(`node ../ipfs.mjs --host "${process.env.IPFS_ENDPOINT}" --action upload --folderPath ${registryPath}`, { stdio: "inherit" });
|
|
509
|
+
if (!fs.existsSync(`./IPFS_HASH.ipfs`)) {
|
|
510
|
+
console.error("Error: Could not upload registry to IPFS, please try again!");
|
|
511
|
+
process.exit(1);
|
|
512
|
+
}
|
|
513
|
+
process.env.IPFS_HASH = fs.readFileSync(`./IPFS_HASH.ipfs`, 'utf8').trim();
|
|
514
|
+
console.log("IPFS_HASH: ", process.env.IPFS_HASH);
|
|
515
|
+
writeEnv('IPFS_HASH', process.env.IPFS_HASH);
|
|
516
|
+
process.chdir(currentDir);
|
|
517
|
+
console.log("Adding certificates for SECURELOCK into IMAGE REGISTRY smart contract...");
|
|
518
|
+
let existing = false;
|
|
519
|
+
try {
|
|
520
|
+
const existingImages = execSync(`node ${runDir}/image_registry.js "${process.env.BLOCKCHAIN_NETWORK}" "${process.env.PROJECT_NAME}" "${process.env.VERSION}" "${process.env.PRIVATE_KEY}" "registerSecureLockImage"`, { stdio: "inherit" });
|
|
521
|
+
if (existingImages.toString().trim().replace('Image hash: ', '') === process.env.IPFS_HASH) {
|
|
522
|
+
console.log("Certificates for SECURELOCK already added to IMAGE REGISTRY smart contract");
|
|
523
|
+
}
|
|
524
|
+
existing = true;
|
|
525
|
+
} catch (error) {
|
|
526
|
+
// console.error("Error: Could not add certificates for SECURELOCK into IMAGE REGISTRY smart contract");
|
|
527
|
+
// console.error(error);
|
|
528
|
+
// process.exit(1);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
if (!existing) {
|
|
532
|
+
const res = execSync(`node ${runDir}/image_registry.js "${process.env.BLOCKCHAIN_NETWORK}" "" "" "" "registerSecureLockImage"`, { stdio: "inherit" });
|
|
533
|
+
}
|
|
534
|
+
console.log("Script completed successfully. You can start testing the application now. (eg. npm run start)");
|
|
535
|
+
process.exit(0);
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
main();
|