-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[grid] Securing 0mq when user provides a certificate
Fixes #7856 The initial idea was to use `Curve` security and reuse the certificate(s) provided by the user when they want HTTPS in the Grid. However, the docs for 0mq and Curve with XPUB/XSUB and security are almost non-existent. Therefore, the approach is to create a small but hard to guess registration secret based on the provided certificate, given that the user provides did not provide a registration secret.
- Loading branch information
Showing
12 changed files
with
94 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
java/server/src/org/openqa/selenium/grid/security/SecretOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.grid.security; | ||
|
||
import org.openqa.selenium.grid.config.Config; | ||
import org.openqa.selenium.grid.config.ConfigException; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.Arrays; | ||
import java.util.logging.Logger; | ||
|
||
import static java.util.Base64.getEncoder; | ||
|
||
public class SecretOptions { | ||
|
||
private static final String SERVER_SECTION = "server"; | ||
|
||
private static final Logger LOG = Logger.getLogger(SecretOptions.class.getName()); | ||
private final Config config; | ||
|
||
public SecretOptions(Config config) { | ||
this.config = config; | ||
} | ||
|
||
public Secret getRegistrationSecret() { | ||
String secret = ""; | ||
if ((isSecure() || isSelfSigned()) && config.get(SERVER_SECTION, "registration-secret").isEmpty()) { | ||
try { | ||
secret = getEncoder().encodeToString(Arrays.copyOfRange(Files.readAllBytes(getCertificate().toPath()), 0, 32)); | ||
return new Secret(secret); | ||
} catch (IOException e) { | ||
throw new ConfigException("Cannot read the certificate file: " + e.getMessage()); | ||
} | ||
} | ||
return config.get(SERVER_SECTION, "registration-secret").map(Secret::new).orElse(new Secret(secret)); | ||
} | ||
|
||
private boolean isSecure() { | ||
return config.get(SERVER_SECTION, "https-private-key").isPresent() && config.get(SERVER_SECTION, "https-certificate").isPresent(); | ||
} | ||
|
||
private boolean isSelfSigned() { | ||
return config.getBool(SERVER_SECTION, "https-self-signed").orElse(false); | ||
} | ||
|
||
private File getCertificate() { | ||
String certificatePath = config.get(SERVER_SECTION, "https-certificate").orElse(null); | ||
if (certificatePath != null) { | ||
return new File(certificatePath); | ||
} | ||
throw new ConfigException("you must provide a certificate via --https-certificate when using --https"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters