Skip to content

Commit

Permalink
Merge pull request #128 from kushaldas/disable_otp
Browse files Browse the repository at this point in the history
Getting ready for 0.12.0 release
  • Loading branch information
kushaldas authored Jan 12, 2023
2 parents 30b6571 + 3e707b0 commit fa7eda0
Show file tree
Hide file tree
Showing 13 changed files with 251 additions and 685 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
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."
Expand All @@ -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]
Expand Down
827 changes: 159 additions & 668 deletions LICENSE

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ sudo apt install -y python3-dev libnettle8 nettle-dev libhogweed6 python3-pip py
```
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -U pip setuptools
python3 -m pip install -r requirements-dev.txt
python -m pip install -U pip setuptools
python -m pip install -r requirements-dev.txt
python setup.py develop
```

Expand All @@ -48,5 +48,5 @@ Please read the [Introduction](https://johnnycanencrypt.readthedocs.io/en/latest
Please go through the [full API documentation](https://johnnycanencrypt.readthedocs.io/en/latest/api.html) for detailed
descriptions.

## LICENSE: GPL-3.0-or-later
## LICENSE: LGPL-3.0-or-later

8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## [unreleased]

## [0.12.0] - 2023-01-12

### Added

- Adds `enable_otp_usb` in rjce.
- Adds `disable_otp_usb` in rjce.
- Changed license to LGPL-3.0-or-later

## [0.11.1] - 2022-12-05

### Added
Expand Down
4 changes: 2 additions & 2 deletions docs/build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Then you can just use `pip` module to install in your virtualenvironment.

::

python3 -m pip install johnnycanencrypt
python -m pip install johnnycanencrypt


Building Johnny Can Encrypt for development
Expand Down Expand Up @@ -67,7 +67,7 @@ All of these tests are right now kept as a Python script, and requires Yubikey s

::

python3 smartcardtests/smartcards.py
python smartcardtests/smartcards.py

When asked, please make sure that only the test smartcard is conneccted to the system, and then type "Yes", without quotes.

6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
# -- Project information -----------------------------------------------------

project = 'Johnny Can Encrypt'
copyright = '2020-2022, Kushal Das'
copyright = '2020-present, Kushal Das'
author = 'Kushal Das'

# The short X.Y version
version = '0.11.1'
version = '0.12.0'
# The full version, including alpha/beta/rc tags
release = '0.11.1'
release = '0.12.0'


# -- General configuration ---------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions docs/rustimplementation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ In most cases you don't have to use these, but if you have a reason, feel free t

This function takes a public key and optional comment and then provides a string representing the authentication subkey to be used inside of SSH.


.. function:: enable_otp_usb() -> bool

This function enables OTP application in the Yubikey.

.. function:: disable_otp_usb() -> bool

This function disables OTP application in the Yubikey.



.. class:: Johnny(filepath)

It creates an object of type `Johnny`, you can provide path to the either public key, or the private key based on the operation
Expand Down
2 changes: 1 addition & 1 deletion johnnycanencrypt/__init__.py
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
Expand Down
2 changes: 1 addition & 1 deletion johnnycanencrypt/exceptions.py
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
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ requires = ["setuptools", "wheel", "setuptools-rust"]

[project]
name = "johnnycanencrypt"
version = "0.11.1"
version = "0.12.0"
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)",
"Programming Language :: Rust",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name="johnnycanencrypt",
version="0.11.1",
version="0.12.0",
rust_extensions=[
RustExtension("johnnycanencrypt.johnnycanencrypt", binding=Binding.PyO3)
],
Expand Down
20 changes: 19 additions & 1 deletion src/lib.rs
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;
Expand Down Expand Up @@ -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<()> {
Expand Down Expand Up @@ -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>()?;
Expand Down
40 changes: 39 additions & 1 deletion src/scard.rs
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;
Expand All @@ -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> {
Expand Down

0 comments on commit fa7eda0

Please sign in to comment.