@@ -102,7 +102,6 @@ public class SSLModuleBuiltins extends PythonBuiltins {
102
102
// Taken from CPython
103
103
static final String DEFAULT_CIPHER_STRING = "DEFAULT:!aNULL:!eNULL:!MD5:!3DES:!DES:!RC4:!IDEA:!SEED:!aDSS:!SRP:!PSK" ;
104
104
105
- private static boolean defaultsInitializedAtRuntime ;
106
105
private static List <SSLProtocol > supportedProtocols ;
107
106
private static SSLProtocol minimumVersion ;
108
107
private static SSLProtocol maximumVersion ;
@@ -147,32 +146,28 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
147
146
}
148
147
149
148
private static synchronized void loadDefaults () {
150
- if (! defaultsInitializedAtRuntime ) {
149
+ if (ImageInfo . inImageBuildtimeCode () ) {
151
150
// The values are dependent on system properties, don't bake them into the image
152
- if (ImageInfo .inImageBuildtimeCode ()) {
153
- supportedProtocols = new ArrayList <>();
154
- } else {
155
- try {
156
- SSLContext context = SSLContext .getInstance ("TLS" );
157
- context .init (null , null , null );
158
- List <SSLProtocol > protocols = new ArrayList <>(SSLProtocol .values ().length );
159
- for (SSLProtocol protocol : SSLProtocol .values ()) {
160
- if (tryProtocolAvailability (context , protocol )) {
161
- protocols .add (protocol );
162
- }
163
- }
164
- supportedProtocols = Collections .unmodifiableList (protocols );
165
- if (!supportedProtocols .isEmpty ()) {
166
- minimumVersion = supportedProtocols .get (0 );
167
- maximumVersion = supportedProtocols .get (supportedProtocols .size () - 1 );
168
- }
169
- } catch (NoSuchAlgorithmException | KeyManagementException | PException e ) {
170
- // This module is not essential for the interpreter to function, so don't fail
171
- // at startup, let it fail, when it gets used
172
- supportedProtocols = new ArrayList <>();
151
+ throw new AssertionError ("SSL module initialized at build time" );
152
+ }
153
+ try {
154
+ SSLContext context = SSLContext .getInstance ("TLS" );
155
+ context .init (null , null , null );
156
+ List <SSLProtocol > protocols = new ArrayList <>(SSLProtocol .values ().length );
157
+ for (SSLProtocol protocol : SSLProtocol .values ()) {
158
+ if (tryProtocolAvailability (context , protocol )) {
159
+ protocols .add (protocol );
173
160
}
174
- defaultsInitializedAtRuntime = true ;
175
161
}
162
+ supportedProtocols = Collections .unmodifiableList (protocols );
163
+ if (!supportedProtocols .isEmpty ()) {
164
+ minimumVersion = supportedProtocols .get (0 );
165
+ maximumVersion = supportedProtocols .get (supportedProtocols .size () - 1 );
166
+ }
167
+ } catch (NoSuchAlgorithmException | KeyManagementException | PException e ) {
168
+ // This module is not essential for the interpreter to function, so don't fail
169
+ // at startup, let it fail, when it gets used
170
+ supportedProtocols = new ArrayList <>();
176
171
}
177
172
}
178
173
0 commit comments