Compare commits
	
		
			1 Commits
		
	
	
		
			master
			...
			3280c5c04d
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 3280c5c04d | 
							
								
								
									
										1148
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1148
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -1,6 +1,6 @@ | ||||
| [package] | ||||
| name = "light-openid" | ||||
| version = "1.0.4" | ||||
| version = "1.0.2" | ||||
| edition = "2021" | ||||
| repository = "https://gitea.communiquons.org/pierre/light-openid" | ||||
| authors = ["Pierre HUBERT <pierre.git@communiquons.org>"] | ||||
| @@ -12,7 +12,7 @@ license = "GPL-2.0-or-later" | ||||
|  | ||||
| [dependencies] | ||||
| log = "0.4.21" | ||||
| reqwest = { version = "0.12.14", features = ["json"] }  | ||||
| reqwest = { version = "0.12.3", features = ["json"] } | ||||
| base64 = "0.22.0" | ||||
| serde = { version = "1.0.198", features = ["derive"] } | ||||
| serde_json = "1.0.115" | ||||
| @@ -21,7 +21,7 @@ urlencoding = "2.1.3" | ||||
| # Dependencies for crypto wrapper | ||||
| bincode = { version = "2.0.0-rc.3", optional = true } | ||||
| aes-gcm = { version = "0.10.3", optional = true } | ||||
| rand = { version = "0.9.0", optional = true } | ||||
| rand = { version = "0.8.5", optional = true } | ||||
|  | ||||
| [features] | ||||
| crypto-wrapper = ["bincode", "aes-gcm", "rand"] | ||||
|   | ||||
| @@ -1,8 +1,9 @@ | ||||
| { | ||||
|   "$schema": "https://docs.renovatebot.com/renovate-schema.json", | ||||
|   "extends": [ | ||||
|     ":automergeAll", | ||||
|     ":enableVulnerabilityAlerts", | ||||
|     ":ignoreUnstable" | ||||
|   "packageRules": [ | ||||
|     { | ||||
|       "matchUpdateTypes": ["major", "minor", "patch"], | ||||
|       "automerge": true | ||||
|     } | ||||
|   ] | ||||
| } | ||||
| } | ||||
|   | ||||
| @@ -39,7 +39,7 @@ impl Error for StateError {} | ||||
|  | ||||
| impl fmt::Display for StateError { | ||||
|     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||
|         write!(f, "StateManager error {self:?}") | ||||
|         write!(f, "StateManager error {:?}", self) | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -38,7 +38,7 @@ impl OpenIDConfig { | ||||
|         code: &str, | ||||
|         redirect_uri: &str, | ||||
|     ) -> Result<(OpenIDTokenResponse, String), Box<dyn Error>> { | ||||
|         let authorization = BASE64_STANDARD.encode(format!("{client_id}:{client_secret}")); | ||||
|         let authorization = BASE64_STANDARD.encode(format!("{}:{}", client_id, client_secret)); | ||||
|  | ||||
|         let mut params = HashMap::new(); | ||||
|         params.insert("grant_type", "authorization_code"); | ||||
|   | ||||
| @@ -1,10 +1,12 @@ | ||||
| use std::error::Error; | ||||
| use std::io::ErrorKind; | ||||
|  | ||||
| use aes_gcm::aead::{Aead, OsRng}; | ||||
| use aes_gcm::{Aes256Gcm, Key, KeyInit, Nonce}; | ||||
| use base64::engine::general_purpose::STANDARD as BASE64_STANDARD; | ||||
| use base64::Engine as _; | ||||
| use bincode::{Decode, Encode}; | ||||
| use rand::Rng; | ||||
| use std::error::Error; | ||||
|  | ||||
| /// The lenght of the nonce used to initialize encryption | ||||
| const NONCE_LEN: usize = 12; | ||||
| @@ -24,9 +26,9 @@ impl CryptoWrapper { | ||||
|     } | ||||
|  | ||||
|     /// Encrypt some data, returning the result as a base64-encoded string | ||||
|     pub fn encrypt<T: Encode + Decode<()>>(&self, data: &T) -> Result<String, Box<dyn Error>> { | ||||
|     pub fn encrypt<T: Encode + Decode>(&self, data: &T) -> Result<String, Box<dyn Error>> { | ||||
|         let aes_key = Aes256Gcm::new(&self.key); | ||||
|         let nonce_bytes = rand::rng().random::<[u8; NONCE_LEN]>(); | ||||
|         let nonce_bytes = rand::thread_rng().gen::<[u8; NONCE_LEN]>(); | ||||
|  | ||||
|         let serialized_data = bincode::encode_to_vec(data, bincode::config::standard())?; | ||||
|  | ||||
| @@ -39,11 +41,12 @@ impl CryptoWrapper { | ||||
|     } | ||||
|  | ||||
|     /// Decrypt some data previously encrypted using the [`CryptoWrapper::encrypt`] method | ||||
|     pub fn decrypt<T: Decode<()>>(&self, input: &str) -> Result<T, Box<dyn Error>> { | ||||
|     pub fn decrypt<T: Decode>(&self, input: &str) -> Result<T, Box<dyn Error>> { | ||||
|         let bytes = BASE64_STANDARD.decode(input)?; | ||||
|  | ||||
|         if bytes.len() < NONCE_LEN { | ||||
|             return Err(Box::new(std::io::Error::other( | ||||
|             return Err(Box::new(std::io::Error::new( | ||||
|                 ErrorKind::Other, | ||||
|                 "Input string is smaller than nonce!", | ||||
|             ))); | ||||
|         } | ||||
| @@ -56,8 +59,9 @@ impl CryptoWrapper { | ||||
|         let dec = match aes_key.decrypt(Nonce::from_slice(nonce), enc) { | ||||
|             Ok(d) => d, | ||||
|             Err(e) => { | ||||
|                 log::error!("Failed to decrypt wrapped data! {e:#?}"); | ||||
|                 return Err(Box::new(std::io::Error::other( | ||||
|                 log::error!("Failed to decrypt wrapped data! {:#?}", e); | ||||
|                 return Err(Box::new(std::io::Error::new( | ||||
|                     ErrorKind::Other, | ||||
|                     "Failed to decrypt wrapped data!", | ||||
|                 ))); | ||||
|             } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user