1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.gridsystems.innergrid.serializers;
18
19 import java.io.ByteArrayInputStream;
20 import java.security.cert.CertificateException;
21 import java.security.cert.CertificateFactory;
22 import java.security.cert.X509Certificate;
23
24 import org.apache.axis.InternalException;
25 import org.apache.axis.encoding.Base64;
26 import org.apache.axis.encoding.DeserializationContext;
27 import org.apache.axis.encoding.Deserializer;
28 import org.apache.axis.encoding.DeserializerImpl;
29 import org.xml.sax.SAXException;
30
31
32
33
34
35
36
37 public class CertificateDeserializer extends DeserializerImpl implements Deserializer {
38
39
40
41 private static final long serialVersionUID = 1435657457748L;
42
43
44
45
46 private final StringBuffer buffer = new StringBuffer();
47
48
49
50
51 @Override public void characters(char[] chars, int start, int end) {
52 buffer.append(chars, start, end);
53 }
54
55
56
57
58 @Override public void onEndElement(String namespace, String localName,
59 DeserializationContext context) throws SAXException {
60
61
62 String buf = buffer.toString();
63 buffer.setLength(0);
64
65 byte[] encoded = Base64.decode(buf);
66 ByteArrayInputStream bais = new ByteArrayInputStream(encoded);
67
68 try {
69 CertificateFactory cf = CertificateFactory.getInstance("X.509");
70 while (bais.available() > 0) {
71 value = (X509Certificate)cf.generateCertificate(bais);
72 return;
73 }
74 } catch (CertificateException e) {
75 throw new InternalException(e);
76 }
77
78 throw new SAXException("No encoded certificates in '" + buf + "'");
79 }
80 }