You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by "Colm O hEigeartaigh (Jira)" <ji...@apache.org> on 2023/10/04 05:14:00 UTC

[jira] [Commented] (SANTUARIO-606) Avoid creating the SecureRandom in XMLSecurityConstants during class initialization

    [ https://issues.apache.org/jira/browse/SANTUARIO-606?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17771701#comment-17771701 ] 

Colm O hEigeartaigh commented on SANTUARIO-606:
-----------------------------------------------

It's fine with me, if it can be done in a thread-safe way. Can you prepare a PR?

> Avoid creating the SecureRandom in XMLSecurityConstants during class initialization
> -----------------------------------------------------------------------------------
>
>                 Key: SANTUARIO-606
>                 URL: https://issues.apache.org/jira/browse/SANTUARIO-606
>             Project: Santuario
>          Issue Type: Task
>          Components: Java
>            Reporter: Peter Palaga
>            Assignee: Colm O hEigeartaigh
>            Priority: Major
>
> {{org.apache.xml.security.stax.ext.XMLSecurityConstants.SECURE_RANDOM}} currently gets initialized in the class initializer:
> {code}
> static {
>         try {
>             String PrngAlgorithm = System.getProperty(RANDOM_ALGORITHM_KEY);
>             SECURE_RANDOM = PrngAlgorithm != null ? SecureRandom.getInstance(PrngAlgorithm) : new SecureRandom();
>         } catch (NoSuchAlgorithmException e) {
>             throw new RuntimeException(e);
>         }
> ...
> {code}
> This makes it harder to compile the library to native image using GraalVM. Especially with Quarkus, GraalVM is configured to run class initializers at build time to be able to store the heap into the native image binary for faster boot at runtime. At the same time, certain types, such as SecureRandom are not allowed to get initialized at build time, because then, every execution of the binary might produce the same random numbers sequence. Thus special GraalVM settings are needed for XMLSecurityConstants to be able to compile it to native image. 
> I guess it would not harm at all to initialize the SECURE_RANDOM lazily when {{XMLSecurityConstants.generateBytes(int)}} is called for the first time?



--
This message was sent by Atlassian Jira
(v8.20.10#820010)