use of javax.annotation.Nullable in project keywhiz by square.
the class ExpirationExtractor method expirationFromEncodedCertificateChain.
@Nullable
public static Instant expirationFromEncodedCertificateChain(byte[] content) {
PemReader reader = new PemReader(new InputStreamReader(new ByteArrayInputStream(content), UTF_8));
PemObject object;
try {
object = reader.readPemObject();
} catch (IOException e) {
// Should never occur (reading form byte array)
throw Throwables.propagate(e);
}
Instant earliest = null;
while (object != null) {
if (object.getType().equals("CERTIFICATE")) {
Instant expiry = expirationFromRawCertificate(object.getContent());
if (earliest == null || expiry.isBefore(earliest)) {
earliest = expiry;
}
}
try {
object = reader.readPemObject();
} catch (IOException e) {
// Should never occur (reading form byte array)
throw Throwables.propagate(e);
}
}
return earliest;
}
use of javax.annotation.Nullable in project keywhiz by square.
the class ExpirationExtractor method expirationFromKeystore.
@Nullable
public static Instant expirationFromKeystore(String type, String password, byte[] content) {
KeyStore ks;
try {
ks = KeyStore.getInstance(type);
} catch (KeyStoreException e) {
// Should never occur (assuming JCE is installed)
throw Throwables.propagate(e);
}
try {
ks.load(new ByteArrayInputStream(content), password.toCharArray());
} catch (IOException | NoSuchAlgorithmException | CertificateException e) {
// Failed to parse
logger.info("Failed to parse keystore", e);
return null;
}
Instant earliest = null;
try {
for (String alias : list(ks.aliases())) {
Certificate[] chain = ks.getCertificateChain(alias);
if (chain == null) {
Certificate certificate = ks.getCertificate(alias);
if (certificate == null) {
// No certs in this entry
continue;
}
chain = new Certificate[] { certificate };
}
for (Certificate cert : chain) {
if (cert instanceof X509Certificate) {
X509Certificate c = (X509Certificate) cert;
if (earliest == null || c.getNotAfter().toInstant().isBefore(earliest)) {
earliest = c.getNotAfter().toInstant();
}
}
}
}
} catch (KeyStoreException e) {
// Should never occur (ks was initialized)
throw Throwables.propagate(e);
}
return earliest;
}
use of javax.annotation.Nullable in project bazel by bazelbuild.
the class NewHttpArchiveFunction method fetch.
@Nullable
@Override
public RepositoryDirectoryValue.Builder fetch(Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env, Map<String, String> markerData) throws RepositoryFunctionException, InterruptedException {
NewRepositoryBuildFileHandler buildFileHandler = new NewRepositoryBuildFileHandler(directories.getWorkspace());
if (!buildFileHandler.prepareBuildFile(rule, env)) {
return null;
}
try {
FileSystemUtils.createDirectoryAndParents(outputDirectory);
} catch (IOException e) {
throw new RepositoryFunctionException(new IOException("Could not create directory for " + rule.getName() + ": " + e.getMessage()), Transience.TRANSIENT);
}
// Download.
Path downloadedPath = downloader.download(rule, outputDirectory, env.getListener(), clientEnvironment);
// Decompress.
Path decompressed;
WorkspaceAttributeMapper mapper = WorkspaceAttributeMapper.of(rule);
String prefix = null;
if (mapper.isAttributeValueExplicitlySpecified("strip_prefix")) {
try {
prefix = mapper.get("strip_prefix", Type.STRING);
} catch (EvalException e) {
throw new RepositoryFunctionException(e, Transience.PERSISTENT);
}
}
decompressed = DecompressorValue.decompress(DecompressorDescriptor.builder().setTargetKind(rule.getTargetKind()).setTargetName(rule.getName()).setArchivePath(downloadedPath).setRepositoryPath(outputDirectory).setPrefix(prefix).build());
// Finally, write WORKSPACE and BUILD files.
createWorkspaceFile(decompressed, rule.getTargetKind(), rule.getName());
buildFileHandler.finishBuildFile(outputDirectory);
return RepositoryDirectoryValue.builder().setPath(outputDirectory);
}
use of javax.annotation.Nullable in project bazel by bazelbuild.
the class RedirectChaser method followRedirects.
/**
* Follows the 'srcs' attribute of the given label recursively. Keeps repeating as long as the
* labels are either <code>alias</code> or <code>bind</code> rules.
*
* @param env for loading the packages
* @param label the label to start at
* @param name user-meaningful description of the content being resolved
* @return the label which cannot be further resolved
* @throws InvalidConfigurationException if something goes wrong
*/
@Nullable
public static Label followRedirects(ConfigurationEnvironment env, Label label, String name) throws InvalidConfigurationException, InterruptedException {
Label oldLabel = null;
Set<Label> visitedLabels = new HashSet<>();
visitedLabels.add(label);
try {
while (true) {
Target possibleRedirect = env.getTarget(label);
if (possibleRedirect == null) {
return null;
}
Label newLabel = getBindOrAliasRedirect(possibleRedirect);
if (newLabel == null) {
return label;
}
newLabel = label.resolveRepositoryRelative(newLabel);
oldLabel = label;
label = newLabel;
if (!visitedLabels.add(label)) {
throw new InvalidConfigurationException("The " + name + " points to a rule which " + "recursively references itself. The label " + label + " is part of the loop");
}
}
} catch (NoSuchThingException e) {
String prefix = oldLabel == null ? "" : "in target '" + oldLabel + "': ";
throw new InvalidConfigurationException(prefix + e.getMessage(), e);
}
}
use of javax.annotation.Nullable in project bazel by bazelbuild.
the class ConfigurationFactory method getConfiguration.
/**
* Returns a {@link com.google.devtools.build.lib.analysis.config.BuildConfiguration} based on the
* given set of build options.
*
* <p>If the configuration has already been created, re-uses it, otherwise, creates a new one.
*/
@Nullable
public BuildConfiguration getConfiguration(PackageProviderForConfigurations loadedPackageProvider, BuildOptions buildOptions, boolean actionsDisabled, Cache<String, BuildConfiguration> cache) throws InvalidConfigurationException, InterruptedException {
String cacheKey = buildOptions.computeCacheKey();
BuildConfiguration result = cache.getIfPresent(cacheKey);
if (result != null) {
return result;
}
Map<Class<? extends Fragment>, Fragment> fragments = new HashMap<>();
// Create configuration fragments
for (ConfigurationFragmentFactory factory : configurationFragmentFactories) {
Class<? extends Fragment> fragmentType = factory.creates();
Fragment fragment = loadedPackageProvider.getFragment(buildOptions, fragmentType);
if (fragment != null && fragments.get(fragment.getClass()) == null) {
fragments.put(fragment.getClass(), fragment);
}
}
BlazeDirectories directories = loadedPackageProvider.getDirectories();
if (loadedPackageProvider.valuesMissing()) {
return null;
}
result = new BuildConfiguration(directories, fragments, buildOptions, actionsDisabled);
cache.put(cacheKey, result);
return result;
}
Aggregations