-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from kushaldas/disable_otp
Getting ready for 0.12.0 release
- Loading branch information
Showing
13 changed files
with
251 additions
and
685 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "johnnycanencrypt" | ||
version = "0.11.1" | ||
version = "0.12.0" | ||
authors = ["Kushal Das <[email protected]>"] | ||
edition = "2018" | ||
description = "Python module for OpenPGP." | ||
|
@@ -27,7 +27,7 @@ anyhow = "1.0.62" | |
chrono = "0.4.22" | ||
tempfile = "3.0.0" | ||
#talktosc = { git = "https://github.com/kushaldas/talktosc", branch="main"} | ||
talktosc = "0.1.3" | ||
talktosc = "0.2" | ||
sshkeys = "0.3.2" | ||
|
||
[dependencies.pyo3] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# SPDX-FileCopyrightText: © 2020 Kushal Das <[email protected]> | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
||
import os | ||
import shutil | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# SPDX-FileCopyrightText: © 2020 Kushal Das <[email protected]> | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
||
class KeyNotFoundError(Exception): | ||
pass | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// SPDX-FileCopyrightText: © 2020 Kushal Das <[email protected]> | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
||
use openpgp::packet::Signature; | ||
use openpgp::KeyHandle; | ||
|
@@ -3098,6 +3098,22 @@ pub fn set_keyslot_touch_policy( | |
} | ||
} | ||
|
||
#[pyfunction] | ||
pub fn enable_otp_usb() -> Result<bool> { | ||
match scard::change_otp(true) { | ||
Ok(value) => Ok(value), | ||
Err(value) => Err(CardError::new_err(format!("Error {}", value)).into()), | ||
} | ||
} | ||
|
||
#[pyfunction] | ||
pub fn disable_otp_usb() -> Result<bool> { | ||
match scard::change_otp(false) { | ||
Ok(value) => Ok(value), | ||
Err(value) => Err(CardError::new_err(format!("Error {}", value)).into()), | ||
} | ||
} | ||
|
||
/// A Python module implemented in Rust. | ||
#[pymodule] | ||
fn johnnycanencrypt(_py: Python, m: &PyModule) -> PyResult<()> { | ||
|
@@ -3137,6 +3153,8 @@ fn johnnycanencrypt(_py: Python, m: &PyModule) -> PyResult<()> { | |
m.add_wrapped(wrap_pyfunction!(get_card_version))?; | ||
m.add_wrapped(wrap_pyfunction!(get_keyslot_touch_policy))?; | ||
m.add_wrapped(wrap_pyfunction!(set_keyslot_touch_policy))?; | ||
m.add_wrapped(wrap_pyfunction!(enable_otp_usb))?; | ||
m.add_wrapped(wrap_pyfunction!(disable_otp_usb))?; | ||
m.add("CryptoError", _py.get_type::<CryptoError>())?; | ||
m.add("SameKeyError", _py.get_type::<SameKeyError>())?; | ||
m.add_class::<Johnny>()?; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// SPDX-FileCopyrightText: © 2020 Kushal Das <[email protected]> | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
||
use crate::openpgp::packet::key; | ||
use crate::openpgp::types::SymmetricAlgorithm; | ||
|
@@ -9,6 +9,44 @@ use openpgp::packet::prelude::*; | |
use sequoia_openpgp as openpgp; | ||
use talktosc::*; | ||
|
||
#[allow(unused)] | ||
pub fn change_otp(enable: bool) -> Result<bool, errors::TalktoSCError> { | ||
let card = talktosc::create_connection(); | ||
let card = match card { | ||
Ok(card) => card, | ||
Err(value) => return Err(value), | ||
}; | ||
let select_mgmt = apdus::create_apdu_management_selection(); | ||
let enable_apdu = apdus::create_usb_otp_enable(); | ||
let disable_apdu = apdus::create_usb_otp_disable(); | ||
let resp = talktosc::send_and_parse(&card, select_mgmt); | ||
let resp = match resp { | ||
Ok(_) => resp.unwrap(), | ||
Err(value) => { | ||
talktosc::disconnect(card); | ||
return Err(value); | ||
} | ||
}; | ||
|
||
let send_apdu = if enable { enable_apdu } else { disable_apdu }; | ||
let resp = talktosc::send_and_parse(&card, send_apdu); | ||
let resp = match resp { | ||
Ok(_) => resp.unwrap(), | ||
Err(value) => { | ||
talktosc::disconnect(card); | ||
return Err(value); | ||
} | ||
}; | ||
|
||
// Verify if the otp enable/disable worked or not | ||
if !resp.is_okay() { | ||
talktosc::disconnect(card); | ||
return Err(errors::TalktoSCError::OtpError); | ||
} | ||
talktosc::disconnect(card); | ||
Ok(true) | ||
} | ||
|
||
// To change the admin pin | ||
#[allow(unused)] | ||
pub fn chagne_admin_pin(pw3change: apdus::APDU) -> Result<bool, errors::TalktoSCError> { | ||
|