Skip to content

Commit a4b2d70

Browse files
authored
Merge pull request #4 from cmdscale/fix-salt-func
braking: changed salt func
2 parents a7b5a9b + 315c7a4 commit a4b2d70

6 files changed

Lines changed: 26 additions & 16 deletions

File tree

tssh-core/migrations/V1__init.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ username VARCHAR(256) NOT NULL,
1313
port INTEGER NOT NULL,
1414
pub_key VARCHAR(2056) NOT NULL,
1515
template TEXT NOT NULL,
16-
UNIQUE(host,username),
16+
UNIQUE(host,username,port),
1717
FOREIGN KEY(backup_key_id) REFERENCES BackupKeys(id)
1818
);
1919

tssh-core/src/sqlite/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,11 @@ fn keys() -> Result<()> {
354354
let err = db.add_key(key);
355355
assert!(err.is_err());
356356

357-
//adding a key with same user,host combination must fail
357+
//adding a key with same user,host,port combination must fail
358358
let mut key = DBKey::generate_random_key();
359359
key.host = ret.host;
360360
key.username = ret.username;
361+
key.port =ret.port;
361362
let err = db.add_key(key);
362363
assert!(err.is_err());
363364

tssh-core/src/tpm/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ impl TPMEccPubKey {
408408
raw_point.extend_from_slice(&self.y);
409409

410410
let mut ret = Vec::new();
411-
ret.push(0x4);
411+
ret.push(0x04);
412412

413413
if raw_point.len() < 128 {
414414
ret.push(raw_point.len() as u8);
@@ -798,7 +798,9 @@ pub struct Salt {
798798
impl Salt {
799799
fn new(a: &[u8], b: &[u8], c: &[u8]) -> Self {
800800
let mut hasher = sha2::Sha512::new();
801+
hasher.update(a.len().to_be_bytes());
801802
hasher.update(a);
803+
hasher.update(b.len().to_be_bytes());
802804
hasher.update(b);
803805
hasher.update(c);
804806

tssh-pkcs11/src/pkcs11/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ pub unsafe extern "C" fn C_GetMechanismList(
774774
return CKR_OK;
775775
}
776776

777-
if unsafe { *pul_count } < 1 {
777+
if unsafe { *pul_count } < SUPPORTED_MECHANISMS.len() as u64 {
778778
error!("get mechaninslam list buffer too small");
779779
return CKR_BUFFER_TOO_SMALL;
780780
}

tssh/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ pub fn write_pkcs11_lib(path: &PathBuf) -> Result<()> {
294294
.write(true)
295295
.create(true)
296296
.truncate(true)
297-
.mode(0o600)
297+
.mode(0o700)
298298
.open(path)
299299
.context("while creating lib file")?;
300300

tssh/src/ssh_writer/mod.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ impl FileEntry {
5151
}
5252
}
5353

54-
impl From<(DBKey, &str, &str)> for FileEntry {
55-
fn from((value, lib_path, file_path): (DBKey, &str, &str)) -> Self {
56-
let host_template = HostTemplate::try_from(&value).expect("change this"); //TODO: change
54+
impl TryFrom<(DBKey, &str, &str)> for FileEntry{
55+
type Error=anyhow::Error;
56+
57+
fn try_from((db_key, lib_path, file_path): (DBKey, &str, &str)) -> std::prelude::v1::Result<Self, Self::Error> {
58+
59+
let host_template = HostTemplate::try_from(&db_key).context("while parsing host template from db key")?;
5760

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

72-
Self {
73-
host: value.host,
74-
username: value.username,
75-
port: value.port,
75+
Ok(Self {
76+
host: db_key.host,
77+
username: db_key.username,
78+
port: db_key.port,
7679
pkcs11_provider: lib_path.to_string(),
7780
identity_file: file_path.to_string(),
7881
accepted_algorithms: accepted_algorithms.to_string(),
79-
}
82+
})
83+
84+
8085
}
8186
}
8287

88+
89+
8390
const KEY_DIR_NAME: &str = "keys";
8491
const SSH_FILE_NAME: &str = "ssh_file";
8592

@@ -111,17 +118,17 @@ where
111118
file.write_all(x.pub_key.as_bytes())
112119
.context("while writing to keyfile")?;
113120
ssh_file_content.push_str(
114-
FileEntry::from((
121+
FileEntry::try_from((
115122
x,
116123
env.lib_path.to_string_lossy().to_string().as_str(),
117124
file_path.to_string_lossy().to_string().as_str(),
118-
))
125+
))?
119126
.as_file_entry()
120127
.as_str(),
121128
);
122129
}
123130

124-
std::fs::write(tssh_ssh_file_path, ssh_file_content.as_bytes()).context("wile writing ssh file")
131+
std::fs::write(tssh_ssh_file_path, ssh_file_content.as_bytes()).context("while writing ssh file")
125132
}
126133

127134
pub fn generate_include(env: &DirEnv) -> Result<String> {

0 commit comments

Comments
 (0)