diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2019-08-19 11:47:35 +0200 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2019-08-19 11:47:35 +0200 |
commit | 2af85a042b5d7ca94fdc8a0b8a04c258d6b64df2 (patch) | |
tree | e697607d1dd6cdd4de57a8fd1b9de345317a2619 /tenant-auth | |
parent | 0c4ce4cb5bb3573b7b6c21573224b0edd064b177 (diff) |
Rename EndpointAuthenticator -> Authenticator, and doc fixes
Diffstat (limited to 'tenant-auth')
-rw-r--r-- | tenant-auth/src/main/java/ai/vespa/hosted/auth/EndpointAuthenticator.java | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/tenant-auth/src/main/java/ai/vespa/hosted/auth/EndpointAuthenticator.java b/tenant-auth/src/main/java/ai/vespa/hosted/auth/EndpointAuthenticator.java deleted file mode 100644 index abb4197bda1..00000000000 --- a/tenant-auth/src/main/java/ai/vespa/hosted/auth/EndpointAuthenticator.java +++ /dev/null @@ -1,68 +0,0 @@ -package ai.vespa.hosted.auth; - -import com.yahoo.config.provision.SystemName; -import com.yahoo.security.KeyUtils; -import com.yahoo.security.SslContextBuilder; -import com.yahoo.security.X509CertificateUtils; - -import javax.net.ssl.SSLContext; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.net.http.HttpRequest; -import java.nio.file.Files; -import java.nio.file.Path; -import java.security.NoSuchAlgorithmException; -import java.security.PrivateKey; -import java.security.cert.X509Certificate; -import java.time.Instant; -import java.util.Optional; - -import static ai.vespa.hosted.api.Properties.getNonBlankProperty; - -/** - * Authenticates against the hosted Vespa API using private key signatures, and against Vespa applications using mutual TLS. - * - * @author jonmv - */ -public class EndpointAuthenticator implements ai.vespa.hosted.api.EndpointAuthenticator { - - /** Don't touch. */ - public EndpointAuthenticator(@SuppressWarnings("unused") SystemName __) { } - - /** - * If {@code System.getProperty("vespa.test.credentials.root")} is set, key and certificate files - * "key" and "cert" in that directory are used; otherwise, the system default SSLContext is returned. - */ - @Override - public SSLContext sslContext() { - try { - Optional<String> credentialsRootProperty = getNonBlankProperty("vespa.test.credentials.root"); - if (credentialsRootProperty.isEmpty()) - return SSLContext.getDefault(); - - Path credentialsRoot = Path.of(credentialsRootProperty.get()); - Path certificateFile = credentialsRoot.resolve("cert"); - Path privateKeyFile = credentialsRoot.resolve("key"); - - X509Certificate certificate = X509CertificateUtils.fromPem(new String(Files.readAllBytes(certificateFile))); - if ( Instant.now().isBefore(certificate.getNotBefore().toInstant()) - || Instant.now().isAfter(certificate.getNotAfter().toInstant())) - throw new IllegalStateException("Certificate at '" + certificateFile + "' is valid between " + - certificate.getNotBefore() + " and " + certificate.getNotAfter() + " — not now."); - - PrivateKey privateKey = KeyUtils.fromPemEncodedPrivateKey(new String(Files.readAllBytes(privateKeyFile))); - return new SslContextBuilder().withKeyStore(privateKey, certificate).build(); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - catch (NoSuchAlgorithmException e) { - throw new IllegalStateException(e); - } - } - - @Override - public HttpRequest.Builder authenticated(HttpRequest.Builder request) { - return request; - } - -} |