1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.ssl;
17
18 import javax.security.cert.CertificateException;
19 import javax.security.cert.CertificateExpiredException;
20 import javax.security.cert.CertificateNotYetValidException;
21 import javax.security.cert.X509Certificate;
22 import java.math.BigInteger;
23 import java.security.InvalidKeyException;
24 import java.security.NoSuchAlgorithmException;
25 import java.security.NoSuchProviderException;
26 import java.security.Principal;
27 import java.security.PublicKey;
28 import java.security.SignatureException;
29 import java.util.Date;
30
31 final class OpenSslJavaxX509Certificate extends X509Certificate {
32 private final byte[] bytes;
33 private X509Certificate wrapped;
34
35 public OpenSslJavaxX509Certificate(byte[] bytes) {
36 this.bytes = bytes;
37 }
38
39 @Override
40 public void checkValidity() throws CertificateExpiredException, CertificateNotYetValidException {
41 unwrap().checkValidity();
42 }
43
44 @Override
45 public void checkValidity(Date date) throws CertificateExpiredException, CertificateNotYetValidException {
46 unwrap().checkValidity(date);
47 }
48
49 @Override
50 public int getVersion() {
51 return unwrap().getVersion();
52 }
53
54 @Override
55 public BigInteger getSerialNumber() {
56 return unwrap().getSerialNumber();
57 }
58
59 @Override
60 public Principal getIssuerDN() {
61 return unwrap().getIssuerDN();
62 }
63
64 @Override
65 public Principal getSubjectDN() {
66 return unwrap().getSubjectDN();
67 }
68
69 @Override
70 public Date getNotBefore() {
71 return unwrap().getNotBefore();
72 }
73
74 @Override
75 public Date getNotAfter() {
76 return unwrap().getNotAfter();
77 }
78
79 @Override
80 public String getSigAlgName() {
81 return unwrap().getSigAlgName();
82 }
83
84 @Override
85 public String getSigAlgOID() {
86 return unwrap().getSigAlgOID();
87 }
88
89 @Override
90 public byte[] getSigAlgParams() {
91 return unwrap().getSigAlgParams();
92 }
93
94 @Override
95 public byte[] getEncoded() {
96 return bytes.clone();
97 }
98
99 @Override
100 public void verify(PublicKey key)
101 throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException,
102 SignatureException {
103 unwrap().verify(key);
104 }
105
106 @Override
107 public void verify(PublicKey key, String sigProvider)
108 throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException,
109 SignatureException {
110 unwrap().verify(key, sigProvider);
111 }
112
113 @Override
114 public String toString() {
115 return unwrap().toString();
116 }
117
118 @Override
119 public PublicKey getPublicKey() {
120 return unwrap().getPublicKey();
121 }
122
123 private X509Certificate unwrap() {
124 X509Certificate wrapped = this.wrapped;
125 if (wrapped == null) {
126 try {
127 wrapped = this.wrapped = X509Certificate.getInstance(bytes);
128 } catch (CertificateException e) {
129 throw new IllegalStateException(e);
130 }
131 }
132 return wrapped;
133 }
134 }