Skip to content

Commit

Permalink
certificate cleanup & patches
Browse files Browse the repository at this point in the history
certs organized
get public cert from main cert
skip request bodies for get methods
  • Loading branch information
tomekmarchi committed Nov 9, 2023
1 parent 57eb01b commit 97e931b
Show file tree
Hide file tree
Showing 35 changed files with 79 additions and 42 deletions.
Binary file removed profiles/Adobe Content Certificate 10-5.cer
Binary file not shown.
Binary file removed profiles/default-Ephemeral.cert
Binary file not shown.
Binary file removed profiles/default-EphemeralPublic.cert
Binary file not shown.
Binary file removed profiles/default-Master.cert
Binary file not shown.
Binary file removed profiles/default-MasterPublic.cert
Binary file not shown.
Binary file removed profiles/default-Profile.cert
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added profiles/default/default-Master/default-Master.cert
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 3 additions & 2 deletions scripts/certificates.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const domainProfile = await createProfile({
},
},
},
savePath: `${dirname}/../services`,
savePath: `${dirname}/../serverApp/certs`,
certificateName: 'universal.web'
});
console.log('DOMAIN Profile created (Master & IDENTITY CERTIFICATEs)', decode(domainProfile.ephemeral.certificate));
Expand All @@ -142,7 +142,8 @@ const profile = await createProfile({
viat: true
}
},
savePath: `${dirname}/../profiles`,
savePath: `${dirname}/../profiles/default`,
folder: 'default',
certificateName: 'default',
saveToKeychain: {
account: 'Universal Web Profile'
Expand Down
2 changes: 2 additions & 0 deletions scripts/request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { get } from '#udsp';
const response = get('uw://127.0.0.1/index.html');
1 change: 0 additions & 1 deletion scripts/simulateClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ console.log('STARTING CLIENT');
console.time('Full');
import { currentPath } from '@universalweb/acid';
import { client } from '#udsp';
import { decode } from '#utilities/serialize';
console.time('Connected');
// Universal Web Socket
const uwClient = await client({
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 1 addition & 3 deletions serverApp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ const appServer = await server({
// default file extension default is .js but WWW default is www
defaultExtension: 'html',
// Domain certificate to be loaded used for connection encryption
certificatePath: path.join(currentPath(import.meta), '../services/universal.web-Ephemeral.cert'),
// Public Domain certificate to be sent in its raw format for validation when a client connects but doesn't have a certificate
certificatePublicPath: path.join(currentPath(import.meta), '../services/universal.web-EphemeralPublic.cert'),
certificatePath: path.join(currentPath(import.meta), '/universal_web-Ephemeral/universal.web-Ephemeral.cert'),
// Where to load app resources from
resourceDirectory: path.join(currentPath(import.meta), 'resources'),
rootDirectory: currentPath(import.meta),
Expand Down
Binary file removed services/universal.web-Ephemeral.cert
Binary file not shown.
Binary file removed services/universal.web-EphemeralPublic.cert
Binary file not shown.
Binary file removed services/universal.web-Master.cert
Binary file not shown.
Binary file removed services/universal.web-MasterPublic.cert
Binary file not shown.
Binary file removed services/universal.web-Profile.cert
Binary file not shown.
10 changes: 7 additions & 3 deletions udsp/UWRL/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class UWRL {
this.params = urlObject.search;
this.parameters = urlObject.searchParams;
}
this.href = url;
this.url = url;
this.origin = `${urlObject.protocol}//${urlObject.host}`;
this.port = urlObject.port;
this.host = urlObject.host;
Expand All @@ -52,13 +52,17 @@ class UWRL {
get searchParams() {
return this.parameters;
}
get href() {
return this.url;
}
hash = '';
isUWRL = true;
}
export function uwrl(...args) {
return new UWRL(...args);
}
// Supports Username Password and URL Fragments
// Server can opt in to get the URL fragments
// fragments are turned into client side state tracking
// const uwri = new UWRL('uw://example.com:8080/path/to/resource{"query":"value", "#": "fragment", ":": ["username", "password"]}');
// console.log(uwri);
const uwri2 = new UWRL('https://example.com/?query=1#wow');
console.log(uwri2);
13 changes: 13 additions & 0 deletions udsp/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
import { isString } from '@universalweb/acid';
import { client } from './client/index.js';
import { uwrl } from './UWRL/index.js';
export async function request(method = 'get', url, params, data) {
const uwrlObject = isString(url) ? uwrl(url) : url;
const uwClient = await client({
url: uwrlObject
});
return uwClient.request(method, uwrlObject, params, data).send();
}
export async function get(url, params) {
return request('get', url, params);
}
export * from './client/index.js';
export * from './server/index.js';
15 changes: 10 additions & 5 deletions udsp/request/ask.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ export class Ask extends Base {
this.path = path;
}
this.maxFrameSize = destination.maxFrameSize;
this.request = clientRequestObject({
data,
head,
source: this,
});
const requestObject = {
source: this
};
if (data) {
requestObject.data = data;
}
if (head) {
requestObject.head = head;
}
this.request = clientRequestObject(requestObject);
this.response = clientResponseObject({
source: this,
});
Expand Down
13 changes: 5 additions & 8 deletions udsp/request/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { onPath } from './onPath.js';
import { onHead } from './onHead.js';
import { onParameters } from './onParameters.js';
import { fire } from './events/fire.js';
const noPayloadMethods = /get|head|ping/;
/**
* @todo
* Add support for headers which indicate the headers content encoding?
Expand All @@ -32,6 +33,7 @@ export class Base {
if (this.isAsk) {
this.handshake = source.handshake;
}
this.noData = noPayloadMethods.test(this.method);
}
setHeaders(target) {
const source = (this.isAsk) ? this.request : this.response;
Expand Down Expand Up @@ -117,15 +119,7 @@ export class Base {
this.readyState = 2;
this.pathAssembled = true;
}
processStates = [this.processPath, this.processParameters, this.processHead, this.processData];
processState = 0;
async getProcessState() {
const {
processState,
processStates
} = this;
return processStates[processState]();
}
async processHead() {
if (this.headAssembled) {
return console.log('Head already processed');
Expand Down Expand Up @@ -269,6 +263,9 @@ export class Base {
if (this.state === 4) {
this.state = 5;
}
if (this.isReply && this.noData) {
return this.completeReceived();
}
if (this.totalIncomingDataSize === 0) {
return this.completeReceived();
}
Expand Down
1 change: 1 addition & 0 deletions udsp/request/objects/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class Base {
domainCertificate,
profileCertificate,
source,
method
} = config;
if (hasValue(data)) {
this.data = data;
Expand Down
2 changes: 0 additions & 2 deletions udsp/request/reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ export class Reply extends Base {
const { replyQueue, } = source;
this.events = source.events;
this.requestMethods = source.requestMethods;
// console.log(source);
// // console.log(message);
this.streamIdSize = numberEncodedSize(id);
this.maxFrameSize = source.destination.maxFrameSize;
this.request = serverRequestObject({
Expand Down
11 changes: 2 additions & 9 deletions udsp/server/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,12 @@ export class Server extends UDSP {
async setCertificate() {
const {
configuration,
configuration: {
certificatePath,
certificatePublicPath
}
configuration: { certificatePath, }
} = this;
if (certificatePath) {
this.certificate = await parseCertificate(certificatePath);
console.log(this.certificate);
this.certificatePublic = this.certificate.certificate;
this.keypair = {
publicKey: this.certificate.publicKey,
privateKey: this.certificate.privateKey,
Expand All @@ -129,11 +127,6 @@ export class Server extends UDSP {
this.ipVersion = this.certificate.ipVersion;
}
}
if (certificatePublicPath) {
this.certificatePublic = await loadCertificate(certificatePublicPath);
this.certificatePublicSize = this.certificatePublic.length;
this.chunkCertificate();
}
if (this.certificate) {
this.publicKeyCryptography = getPublicKeyAlgorithm(this.certificate.publicKeyAlgorithm);
const convertSignKeypairToEncryptionKeypair = processPublicKey(this.certificate);
Expand Down
14 changes: 8 additions & 6 deletions utilities/certificate/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ export async function saveCertificate(config) {
const {
certificate,
savePath,
certificateName
certificateName,
} = config;
const savePathRoot = `${resolve(`${savePath}`)}/${certificateName}`;
const folderName = certificateName.replace(/\./g, '_');
const savePathRoot = `${resolve(`${savePath}`)}/${folderName}/${certificateName}`;
const publicCertificate = certificate.certificate;
const encodedCertificate = encode(certificate);
await write(`${savePathRoot}Public.cert`, publicCertificate);
await write(`${savePathRoot}.cert`, encodedCertificate);
await write(`${savePathRoot}Public.cert`, publicCertificate, 'binary', true);
await write(`${savePathRoot}.cert`, encodedCertificate, 'binary', true);
}
export async function saveProfile(config) {
const {
Expand All @@ -36,6 +37,7 @@ export async function saveProfile(config) {
certificateName: `${certificateName}-Master`
};
await saveCertificate(master);
const savePathRoot = `${resolve(`${savePath}`)}/${certificateName}-Profile.cert`;
await write(savePathRoot, encode(profile));
const folderName = certificateName.replace(/\./g, '_');
const savePathRoot = `${resolve(`${savePath}`)}/${folderName}-Profile/${certificateName}-Profile.cert`;
await write(savePathRoot, encode(profile), 'binary', true);
}
26 changes: 23 additions & 3 deletions utilities/file.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
import { readFileSync } from 'fs';
import fs from 'node:fs';
const { readFileSync } = fs;
import {
writeFile,
readFile,
} from 'node:fs/promises';
import { promise, jsonParse } from '@universalweb/acid';
import { normalize } from 'path';
import path from 'path';
const { normalize } = path;
import { decode } from '#utilities/serialize';
export async function write(filePath, contents, encode) {
function createFoldersIfNotExist(folderPath) {
const directories = path.normalize(folderPath).split(path.sep);
let currentPath = `${path.sep}`;
console.log(directories);
for (const dir of directories) {
if (dir.length) {
currentPath = path.join(currentPath, dir);
const pathExists = fs.existsSync(currentPath);
console.log(pathExists, currentPath);
if (!pathExists) {
fs.mkdirSync(currentPath);
}
}
}
}
export async function write(filePath, contents, encode, createPathFlag) {
const pathNormalized = normalize(filePath);
console.log('FILE WRITE', pathNormalized, contents.length, encode);
if (createPathFlag) {
createFoldersIfNotExist(path.dirname(pathNormalized));
}
return writeFile(pathNormalized, contents, encode);
}
export async function read(filePath, encode) {
Expand Down
4 changes: 4 additions & 0 deletions utilities/readEncoded.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { decode } from '#utilities/serialize';
import { readMsgpack } from './file.js';
import { parseCertificate } from '#certificate';
// console.log(decode(readMsgpack('').certificate));

0 comments on commit 97e931b

Please sign in to comment.