Search in sources :

Example 6 with X509Metadata

use of com.gitblit.utils.X509Utils.X509Metadata in project gitblit by gitblit.

the class GitblitAuthority method prepareX509Infrastructure.

private boolean prepareX509Infrastructure() {
    if (caKeystorePassword == null) {
        JPasswordField pass = new JPasswordField(10);
        pass.setText(caKeystorePassword);
        pass.addAncestorListener(new RequestFocusListener());
        JPanel panel = new JPanel(new BorderLayout());
        panel.add(new JLabel(Translation.get("gb.enterKeystorePassword")), BorderLayout.NORTH);
        panel.add(pass, BorderLayout.CENTER);
        int result = JOptionPane.showConfirmDialog(GitblitAuthority.this, panel, Translation.get("gb.password"), JOptionPane.OK_CANCEL_OPTION);
        if (result == JOptionPane.OK_OPTION) {
            caKeystorePassword = new String(pass.getPassword());
        } else {
            return false;
        }
    }
    X509Metadata metadata = new X509Metadata("localhost", caKeystorePassword);
    setMetadataDefaults(metadata);
    metadata.notAfter = new Date(System.currentTimeMillis() + 10 * TimeUtils.ONEYEAR);
    X509Utils.prepareX509Infrastructure(metadata, folder, this);
    return true;
}
Also used : JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) JPasswordField(javax.swing.JPasswordField) X509Metadata(com.gitblit.utils.X509Utils.X509Metadata) JLabel(javax.swing.JLabel) Point(java.awt.Point) Date(java.util.Date)

Example 7 with X509Metadata

use of com.gitblit.utils.X509Utils.X509Metadata in project gitblit by gitblit.

the class HttpUtils method getUserModelFromCertificate.

/**
	 * Creates a UserModel from a certificate
	 * @param cert
	 * @param usernameOids if unspecified CN is used as the username
	 * @return
	 */
public static UserModel getUserModelFromCertificate(X509Certificate cert, String... usernameOIDs) {
    X509Metadata metadata = X509Utils.getMetadata(cert);
    UserModel user = new UserModel(metadata.commonName);
    user.emailAddress = metadata.emailAddress;
    user.isAuthenticated = false;
    if (usernameOIDs == null || usernameOIDs.length == 0) {
        // use default usename<->CN mapping
        usernameOIDs = new String[] { "CN" };
    }
    // determine username from OID fingerprint
    StringBuilder an = new StringBuilder();
    for (String oid : usernameOIDs) {
        String val = metadata.getOID(oid.toUpperCase(), null);
        if (val != null) {
            an.append(val).append(' ');
        }
    }
    user.username = an.toString().trim();
    return user;
}
Also used : UserModel(com.gitblit.models.UserModel) X509Metadata(com.gitblit.utils.X509Utils.X509Metadata)

Example 8 with X509Metadata

use of com.gitblit.utils.X509Utils.X509Metadata in project gitblit by gitblit.

the class X509UtilsTest method testUserBundle.

@Test
public void testUserBundle() throws Exception {
    File storeFile = new File(folder, X509Utils.CA_KEY_STORE);
    X509Metadata userMetadata = new X509Metadata("james", "james");
    userMetadata.serverHostname = "www.myserver.com";
    userMetadata.userDisplayname = "James Moger";
    userMetadata.passwordHint = "your name";
    File zip = X509Utils.newClientBundle(userMetadata, storeFile, caPassword, log);
    assertTrue(zip.exists());
    List<String> expected = Arrays.asList(userMetadata.commonName + ".pem", userMetadata.commonName + ".p12", userMetadata.commonName + ".cer", "ca.cer", "README.TXT");
    ZipInputStream zis = new ZipInputStream(new FileInputStream(zip));
    ZipEntry entry = null;
    while ((entry = zis.getNextEntry()) != null) {
        assertTrue("Unexpected file: " + entry.getName(), expected.contains(entry.getName()));
    }
    zis.close();
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) X509Metadata(com.gitblit.utils.X509Utils.X509Metadata) ZipEntry(java.util.zip.ZipEntry) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 9 with X509Metadata

use of com.gitblit.utils.X509Utils.X509Metadata in project gitblit by gitblit.

the class X509UtilsTest method prepare.

@Before
public void prepare() throws Exception {
    cleanUp();
    X509Metadata goMetadata = new X509Metadata("localhost", caPassword);
    X509Utils.prepareX509Infrastructure(goMetadata, folder, log);
}
Also used : X509Metadata(com.gitblit.utils.X509Utils.X509Metadata) Before(org.junit.Before)

Aggregations

X509Metadata (com.gitblit.utils.X509Utils.X509Metadata)9 File (java.io.File)5 UserModel (com.gitblit.models.UserModel)4 PrivateKey (java.security.PrivateKey)3 X509Certificate (java.security.cert.X509Certificate)3 Date (java.util.Date)3 Test (org.junit.Test)3 BorderLayout (java.awt.BorderLayout)2 IOException (java.io.IOException)2 FileBasedConfig (org.eclipse.jgit.storage.file.FileBasedConfig)2 AuthenticationProvider (com.gitblit.auth.AuthenticationProvider)1 UsernamePasswordAuthenticationProvider (com.gitblit.auth.AuthenticationProvider.UsernamePasswordAuthenticationProvider)1 GitblitAuthority (com.gitblit.authority.GitblitAuthority)1 NewCertificateConfig (com.gitblit.authority.NewCertificateConfig)1 HeaderPanel (com.gitblit.client.HeaderPanel)1 GitblitContext (com.gitblit.servlet.GitblitContext)1 RevocationReason (com.gitblit.utils.X509Utils.RevocationReason)1 X509Log (com.gitblit.utils.X509Utils.X509Log)1 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)1 InMemoryDirectoryServerConfig (com.unboundid.ldap.listener.InMemoryDirectoryServerConfig)1