use of com.fathomdb.hash.Md5Hash in project platformlayer by platformlayer.
the class CryptoUtils method md5.
public static Md5Hash md5(byte[] b1, byte[] b2) {
MessageDigest digest = buildMd5();
digest.update(b1);
byte[] hash = digest.digest(b2);
return new Md5Hash(hash);
}
use of com.fathomdb.hash.Md5Hash in project platformlayer by platformlayer.
the class SecretStore method findChallengeForCertificate.
// public CryptoKey getSecretFromToken(final int tokenId, final byte[] tokenSecret) {
// SecretStoreDecoder visitor = new SecretStoreDecoder() {
// @Override
// public void visitToken(int itemTokenId, byte[] itemData) {
// if (itemTokenId == tokenId) {
// // We want this to be reversible; so we XOR it.
// // Both keys are random, so this is secure
// if (tokenSecret.length == itemData.length) {
// byte[] key = SecretStore.xorByteArrays(itemData, tokenSecret);
// setSecretKey(FathomdbCrypto.deserializeKey(key));
// }
// }
// }
// };
//
// try {
// read(encoded, visitor);
// } catch (IOException e) {
// throw new IllegalArgumentException("Secret data is corrupted", e);
// }
// return visitor.getSecretKey();
// }
// static class TokenSecretFinder extends SecretStoreVisitor {
// final int tokenId;
// final CryptoKey userSecret;
//
// public TokenSecretFinder(int tokenId, CryptoKey userSecret) {
// this.tokenId = tokenId;
// this.userSecret = userSecret;
// }
//
// public byte[] tokenSecret;
//
// @Override
// public void visitToken(int tokenId, byte[] data) {
// if (tokenId == this.tokenId) {
// byte[] userSecretBytes = FathomdbCrypto.serialize(userSecret);
// this.tokenSecret = SecretStore.xorByteArrays(userSecretBytes, data);
// }
// }
// }
// public byte[] getTokenSecretWithUserSecret(int tokenId, CryptoKey userSecret) {
// TokenSecretFinder visitor = new TokenSecretFinder(tokenId, userSecret);
//
// try {
// read(encoded, visitor);
// } catch (IOException e) {
// throw new IllegalArgumentException("Secret data is corrupted", e);
// }
// return visitor.tokenSecret;
// }
public byte[] findChallengeForCertificate(X509Certificate[] certificateChain) {
if (certificateChain.length == 0) {
throw new IllegalArgumentException();
}
X509Certificate certificate = certificateChain[0];
Md5Hash signature = OpenSshUtils.getSignature(certificate.getPublicKey());
final byte[] signatureBytes = signature.toByteArray();
SecretStoreDecoder visitor = new SecretStoreDecoder() {
@Override
public void visitGenericAsymetricKey(byte[] publicKeySignature, byte[] data) {
if (Arrays.equals(publicKeySignature, signatureBytes)) {
result = data;
}
}
};
try {
read(encoded, visitor);
} catch (IOException e) {
throw new IllegalArgumentException("Secret data is corrupted", e);
}
return (byte[]) visitor.result;
}
use of com.fathomdb.hash.Md5Hash in project platformlayer by platformlayer.
the class DownloadFileByHash method uploadFile.
@Override
protected void uploadFile(OpsTarget target, File remoteFilePath) throws IOException, OpsException {
target.mkdir(remoteFilePath.getParentFile());
Md5Hash resolved = getResolved(target);
CasStoreObject casObject;
CasStoreMap casStoreMap = cas.getCasStoreMap(target);
try {
casObject = casStoreMap.findArtifact(new OpsCasTarget(target), resolved);
} catch (Exception e) {
throw new OpsException("Error while resolving artifact:" + getHumanName(), e);
}
if (url != null && casObject == null) {
target.mkdir(remoteFilePath.getParentFile());
CurlRequest curlRequest = new CurlRequest(url);
curlRequest.bareRequest = true;
CommandEnvironment commandEnvironment = httpProxies.getHttpProxyEnvironment(target, Usage.General, url);
Command curlCommand = curlRequest.toCommand();
curlCommand.addLiteral(">");
curlCommand.addFile(remoteFilePath);
curlCommand.setEnvironment(commandEnvironment);
curlCommand.setTimeout(TimeSpan.FIVE_MINUTES);
// TODO: Can we cache into CAS instead??
log.info("Not found in CAS system; downloading directly: " + url);
target.executeCommand(curlCommand);
} else {
if (casObject == null) {
throw new OpsException("Unable to find artifact: " + getHumanName());
}
log.info("Doing a CAS copy from " + casObject + " to target");
cas.copyObject(casStoreMap, casObject, new OpsCasTarget(target), remoteFilePath, true);
}
}
use of com.fathomdb.hash.Md5Hash in project platformlayer by platformlayer.
the class FilesystemCasStore method checkDirectory.
private File checkDirectory(File base, Md5Hash hash, int splits) throws OpsException {
String relativePath = toRelativePath(hash, splits);
File seedFile = new File(base, relativePath);
FilesystemInfo seedFileInfo = host.getFilesystemInfoFile(seedFile);
if (seedFileInfo != null) {
Md5Hash seedFileHash = host.getFileHash(seedFile);
if (!seedFileHash.equals(hash)) {
log.warn("Hash mismatch on file: " + seedFile);
return null;
}
// For LRU
host.touchFile(seedFile);
return seedFile;
}
return null;
}
use of com.fathomdb.hash.Md5Hash in project platformlayer by platformlayer.
the class JenkinsCasStore method findTag.
@Override
public Md5Hash findTag(String tag) throws OpsException {
URI uri = client.getBaseUrl();
// TODO: Match jenkins host??
String[] tokens = tag.split(":");
if (tokens.length != 3) {
return null;
}
String jobKey = tokens[0];
String promotionKey = tokens[1];
String fileName = tokens[2];
String treeFilter = "fingerprint[fileName,hash]";
BuildInfo buildInfo;
try {
buildInfo = client.findPromotedBuild(jobKey, promotionKey, treeFilter);
if (buildInfo == null) {
return null;
}
} catch (JenkinsException e) {
throw new OpsException("Error communicating with Jenkins", e);
}
FingerprintInfo found = null;
List<FingerprintInfo> fingerprints = buildInfo.getFingerprints();
for (FingerprintInfo fingerprint : fingerprints) {
if (fileName.equals(fingerprint.getFileName())) {
found = fingerprint;
}
}
if (found == null) {
for (FingerprintInfo fingerprint : fingerprints) {
String fingerprintFileName = fingerprint.getFileName();
if (fingerprintFileName.contains(":")) {
// Strip the maven prefix
fingerprintFileName = fingerprintFileName.substring(fingerprintFileName.indexOf(':') + 1);
}
if (fileName.equals(fingerprintFileName)) {
found = fingerprint;
}
}
}
if (found == null) {
log.warn("Could not find fingerprinted file with name: " + fileName + " in " + buildInfo);
return null;
}
String hash = found.getHash();
if (hash == null) {
throw new IllegalStateException();
}
// We return the hash in the hope that we've already copied the artifact!
return new Md5Hash(hash);
}
Aggregations