Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tssh-core/migrations/V1__init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ username VARCHAR(256) NOT NULL,
port INTEGER NOT NULL,
pub_key VARCHAR(2056) NOT NULL,
template TEXT NOT NULL,
UNIQUE(host,username),
UNIQUE(host,username,port),
FOREIGN KEY(backup_key_id) REFERENCES BackupKeys(id)
);

Expand Down
3 changes: 2 additions & 1 deletion tssh-core/src/sqlite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,11 @@ fn keys() -> Result<()> {
let err = db.add_key(key);
assert!(err.is_err());

//adding a key with same user,host combination must fail
//adding a key with same user,host,port combination must fail
let mut key = DBKey::generate_random_key();
key.host = ret.host;
key.username = ret.username;
key.port =ret.port;
let err = db.add_key(key);
assert!(err.is_err());

Expand Down
4 changes: 3 additions & 1 deletion tssh-core/src/tpm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ impl TPMEccPubKey {
raw_point.extend_from_slice(&self.y);

let mut ret = Vec::new();
ret.push(0x4);
ret.push(0x04);

if raw_point.len() < 128 {
ret.push(raw_point.len() as u8);
Expand Down Expand Up @@ -798,7 +798,9 @@ pub struct Salt {
impl Salt {
fn new(a: &[u8], b: &[u8], c: &[u8]) -> Self {
let mut hasher = sha2::Sha512::new();
hasher.update(a.len().to_be_bytes());
hasher.update(a);
hasher.update(b.len().to_be_bytes());
hasher.update(b);
hasher.update(c);

Expand Down
2 changes: 1 addition & 1 deletion tssh-pkcs11/src/pkcs11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ pub unsafe extern "C" fn C_GetMechanismList(
return CKR_OK;
}

if unsafe { *pul_count } < 1 {
if unsafe { *pul_count } < SUPPORTED_MECHANISMS.len() as u64 {
error!("get mechaninslam list buffer too small");
return CKR_BUFFER_TOO_SMALL;
}
Expand Down
2 changes: 1 addition & 1 deletion tssh/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ pub fn write_pkcs11_lib(path: &PathBuf) -> Result<()> {
.write(true)
.create(true)
.truncate(true)
.mode(0o600)
.mode(0o700)
.open(path)
.context("while creating lib file")?;

Expand Down
29 changes: 18 additions & 11 deletions tssh/src/ssh_writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ impl FileEntry {
}
}

impl From<(DBKey, &str, &str)> for FileEntry {
fn from((value, lib_path, file_path): (DBKey, &str, &str)) -> Self {
let host_template = HostTemplate::try_from(&value).expect("change this"); //TODO: change
impl TryFrom<(DBKey, &str, &str)> for FileEntry{
type Error=anyhow::Error;

fn try_from((db_key, lib_path, file_path): (DBKey, &str, &str)) -> std::prelude::v1::Result<Self, Self::Error> {

let host_template = HostTemplate::try_from(&db_key).context("while parsing host template from db key")?;

let accepted_algorithms = match host_template.template {
tssh_core::tpm::Template::RSA(rsa_template) => match rsa_template.keybits {
Expand All @@ -69,17 +72,21 @@ impl From<(DBKey, &str, &str)> for FileEntry {
},
};

Self {
host: value.host,
username: value.username,
port: value.port,
Ok(Self {
host: db_key.host,
username: db_key.username,
port: db_key.port,
pkcs11_provider: lib_path.to_string(),
identity_file: file_path.to_string(),
accepted_algorithms: accepted_algorithms.to_string(),
}
})


}
}



const KEY_DIR_NAME: &str = "keys";
const SSH_FILE_NAME: &str = "ssh_file";

Expand Down Expand Up @@ -111,17 +118,17 @@ where
file.write_all(x.pub_key.as_bytes())
.context("while writing to keyfile")?;
ssh_file_content.push_str(
FileEntry::from((
FileEntry::try_from((
x,
env.lib_path.to_string_lossy().to_string().as_str(),
file_path.to_string_lossy().to_string().as_str(),
))
))?
.as_file_entry()
.as_str(),
);
}

std::fs::write(tssh_ssh_file_path, ssh_file_content.as_bytes()).context("wile writing ssh file")
std::fs::write(tssh_ssh_file_path, ssh_file_content.as_bytes()).context("while writing ssh file")
}

pub fn generate_include(env: &DirEnv) -> Result<String> {
Expand Down
Loading