01: package org.bouncycastle.asn1.test;
02:
03: import java.io.ByteArrayInputStream;
04: import java.io.ByteArrayOutputStream;
05:
06: import org.bouncycastle.asn1.ASN1InputStream;
07: import org.bouncycastle.asn1.ASN1Sequence;
08: import org.bouncycastle.asn1.DEROutputStream;
09: import org.bouncycastle.asn1.pkcs.CertificationRequest;
10: import org.bouncycastle.util.encoders.Base64;
11: import org.bouncycastle.util.test.SimpleTestResult;
12: import org.bouncycastle.util.test.Test;
13: import org.bouncycastle.util.test.TestResult;
14:
15: public class PKCS10Test implements Test {
16: byte[] req1 = Base64
17: .decode("MIHoMIGTAgEAMC4xDjAMBgNVBAMTBVRlc3QyMQ8wDQYDVQQKEwZBbmFUb20xCzAJBgNVBAYTAlNF"
18: + "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALlEt31Tzt2MlcOljvacJgzQVhmlMoqAOgqJ9Pgd3Gux"
19: + "Z7/WcIlgW4QCB7WZT21O1YoghwBhPDMcNGrHei9kHQkCAwEAAaAAMA0GCSqGSIb3DQEBBQUAA0EA"
20: + "NDEI4ecNtJ3uHwGGlitNFq9WxcoZ0djbQJ5hABMotav6gtqlrwKXY2evaIrsNwkJtNdwwH18aQDU"
21: + "KCjOuBL38Q==");
22:
23: byte[] req2 = Base64
24: .decode("MIIB6TCCAVICAQAwgagxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRQwEgYDVQQH"
25: + "EwtTYW50YSBDbGFyYTEMMAoGA1UEChMDQUJCMVEwTwYDVQQLHEhQAAAAAAAAAG8AAAAAAAAAdwAA"
26: + "AAAAAABlAAAAAAAAAHIAAAAAAAAAIAAAAAAAAABUAAAAAAAAABxIAAAAAAAARAAAAAAAAAAxDTAL"
27: + "BgNVBAMTBGJsdWUwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANETRZ+6occCOrFxNhfKIp4C"
28: + "mMkxwhBNb7TnnahpbM9O0r4hrBPcfYuL7u9YX/jN0YNUP+/CiT39HhSe/bikaBPDEyNsl988I8vX"
29: + "piEdgxYq/+LTgGHbjRsRYCkPtmzwBbuBldNF8bV7pu0v4UScSsExmGqqDlX1TbPU8KkPU1iTAgMB"
30: + "AAGgADANBgkqhkiG9w0BAQQFAAOBgQAFbrs9qUwh93CtETk7DeUD5HcdCnxauo1bck44snSV6MZV"
31: + "OCIGaYu1501kmhEvAtVVRr6SEHwimfQDDIjnrWwYsEr/DT6tkTZAbfRd3qUu3iKjT0H0vlUZp0hJ"
32: + "66mINtBM84uZFBfoXiWY8M3FuAnGmvy6ah/dYtJorTxLKiGkew==");
33:
34: public String getName() {
35: return "PKCS10";
36: }
37:
38: public TestResult pkcs10Test(String testName, byte[] req) {
39: try {
40: ByteArrayInputStream bIn = new ByteArrayInputStream(req);
41: ASN1InputStream aIn = new ASN1InputStream(bIn);
42:
43: CertificationRequest r = new CertificationRequest(
44: (ASN1Sequence) aIn.readObject());
45:
46: ByteArrayOutputStream bOut = new ByteArrayOutputStream();
47: DEROutputStream dOut = new DEROutputStream(bOut);
48:
49: dOut.writeObject(r.getDERObject());
50:
51: byte[] bytes = bOut.toByteArray();
52:
53: if (bytes.length != req.length) {
54: return new SimpleTestResult(false, getName() + ": "
55: + testName + " failed length test");
56: }
57:
58: for (int i = 0; i != req.length; i++) {
59: if (bytes[i] != req[i]) {
60: return new SimpleTestResult(false, getName() + ": "
61: + testName + " failed comparison test");
62: }
63: }
64: } catch (Exception e) {
65: return new SimpleTestResult(false, getName()
66: + ": Exception - " + testName + " " + e.toString());
67: }
68:
69: return new SimpleTestResult(true, getName() + ": Okay");
70: }
71:
72: public TestResult perform() {
73: TestResult res = pkcs10Test("basic CR", req1);
74:
75: if (!res.isSuccessful()) {
76: return res;
77: }
78:
79: return pkcs10Test("Universal CR", req2);
80: }
81:
82: public static void main(String[] args) {
83: Test test = new PKCS10Test();
84:
85: TestResult result = test.perform();
86:
87: System.out.println(result);
88: }
89: }
|