-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SG-534] and [SG-535] Implement Credential Create and Update commands (…
…#3342) * Status command start * Refactor ipc test service and add status command * fixed linter errors * Move types into a model file * Cleanup and comments * Fix auth status condition * Remove .vscode settings file. Fix this in a separate work item * Implement bw-credential-retrieval * Add active field to status response * Add bw-credential-create * Better response handling in test runner * Extract native messaging types into their own files * Remove experimental decorators * Turn off no console lint rule for the test runner * Casing fix * Models import casing fixes * bw-cipher-create move type into its own file * Use LogUtils for all logging * Implement bw-credential-update * Give naming conventions for types * Rename file correctly
- Loading branch information
1 parent
98dc690
commit 83a32e3
Showing
12 changed files
with
293 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
apps/desktop/native-messaging-test-runner/src/bw-credential-create.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import "module-alias/register"; | ||
|
||
import yargs from "yargs"; | ||
import { hideBin } from "yargs/helpers"; | ||
|
||
import { LogUtils } from "./logUtils"; | ||
import NativeMessageService from "./nativeMessageService"; | ||
import * as config from "./variables"; | ||
|
||
const argv: any = yargs(hideBin(process.argv)).option("name", { | ||
alias: "n", | ||
demand: true, | ||
describe: "Name that the created login will be given", | ||
type: "string", | ||
}).argv; | ||
|
||
const { name } = argv; | ||
|
||
(async () => { | ||
const nativeMessageService = new NativeMessageService(1.0); | ||
// Handshake | ||
LogUtils.logWarning("Sending Handshake"); | ||
const handshakeResponse = await nativeMessageService.sendHandshake(config.testRsaPublicKey); | ||
|
||
if (handshakeResponse.status !== "success") { | ||
LogUtils.logError(" Handshake failed. Status was:", handshakeResponse.status); | ||
nativeMessageService.disconnect(); | ||
return; | ||
} | ||
|
||
LogUtils.logSuccess("Handshake success response"); | ||
const response = await nativeMessageService.credentialCreation(handshakeResponse.sharedKey, name); | ||
|
||
if (response.payload.status === "failure") { | ||
LogUtils.logError("Failure response returned "); | ||
} else if (response.payload.status === "success") { | ||
LogUtils.logSuccess("Success response returned "); | ||
} else if (response.payload.error === "locked") { | ||
LogUtils.logError("Error: vault is locked"); | ||
} else { | ||
LogUtils.logWarning("Other response: ", response); | ||
} | ||
|
||
nativeMessageService.disconnect(); | ||
})(); |
80 changes: 80 additions & 0 deletions
80
apps/desktop/native-messaging-test-runner/src/bw-credential-update.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import "module-alias/register"; | ||
|
||
import yargs from "yargs"; | ||
import { hideBin } from "yargs/helpers"; | ||
|
||
import { LogUtils } from "./logUtils"; | ||
import NativeMessageService from "./nativeMessageService"; | ||
import * as config from "./variables"; | ||
|
||
// Command line arguments | ||
const argv: any = yargs(hideBin(process.argv)) | ||
.option("name", { | ||
alias: "n", | ||
demand: true, | ||
describe: "Name that the updated login will be given", | ||
type: "string", | ||
}) | ||
.option("username", { | ||
alias: "u", | ||
demand: true, | ||
describe: "Username that the login will be given", | ||
type: "string", | ||
}) | ||
.option("password", { | ||
alias: "p", | ||
demand: true, | ||
describe: "Password that the login will be given", | ||
type: "string", | ||
}) | ||
.option("uri", { | ||
demand: true, | ||
describe: "Uri that the login will be given", | ||
type: "string", | ||
}).argv; | ||
|
||
const { name, username, password, uri } = argv; | ||
|
||
(async () => { | ||
const nativeMessageService = new NativeMessageService(1.0); | ||
// Handshake | ||
LogUtils.logWarning("Sending Handshake"); | ||
const handshakeResponse = await nativeMessageService.sendHandshake(config.testRsaPublicKey); | ||
|
||
if (handshakeResponse.status !== "success") { | ||
LogUtils.logError(" Handshake failed. Status was:", handshakeResponse.status); | ||
nativeMessageService.disconnect(); | ||
return; | ||
} | ||
LogUtils.logSuccess("Handshake success response"); | ||
|
||
// Get active account userId | ||
const status = await nativeMessageService.checkStatus(handshakeResponse.sharedKey); | ||
|
||
const activeUser = status.payload.filter((a) => a.active === true && a.status === "unlocked")[0]; | ||
if (activeUser === undefined) { | ||
LogUtils.logError("No active or unlocked user"); | ||
} | ||
LogUtils.logWarning("Active userId: " + activeUser.id); | ||
|
||
const response = await nativeMessageService.credentialUpdate( | ||
handshakeResponse.sharedKey, | ||
name, | ||
password, | ||
username, | ||
uri, | ||
activeUser.id, | ||
// Replace with credentialId you want to update | ||
"2a08b546-fa9d-48cc-ae8e-ae7601207da9" | ||
); | ||
|
||
if (response.payload.status === "failure") { | ||
LogUtils.logError("Failure response returned "); | ||
} else if (response.payload.status === "success") { | ||
LogUtils.logSuccess("Success response returned "); | ||
} else { | ||
LogUtils.logWarning("Other response: ", response); | ||
} | ||
|
||
nativeMessageService.disconnect(); | ||
})(); |
7 changes: 4 additions & 3 deletions
7
apps/desktop/native-messaging-test-runner/src/bw-handshake.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
import { LogUtils } from "./logUtils"; | ||
import NativeMessageService from "./nativeMessageService"; | ||
import * as config from "./variables"; | ||
|
||
(async () => { | ||
const nativeMessageService = new NativeMessageService(1.0); | ||
|
||
const response = await nativeMessageService.sendHandshake(config.testRsaPublicKey); | ||
console.log("[Handshake Command]\x1b[32m Received response to handshake request \x1b[0m"); | ||
LogUtils.logSuccess("Received response to handshake request"); | ||
if (response.status === "success") { | ||
console.log("[Handshake Command]\x1b[32m Handshake success response \x1b[0m"); | ||
LogUtils.logSuccess("Handshake success response"); | ||
} else { | ||
console.log("[Handshake Command]\x1b[31m Handshake failure response \x1b[0m"); | ||
LogUtils.logError("Handshake failure response"); | ||
} | ||
nativeMessageService.disconnect(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,23 @@ | ||
import "module-alias/register"; | ||
import { LogUtils } from "./logUtils"; | ||
import NativeMessageService from "./nativeMessageService"; | ||
import * as config from "./variables"; | ||
|
||
(async () => { | ||
const nativeMessageService = new NativeMessageService(1.0); | ||
|
||
console.log("[Status Command]\x1b[32m Sending Handshake \x1b[0m"); | ||
LogUtils.logWarning("Sending Handshake"); | ||
const handshakeResponse = await nativeMessageService.sendHandshake(config.testRsaPublicKey); | ||
console.log("[Status Command]\x1b[32m Received response to handshake request \x1b[0m"); | ||
LogUtils.logSuccess("Received response to handshake request"); | ||
|
||
if (handshakeResponse.status !== "success") { | ||
console.log( | ||
`[Status Command]\x1b[31m Handshake failed \x1b[0m Status was: ${handshakeResponse.status}` | ||
); | ||
LogUtils.logError(" Handshake failed. Status was:", handshakeResponse.status); | ||
nativeMessageService.disconnect(); | ||
return; | ||
} | ||
console.log("[Status Command]\x1b[32m Handshake success response \x1b[0m"); | ||
LogUtils.logSuccess("Handshake success response"); | ||
const status = await nativeMessageService.checkStatus(handshakeResponse.sharedKey); | ||
|
||
console.log(`[Status Command] Status output is: `, status); | ||
|
||
LogUtils.logSuccess("Status output is: ", status); | ||
nativeMessageService.disconnect(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...models/nativeMessaging/ciphersResponse.ts → .../models/nativeMessaging/cipherResponse.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
apps/desktop/src/models/nativeMessaging/credentialCreatePayload.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export type CredentialCreatePayload = { | ||
userId: string; | ||
userName: string; | ||
password: string; | ||
name: string; | ||
uri: string; | ||
}; |
8 changes: 8 additions & 0 deletions
8
apps/desktop/src/models/nativeMessaging/credentialUpdatePayload.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export type CredentialUpdatePayload = { | ||
userId: string; | ||
userName: string; | ||
password: string; | ||
name: string; | ||
uri: string; | ||
credentialId: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.