pub enum SecurityPolicy {
Unknown,
None,
Aes128Sha256RsaOaep,
Basic256Sha256,
Aes256Sha256RsaPss,
Basic128Rsa15,
Basic256,
}Expand description
SecurityPolicy implies what encryption and signing algorithms and their relevant key strengths are used during an encrypted session.
Variants§
Unknown
Security policy is unknown, this is generally an error.
None
No security.
Aes128Sha256RsaOaep
AES128/SHA256 RSA-OAEP.
Basic256Sha256
Basic256/SHA256
Aes256Sha256RsaPss
AES256/SHA256 RSA-PSS
Basic128Rsa15
Basic128. Note that this security policy is deprecated.
Basic256
Basic256.
Implementations§
Source§impl SecurityPolicy
impl SecurityPolicy
Sourcepub fn to_uri(&self) -> &'static str
pub fn to_uri(&self) -> &'static str
Get the security policy URI from this policy.
This will panic if the security policy is Unknown.
Sourcepub fn is_supported(&self) -> bool
pub fn is_supported(&self) -> bool
Returns true if the security policy is supported. It might be recognized but be unsupported by the implementation
Sourcepub fn is_deprecated(&self) -> bool
pub fn is_deprecated(&self) -> bool
Returns true if the security policy has been deprecated by the OPC UA specification
Sourcepub fn to_str(&self) -> &'static str
pub fn to_str(&self) -> &'static str
Get a string representation of this policy.
This will panic if the security policy is Unknown.
Sourcepub fn asymmetric_encryption_algorithm(&self) -> Option<&'static str>
pub fn asymmetric_encryption_algorithm(&self) -> Option<&'static str>
Get the asymmetric encryption algorithm for this security policy.
This will panic if the security policy is Unknown or None.
Sourcepub fn asymmetric_signature_algorithm(&self) -> &'static str
pub fn asymmetric_signature_algorithm(&self) -> &'static str
Get the asymmetric signature algorithm for this security policy.
This will panic if the security policy is Unknown or None.
Sourcepub fn plain_block_size(&self) -> usize
pub fn plain_block_size(&self) -> usize
Plaintext block size in bytes.
This will panic if the security policy is Unknown or None.
Sourcepub fn symmetric_signature_size(&self) -> usize
pub fn symmetric_signature_size(&self) -> usize
Signature size in bytes.
This will panic if the security policy is Unknown.
Sourcepub fn is_valid_keylength(&self, keylength: usize) -> bool
pub fn is_valid_keylength(&self, keylength: usize) -> bool
Tests if the supplied key length is valid for this policy
Sourcepub fn random_nonce(&self) -> ByteString
pub fn random_nonce(&self) -> ByteString
Creates a random nonce in a bytestring with a length appropriate for the policy
Sourcepub fn secure_channel_nonce_length(&self) -> usize
pub fn secure_channel_nonce_length(&self) -> usize
Length of the secure channel nonce for this security policy.
Sourcepub fn from_uri(uri: &str) -> SecurityPolicy
pub fn from_uri(uri: &str) -> SecurityPolicy
Get the security policy from the given URI. Returns Unknown
if the URI does not match any known policy.
Sourcepub fn legacy_sequence_numbers(&self) -> bool
pub fn legacy_sequence_numbers(&self) -> bool
Returns whether the security policy uses legacy sequence numbers.
Sourcepub fn make_secure_channel_keys(
&self,
secret: &[u8],
seed: &[u8],
) -> AesDerivedKeys
pub fn make_secure_channel_keys( &self, secret: &[u8], seed: &[u8], ) -> AesDerivedKeys
Part 6 6.7.5 Deriving keys Once the SecureChannel is established the Messages are signed and encrypted with keys derived from the Nonces exchanged in the OpenSecureChannel call. These keys are derived by passing the Nonces to a pseudo-random function which produces a sequence of bytes from a set of inputs. A pseudo-random function is represented by the following function declaration:
Byte[] PRF( Byte[] secret, Byte[] seed, i32 length, i32 offset)Where length is the number of bytes to return and offset is a number of bytes from the beginning of the sequence.
The lengths of the keys that need to be generated depend on the SecurityPolicy used for the channel. The following information is specified by the SecurityPolicy:
a) SigningKeyLength (from the DerivedSignatureKeyLength); b) EncryptingKeyLength (implied by the SymmetricEncryptionAlgorithm); c) EncryptingBlockSize (implied by the SymmetricEncryptionAlgorithm).
The parameters passed to the pseudo random function are specified in Table 33.
Table 33 – Cryptography key generation parameters
Key | Secret | Seed | Length | Offset ClientSigningKey | ServerNonce | ClientNonce | SigningKeyLength | 0 ClientEncryptingKey | ServerNonce | ClientNonce | EncryptingKeyLength | SigningKeyLength ClientInitializationVector | ServerNonce | ClientNonce | EncryptingBlockSize | SigningKeyLength + EncryptingKeyLength ServerSigningKey | ClientNonce | ServerNonce | SigningKeyLength | 0 ServerEncryptingKey | ClientNonce | ServerNonce | EncryptingKeyLength | SigningKeyLength ServerInitializationVector | ClientNonce | ServerNonce | EncryptingBlockSize | SigningKeyLength + EncryptingKeyLength
The Client keys are used to secure Messages sent by the Client. The Server keys are used to secure Messages sent by the Server.
Sourcepub fn asymmetric_sign(
&self,
signing_key: &PKey<RsaPrivateKey>,
data: &[u8],
signature: &mut [u8],
) -> Result<usize, Error>
pub fn asymmetric_sign( &self, signing_key: &PKey<RsaPrivateKey>, data: &[u8], signature: &mut [u8], ) -> Result<usize, Error>
Produce a signature of the data using an asymmetric key. Stores the signature in the supplied
signature buffer. Returns the size of the signature within that buffer.
Sourcepub fn asymmetric_verify_signature(
&self,
verification_key: &PKey<RsaPublicKey>,
data: &[u8],
signature: &[u8],
) -> Result<(), Error>
pub fn asymmetric_verify_signature( &self, verification_key: &PKey<RsaPublicKey>, data: &[u8], signature: &[u8], ) -> Result<(), Error>
Verifies a signature of the data using an asymmetric key. In a debugging scenario, the signing key can also be supplied so that the supplied signature can be compared to a freshly generated signature.
Sourcepub fn symmetric_padding_info(&self) -> PaddingInfo
pub fn symmetric_padding_info(&self) -> PaddingInfo
Get information about message padding for symmetric encryption using this policy.
Sourcepub fn asymmetric_padding_info(
&self,
remote_key: &PKey<RsaPublicKey>,
) -> PaddingInfo
pub fn asymmetric_padding_info( &self, remote_key: &PKey<RsaPublicKey>, ) -> PaddingInfo
Get information about message padding for asymmetric encryption using this policy, requires the public key of the receiver.
Sourcepub fn calculate_cipher_text_size(
&self,
plain_text_size: usize,
key: &PKey<RsaPublicKey>,
) -> usize
pub fn calculate_cipher_text_size( &self, plain_text_size: usize, key: &PKey<RsaPublicKey>, ) -> usize
Calculate the size of the cipher text for asymmetric encryption.
Sourcepub fn asymmetric_encrypt(
&self,
encryption_key: &PKey<RsaPublicKey>,
src: &[u8],
dst: &mut [u8],
) -> Result<usize, Error>
pub fn asymmetric_encrypt( &self, encryption_key: &PKey<RsaPublicKey>, src: &[u8], dst: &mut [u8], ) -> Result<usize, Error>
Encrypts a message using the supplied encryption key, returns the encrypted size. Destination buffer must be large enough to hold encrypted bytes including any padding.
Sourcepub fn asymmetric_decrypt(
&self,
decryption_key: &PKey<RsaPrivateKey>,
src: &[u8],
dst: &mut [u8],
) -> Result<usize, Error>
pub fn asymmetric_decrypt( &self, decryption_key: &PKey<RsaPrivateKey>, src: &[u8], dst: &mut [u8], ) -> Result<usize, Error>
Decrypts a message whose thumbprint matches the x509 cert and private key pair.
Returns the number of decrypted bytes
Sourcepub fn symmetric_sign(
&self,
keys: &AesDerivedKeys,
data: &[u8],
signature: &mut [u8],
) -> Result<(), Error>
pub fn symmetric_sign( &self, keys: &AesDerivedKeys, data: &[u8], signature: &mut [u8], ) -> Result<(), Error>
Produce a signature of some data using the supplied symmetric key. Signing algorithm is determined
by the security policy. Signature is stored in the supplied signature argument.
Sourcepub fn symmetric_verify_signature(
&self,
keys: &AesDerivedKeys,
data: &[u8],
signature: &[u8],
) -> Result<(), Error>
pub fn symmetric_verify_signature( &self, keys: &AesDerivedKeys, data: &[u8], signature: &[u8], ) -> Result<(), Error>
Verify the signature of a data block using the supplied symmetric key.
Sourcepub fn symmetric_encrypt(
&self,
keys: &AesDerivedKeys,
src: &[u8],
dst: &mut [u8],
) -> Result<usize, Error>
pub fn symmetric_encrypt( &self, keys: &AesDerivedKeys, src: &[u8], dst: &mut [u8], ) -> Result<usize, Error>
Encrypt the supplied data using the supplied key storing the result in the destination.
Sourcepub fn symmetric_decrypt(
&self,
keys: &AesDerivedKeys,
src: &[u8],
dst: &mut [u8],
) -> Result<usize, Error>
pub fn symmetric_decrypt( &self, keys: &AesDerivedKeys, src: &[u8], dst: &mut [u8], ) -> Result<usize, Error>
Decrypts the supplied data using the supplied key storing the result in the destination.
Sourcepub fn encrypting_key_length(&self) -> usize
pub fn encrypting_key_length(&self) -> usize
Get the key length used for symmetric encryption.
Trait Implementations§
Source§impl Clone for SecurityPolicy
impl Clone for SecurityPolicy
Source§fn clone(&self) -> SecurityPolicy
fn clone(&self) -> SecurityPolicy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more