Skip to content

Commit

Permalink
Get Certificate during handshake support
Browse files Browse the repository at this point in the history
  • Loading branch information
Universal Web committed Jul 19, 2023
1 parent c4d6f8c commit d414709
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
58 changes: 30 additions & 28 deletions udsp/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ export class Client extends UDSP {
destination.port = port;
}
// console.log('Destination', destination.cryptography);
}
async getKeychainSave(keychain) {
return keychainGet(keychain);
}
async setCertificate() {
const {
keychain,
certificate
} = this.configuration;
if (isString(certificate)) {
this.certificate = await parseCertificate(certificate);
}
if (keychain) {
// console.log('Loading Keychain', keychain);
this.certificate = await this.getKeychainSave(keychain);
}
}
async configCryptography() {
// console.log(this.cryptography);
const { destination, } = this;
const cryptoConfig = assign({
isClient: true,
generate: {
Expand All @@ -103,40 +123,18 @@ export class Client extends UDSP {
if (destination.autoLogin && this.autoLogin) {
this.autoLogin = true;
}
}
async getKeychainSave(keychain) {
return keychainGet(keychain);
}
async setCertificate() {
const {
keychain,
certificate
} = this.configuration;
if (isString(certificate)) {
this.certificate = await parseCertificate(certificate);
}
if (keychain) {
// console.log('Loading Keychain', keychain);
this.certificate = await this.getKeychainSave(keychain);
}
if (this.certificate.ephemeral) {
this.activeCertificate = this.certificate.ephemeral;
} else if (this.certificate.master) {
this.activeCertificate = this.certificate.ephemeral;
}
}
async configCryptography() {
// console.log(this.cryptography);
if (!this.keyPair) {
this.keypair = this.cryptography.generated.keypair;
this.encryptKeypair = this.cryptography.generated.encryptKeypair;
this.connectionIdKeypair = this.cryptography.generated.connectionIdKeypair;
success(`Created Connection Keypair`);
}
success(`Created Connection Keypair`);
this.sessionKeys = this.cryptography.generated.sessionKeys;
success(`Created Shared Keys`);
success(`receiveKey: ${toBase64(this.sessionKeys.receiveKey)}`);
success(`transmitKey: ${toBase64(this.sessionKeys.transmitKey)}`);
if (this.sessionKeys) {
success(`Created Shared Keys`);
success(`receiveKey: ${toBase64(this.sessionKeys.receiveKey)}`);
success(`transmitKey: ${toBase64(this.sessionKeys.transmitKey)}`);
}
}
async attachEvents() {
const thisClient = this;
Expand Down Expand Up @@ -274,6 +272,10 @@ export class Client extends UDSP {
this.endHandshake(message);
}
}
loadCertificate(certificate) {
this.certificates = certificate;
this.configCryptography();
}
request = request;
fetch = fetchRequest;
processMessage = processMessage;
Expand Down
11 changes: 5 additions & 6 deletions udsp/cryptography.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ const {
class Cryptography {
constructor(config) {
this.config = config;
return this.initialize();
}
initialize(config) {
// console.log(config);
const { cryptography: cryptographyConfig } = config;
const { cryptography: cryptographyConfig = {} } = config;
let {
encryptClientConnectionId,
encryptServerConnectionId,
Expand Down Expand Up @@ -178,7 +181,7 @@ class Cryptography {
this.generated.connectionIdKeypair = this.generated.keypair;
this.generated.encryptKeypair = this.generated.keypair;
}
if (generate?.clientSessionKeys) {
if (generate?.clientSessionKeys && this.encryptionKeypair.publicKey) {
// console.log(this.encryptionKeypair);
this.generated.sessionKeys = this.clientSessionKeys(this.generated.keypair, this.encryptionKeypair.publicKey);
}
Expand All @@ -192,7 +195,6 @@ class Cryptography {
if (this.encryptMethod.overhead) {
this.encryptOverhead = this.encryptMethod.overhead;
}
return this.initialize();
}
generated = {
destination: {}
Expand Down Expand Up @@ -230,9 +232,6 @@ class Cryptography {
convertSignKeypair(...args) {
return this.convertSignKeypairMethod(...args);
}
async initialize() {
return this;
}
}
export function cryptography(...args) {
return construct(Cryptography, args);
Expand Down

0 comments on commit d414709

Please sign in to comment.