Search in sources :

Example 6 with SshKey

use of com.gitblit.transport.ssh.SshKey in project gitblit by gitblit.

the class Receive method runImpl.

@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);
    } catch (Exception e) {
        throw new Failure(1, "fatal: Cannot receive pack: ", e);
    }
}
Also used : SshKey(com.gitblit.transport.ssh.SshKey) ReceivePack(org.eclipse.jgit.transport.ReceivePack)

Example 7 with SshKey

use of com.gitblit.transport.ssh.SshKey in project gitblit by gitblit.

the class Upload method runImpl.

@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) {
        throw new Failure(1, "fatal: Cannot upload pack: ", e);
    }
}
Also used : SshKey(com.gitblit.transport.ssh.SshKey) UploadPack(org.eclipse.jgit.transport.UploadPack)

Example 8 with SshKey

use of com.gitblit.transport.ssh.SshKey in project gitblit by gitblit.

the class LdapPublicKeyManagerTest method testGetKeysPermissions.

@Test
public void testGetKeysPermissions() throws LDAPException {
    // This test is independent from authentication mode, so run only once.
    assumeTrue(authMode == AuthMode.ANONYMOUS);
    String keyRsaOne = getRsaPubKey("UserOne@example.com");
    String keyRsaTwo = getRsaPubKey("");
    String keyDsaTwo = getDsaPubKey("UserTwo at example.com");
    String keyRsaThree = getRsaPubKey("UserThree@example.com");
    String keyDsaThree = getDsaPubKey("READ key for user 'Three' @example.com");
    String keyEcThree = getEcPubKey("UserThree@example.com");
    getDS().modify(DN_USER_ONE, new Modification(ModificationType.ADD, "sshPublicKey", keyRsaOne));
    getDS().modify(DN_USER_ONE, new Modification(ModificationType.ADD, "sshPublicKey", "  	 " + keyRsaTwo));
    getDS().modify(DN_USER_ONE, new Modification(ModificationType.ADD, "sshPublicKey", "no-agent-forwarding " + keyDsaTwo));
    getDS().modify(DN_USER_ONE, new Modification(ModificationType.ADD, "sshPublicKey", " command=\"sh /etc/netstart tun0 \" " + keyRsaThree));
    getDS().modify(DN_USER_ONE, new Modification(ModificationType.ADD, "sshPublicKey", " command=\"netstat -nult\",environment=\"gb=\\\"What now\\\"\" " + keyDsaThree));
    getDS().modify(DN_USER_ONE, new Modification(ModificationType.ADD, "sshPublicKey", "environment=\"SSH=git\",command=\"netstat -nult\",environment=\"gbPerms=VIEW\" " + keyEcThree));
    getDS().modify(DN_USER_TWO, new Modification(ModificationType.ADD, "sshPublicKey", "environment=\"gbPerm=R\" " + keyRsaOne));
    getDS().modify(DN_USER_TWO, new Modification(ModificationType.ADD, "sshPublicKey", " restrict,environment=\"gbperm=V\" 	 " + keyRsaTwo));
    getDS().modify(DN_USER_TWO, new Modification(ModificationType.ADD, "sshPublicKey", "restrict,environment=\"GBPerm=RW\",pty " + keyDsaTwo));
    getDS().modify(DN_USER_TWO, new Modification(ModificationType.ADD, "sshPublicKey", " environment=\"gbPerm=CLONE\",environment=\"X=\\\" Y \\\"\" " + keyRsaThree));
    getDS().modify(DN_USER_TWO, new Modification(ModificationType.ADD, "sshPublicKey", " environment=\"A = B \",from=\"*.example.com,!pc.example.com\",environment=\"gbPerm=VIEW\" " + keyDsaThree));
    getDS().modify(DN_USER_TWO, new Modification(ModificationType.ADD, "sshPublicKey", "environment=\"SSH=git\",environment=\"gbPerm=PUSH\",environment=\"XYZ='Ali Baba'\" " + keyEcThree));
    getDS().modify(DN_USER_THREE, new Modification(ModificationType.ADD, "sshPublicKey", "environment=\"gbPerm=R\",environment=\"josh=\\\"mean\\\"\",tunnel=\"0\" " + keyRsaOne));
    getDS().modify(DN_USER_THREE, new Modification(ModificationType.ADD, "sshPublicKey", " environment=\" gbPerm = V \" 	 " + keyRsaTwo));
    getDS().modify(DN_USER_THREE, new Modification(ModificationType.ADD, "sshPublicKey", "command=\"sh echo \\\"Nope, not you!\\\" \",user-rc,environment=\"gbPerm=RW\" " + keyDsaTwo));
    getDS().modify(DN_USER_THREE, new Modification(ModificationType.ADD, "sshPublicKey", "environment=\"gbPerm=VIEW\",command=\"sh /etc/netstart tun0 \",environment=\"gbPerm=CLONE\",no-pty " + keyRsaThree));
    getDS().modify(DN_USER_THREE, new Modification(ModificationType.ADD, "sshPublicKey", "	command=\"netstat -nult\",environment=\"gbPerm=VIEW\" " + keyDsaThree));
    getDS().modify(DN_USER_THREE, new Modification(ModificationType.ADD, "sshPublicKey", "environment=\"SSH=git\",command=\"netstat -nult\",environment=\"gbPerm=PUSH\" " + keyEcThree));
    LdapKeyManager kmgr = new LdapKeyManager(settings);
    List<SshKey> keys = kmgr.getKeys("UserOne");
    assertNotNull(keys);
    assertEquals(6, keys.size());
    for (SshKey key : keys) {
        assertEquals(AccessPermission.PUSH, key.getPermission());
    }
    keys = kmgr.getKeys("UserTwo");
    assertNotNull(keys);
    assertEquals(6, keys.size());
    int seen = 0;
    for (SshKey key : keys) {
        if (keyRsaOne.equals(key.getRawData())) {
            assertEquals(AccessPermission.CLONE, key.getPermission());
            seen += 1 << 0;
        } else if (keyRsaTwo.equals(key.getRawData())) {
            assertEquals(AccessPermission.VIEW, key.getPermission());
            seen += 1 << 1;
        } else if (keyDsaTwo.equals(key.getRawData())) {
            assertEquals(AccessPermission.PUSH, key.getPermission());
            seen += 1 << 2;
        } else if (keyRsaThree.equals(key.getRawData())) {
            assertEquals(AccessPermission.CLONE, key.getPermission());
            seen += 1 << 3;
        } else if (keyDsaThree.equals(key.getRawData())) {
            assertEquals(AccessPermission.VIEW, key.getPermission());
            seen += 1 << 4;
        } else if (keyEcThree.equals(key.getRawData())) {
            assertEquals(AccessPermission.PUSH, key.getPermission());
            seen += 1 << 5;
        }
    }
    assertEquals(63, seen);
    keys = kmgr.getKeys("UserThree");
    assertNotNull(keys);
    assertEquals(6, keys.size());
    seen = 0;
    for (SshKey key : keys) {
        if (keyRsaOne.equals(key.getRawData())) {
            assertEquals(AccessPermission.CLONE, key.getPermission());
            seen += 1 << 0;
        } else if (keyRsaTwo.equals(key.getRawData())) {
            assertEquals(AccessPermission.VIEW, key.getPermission());
            seen += 1 << 1;
        } else if (keyDsaTwo.equals(key.getRawData())) {
            assertEquals(AccessPermission.PUSH, key.getPermission());
            seen += 1 << 2;
        } else if (keyRsaThree.equals(key.getRawData())) {
            assertEquals(AccessPermission.CLONE, key.getPermission());
            seen += 1 << 3;
        } else if (keyDsaThree.equals(key.getRawData())) {
            assertEquals(AccessPermission.VIEW, key.getPermission());
            seen += 1 << 4;
        } else if (keyEcThree.equals(key.getRawData())) {
            assertEquals(AccessPermission.PUSH, key.getPermission());
            seen += 1 << 5;
        }
    }
    assertEquals(63, seen);
}
Also used : SshKey(com.gitblit.transport.ssh.SshKey) Modification(com.unboundid.ldap.sdk.Modification) LdapKeyManager(com.gitblit.transport.ssh.LdapKeyManager) Test(org.junit.Test)

