use of org.gudy.bouncycastle.asn1.x509.GeneralNames in project keystore-explorer by kaikramer.
the class DAuthorityKeyIdentifier method prepopulateWithAuthorityCertDetails.
private void prepopulateWithAuthorityCertDetails(X500Name authorityCertName, BigInteger authorityCertSerialNumber) {
if (authorityCertName != null) {
try {
GeneralName generalName = new GeneralName(GeneralName.directoryName, authorityCertName);
GeneralNames generalNames = new GeneralNames(generalName);
jgnAuthorityCertIssuer.setGeneralNames(generalNames);
} catch (Exception ex) {
DError dError = new DError(this, ex);
dError.setLocationRelativeTo(this);
dError.setVisible(true);
return;
}
}
if (authorityCertSerialNumber != null) {
jtfAuthorityCertSerialNumber.setText("" + authorityCertSerialNumber.toString());
jtfAuthorityCertSerialNumber.setCaretPosition(0);
}
}
use of org.gudy.bouncycastle.asn1.x509.GeneralNames in project keystore-explorer by kaikramer.
the class DAuthorityKeyIdentifier method okPressed.
private void okPressed() {
byte[] keyIdentifier = jkiKeyIdentifier.getKeyIdentifier();
GeneralNames authorityCertIssuer = jgnAuthorityCertIssuer.getGeneralNames();
BigInteger authorityCertSerialNumber = null;
String authorityCertSerialNumberStr = jtfAuthorityCertSerialNumber.getText().trim();
if (authorityCertSerialNumberStr.length() != 0) {
try {
authorityCertSerialNumber = new BigInteger(authorityCertSerialNumberStr);
if (authorityCertSerialNumber.compareTo(BigInteger.ONE) < 0) {
JOptionPane.showMessageDialog(this, res.getString("DAuthorityKeyIdentifier.AuthorityCertSerialNumberNonZero.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(this, res.getString("DAuthorityKeyIdentifier.AuthorityCertSerialNumberNotInteger.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
}
// serial number are required
if ((keyIdentifier == null) && ((authorityCertIssuer.getNames().length == 0) || (authorityCertSerialNumber == null))) {
JOptionPane.showMessageDialog(this, res.getString("DAuthorityKeyIdentifier.ValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
AuthorityKeyIdentifier authorityKeyIdentifier;
if ((keyIdentifier != null) && (authorityCertSerialNumber == null)) {
// only key identifier
authorityKeyIdentifier = new AuthorityKeyIdentifier(keyIdentifier);
} else if (keyIdentifier == null) {
// only issuer / serial
authorityKeyIdentifier = new AuthorityKeyIdentifier(authorityCertIssuer, authorityCertSerialNumber);
} else {
// both
authorityKeyIdentifier = new AuthorityKeyIdentifier(keyIdentifier, authorityCertIssuer, authorityCertSerialNumber);
}
try {
value = authorityKeyIdentifier.getEncoded(ASN1Encoding.DER);
} catch (IOException ex) {
DError dError = new DError(this, ex);
dError.setLocationRelativeTo(this);
dError.setVisible(true);
return;
}
closeDialog();
}
use of org.gudy.bouncycastle.asn1.x509.GeneralNames in project keystore-explorer by kaikramer.
the class DIssuerAlternativeName method okPressed.
private void okPressed() {
GeneralNames issuerAlternativeName = jgnAlternativeName.getGeneralNames();
if (issuerAlternativeName.getNames().length == 0) {
JOptionPane.showMessageDialog(this, res.getString("DIssuerAlternativeName.ValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
try {
value = issuerAlternativeName.getEncoded(ASN1Encoding.DER);
} catch (IOException ex) {
DError dError = new DError(this, ex);
dError.setLocationRelativeTo(this);
dError.setVisible(true);
return;
}
closeDialog();
}
use of org.gudy.bouncycastle.asn1.x509.GeneralNames in project dcos-commons by mesosphere.
the class CertificateNamesGeneratorTest method testDiscoveryNameAddedAsSan.
@Test
public void testDiscoveryNameAddedAsSan() {
Mockito.when(mockTaskSpec.getDiscovery()).thenReturn(Optional.of(mockDiscoverySpec));
Mockito.when(mockDiscoverySpec.getPrefix()).thenReturn(Optional.of("custom-name"));
CertificateNamesGenerator certificateNamesGenerator = new CertificateNamesGenerator(TestConstants.SERVICE_NAME, mockTaskSpec, mockPodInstance, mockSchedulerConfig);
GeneralNames sans = certificateNamesGenerator.getSANs();
Assert.assertEquals(1, sans.getNames().length);
List<String> names = Arrays.stream(sans.getNames()).map(name -> name.getName().toString()).collect(Collectors.toList());
Assert.assertEquals(1, names.size());
Assert.assertTrue(names.contains(String.format("custom-name-0.%s.%s", TestConstants.SERVICE_NAME, Constants.DNS_TLD)));
// echo -n "custom-name-0.service-name.autoip.dcos.thisdcos.directory" | sha1sum
Assert.assertEquals("6ce3490a694a0917beec2bd5f7ac978be7a59ef0", certificateNamesGenerator.getSANsHash());
}
use of org.gudy.bouncycastle.asn1.x509.GeneralNames in project dcos-commons by mesosphere.
the class CertificateNamesGeneratorTest method testVipsAddedAsSans.
@Test
public void testVipsAddedAsSans() {
Mockito.when(mockResourceSet.getResources()).thenReturn(Collections.singletonList(mockVIPSpec));
Mockito.when(mockVIPSpec.getVipName()).thenReturn("test-vip");
Mockito.when(mockVIPSpec.getPort()).thenReturn(8000L);
CertificateNamesGenerator certificateNamesGenerator = new CertificateNamesGenerator(TestConstants.SERVICE_NAME, mockTaskSpec, mockPodInstance, mockSchedulerConfig);
GeneralNames sans = certificateNamesGenerator.getSANs();
Assert.assertEquals(2, sans.getNames().length);
List<String> names = Arrays.stream(sans.getNames()).map(name -> name.getName().toString()).collect(Collectors.toList());
Assert.assertEquals(2, names.size());
Assert.assertTrue(names.contains(taskDnsName(TestConstants.TASK_NAME, TestConstants.SERVICE_NAME)));
Assert.assertTrue(names.contains(taskVipName("test-vip", TestConstants.SERVICE_NAME)));
// echo -n "some-pod-test-task-name.service-name.autoip.dcos.thisdcos.directory;test-vip.service-name.l4lb.thisdcos.directory" | sha1sum
Assert.assertEquals("99f8ec48101c439ce41eb62662056dc0ff5d227a", certificateNamesGenerator.getSANsHash());
}
Aggregations