blob: c050ddce2c61c5c4cf19e4e1a69db745a75065cd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.athenz.identity;
import com.yahoo.athenz.auth.util.Crypto;
import com.yahoo.container.jdisc.athenz.AthenzIdentityProvider;
import com.yahoo.vespa.athenz.api.AthenzDomain;
import com.yahoo.vespa.athenz.api.AthenzIdentityCertificate;
import com.yahoo.vespa.athenz.api.AthenzService;
import com.yahoo.vespa.athenz.tls.AthenzSslContextBuilder;
import javax.net.ssl.SSLContext;
import java.io.File;
import java.nio.file.Paths;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
/**
* @author mortent
*/
public class SiaIdentityProvider implements AthenzIdentityProvider {
private final AthenzDomain domain;
private final AthenzService service;
private final String path;
public SiaIdentityProvider(SiaProviderConfig siaProviderConfig) {
this.domain = new AthenzDomain(siaProviderConfig.athenzDomain());
this.service = new AthenzService(domain, siaProviderConfig.athenzService());
this.path = siaProviderConfig.keyPathPrefix();
}
@Override
public String getDomain() {
return domain.getName();
}
@Override
public String getService() {
return service.getName();
}
@Override
public SSLContext getIdentitySslContext() {
X509Certificate certificate = Crypto.loadX509Certificate(Paths.get(path, "certs", String.format("%s.%s.cert.pem", getDomain(),getService())).toFile());
PrivateKey privateKey = Crypto.loadPrivateKey(Paths.get(path, "keys", String.format("%s.%s.key.pem", getDomain(),getService())).toFile());
return new AthenzSslContextBuilder()
.withIdentityCertificate(new AthenzIdentityCertificate(certificate, privateKey))
.build();
}
}
|