Example 9 with SshKey

use of com.gitblit.transport.ssh.SshKey in project gitblit by gitblit.

the class LdapPublicKeyManagerTest method testGetKeysAttributeName.

@Test
public void testGetKeysAttributeName() throws LDAPException {
    settings.put(Keys.realm.ldap.sshPublicKey, "sshPublicKey");
    String keyRsaOne = getRsaPubKey("UserOne@example.com");
    getDS().modify(DN_USER_ONE, new Modification(ModificationType.ADD, "sshPublicKey", keyRsaOne));
    String keyDsaTwo = getDsaPubKey("UserTwo@example.com");
    getDS().modify(DN_USER_TWO, new Modification(ModificationType.ADD, "publicsshkey", keyDsaTwo));
    String keyRsaThree = getRsaPubKey("UserThree@example.com");
    String keyDsaThree = getDsaPubKey("UserThree@example.com");
    getDS().modify(DN_USER_THREE, new Modification(ModificationType.ADD, "sshPublicKey", keyRsaThree));
    getDS().modify(DN_USER_THREE, new Modification(ModificationType.ADD, "publicsshkey", keyDsaThree));
    LdapKeyManager kmgr = new LdapKeyManager(settings);
    List<SshKey> keys = kmgr.getKeys("UserOne");
    assertNotNull(keys);
    assertEquals(1, keys.size());
    assertEquals(keyRsaOne, keys.get(0).getRawData());
    keys = kmgr.getKeys("UserTwo");
    assertNotNull(keys);
    assertEquals(0, keys.size());
    keys = kmgr.getKeys("UserThree");
    assertNotNull(keys);
    assertEquals(1, keys.size());
    assertEquals(keyRsaThree, keys.get(0).getRawData());
    keys = kmgr.getKeys("UserFour");
    assertNotNull(keys);
    assertEquals(0, keys.size());
    settings.put(Keys.realm.ldap.sshPublicKey, "publicsshkey");
    keys = kmgr.getKeys("UserOne");
    assertNotNull(keys);
    assertEquals(0, keys.size());
    keys = kmgr.getKeys("UserTwo");
    assertNotNull(keys);
    assertEquals(1, keys.size());
    assertEquals(keyDsaTwo, keys.get(0).getRawData());
    keys = kmgr.getKeys("UserThree");
    assertNotNull(keys);
    assertEquals(1, keys.size());
    assertEquals(keyDsaThree, keys.get(0).getRawData());
    keys = kmgr.getKeys("UserFour");
    assertNotNull(keys);
    assertEquals(0, keys.size());
}
Also used : SshKey(com.gitblit.transport.ssh.SshKey) Modification(com.unboundid.ldap.sdk.Modification) LdapKeyManager(com.gitblit.transport.ssh.LdapKeyManager) Test(org.junit.Test)

