Class NonceUtil
java.lang.Object
org.eclipse.milo.opcua.stack.core.util.NonceUtil
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe minimum required nonce length for validation byvalidateNonce(ByteString). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidBlock until theSecureRandominstance has been seeded.static voidblockUntilSecureRandomSeeded(long timeout, TimeUnit unit) Block for at mosttimeoutwaiting for theSecureRandominstance to be seeded.static voidDisable the use of aSecureRandomfor nonce generation.static voidEnable the use of aSecureRandomfor nonce generation.static ByteStringgenerateNonce(int length) static ByteStringgenerateNonce(SecurityPolicy securityPolicy) Generate a nonce for the givenSecurityPolicy.static booleanstatic booleanstatic CompletionStage<Void>Get aCompletionStagethat is completed when theSecureRandominstance has been seeded.static voidvalidateNonce(ByteString nonce) Validate thatnonceis at leastMINIMUM_NONCE_LENGTHand is non-zeroes.static voidvalidateNonce(ByteString nonce, int minimumLength) Validate thatnonceis at leastminimumLengthand is non-zeroes.static voidvalidateNonce(ByteString nonce, SecurityPolicy securityPolicy) Validate thatnoncemeets the minimum length requirement forsecurityPolicyand is non-zeroes.
-
Field Details
-
MINIMUM_NONCE_LENGTH
public static final int MINIMUM_NONCE_LENGTHThe minimum required nonce length for validation byvalidateNonce(ByteString).This is specified by OPC UA Part 4 to be least 32 bytes in the CreateSession and ActivateSession services.
- See Also:
-
-
Constructor Details
-
NonceUtil
public NonceUtil()
-
-
Method Details
-
blockUntilSecureRandomSeeded
Block until theSecureRandominstance has been seeded.- Throws:
ExecutionException- if seeding completed exceptionally.InterruptedException- if the current thread was interrupted.
-
blockUntilSecureRandomSeeded
public static void blockUntilSecureRandomSeeded(long timeout, TimeUnit unit) throws ExecutionException, InterruptedException, TimeoutException Block for at mosttimeoutwaiting for theSecureRandominstance to be seeded.- Parameters:
timeout- the maximum time to wait.unit- theTimeUnitof thetimeoutargument.- Throws:
ExecutionException- if seeding completed exceptionally.InterruptedException- if the current thread was interrupted.TimeoutException- if the wait timed out.
-
secureRandomSeeded
Get aCompletionStagethat is completed when theSecureRandominstance has been seeded.- Returns:
- a
CompletionStagethat is completed when theSecureRandominstance has been seeded.
-
enableSecureRandom
public static void enableSecureRandom()Enable the use of aSecureRandomfor nonce generation. This is the default. -
disableSecureRandom
public static void disableSecureRandom()Disable the use of aSecureRandomfor nonce generation. Not recommended. -
isSecureRandomEnabled
public static boolean isSecureRandomEnabled()- Returns:
trueis nonce generation uses aSecureRandominstance.
-
isSecureRandomSeeded
public static boolean isSecureRandomSeeded()- Returns:
trueif theSecureRandominstance is seeded and available.
-
generateNonce
- Parameters:
length- the length of the nonce to generate.- Returns:
- a nonce of the given length.
-
generateNonce
Generate a nonce for the givenSecurityPolicy.The length is determined by the policy: see
getNonceLength(SecurityPolicy).Important: this should only be used to generate a nonce exchanged when establishing a secure channel. The nonce used by sessions has different length requirements.
- Parameters:
securityPolicy- theSecurityPolicyto use when determining the nonce length.- Returns:
- a nonce of the appropriate length for the given security policy.
-
validateNonce
public static void validateNonce(ByteString nonce, SecurityPolicy securityPolicy) throws UaException Validate thatnoncemeets the minimum length requirement forsecurityPolicyand is non-zeroes.Important: this should only be used to validate the nonce exchanged when establishing a secure channel. The nonce used by sessions has different length requirements.
- Parameters:
nonce- the nonce to validate.securityPolicy- theSecurityPolicydictating the minimum nonce length.- Throws:
UaException- if nonce validation failed.
-
validateNonce
Validate thatnonceis at leastMINIMUM_NONCE_LENGTHand is non-zeroes.- Parameters:
nonce- the nonce to validate.- Throws:
UaException- if nonce validation failed.
-
validateNonce
Validate thatnonceis at leastminimumLengthand is non-zeroes.- Parameters:
nonce- the nonce to validate.minimumLength- the minimum required nonce length- Throws:
UaException- if nonce validation failed.
-