Skip to content

Question: How to correctly handle a Session #235

@EliseChouleur

Description

@EliseChouleur

Hi !
It's more a best practice question than an issue.
I have historical code which I'm updating from rust-pkcs11 to rust-cryptoki.
The usage of cryptoki is to extract certificates and sign some data but also implements the rustls sign capacity :

impl Signer for PKCS11RSASigner {
    fn sign(&self, message: &[u8]) -> Result<Vec<u8>, TLSError> {
        let mut h = Sha256::default();
        let to_sign2 = h.digest(message).to_bytes();

        let mut final_to_sign = vec![0x30, 0x31, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20];
        final_to_sign.extend_from_slice(to_sign2.as_slice());
        
        sign_with_key(final_to_sign.clone(), AUTHENTICATION_KEY_ID).map_err(|err| {
            error!("rustls sign_with_key error : {:?}", err);
            TLSError::NoCertificatesPresented
        })
    }
}

What is be the best practice to handle a session here ?
Create a new one just inside this implementation while there is already one active in the function calling rustls ?
Thanks a lot for your feedback 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions