[][src]Struct yubihsm::client::Client

pub struct Client { /* fields omitted */ }

YubiHSM client: main API in this crate for accessing functions of the HSM hardware device.

Methods

impl Client[src]

pub fn open<C>(
    connector: C,
    credentials: Credentials,
    reconnect: bool
) -> Result<Self, ClientError> where
    C: Into<Connector>, 
[src]

Open a connection via a Connector to a YubiHSM, returning a yubihsm::Client. Valid Connector types are: HttpConnector, UsbConnector, and MockHsm.

pub fn create<C>(
    connector: C,
    credentials: Credentials
) -> Result<Self, ClientError> where
    C: Into<Connector>, 
[src]

Create a yubihsm::Client, but defer connecting until connect() is called.

pub fn connect(&mut self) -> Result<(), ClientError>[src]

Try to make a clone of this client Connect to the HSM (idempotently, i.e. returns success if we have an open connection already)

pub fn is_connected(&self) -> bool[src]

Are we currently connected to the HSM?

pub fn session_id(&self) -> Option<Id>[src]

Get the current session ID (if we have an open session).

pub fn session(&mut self) -> Result<&mut Session, ClientError>[src]

Get current Session (either opening a new one or returning an already open one).

pub fn ping(&mut self) -> Result<Duration, ClientError>[src]

Ping the HSM, ensuring we have a live connection and returning the end-to-end latency.

Blink the HSM's LEDs (to identify it) for the given number of seconds.

https://developers.yubico.com/YubiHSM2/Commands/Blink_Device.html

pub fn delete_object(
    &mut self,
    object_id: Id,
    object_type: Type
) -> Result<(), ClientError>
[src]

Delete an object of the given ID and type.

https://developers.yubico.com/YubiHSM2/Commands/Delete_Object.html

pub fn device_info(&mut self) -> Result<DeviceInfoResponse, ClientError>[src]

pub fn echo<M>(&mut self, msg: M) -> Result<Vec<u8>, ClientError> where
    M: Into<Vec<u8>>, 
[src]

pub fn export_wrapped(
    &mut self,
    wrap_key_id: Id,
    object_type: Type,
    object_id: Id
) -> Result<Message, ClientError>
[src]

Export an encrypted object from the HSM using the given key-wrapping key.

https://developers.yubico.com/YubiHSM2/Commands/Export_Wrapped.html

pub fn generate_asymmetric_key(
    &mut self,
    key_id: Id,
    label: Label,
    domains: Domain,
    capabilities: Capability,
    algorithm: Algorithm
) -> Result<Id, ClientError>
[src]

pub fn generate_hmac_key(
    &mut self,
    key_id: Id,
    label: Label,
    domains: Domain,
    capabilities: Capability,
    algorithm: Algorithm
) -> Result<Id, ClientError>
[src]

pub fn generate_wrap_key(
    &mut self,
    key_id: Id,
    label: Label,
    domains: Domain,
    capabilities: Capability,
    delegated_capabilities: Capability,
    algorithm: Algorithm
) -> Result<Id, ClientError>
[src]

Generate a new wrap key within the HSM.

Delegated capabilities are the set of Capability bits that an object is allowed to have when imported or exported using the wrap key.

https://developers.yubico.com/YubiHSM2/Commands/Generate_Wrap_Key.html

pub fn get_log_entries(&mut self) -> Result<LogEntries, ClientError>[src]

pub fn get_object_info(
    &mut self,
    object_id: Id,
    object_type: Type
) -> Result<Info, ClientError>
[src]

pub fn get_opaque(&mut self, object_id: Id) -> Result<Vec<u8>, ClientError>[src]

pub fn get_command_audit_option(
    &mut self,
    command: Code
) -> Result<AuditOption, ClientError>
[src]

Get the audit policy setting for a particular command.

https://developers.yubico.com/YubiHSM2/Commands/Get_Option.html

pub fn get_commands_audit_options(
    &mut self
) -> Result<Vec<AuditCommand>, ClientError>
[src]

Get the audit policy settings for all commands.

https://developers.yubico.com/YubiHSM2/Commands/Get_Option.html

pub fn get_force_audit_option(&mut self) -> Result<AuditOption, ClientError>[src]

Get the forced auditing global option: when enabled, the device will refuse operations if the [log store] becomes full.

https://developers.yubico.com/YubiHSM2/Commands/Get_Option.html [log store]: https://developers.yubico.com/YubiHSM2/Concepts/Logs.html

pub fn get_pseudo_random(
    &mut self,
    bytes: usize
) -> Result<Vec<u8>, ClientError>
[src]

Get some number of bytes of pseudo random data generated on the device.

https://developers.yubico.com/YubiHSM2/Commands/Get_Pseudo_Random.html

pub fn get_public_key(&mut self, key_id: Id) -> Result<PublicKey, ClientError>[src]

Get the public key for an asymmetric key stored on the device.

https://developers.yubico.com/YubiHSM2/Commands/Get_Public_Key.html

pub fn get_storage_info(
    &mut self
) -> Result<GetStorageInfoResponse, ClientError>
[src]

Get storage status (i.e. currently free storage) from the HSM device.

https://developers.yubico.com/YubiHSM2/Commands/Get_Storage_Info.html

pub fn import_wrapped<M>(
    &mut self,
    wrap_key_id: Id,
    wrap_message: M
) -> Result<ImportWrappedResponse, ClientError> where
    M: Into<Message>, 
[src]

Import an encrypted object from the HSM using the given key-wrapping key.

https://developers.yubico.com/YubiHSM2/Commands/Import_Wrapped.html

pub fn list_objects(
    &mut self,
    filters: &[Filter]
) -> Result<Vec<Entry>, ClientError>
[src]

List objects visible from the current session.

Optionally apply a set of provided filters which select objects based on their attributes.

https://developers.yubico.com/YubiHSM2/Commands/List_Objects.html

pub fn put_asymmetric_key<K>(
    &mut self,
    key_id: Id,
    label: Label,
    domains: Domain,
    capabilities: Capability,
    algorithm: Algorithm,
    key_bytes: K
) -> Result<Id, ClientError> where
    K: Into<Vec<u8>>, 
[src]

Put an existing asymmetric key into the HSM.

https://developers.yubico.com/YubiHSM2/Commands/Put_Asymmetric.html

pub fn put_authentication_key<K>(
    &mut self,
    key_id: Id,
    label: Label,
    domains: Domain,
    capabilities: Capability,
    delegated_capabilities: Capability,
    algorithm: Algorithm,
    authentication_key: K
) -> Result<Id, ClientError> where
    K: Into<Key>, 
[src]

Put an existing authentication::Key into the HSM.

https://developers.yubico.com/YubiHSM2/Commands/Put_Authentication_Key.html

pub fn put_hmac_key<K>(
    &mut self,
    key_id: Id,
    label: Label,
    domains: Domain,
    capabilities: Capability,
    algorithm: Algorithm,
    key_bytes: K
) -> Result<Id, ClientError> where
    K: Into<Vec<u8>>, 
[src]

pub fn put_opaque<B>(
    &mut self,
    object_id: Id,
    label: Label,
    domains: Domain,
    capabilities: Capability,
    algorithm: Algorithm,
    opaque_data: B
) -> Result<Id, ClientError> where
    B: Into<Vec<u8>>, 
[src]

Put an opaque object (X.509 certificate or other bytestring) into the HSM.

https://developers.yubico.com/YubiHSM2/Commands/Put_Opaque.html

pub fn put_otp_aead_key<K>(
    &mut self,
    key_id: Id,
    label: Label,
    domains: Domain,
    capabilities: Capability,
    algorithm: Algorithm,
    key_bytes: K
) -> Result<Id, ClientError> where
    K: Into<Vec<u8>>, 
[src]

pub fn put_wrap_key<K>(
    &mut self,
    key_id: Id,
    label: Label,
    domains: Domain,
    capabilities: Capability,
    delegated_capabilities: Capability,
    algorithm: Algorithm,
    key_bytes: K
) -> Result<Id, ClientError> where
    K: Into<Vec<u8>>, 
[src]

pub fn reset_device(&mut self) -> Result<(), ClientError>[src]

Reset the HSM to a factory default state and reboot, clearing all stored objects and restoring the default auth key.

WARNING: This wipes all keys and other data from the HSM! Make absolutely sure you want to use this!

https://developers.yubico.com/YubiHSM2/Commands/Reset_Device.html

pub fn set_command_audit_option(
    &mut self,
    command: Code,
    audit_option: AuditOption
) -> Result<(), ClientError>
[src]

Configure the audit policy settings for a particular command, e.g. auditing should be On, Off, or Fix (i.e. fixed permanently on).

https://developers.yubico.com/YubiHSM2/Commands/Set_Option.html

pub fn set_force_audit_option(
    &mut self,
    option: AuditOption
) -> Result<(), ClientError>
[src]

