SslProtocolProvider.java
6.35 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.keystore.KeyStoreService
* com.day.cq.replication.AgentConfig
* com.day.cq.replication.ReplicationException
* com.day.cq.replication.ReplicationLog
* com.scene7.is.util.callbacks.Func1
* com.scene7.is.util.callbacks.Option
* org.apache.commons.httpclient.protocol.Protocol
* org.apache.commons.httpclient.protocol.ProtocolSocketFactory
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
* org.jetbrains.annotations.NotNull
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.dam.aod.replication.transport_config;
import com.adobe.cq.dam.aod.replication.Util;
import com.adobe.cq.dam.aod.replication.transport_config.AuthSSLProtocolSocketFactory;
import com.adobe.cq.dam.aod.replication.transport_config.EasySSLProtocolSocketFactory;
import com.adobe.cq.dam.aod.replication.transport_config.ResourceResolverProvider;
import com.adobe.cq.dam.aod.replication.transport_config.TokenProviderImpl;
import com.adobe.granite.keystore.KeyStoreService;
import com.day.cq.replication.AgentConfig;
import com.day.cq.replication.ReplicationException;
import com.day.cq.replication.ReplicationLog;
import com.scene7.is.util.callbacks.Func1;
import com.scene7.is.util.callbacks.Option;
import java.net.URL;
import java.util.Iterator;
import javax.net.ssl.KeyManager;
import javax.net.ssl.TrustManager;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Service(value={SslProtocolProvider.class})
@Component
public final class SslProtocolProvider {
@Reference
private final ResourceResolverProvider resolverProvider;
@Reference
private final KeyStoreService keyStoreService;
private static final Logger log = LoggerFactory.getLogger(SslProtocolProvider.class);
@NotNull
private final String[] disabledSuites = new String[0];
@NotNull
private final String[] enabledSuites = new String[0];
public static SslProtocolProvider sslProtocolProvider(ResourceResolverProvider resolverProvider, KeyStoreService keyStoreService) {
return new SslProtocolProvider(resolverProvider, keyStoreService);
}
public Protocol getProtocol(final AgentConfig config, final ReplicationLog log) {
return (Protocol)this.resolverProvider.withResolver(config.getAgentUserId(), new Func1<ResourceResolver, Protocol>(){
public Protocol call(ResourceResolver resolver) {
return SslProtocolProvider.this.getProtocol(resolver, config, log);
}
});
}
public SslProtocolProvider() {
this.resolverProvider = (ResourceResolverProvider)Util.initRef();
this.keyStoreService = (KeyStoreService)Util.initRef();
}
private SslProtocolProvider(ResourceResolverProvider resolverProvider, KeyStoreService keyStoreService) {
this.resolverProvider = resolverProvider;
this.keyStoreService = keyStoreService;
}
private Protocol getProtocol(ResourceResolver resolver, AgentConfig config, ReplicationLog log) {
Iterator i$ = this.getSocketFactory(resolver, config, log).iterator();
if (i$.hasNext()) {
ProtocolSocketFactory socketFactory = (ProtocolSocketFactory)i$.next();
int port = 443;
try {
URL uri = Util.serverUrl(config.getTransportURI());
port = uri.getPort();
}
catch (ReplicationException e) {
log.warn("Port failed : " + e.getMessage() + ", port:" + port);
}
return new Protocol("https", socketFactory, port);
}
return Protocol.getProtocol((String)"https");
}
private Option<? extends ProtocolSocketFactory> getSocketFactory(ResourceResolver resolver, AgentConfig config, ReplicationLog log) {
if (config.getProperties().get(TokenProviderImpl.KeyStoreConstants.keystoreAlias.name(), String.class) != null) {
return Option.some((Object)new AuthSSLProtocolSocketFactory(null, null, this.disabledSuites, this.enabledSuites));
}
switch (config.getSSLConfig()) {
case "relaxed": {
log.debug("* Using Relaxed SSL configuration *");
boolean allowExpired = config.allowsExpiredCertificates();
log.debug("* Accept expired SSL certificates: %s", new Object[]{allowExpired});
return Option.some((Object)new EasySSLProtocolSocketFactory(allowExpired, this.disabledSuites, this.enabledSuites));
}
case "clientauth": {
log.info("* Using Client Auth SSL configuration *");
KeyManager keyManager = this.keyStoreService.getKeyManager(resolver);
TrustManager trustManager = this.keyStoreService.getTrustManager(resolver);
return Option.some((Object)new AuthSSLProtocolSocketFactory(keyManager, trustManager, this.disabledSuites, this.enabledSuites));
}
case "default": {
return Option.none();
}
}
throw new UnsupportedOperationException("Unsupported SSL configuration: '" + config.getSSLConfig() + '\'');
}
protected void bindResolverProvider(ResourceResolverProvider resourceResolverProvider) {
this.resolverProvider = resourceResolverProvider;
}
protected void unbindResolverProvider(ResourceResolverProvider resourceResolverProvider) {
if (this.resolverProvider == resourceResolverProvider) {
this.resolverProvider = null;
}
}
protected void bindKeyStoreService(KeyStoreService keyStoreService) {
this.keyStoreService = keyStoreService;
}
protected void unbindKeyStoreService(KeyStoreService keyStoreService) {
if (this.keyStoreService == keyStoreService) {
this.keyStoreService = null;
}
}
}