mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-01 22:12:26 +01:00
cli: add stdio control server
* signing: implement signing service on the web * wip * cli: implement stdio service This is used to implement the exec server for WSL. Guarded behind a signed handshake. * update distro * rm debug * address pr comments
This commit is contained in:
41
cli/src/tunnels/challenge.rs
Normal file
41
cli/src/tunnels/challenge.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
#[cfg(not(feature = "vsda"))]
|
||||
pub fn create_challenge() -> String {
|
||||
use rand::distributions::{Alphanumeric, DistString};
|
||||
Alphanumeric.sample_string(&mut rand::thread_rng(), 16)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "vsda"))]
|
||||
pub fn sign_challenge(challenge: &str) -> String {
|
||||
use sha2::{Digest, Sha256};
|
||||
let mut hash = Sha256::new();
|
||||
hash.update(challenge.as_bytes());
|
||||
let result = hash.finalize();
|
||||
base64::encode_config(result, base64::URL_SAFE_NO_PAD)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "vsda"))]
|
||||
pub fn verify_challenge(challenge: &str, response: &str) -> bool {
|
||||
sign_challenge(challenge) == response
|
||||
}
|
||||
|
||||
#[cfg(feature = "vsda")]
|
||||
pub fn create_challenge() -> String {
|
||||
use rand::distributions::{Alphanumeric, DistString};
|
||||
let str = Alphanumeric.sample_string(&mut rand::thread_rng(), 16);
|
||||
vsda::create_new_message(&str)
|
||||
}
|
||||
|
||||
#[cfg(feature = "vsda")]
|
||||
pub fn sign_challenge(challenge: &str) -> String {
|
||||
vsda::sign(challenge)
|
||||
}
|
||||
|
||||
#[cfg(feature = "vsda")]
|
||||
pub fn verify_challenge(challenge: &str, response: &str) -> bool {
|
||||
vsda::validate(challenge, response)
|
||||
}
|
||||
Reference in New Issue
Block a user