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;
}
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;
}
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();
}
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);
}
Aggregations