Skip to content

Commit c65a850

Browse files
author
Flavio Oliveira
committed
printable_characters - check if it is ascii
1 parent 9bad34b commit c65a850

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

Diff for: Cargo.toml

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
[package]
22
name = "yubico"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
authors = ["Flavio Oliveira <[email protected]>"]
55

66
description = "Yubikey client API library"
7-
license = "MIT"
7+
license = "MIT OR Apache-2.0"
88
keywords = ["HMS", "yubikey", "authentication", "encryption", "OTP"]
9-
9+
categories = ["authentication"]
1010
repository = "https://github.com/wisespace-io/yubico-rs"
1111
readme = "README.md"
1212

13+
[badges]
14+
travis-ci = { repository = "wisespace-io/yubico-rs" }
15+
1316
[lib]
1417
name = "yubico"
1518
path = "src/lib.rs"
@@ -19,6 +22,6 @@ url = "1.4"
1922
hyper = { version = "0.10", default-features = false }
2023
hyper-native-tls = "0.2.2"
2124
rand = "0.3.15"
22-
base64 = "^0.4"
25+
base64 = "^0.5"
2326
threadpool = "1.3"
2427
rust-crypto = "^0.2"

Diff for: LICENSE

+4-17
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
1-
MIT License
2-
31
Copyright (c) 2016 Flavio Oliveira
42

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
3+
Licensed under either of
114

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
5+
* Apache License, Version 2.0, (http://www.apache.org/licenses/LICENSE-2.0)
6+
* MIT license (http://opensource.org/licenses/MIT)
147

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
8+
at your option.

Diff for: README.md

+3
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,7 @@ fn main() {
3636

3737
## License
3838

39+
Licensed under either of
40+
3941
* MIT license (see [LICENSE](LICENSE) or <http://opensource.org/licenses/MIT>)
42+
* Apache License, Version 2.0 (see [LICENSE](LICENSE) or <http://www.apache.org/licenses/LICENSE-2.0>)

Diff for: src/lib.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extern crate threadpool;
88

99
pub mod yubicoerror;
1010

11+
use std::ascii::AsciiExt;
1112
use yubicoerror::YubicoError;
1213
use hyper::net::HttpsConnector;
1314
use hyper_native_tls::NativeTlsClient;
@@ -62,15 +63,15 @@ impl Yubico {
6263
pub fn new(client_id: String, key: String) -> Self {
6364
Yubico {
6465
client_id: client_id,
65-
key: decode(key.as_ref()).unwrap(),
66+
key: decode(&key[..]).unwrap(),
6667
}
6768
}
6869

6970
// Verify a provided OTP
7071
pub fn verify(&self, otp: String) -> Result<String> {
7172
match self.printable_characters(otp.clone()) {
7273
false => Err(YubicoError::BadOTP),
73-
_ => {
74+
_ => {
7475
let nonce: String = self.generate_nonce();
7576
let mut query = format!("id={}&nonce={}&otp={}&sl=secure", self.client_id, nonce, otp);
7677

@@ -133,7 +134,12 @@ impl Yubico {
133134

134135
// Recommendation is that clients only check that the input consists of 32-48 printable characters
135136
fn printable_characters(&self, otp: String) -> bool {
136-
if otp.len() < 32 || otp.len() > 48 { false } else { true }
137+
for c in otp.chars() {
138+
if !c.is_ascii() {
139+
return false;
140+
}
141+
}
142+
otp.len() > 32 && otp.len() < 48
137143
}
138144

139145
fn process(&self, sender: Sender<Response>, api_host: &str, request: Request) {
@@ -146,18 +152,21 @@ impl Yubico {
146152
let signature_response : &str = &*response_map.get("h").unwrap();
147153
if !self.is_same_signature(signature_response, response_map.clone()) {
148154
sender.send(Response::Signal(Err(YubicoError::SignatureMismatch))).unwrap();
155+
return;
149156
}
150157

151158
// Check if "otp" in the response is the same as the "otp" supplied in the request.
152159
let otp_response : &str = &*response_map.get("otp").unwrap();
153160
if !request.otp.contains(otp_response) {
154161
sender.send(Response::Signal(Err(YubicoError::OTPMismatch))).unwrap();
162+
return;
155163
}
156164

157165
// Check if "nonce" in the response is the same as the "nonce" supplied in the request.
158166
let nonce_response : &str = &*response_map.get("nonce").unwrap();
159167
if !request.nonce.contains(nonce_response) {
160168
sender.send(Response::Signal(Err(YubicoError::NonceMismatch))).unwrap();
169+
return;
161170
}
162171

163172
// Check the status of the operation
@@ -195,7 +204,6 @@ impl Yubico {
195204
query.pop(); // remove last &
196205

197206
let signature = self.build_signature(query.clone());
198-
199207
let decoded_signature = &decode(signature_response).unwrap()[..];
200208

201209
crypto::util::fixed_time_eq(signature.code(), decoded_signature)

0 commit comments

Comments
 (0)