use of com.google.common.hash.HashCode in project che by eclipse.
the class SHA512PasswordEncryptor method test.
@Override
public boolean test(String password, String passwordHash) {
requireNonNull(password, "Required non-null password");
requireNonNull(passwordHash, "Required non-null password's hash");
// retrieve salt from the hash
final int passwordHashLength = ENCRYPTED_PASSWORD_BYTES_LENGTH * 2;
if (passwordHash.length() < passwordHashLength + SALT_BYTES_LENGTH * 2) {
return false;
}
final HashCode saltHash = HashCode.fromString(passwordHash.substring(passwordHashLength));
// sha1(password + salt)
final HashCode hash = Hashing.sha512().hashBytes(Bytes.concat(password.getBytes(PWD_CHARSET), saltHash.asBytes()));
// test sha1(password + salt) + salt == passwordHash
return (hash.toString() + saltHash.toString()).equals(passwordHash);
}
use of com.google.common.hash.HashCode in project elastic-job by dangdangdotcom.
the class FailoverService method getAllEligibleJobContexts.
/**
* 从失效转移队列中获取所有有资格执行的作业上下文.
*
* @return 有资格执行的作业上下文集合
*/
public Collection<JobContext> getAllEligibleJobContexts() {
if (!regCenter.isExisted(FailoverNode.ROOT)) {
return Collections.emptyList();
}
List<String> jobNames = regCenter.getChildrenKeys(FailoverNode.ROOT);
Collection<JobContext> result = new ArrayList<>(jobNames.size());
Set<HashCode> assignedTasks = new HashSet<>(jobNames.size() * 10, 1);
for (String each : jobNames) {
List<String> taskIdList = regCenter.getChildrenKeys(FailoverNode.getFailoverJobNodePath(each));
if (taskIdList.isEmpty()) {
regCenter.remove(FailoverNode.getFailoverJobNodePath(each));
continue;
}
Optional<CloudJobConfiguration> jobConfig = configService.load(each);
if (!jobConfig.isPresent()) {
regCenter.remove(FailoverNode.getFailoverJobNodePath(each));
continue;
}
List<Integer> assignedShardingItems = getAssignedShardingItems(each, taskIdList, assignedTasks);
if (!assignedShardingItems.isEmpty()) {
if (jobConfig.isPresent()) {
result.add(new JobContext(jobConfig.get(), assignedShardingItems, ExecutionType.FAILOVER));
}
}
}
return result;
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class AndroidBinary method addAccumulateClassNamesStep.
public Supplier<ImmutableMap<String, HashCode>> addAccumulateClassNamesStep(final ImmutableSet<Path> classPathEntriesToDex, ImmutableList.Builder<Step> steps) {
final ImmutableMap.Builder<String, HashCode> builder = ImmutableMap.builder();
steps.add(new AbstractExecutionStep("collect_all_class_names") {
@Override
public StepExecutionResult execute(ExecutionContext context) {
for (Path path : classPathEntriesToDex) {
Optional<ImmutableSortedMap<String, HashCode>> hashes = AccumulateClassNamesStep.calculateClassHashes(context, getProjectFilesystem(), path);
if (!hashes.isPresent()) {
return StepExecutionResult.ERROR;
}
builder.putAll(hashes.get());
}
return StepExecutionResult.SUCCESS;
}
});
return Suppliers.memoize(builder::build);
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class ProvisioningProfileStore method getBestProvisioningProfile.
// If multiple valid ones, find the one which matches the most specifically. I.e.,
// XXXXXXXXXX.com.example.* will match over XXXXXXXXXX.* for com.example.TestApp
public Optional<ProvisioningProfileMetadata> getBestProvisioningProfile(String bundleID, ApplePlatform platform, Optional<ImmutableMap<String, NSObject>> entitlements, Optional<? extends Iterable<CodeSignIdentity>> identities) {
final Optional<String> prefix;
if (entitlements.isPresent()) {
prefix = ProvisioningProfileMetadata.prefixFromEntitlements(entitlements.get());
} else {
prefix = Optional.empty();
}
int bestMatchLength = -1;
Optional<ProvisioningProfileMetadata> bestMatch = Optional.empty();
for (ProvisioningProfileMetadata profile : getProvisioningProfiles()) {
if (profile.getExpirationDate().after(new Date())) {
Pair<String, String> appID = profile.getAppID();
LOG.debug("Looking at provisioning profile " + profile.getUUID() + "," + appID.toString());
if (!prefix.isPresent() || prefix.get().equals(appID.getFirst())) {
String profileBundleID = appID.getSecond();
boolean match;
if (profileBundleID.endsWith("*")) {
// Chop the ending * if wildcard.
profileBundleID = profileBundleID.substring(0, profileBundleID.length() - 1);
match = bundleID.startsWith(profileBundleID);
} else {
match = (bundleID.equals(profileBundleID));
}
if (!match) {
LOG.debug("Ignoring non-matching ID for profile " + profile.getUUID() + ". Expected: " + profileBundleID + ", actual: " + bundleID);
continue;
}
Optional<String> platformName = platform.getProvisioningProfileName();
if (platformName.isPresent() && !profile.getPlatforms().contains(platformName.get())) {
LOG.debug("Ignoring incompatible platform " + platformName.get() + " for profile " + profile.getUUID());
continue;
}
// For example: get-task-allow, aps-environment, etc.
if (entitlements.isPresent()) {
ImmutableMap<String, NSObject> entitlementsDict = entitlements.get();
ImmutableMap<String, NSObject> profileEntitlements = profile.getEntitlements();
for (Entry<String, NSObject> entry : entitlementsDict.entrySet()) {
if (!(entry.getKey().equals("keychain-access-groups") || entry.getKey().equals("application-identifier") || entry.getKey().equals("com.apple.developer.associated-domains") || matchesOrArrayIsSubsetOf(entry.getValue(), profileEntitlements.get(entry.getKey())))) {
match = false;
LOG.debug("Ignoring profile " + profile.getUUID() + " with mismatched entitlement " + entry.getKey() + "; value is " + profileEntitlements.get(entry.getKey()) + " but expected " + entry.getValue());
break;
}
}
}
// Reject any certificate which we know we can't sign with the supplied identities.
ImmutableSet<HashCode> validFingerprints = profile.getDeveloperCertificateFingerprints();
if (match && identities.isPresent() && !validFingerprints.isEmpty()) {
match = false;
for (CodeSignIdentity identity : identities.get()) {
Optional<HashCode> fingerprint = identity.getFingerprint();
if (fingerprint.isPresent() && validFingerprints.contains(fingerprint.get())) {
match = true;
break;
}
}
if (!match) {
LOG.debug("Ignoring profile " + profile.getUUID() + " because it can't be signed with any valid identity in the current keychain.");
continue;
}
}
if (match && profileBundleID.length() > bestMatchLength) {
bestMatchLength = profileBundleID.length();
bestMatch = Optional.of(profile);
}
}
} else {
LOG.debug("Ignoring expired profile " + profile.getUUID());
}
}
LOG.debug("Found provisioning profile " + bestMatch.toString());
return bestMatch;
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class TargetsCommand method computeShowTargetHash.
private void computeShowTargetHash(CommandRunnerParams params, ListeningExecutorService executor, TargetGraphAndTargetNodes targetGraphAndTargetNodes, Map<BuildTarget, ShowOptions.Builder> showRulesResult) throws IOException, InterruptedException, BuildFileParseException, BuildTargetException, CycleException {
LOG.debug("Getting target hash for %s", targetGraphAndTargetNodes.getTargetNodes());
TargetGraphAndTargetNodes targetGraphAndNodesWithTests = computeTargetsAndGraphToShowTargetHash(params, executor, targetGraphAndTargetNodes);
TargetGraph targetGraphWithTests = targetGraphAndNodesWithTests.getTargetGraph();
FileHashLoader fileHashLoader = createOrGetFileHashLoader(params);
// Hash each target's rule description and contents of any files.
ImmutableMap<BuildTarget, HashCode> buildTargetHashes = new TargetGraphHashing(params.getBuckEventBus(), targetGraphWithTests, fileHashLoader, targetGraphAndNodesWithTests.getTargetNodes()).setNumThreads(params.getBuckConfig().getNumThreads()).hashTargetGraph();
ImmutableMap<BuildTarget, HashCode> finalHashes = rehashWithTestsIfNeeded(targetGraphWithTests, targetGraphAndTargetNodes.getTargetNodes(), buildTargetHashes);
for (TargetNode<?, ?> targetNode : targetGraphAndTargetNodes.getTargetNodes()) {
processTargetHash(targetNode.getBuildTarget(), showRulesResult, finalHashes);
}
}
Aggregations