1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package dk.sosi.seal.pki;
30
31 import java.security.cert.X509Certificate;
32
33
34
35
36
37 public class OCESCertificateResolver implements CertificateResolver {
38
39 private IntermediateCertificateCache cache;
40
41 public OCESCertificateResolver(IntermediateCertificateCache cache) {
42 this.cache = cache;
43 }
44
45 public X509Certificate getIssuingCertificate(X509Certificate certificate) {
46 if (certificate == null) {
47 throw new IllegalArgumentException("'certificate' must not be null");
48 }
49 if (OCESUtil.isOCES1Certificate(certificate)) {
50 if (OCESUtil.isIssuerOf(certificate, OCESCertificationAuthority.OCES_1_ROOT_CERTIFICATE)) {
51 return OCESCertificationAuthority.OCES_1_ROOT_CERTIFICATE;
52 } else if (OCESUtil.isIssuerOf(certificate, OCESTestCertificationAuthority.OCES_1_TEST_ROOT_CERTIFICATE)) {
53 return OCESTestCertificationAuthority.OCES_1_TEST_ROOT_CERTIFICATE;
54 } else {
55 throw constructPKIException(certificate);
56 }
57 } else if (OCESUtil.isOCES2Certificate(certificate)) {
58 if (OCESUtil.isIntermediateCertificate(certificate)) {
59 if (OCESUtil.isIssuerOf(certificate, OCESCertificationAuthority.OCES_2_ROOT_CERTIFICATE)) {
60 return OCESCertificationAuthority.OCES_2_ROOT_CERTIFICATE;
61 } else if (OCESUtil.isIssuerOf(certificate, OCESTestCertificationAuthority.OCES_2_TEST_IG_ROOT_CERTIFICATE)) {
62 return OCESTestCertificationAuthority.OCES_2_TEST_IG_ROOT_CERTIFICATE;
63 } else if (OCESUtil.isIssuerOf(certificate, OCESTestCertificationAuthority.OCES_2_TEST_PP_ROOT_CERTIFICATE)) {
64 return OCESTestCertificationAuthority.OCES_2_TEST_PP_ROOT_CERTIFICATE;
65 } else {
66 throw constructPKIException(certificate);
67 }
68 } else {
69 X509Certificate intermediateCertificate = cache.getCertificate(OCESUtil.retrieveIntermediateCertificateURI(certificate));
70 if (OCESUtil.isIssuerOf(certificate, intermediateCertificate)) {
71 return intermediateCertificate;
72 } else {
73 throw constructPKIException(certificate);
74 }
75 }
76 } else {
77 throw constructPKIException(certificate);
78 }
79 }
80
81 private PKIException constructPKIException(X509Certificate certificate) {
82 return new PKIException("Unable to resolve issuing certificate with DN: " + certificate.getIssuerX500Principal().getName());
83 }
84
85 }