Selaa lähdekoodia

Merge branch 'master' into sfedoriv/APIAddSupportForAmazonEC2ComputeCloudService

pull/4/head
Svitlana 4 vuotta sitten
vanhempi
commit
051ad9b68d
3 muutettua tiedostoa jossa 39 lisäystä ja 12 poistoa
  1. +2
    -2
      automation/roles/mitmproxy/files/bubble_passthru.py
  2. +35
    -8
      bubble-server/src/main/java/bubble/rule/passthru/TlsPassthruConfig.java
  3. +2
    -2
      bubble-server/src/test/java/bubble/test/BubbleApiRunnerListener.java

+ 2
- 2
automation/roles/mitmproxy/files/bubble_passthru.py Näytä tiedosto

@@ -84,8 +84,8 @@ def should_passthru(remote_addr, addr):
bubble_log(prefix+' not in redis or empty, calling check_bubble_passthru...')
fqdn = fqdn_for_addr(addr)
if fqdn is None or len(fqdn) == 0:
bubble_log(prefix+' no fqdn found for addr '+addr+', returning (uncached) passthru = True')
return {'fqdn': None, 'addr': addr, 'passthru': True}
bubble_log(prefix+' no fqdn found for addr '+addr+', returning (uncached) passthru = False')
return {'fqdn': None, 'addr': addr, 'passthru': False}
passthru = check_bubble_passthru(remote_addr, addr, fqdn)
bubble_log(prefix+'check_bubble_passthru returned '+repr(passthru)+", storing in redis...")
redis_set(cache_key, json.dumps(passthru), ex=REDIS_PASSTHRU_DURATION)


+ 35
- 8
bubble-server/src/main/java/bubble/rule/passthru/TlsPassthruConfig.java Näytä tiedosto

@@ -16,6 +16,7 @@ import org.cobbzilla.util.string.StringUtil;

import java.io.InputStream;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static bubble.rule.passthru.TlsPassthruFeed.EMPTY_FEEDS;
@@ -68,16 +69,35 @@ public class TlsPassthruConfig {
return !empty(feedList) ? Arrays.stream(feedList).collect(Collectors.toCollection(TreeSet::new)) : Collections.emptySet();
}

@JsonIgnore @Getter(lazy=true) private final AutoRefreshingReference<Set<String>> passthruSetRef = new AutoRefreshingReference<>() {
@Override public Set<String> refresh() { return loadPassthruSet(); }
private static class TlsPassthruMatcher {
@Getter @Setter private String fqdn;
@Getter @Setter private Pattern fqdnPattern;
public boolean hasPattern () { return fqdnPattern != null; }
public TlsPassthruMatcher (String fqdn) {
this.fqdn = fqdn;
if (fqdn.startsWith("/") && fqdn.endsWith("/")) {
this.fqdnPattern = Pattern.compile(fqdn.substring(1, fqdn.length()-1), Pattern.CASE_INSENSITIVE);
}
}
public boolean matches (String val) {
return hasPattern() ? fqdnPattern.matcher(val).matches() : fqdn.equals(val);
}
}

@JsonIgnore @Getter(lazy=true) private final AutoRefreshingReference<Set<TlsPassthruMatcher>> passthruSetRef = new AutoRefreshingReference<>() {
@Override public Set<TlsPassthruMatcher> refresh() { return loadPassthruSet(); }
// todo: load refresh interval from config. implement a config view with an action to set it
@Override public long getTimeout() { return DEFAULT_TLS_FEED_REFRESH_INTERVAL; }
};
@JsonIgnore public Set<String> getPassthruSet() { return getPassthruSetRef().get(); }
@JsonIgnore public Set<TlsPassthruMatcher> getPassthruSet() { return getPassthruSetRef().get(); }

private Set<String> loadPassthruSet() {
final Set<String> set = new HashSet<>();
if (hasFqdnList()) set.addAll(Arrays.asList(fqdnList));
private Set<TlsPassthruMatcher> loadPassthruSet() {
final Set<TlsPassthruMatcher> set = new HashSet<>();
if (hasFqdnList()) {
for (String val : getFqdnList()) {
set.add(new TlsPassthruMatcher(val));
}
}
if (hasFeedList()) {
// put in a set to avoid duplicate URLs
for (TlsPassthruFeed feed : new HashSet<>(Arrays.asList(feedList))) {
@@ -90,7 +110,9 @@ public class TlsPassthruConfig {
if (loaded.hasFqdnList()) recentFeedValues.put(feed.getFeedUrl(), loaded.getFqdnList());
}
}
set.addAll(recentFeedValues.values().stream().flatMap(Collection::stream).collect(Collectors.toSet()));
for (String val : recentFeedValues.values().stream().flatMap(Collection::stream).collect(Collectors.toSet())) {
set.add(new TlsPassthruMatcher(val));
}
if (log.isDebugEnabled()) log.debug("loadPassthruSet: returning fqdnList: "+StringUtil.toString(set, ", "));
return set;
}
@@ -122,6 +144,11 @@ public class TlsPassthruConfig {
return loaded;
}

public boolean isPassthru(String fqdn) { return getPassthruSet().contains(fqdn); }
public boolean isPassthru(String fqdn) {
for (TlsPassthruMatcher match : getPassthruSet()) {
if (match.matches(fqdn)) return true;
}
return false;
}

}

+ 2
- 2
bubble-server/src/test/java/bubble/test/BubbleApiRunnerListener.java Näytä tiedosto

@@ -102,7 +102,7 @@ public class BubbleApiRunnerListener extends SimpleApiRunnerListener {
.stream().filter(c -> c.usesDriver(StripePaymentDriver.class))
.findFirst().orElse(null);
if (stripe == null) {
die("afterScript: no cloud found with driverClass=" + StripePaymentDriver.class.getName());
die("stripTokenizeCard: no cloud found with driverClass=" + StripePaymentDriver.class.getName());
return;
}
stripe.getPaymentDriver(configuration);
@@ -118,7 +118,7 @@ public class BubbleApiRunnerListener extends SimpleApiRunnerListener {
final Token token = Token.create(tokenParams);
ctx.put(CTX_STRIPE_TOKEN, token.getId());
} catch (Exception e) {
die("afterScript: error creating Stripe token: " + e);
die("stripTokenizeCard: error creating Stripe token: " + e);
}
}



Ladataan…
Peruuta
Tallenna