Martin Körper
2014-07-21 15:13:06 UTC
Hi,
I'm new to bouncycastle and have a problem with creating a valid client
certificate request.
I tried something like this (bouncycastle for java, v1.50):
import java.security.cert.X509Certificate;
import org.bouncycastle.crypto.tls.Certificate;
...
public class ClientAuthTlsServer extends DefaultTlsServer {
private Vector<X500Name> clientCAs = null;
public void setClientCAs(Vector<X509Certificate> rootCerts)
{
clientCAs = new Vector<X500Name>();
for(X509Certificate cert : rootCerts)
{
try {
Certificate tlsCert = parseBcTlsCertificate(cert.getEncoded());
clientCAs.add(tlsCert.getCertificateAt(0).getSubject());
}
catch (Exception e) {
}
}
}
private Certificate parseBcTlsCertificate(byte[] derEncodedCertificate)
throws IOException
{
X509CertificateHolder certHolder = new
X509CertificateHolder(derEncodedCertificate);
return new Certificate(new org.bouncycastle.asn1.x509.Certificate[]
{certHolder.toASN1Structure()});
}
@Override
public CertificateRequest getCertificateRequest()
{
return new CertificateRequest(new short[] {
ClientCertificateType.rsa_sign }, null, clientCAs);
}
}
This always results in a malformed packet.
I analyzed the problem using wireshark and tracked it down to
org.bouncycastle.asn1.DERSequence
.encode, line 88:
out.write(BERTags.SEQUENCE | BERTags.CONSTRUCTED);
Somehow this is written to the stream where the length of the subsequent
DN is expected instead (at least by wireshark).
So my question is:
Am I doing something wrong or is this a bug maybe?
Thanks in advance for your help.
Regards,
Martin Körper
I'm new to bouncycastle and have a problem with creating a valid client
certificate request.
I tried something like this (bouncycastle for java, v1.50):
import java.security.cert.X509Certificate;
import org.bouncycastle.crypto.tls.Certificate;
...
public class ClientAuthTlsServer extends DefaultTlsServer {
private Vector<X500Name> clientCAs = null;
public void setClientCAs(Vector<X509Certificate> rootCerts)
{
clientCAs = new Vector<X500Name>();
for(X509Certificate cert : rootCerts)
{
try {
Certificate tlsCert = parseBcTlsCertificate(cert.getEncoded());
clientCAs.add(tlsCert.getCertificateAt(0).getSubject());
}
catch (Exception e) {
}
}
}
private Certificate parseBcTlsCertificate(byte[] derEncodedCertificate)
throws IOException
{
X509CertificateHolder certHolder = new
X509CertificateHolder(derEncodedCertificate);
return new Certificate(new org.bouncycastle.asn1.x509.Certificate[]
{certHolder.toASN1Structure()});
}
@Override
public CertificateRequest getCertificateRequest()
{
return new CertificateRequest(new short[] {
ClientCertificateType.rsa_sign }, null, clientCAs);
}
}
This always results in a malformed packet.
I analyzed the problem using wireshark and tracked it down to
org.bouncycastle.asn1.DERSequence
.encode, line 88:
out.write(BERTags.SEQUENCE | BERTags.CONSTRUCTED);
Somehow this is written to the stream where the length of the subsequent
DN is expected instead (at least by wireshark).
So my question is:
Am I doing something wrong or is this a bug maybe?
Thanks in advance for your help.
Regards,
Martin Körper