- Certificate c = null;
- X509Certificate cert = null;
- String serial = req.getParameter("serial");
- String certData = req.getParameter("cert");
- if (serial != null && !serial.isEmpty()) {
- c = fetchCertificate(serial);
- try {
- cert = c.cert();
- } catch (IOException e) {
- throw new PermamentFormException(new GigiApiException(NOT_LOADED));
- } catch (GeneralSecurityException e) {
- throw new PermamentFormException(new GigiApiException(NOT_LOADED));
- }
- }
- if (certData != null && !certData.isEmpty()) {
- X509Certificate c0;
- byte[] supplied;
- try {
- supplied = PEM.decode("CERTIFICATE", certData);
- c0 = (X509Certificate) CertificateFactory.getInstance("X509").generateCertificate(new ByteArrayInputStream(supplied));
- } catch (IllegalArgumentException e1) {
- throw new PermamentFormException(new GigiApiException("Your certificate could not be parsed"));
- } catch (CertificateException e1) {
- throw new PermamentFormException(new GigiApiException("Your certificate could not be parsed"));
- }
- try {
- String ser = c0.getSerialNumber().toString(16);
- c = fetchCertificate(ser);
- cert = c.cert();
- if ( !Arrays.equals(supplied, cert.getEncoded())) {
- throw new PermamentFormException(new GigiApiException(NOT_FOUND));
- }
- } catch (IOException e) {
- throw new PermamentFormException(new GigiApiException(NOT_LOADED));
- } catch (GeneralSecurityException e) {
- throw new PermamentFormException(new GigiApiException(NOT_LOADED));