Put the forced auditing global option: when enabled, the device will refuse operations if the log store becomes full.

Options are On, Off, or Fix (i.e. fixed permanently on)

https://developers.yubico.com/YubiHSM2/Commands/Put_Option.html

pub fn set_log_index(&mut self, log_index: u16) -> Result<(), ClientError>[src]

Set the index of the last consumed index of the HSM audit log.

https://developers.yubico.com/YubiHSM2/Commands/Set_Log_Index.html

pub fn sign_attestation_certificate(
    &mut self,
    key_id: Id,
    attestation_key_id: Option<Id>
) -> Result<Certificate, ClientError>
[src]

Obtain an X.509 attestation certificate for a key within the HSM. This can be used to demonstrate that a given key was generated by and stored within a HSM in a non-exportable manner.

The key_id is the subject key for which an attestation certificate is created, and theattestation_key_id will be used to sign the attestation certificate.

If no attestation key is given, the device's default attestation key will be used, and can be verified against Yubico's certificate.

https://developers.yubico.com/YubiHSM2/Commands/Sign_Attestation_Certificate.html

pub fn sign_ecdsa<T>(
    &mut self,
    key_id: Id,
    digest: T
) -> Result<Signature, ClientError> where
    T: Into<Vec<u8>>, 
[src]

Compute an ECDSA signature of the given digest (i.e. a precomputed SHA-2 digest)

https://developers.yubico.com/YubiHSM2/Commands/Sign_Ecdsa.html

secp256k1 notes

The YubiHSM 2 does not produce signatures in "low S" form, which is expected for most cryptocurrency applications (the typical use case for secp256k1).

If your application demands this (e.g. Bitcoin), you'll need to normalize the signatures. One option for this is the secp256k1 crate's [Signature::normalize_s] function.

Normalization functionality is built into the yubihsm::signatory API found in this crate (when the secp256k1 feature is enabled).

pub fn sign_ed25519<T>(
    &mut self,
    key_id: Id,
    data: T
) -> Result<Signature, ClientError> where
    T: Into<Vec<u8>>, 
[src]

Compute an Ed25519 signature with the given key ID.

https://developers.yubico.com/YubiHSM2/Commands/Sign_Eddsa.html

pub fn sign_hmac<M>(&mut self, key_id: Id, msg: M) -> Result<Tag, ClientError> where
    M: Into<Vec<u8>>, 
[src]

Compute an HMAC tag of the given data with the given key ID.

https://developers.yubico.com/YubiHSM2/Commands/Sign_Hmac.html

pub fn sign_rsa_pkcs1v15_sha256(
    &mut self,
    key_id: Id,
    data: &[u8]
) -> Result<Signature, ClientError>
[src]

Compute an RSASSA-PKCS#1v1.5 signature of the SHA-256 hash of the given data.

WARNING: This method has not been tested and is not confirmed to actually work! Use at your own risk!

https://developers.yubico.com/YubiHSM2/Commands/Sign_Pkcs1.html

pub fn sign_rsa_pss_sha256(
    &mut self,
    key_id: Id,
    data: &[u8]
) -> Result<Signature, ClientError>
[src]

Compute an RSASSA-PSS signature of the SHA-256 hash of the given data with the given key ID.

WARNING: This method has not been tested and is not confirmed to actually work! Use at your own risk!

https://developers.yubico.com/YubiHSM2/Commands/Sign_Pss.html

pub fn unwrap_data<M>(
    &mut self,
    wrap_key_id: Id,
    wrap_message: M
) -> Result<Vec<u8>, ClientError> where
    M: Into<Message>, 
[src]

Decrypt data which was encrypted (using AES-CCM) under a wrap key.

https://developers.yubico.com/YubiHSM2/Commands/Unwrap_Data.html

pub fn verify_hmac<M, T>(
    &mut self,
    key_id: Id,
    msg: M,
    tag: T
) -> Result<(), ClientError> where
    M: Into<Vec<u8>>,
    T: Into<Tag>, 
[src]

Verify an HMAC tag of the given data with the given key ID.

https://developers.yubico.com/YubiHSM2/Commands/Verify_Hmac.html

pub fn wrap_data(
    &mut self,
    wrap_key_id: Id,
    plaintext: Vec<u8>
) -> Result<Message, ClientError>
[src]

Encrypt data (with AES-CCM) using the given wrap key.

https://developers.yubico.com/YubiHSM2/Commands/Wrap_Data.html

Auto Trait Implementations

impl Send for Client

impl Sync for Client

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Same for T

type Output = T

Should always be Self