Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault on parsing Date #74

Closed
ionut-arm opened this issue Dec 9, 2021 · 1 comment · Fixed by #84
Closed

Segmentation fault on parsing Date #74

ionut-arm opened this issue Dec 9, 2021 · 1 comment · Fixed by #84

Comments

@ionut-arm
Copy link
Member

ionut-arm commented Dec 9, 2021

When requesting StartDate or EndDate attributes on a key we get a segmentation fault. For example, running the following unit test:

#[test]
#[serial]
fn aes_key() -> Result<()> {
    let (pkcs11, slot) = init_pins();

    // set flags
    let mut flags = SessionFlags::new();
    let _ = flags.set_rw_session(true).set_serial_session(true);

    // open a session
    let session = pkcs11.open_session_no_callback(slot, flags)?;

    // log in the session
    session.login(UserType::User, Some(USER_PIN))?;

    // get mechanism
    let mechanism = Mechanism::AesKeyGen;

    // pub key template
    let key_template = vec![
        Attribute::Class(ObjectClass::SECRET_KEY),
        Attribute::Token(true),
        Attribute::Sensitive(true),
        Attribute::ValueLen(16.into()),
        Attribute::KeyType(KeyType::AES),
        Attribute::Label(b"testAES".to_vec()),
        Attribute::Private(true),
    ];

    // generate a key pair
    let key = session.generate_key(&mechanism, &key_template)?;

    let attributes_result =
        session.get_attributes(key, &[AttributeType::EndDate, AttributeType::StartDate]);

    match attributes_result {
        Ok(attributes) => println!("working with version: {:?}", attributes),
        Err(e) => println!("error getting attributes: {:?}", e),
    }
    Ok(())
}

results (for me) in a SIGSEGV.

@ionut-arm
Copy link
Member Author

When a Cryptoki object carries an attribute of this type, and the default value of the attribute is specified to be "empty," then Cryptoki libraries SHALL set the attribute's ulValueLen to 0.

Seems SoftHSM2 at least return an empty date, so we have to add a check for that, and return a "default" value.

Note that implementations of previous versions of Cryptoki may have used other methods to identify an "empty" attribute of type CK_DATE, and applications that needs to interoperate with these libraries therefore have to be flexible in what they accept as an empty value.

And this is the spec giving us the finger and telling us that there's no way to know what "empty" actually means for older implementations :]

ionut-arm added a commit to ionut-arm/rust-cryptoki that referenced this issue Feb 9, 2022
The Date attribute can be returned as empty (i.e., parameter length is 0),
however our parsing did not consider this option.
A test is also added to ensure that any regressions are caught.

Signed-off-by: Ionut Mihalcea <[email protected]>
ionut-arm added a commit to ionut-arm/rust-cryptoki that referenced this issue Feb 9, 2022
The Date attribute can be returned as empty (i.e., parameter length is 0),
however our parsing did not consider this option.
A test is also added to ensure that any regressions are caught.

Signed-off-by: Ionut Mihalcea <[email protected]>
ionut-arm added a commit to ionut-arm/rust-cryptoki that referenced this issue Feb 9, 2022
The Date attribute can be returned as empty (i.e., parameter length is 0),
however our parsing did not consider this option.
A test is also added to ensure that any regressions are caught.

Signed-off-by: Ionut Mihalcea <[email protected]>
ionut-arm added a commit to ionut-arm/rust-cryptoki that referenced this issue Feb 14, 2022
The Date attribute can be returned as empty (i.e., parameter length is 0),
however our parsing did not consider this option.
A test is also added to ensure that any regressions are caught.

Signed-off-by: Ionut Mihalcea <[email protected]>
ionut-arm added a commit that referenced this issue Mar 2, 2022
The Date attribute can be returned as empty (i.e., parameter length is 0),
however our parsing did not consider this option.
A test is also added to ensure that any regressions are caught.

Signed-off-by: Ionut Mihalcea <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant