Skip to content

Commit c49ed41

Browse files
authored
Merge pull request #203 from dzervas/codex/locate-and-fix-a-critical-bug
Fix SAML key PEM header parsing
2 parents e28971f + b6e1ffa commit c49ed41

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

src/config.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,14 @@ impl ConfigFile {
196196
/// filepath
197197
pub fn get_saml_key(&self) -> Result<String, std::io::Error> {
198198
let data = std::fs::read_to_string(&self.saml_key_pem_path)?;
199-
Ok(data
200-
.lines()
201-
.filter(|line| !line.contains("BEGIN CERTIFICATE") && !line.contains("END CERTIFICATE"))
202-
.collect::<String>()
203-
.replace("\n", ""))
204-
}
199+
Ok(data
200+
.lines()
201+
.filter(|line| {
202+
!line.contains("BEGIN PRIVATE KEY") && !line.contains("END PRIVATE KEY")
203+
})
204+
.collect::<String>()
205+
.replace("\n", ""))
206+
}
205207
}
206208

207209
/// Basic key-value store database schema for some minor config values,

src/tests/config.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use crate::config::ConfigFile;
2+
use uuid::Uuid;
3+
4+
#[test]
5+
fn get_saml_key_strips_pem_headers() {
6+
let pem = "-----BEGIN PRIVATE KEY-----\nABCDEF\n-----END PRIVATE KEY-----\n";
7+
let path = std::env::temp_dir().join(format!("testkey-{}.pem", Uuid::new_v4()));
8+
std::fs::write(&path, pem).expect("write pem");
9+
10+
let mut config = ConfigFile::default();
11+
config.saml_key_pem_path = path.to_string_lossy().into_owned();
12+
13+
let key = config.get_saml_key().expect("read key");
14+
assert_eq!(key, "ABCDEF");
15+
}

src/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pub mod flow_scoped;
2+
pub mod config;

0 commit comments

Comments
 (0)