Package com.gitblit.transport.ssh

Examples of com.gitblit.transport.ssh.SshKey


  }

  @Test
  public void testKeysAddCommand() throws Exception {
    KeyPair kp = generator.generateKeyPair();
    SshKey key = new SshKey(kp.getPublic());
    testSshCommand("keys add --permission R", key.getRawData());
    List<SshKey> keys = getKeyManager().getKeys(username);
    assertEquals(String.format("There are %d keys!", keys.size()), 3, keys.size());
    assertEquals(AccessPermission.CLONE, keys.get(2).getPermission());

    String result = testSshCommand("keys ls -L");
View Full Code Here


@CommandMetaData(name = "git-upload-pack", description = "Sends packs to a client for clone and fetch", hidden = true)
public class Upload extends BaseGitCommand {
  @Override
  protected void runImpl() throws Failure {
    try {
      SshKey key = getContext().getClient().getKey();
      if (key != null && !key.canClone()) {
        throw new Failure(1, "Sorry, your SSH public key is not allowed to clone!");
      }
      UploadPack up = uploadPackFactory.create(getContext().getClient(), repo);
      up.upload(in, out, null);
    } catch (Exception e) {
View Full Code Here

@CommandMetaData(name = "git-receive-pack", description = "Receives pushes from a client", hidden = true)
public class Receive extends BaseGitCommand {
  @Override
  protected void runImpl() throws Failure {
    SshKey key = getContext().getClient().getKey();
    if (key != null && !key.canPush()) {
      throw new Failure(1, "Sorry, your SSH public key is not allowed to push changes!");
    }
    try {
      ReceivePack rp = receivePackFactory.create(getContext().getClient(), repo);
      rp.receive(in, out, null);
View Full Code Here

  @Before
  public void prepare() {
    rwKeyPair = generator.generateKeyPair();

    MemoryKeyManager keyMgr = getKeyManager();
    keyMgr.addKey(username, new SshKey(rwKeyPair.getPublic()));

    roKeyPair = generator.generateKeyPair();
    SshKey sshKey = new SshKey(roKeyPair.getPublic());
    sshKey.setPermission(AccessPermission.CLONE);
    keyMgr.addKey(username, sshKey);
  }
View Full Code Here

  protected SshKey parseKey(String rawData) throws UnloggedFailure {
    if (rawData.contains("PRIVATE")) {
      throw new UnloggedFailure(1"Please provide a PUBLIC key, not a PRIVATE key!");
    }
    SshKey key = new SshKey(rawData);
    return key;
  }
View Full Code Here

      List<String> keys = readKeys(addKeys);
      if (keys.isEmpty()) {
        throw new UnloggedFailure("No public keys were read from STDIN!");
      }
      for (String key : keys) {
        SshKey sshKey = parseKey(key);
        try {
          // this method parses the rawdata and produces a public key
          // if it fails it will throw a Buffer.BufferException
          // the null check is a QC verification on top of that
          if (sshKey.getPublicKey() == null) {
            throw new RuntimeException();
          }
        } catch (RuntimeException e) {
          throw new UnloggedFailure("The data read from SDTIN can not be parsed as an SSH public key!");
        }
        if (!StringUtils.isEmpty(permission)) {
          AccessPermission ap = AccessPermission.fromCode(permission);
          if (ap.exceeds(AccessPermission.NONE)) {
            try {
              sshKey.setPermission(ap);
            } catch (IllegalArgumentException e) {
              throw new Failure(1, e.getMessage());
            }
          }
        }
View Full Code Here

              if (keyParameters.size() == 1) {
                throw new Failure(1, "Invalid index specified. There is only 1 registered key.");
              }
              throw new Failure(1, String.format("Invalid index specified. There are %d registered keys.", registeredKeys.size()));
            }
            SshKey sshKey = registeredKeys.get(index - 1);
            if (getKeyManager().removeKey(username, sshKey)) {
              stdout.println(String.format("Removed %s", sshKey.getFingerprint()));
            } else {
              throw new Failure(1,  String.format("failed to remove #%s: %s", keyParameter, sshKey.getFingerprint()));
            }
          } catch (NumberFormatException e) {
            log.warn("failed to remove SSH public key {} from {}", keyParameter, username);
            throw new Failure(1,  String.format("failed to remove key %s", keyParameter));
          }
View Full Code Here

      int len = keys == null ? 0 : keys.size();
      Object[][] data = new Object[len][];
      for (int i = 0; i < len; i++) {
        // show 1-based index numbers with the fingerprint
        // this is useful for comparing with "ssh-add -l"
        SshKey k = keys.get(i);
        data[i] = new Object[] { (i + 1), k.getFingerprint(), k.getComment(),
            k.getPermission(), k.getAlgorithm() };
      }

      stdout.println(FlipTable.of(headers, data, Borders.BODY_HCOLS));
    }
View Full Code Here

    @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 {
        final String username = getContext().getClient().getUsername();
        List<SshKey> keys = getContext().getGitblit().getPublicKeyManager().getKeys(username);
        int index = 0;
        for (int i = 0; i < keys.size(); i++) {
          if (key.equals(keys.get(i))) {
            index = i + 1;
            break;
          }
        }
        asTable(index, key);
View Full Code Here

      if (index > keys.size()) {
        throw new UnloggedFailure(1"Invalid key index!");
      }

      String comment = Joiner.on(" ").join(values);
      SshKey key = keys.get(index - 1);
      key.setComment(comment);
      if (keyManager.addKey(username, key)) {
        stdout.println(String.format("Updated the comment for key #%d.", index));
      } else {
        throw new Failure(1, String.format("Failed to update the comment for key #%d!", index));
      }
View Full Code Here

TOP

Related Classes of com.gitblit.transport.ssh.SshKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.