Issue 719: added some logging for ssh fingerprints

This commit is contained in:
Adrian Cole 2011-10-13 01:49:49 -07:00
parent a1d1f0131f
commit c28a2e38c3
4 changed files with 18 additions and 7 deletions

View File

@ -67,7 +67,7 @@ public class CreateUniqueKeyPair extends CacheLoader<RegionAndName, KeyPair> {
while (keyPair == null) {
try {
keyPair = ec2Client.getKeyPairServices().createKeyPairInRegion(region, getNextName(region, group));
logger.debug("<< created keyPair(%s)", keyPair.getKeyName());
logger.debug("<< created keyPair(%s) fingerprint(%s)", keyPair.getKeyName(), keyPair.getKeyFingerprint());
} catch (IllegalStateException e) {
}

View File

@ -25,9 +25,11 @@ import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.base.Predicates.or;
import static com.google.common.base.Throwables.getCausalChain;
import static com.google.common.collect.Iterables.any;
import static org.jclouds.crypto.SshKeys.fingerprint;
import java.io.IOException;
import java.io.InputStream;
import java.security.spec.RSAPrivateCrtKeySpec;
import java.util.concurrent.TimeUnit;
import javax.annotation.PostConstruct;
@ -48,6 +50,7 @@ import net.schmizz.sshj.xfer.InMemorySourceFile;
import org.apache.commons.io.input.ProxyInputStream;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.crypto.Pems;
import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
@ -92,7 +95,8 @@ public class SshjSshClient implements SshClient {
private final int port;
private final String username;
private final String password;
private final String toString;
@Inject(optional = true)
@Named("jclouds.ssh.max-retries")
@VisibleForTesting
@ -135,6 +139,13 @@ public class SshjSshClient implements SshClient {
this.timeoutMillis = timeout;
this.password = password;
this.privateKey = privateKey;
if (privateKey == null) {
this.toString = String.format("%s@%s:%d", username, host, port);
} else {
RSAPrivateCrtKeySpec key = (RSAPrivateCrtKeySpec) Pems.privateKeySpec(new String(privateKey));
String fingerPrint = fingerprint(key.getPublicExponent(), key.getModulus());
this.toString = String.format("%s:[%s]@%s:%d", username, fingerPrint, host, port);
}
}
@Override
@ -391,7 +402,7 @@ public class SshjSshClient implements SshClient {
@Override
public String toString() {
return String.format("%s@%s:%d", username, host, port);
return toString ;
}
@PreDestroy

View File

@ -69,12 +69,12 @@ public class ImportOrReturnExistingKeypair implements Function<RegionNameAndPubl
try {
keyPair = ec2Client.getKeyPairServices().importKeyPairInRegion(region, "jclouds#" + group,
publicKeyMaterial);
logger.debug("<< imported keyPair(%s)", keyPair.getKeyName());
logger.debug("<< imported keyPair(%s) fingerprint(%s)", keyPair.getKeyName(), keyPair.getKeyFingerprint());
} catch (IllegalStateException e) {
keyPair = Iterables.getFirst(
ec2Client.getKeyPairServices().describeKeyPairsInRegion(region, "jclouds#" + group), null);
if (keyPair != null)
logger.debug("<< retrieved existing keyPair(%s)", keyPair.getKeyName());
logger.debug("<< retrieved existing keyPair(%s) fingerprint(%s)", keyPair.getKeyName(), keyPair.getKeyFingerprint());
}
return keyPair;
}

View File

@ -130,13 +130,13 @@ public class AWSKeyPairClientLiveTest {
Set<? extends NodeMetadata> nodes = noSshContext.getComputeService().createNodesInGroup(group, 1, options);
NodeMetadata first = get(nodes, 0);
// credentials should be present as this is the default user from the image
assert first.getCredentials() != null : first;
assert first.getCredentials().identity != null : first;
assert first.getCredentials().credential == null : first;
assert first.getCredentials().credential != null : first;
AWSRunningInstance instance = getInstance(instanceClient, first.getProviderId());
assert instance.getSpotInstanceRequestId() != null : instance;
assertEquals(instance.getKeyName(), "jclouds#" + group);
Map<? extends NodeMetadata, ExecResponse> responses = computeContext.getComputeService()