Search in sources :

Example 1 with HashCode

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);
}
Also used : HashCode(com.google.common.hash.HashCode)

Example 2 with HashCode

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;
}
Also used : HashCode(com.google.common.hash.HashCode) CloudJobConfiguration(com.dangdang.ddframe.job.cloud.scheduler.config.job.CloudJobConfiguration) ArrayList(java.util.ArrayList) JobContext(com.dangdang.ddframe.job.cloud.scheduler.context.JobContext) HashSet(java.util.HashSet)

Example 3 with HashCode

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);
}
Also used : Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) HashCode(com.google.common.hash.HashCode) ExecutionContext(com.facebook.buck.step.ExecutionContext) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) Optional(java.util.Optional) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 4 with HashCode

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;
}
Also used : NSObject(com.dd.plist.NSObject) Date(java.util.Date) HashCode(com.google.common.hash.HashCode)

Example 5 with HashCode

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);
    }
}
Also used : TargetGraphAndTargetNodes(com.facebook.buck.rules.TargetGraphAndTargetNodes) FileHashLoader(com.facebook.buck.hashing.FileHashLoader) HashCode(com.google.common.hash.HashCode) BuildTarget(com.facebook.buck.model.BuildTarget) TargetGraphHashing(com.facebook.buck.rules.TargetGraphHashing) TargetGraph(com.facebook.buck.rules.TargetGraph)

Aggregations

HashCode (com.google.common.hash.HashCode)120 Path (java.nio.file.Path)40 Test (org.junit.Test)39 BuildTarget (com.facebook.buck.model.BuildTarget)19 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)13 IOException (java.io.IOException)13 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)12 PathSourcePath (com.facebook.buck.rules.PathSourcePath)11 FileHashCache (com.facebook.buck.util.cache.FileHashCache)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)10 Sha1HashCode (com.facebook.buck.util.sha1.Sha1HashCode)10 Hasher (com.google.common.hash.Hasher)9 Map (java.util.Map)9 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)7 SourcePath (com.facebook.buck.rules.SourcePath)7 File (java.io.File)7 BuckEventBus (com.facebook.buck.event.BuckEventBus)6 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)6 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)5