Example 10 with SshKey

use of com.gitblit.transport.ssh.SshKey in project gitblit by gitblit.

the class LdapPublicKeyManagerTest method testGetKeysPrefixed.

@Test
public void testGetKeysPrefixed() throws LDAPException {
    // This test is independent from authentication mode, so run only once.
    assumeTrue(authMode == AuthMode.ANONYMOUS);
    String keyRsaOne = getRsaPubKey("UserOne@example.com");
    getDS().modify(DN_USER_ONE, new Modification(ModificationType.ADD, "sshPublicKey", keyRsaOne));
    String keyRsaTwo = getRsaPubKey("UserTwo@example.com");
    String keyDsaTwo = getDsaPubKey("UserTwo@example.com");
    getDS().modify(DN_USER_TWO, new Modification(ModificationType.ADD, "altSecurityIdentities", keyRsaTwo));
    getDS().modify(DN_USER_TWO, new Modification(ModificationType.ADD, "altSecurityIdentities", "SSHKey: " + keyDsaTwo));
    String keyRsaThree = getRsaPubKey("UserThree@example.com");
    String keyDsaThree = getDsaPubKey("UserThree@example.com");
    String keyEcThree = getEcPubKey("UserThree@example.com");
    getDS().modify(DN_USER_THREE, new Modification(ModificationType.ADD, "altSecurityIdentities", " SshKey :\r\n" + keyRsaThree));
    getDS().modify(DN_USER_THREE, new Modification(ModificationType.ADD, "altSecurityIdentities", "	sshkey: " + keyDsaThree));
    getDS().modify(DN_USER_THREE, new Modification(ModificationType.ADD, "altSecurityIdentities", "ECDSAKey	:\n " + keyEcThree));
    LdapKeyManager kmgr = new LdapKeyManager(settings);
    settings.put(Keys.realm.ldap.sshPublicKey, "altSecurityIdentities");
    List<SshKey> keys = kmgr.getKeys("UserOne");
    assertNotNull(keys);
    assertEquals(0, keys.size());
    keys = kmgr.getKeys("UserTwo");
    assertNotNull(keys);
    assertEquals(1, keys.size());
    assertEquals(keyRsaTwo, keys.get(0).getRawData());
    keys = kmgr.getKeys("UserThree");
    assertNotNull(keys);
    assertEquals(0, keys.size());
    keys = kmgr.getKeys("UserFour");
    assertNotNull(keys);
    assertEquals(0, keys.size());
    settings.put(Keys.realm.ldap.sshPublicKey, "altSecurityIdentities:SSHKey");
    keys = kmgr.getKeys("UserOne");
    assertNotNull(keys);
    assertEquals(0, keys.size());
    keys = kmgr.getKeys("UserTwo");
    assertNotNull(keys);
    assertEquals(1, keys.size());
    assertEquals(keyDsaTwo, keys.get(0).getRawData());
    keys = kmgr.getKeys("UserThree");
    assertNotNull(keys);
    assertEquals(2, keys.size());
    assertEquals(keyRsaThree, keys.get(0).getRawData());
    assertEquals(keyDsaThree, keys.get(1).getRawData());
    keys = kmgr.getKeys("UserFour");
    assertNotNull(keys);
    assertEquals(0, keys.size());
    settings.put(Keys.realm.ldap.sshPublicKey, "altSecurityIdentities:ECDSAKey");
    keys = kmgr.getKeys("UserOne");
    assertNotNull(keys);
    assertEquals(0, keys.size());
    keys = kmgr.getKeys("UserTwo");
    assertNotNull(keys);
    assertEquals(0, keys.size());
    keys = kmgr.getKeys("UserThree");
    assertNotNull(keys);
    assertEquals(1, keys.size());
    assertEquals(keyEcThree, keys.get(0).getRawData());
    keys = kmgr.getKeys("UserFour");
    assertNotNull(keys);
    assertEquals(0, keys.size());
}
Also used : SshKey(com.gitblit.transport.ssh.SshKey) Modification(com.unboundid.ldap.sdk.Modification) LdapKeyManager(com.gitblit.transport.ssh.LdapKeyManager) Test(org.junit.Test)

Aggregations

SshKey (com.gitblit.transport.ssh.SshKey)12 Test (org.junit.Test)7 LdapKeyManager (com.gitblit.transport.ssh.LdapKeyManager)6 Modification (com.unboundid.ldap.sdk.Modification)6 KeyPair (java.security.KeyPair)2 AccessPermission (com.gitblit.Constants.AccessPermission)1 UserModel (com.gitblit.models.UserModel)1 MemoryKeyManager (com.gitblit.transport.ssh.MemoryKeyManager)1 Signature (java.security.Signature)1 ArrayList (java.util.ArrayList)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)1 AjaxButton (org.apache.wicket.ajax.markup.html.form.AjaxButton)1 Label (org.apache.wicket.markup.html.basic.Label)1 Form (org.apache.wicket.markup.html.form.Form)1 Item (org.apache.wicket.markup.repeater.Item)1 DataView (org.apache.wicket.markup.repeater.data.DataView)1 ListDataProvider (org.apache.wicket.markup.repeater.data.ListDataProvider)1 ReceivePack (org.eclipse.jgit.transport.ReceivePack)1 UploadPack (org.eclipse.jgit.transport.UploadPack)1