src/main/java/com/gitblit/transport/ssh/CachingPublicKeyAuthenticator.java
@@ -90,6 +90,7 @@ UserModel user = authManager.authenticate(username, key); if (user != null) { client.setUser(user); client.setKey(key); return true; } } src/main/java/com/gitblit/transport/ssh/SshDaemonClient.java
@@ -32,6 +32,7 @@ private final SocketAddress remoteAddress; private volatile UserModel user; private volatile SshKey key; private volatile String repositoryName; SshDaemonClient(SocketAddress peer) { @@ -61,4 +62,13 @@ public String getRepositoryName() { return repositoryName; } public SshKey getKey() { return key; } public void setKey(SshKey key) { this.key = key; } } src/main/java/com/gitblit/transport/ssh/WelcomeShell.java
@@ -134,6 +134,8 @@ msg.append(user.getDisplayName()); msg.append(", you have successfully connected over SSH."); msg.append(nl); msg.append(" Interactive shells are disabled."); msg.append(nl); msg.append(nl); msg.append(" client: "); msg.append(session.getClientVersion()); @@ -156,6 +158,9 @@ msg.append(nl); msg.append(nl); if (client.getKey() == null) { // user has authenticated with a password // display add public key instructions msg.append(" You may upload an SSH public key with the following syntax:"); msg.append(nl); msg.append(nl); @@ -167,6 +172,7 @@ msg.append(b2); msg.append(nl); msg.append(nl); } // display the core commands SshCommandFactory cmdFactory = (SshCommandFactory) session.getFactoryManager().getCommandFactory(); src/main/java/com/gitblit/transport/ssh/commands/BaseCommand.java
@@ -219,7 +219,7 @@ msg.write(' '); msg.write(commandName); msg.write('\n'); msg.write(' '); msg.write(" "); clp.printSingleLineUsage(msg, null); msg.write("\n\n"); msg.write("ARGUMENTS & OPTIONS\n"); src/main/java/com/gitblit/transport/ssh/gitblit/KeysDispatcher.java
@@ -48,6 +48,7 @@ register(user, AddKey.class); register(user, RemoveKey.class); register(user, ListKeys.class); register(user, WhichKey.class); } @CommandMetaData(name = "add", description = "Add an SSH public key to your account") @@ -177,4 +178,33 @@ stdout.println(FlipTable.of(headers, data, Borders.BODY_HCOLS)); } } @CommandMetaData(name = "which", description = "Display the SSH public key used for this session") public static class WhichKey extends SshCommand { @Option(name = "-L", usage = "list complete public key parameters") private boolean showRaw; @Override public void run() throws UnloggedFailure { SshKey key = getContext().getClient().getKey(); if (key == null) { throw new UnloggedFailure(1, "You have not authenticated with an SSH public key."); } if (showRaw) { stdout.println(key.getRawData()); } else { asTable(key); } } protected void asTable(SshKey key) { String[] headers = { "Fingerprint", "Comment", "Type" }; Object[][] data = new Object[1][]; data[0] = new Object[] { key.getFingerprint(), key.getComment(), key.getAlgorithm() }; stdout.println(FlipTable.of(headers, data, Borders.BODY_HCOLS)); } } }