}
public void test01Pkcs10RequestMessage() throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, SignatureException {
X509Name dn = new X509Name("CN=Test,OU=foo");
PKCS10CertificationRequest basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
keyPair.getPublic(), new DERSet(), keyPair.getPrivate());
PKCS10RequestMessage msg = new PKCS10RequestMessage(basicpkcs10);
String username = msg.getUsername();
assertEquals("Test", username);
dn = new X509Name("C=SE, O=Foo, CN=Test Testsson");
basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
keyPair.getPublic(), new DERSet(), keyPair.getPrivate());
msg = new PKCS10RequestMessage(basicpkcs10);
username = msg.getUsername();
assertEquals("Test", username);
// oid for unstructuredName, will be handles specially by EJBCA
dn = new X509Name("CN=Test + 1.2.840.113549.1.9.2=AttrValue1");
basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
keyPair.getPublic(), new DERSet(), keyPair.getPrivate());
msg = new PKCS10RequestMessage(basicpkcs10);
username = msg.getUsername();
assertEquals("Test", username);
dn = new X509Name("CN=Test + 1.2.840.113549.1.9.2=AttrValue1 AttrValue2");
basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
keyPair.getPublic(), new DERSet(), keyPair.getPrivate());
msg = new PKCS10RequestMessage(basicpkcs10);
username = msg.getUsername();
assertEquals("Test", username);
dn = new X509Name("CN=Test+1.2.840.113549.1.9.2=AttrValue1");
basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
keyPair.getPublic(), new DERSet(), keyPair.getPrivate());
msg = new PKCS10RequestMessage(basicpkcs10);
username = msg.getUsername();
assertEquals("Test", username);
dn = new X509Name("CN=Test+1.2.840.113549.1.9.2=AttrValue1 AttrValue2");
basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
keyPair.getPublic(), new DERSet(), keyPair.getPrivate());
msg = new PKCS10RequestMessage(basicpkcs10);
username = msg.getUsername();
assertEquals("Test", username);
// Completely unknown oid
dn = new X509Name("CN=Test + 1.2.840.113549.1.9.3=AttrValue1");
basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
keyPair.getPublic(), new DERSet(), keyPair.getPrivate());
msg = new PKCS10RequestMessage(basicpkcs10);
username = msg.getUsername();
assertEquals("Test", username);
dn = new X509Name("CN=Test + 1.2.840.113549.1.9.3=AttrValue1 AttrValue2");
basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
keyPair.getPublic(), new DERSet(), keyPair.getPrivate());
msg = new PKCS10RequestMessage(basicpkcs10);
username = msg.getUsername();
assertEquals("Test", username);
dn = new X509Name("CN=Test+1.2.840.113549.1.9.3=AttrValue1");
basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
keyPair.getPublic(), new DERSet(), keyPair.getPrivate());
msg = new PKCS10RequestMessage(basicpkcs10);
username = msg.getUsername();
assertEquals("Test", username);
dn = new X509Name("CN=Test+1.2.840.113549.1.9.3=AttrValue1 AttrValue2");
basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
keyPair.getPublic(), new DERSet(), keyPair.getPrivate());
msg = new PKCS10RequestMessage(basicpkcs10);
username = msg.getUsername();
assertEquals("Test", username);
dn = new X509Name("1.2.840.113549.1.9.3=AttrValue1 AttrValue2+CN=Test");
basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
keyPair.getPublic(), new DERSet(), keyPair.getPrivate());
msg = new PKCS10RequestMessage(basicpkcs10);
username = msg.getUsername();
assertEquals("Test", username);
dn = new X509Name("1.2.840.113549.1.9.3=AttrValue1 AttrValue2+CN=Test+O=abc");
basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
keyPair.getPublic(), new DERSet(), keyPair.getPrivate());
msg = new PKCS10RequestMessage(basicpkcs10);
username = msg.getUsername();
assertEquals("Test", username);
dn = new X509Name("1.2.840.113549.1.9.3=AttrValue1\\+\\= AttrValue2+CN=Test+O=abc"); // very strange, but should still be valid
basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
keyPair.getPublic(), new DERSet(), keyPair.getPrivate());
msg = new PKCS10RequestMessage(basicpkcs10);
username = msg.getUsername();
assertEquals("Test", username);