List of usage examples for org.bouncycastle.asn1.x509 AttributeCertificate getEncoded
public byte[] getEncoded() throws IOException
From source file:doti.gca.view.PrincipalFrame.java
private void btnExecutarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExecutarActionPerformed try {/*from ww w . jav a 2s . c o m*/ progresbar.setValue(5); txtLog.append("Carregando certificado...\n"); // Carrega dados do certificado int linhaSelecionada = jTable3.getSelectedRow(); String alias = ((Item) dados[linhaSelecionada][0]).getAlias(); X509Certificate certificado = KeyStoreLoader.loadCertificado(alias); PrivateKey chavePrivada = KeyStoreLoader.loadPrivateKey(alias); progresbar.setValue(progresbar.getValue() + 5); txtLog.append("Carregando token de acesso a API...\n"); // Requisita token para acessar a api String token = JOptionPane.showInputDialog(new JPasswordField(), "Insira o token de acesso ao Servidor.", "Token de acesso", JOptionPane.PLAIN_MESSAGE); progresbar.setValue(progresbar.getValue() + 1); txtLog.append("Carregando carteirinhas...\n"); // Carrega carteirinhas da api JSONObject json = RemoteHttp.getCarteirinhas(token); JSONObject entidade = json.getJSONObject("entidade"); JSONArray carteirinhas = entidade.getJSONArray("carteirinhas"); progresbar.setValue(progresbar.getValue() + 10); // Cria JSONArray para enviar certificados JSONArray certificadosJSON = new JSONArray(); // Itera sobre as carteirinhas baixadas txtLog.append("Criando certificados...\n"); Iterator it = carteirinhas.iterator(); int acrecimo = 80 / carteirinhas.length(); while (it.hasNext()) { JSONObject carteirinha = (JSONObject) it.next(); // Cria certificado AttributeCertificate ca = createCertificado(certificado, chavePrivada, carteirinha, entidade.getString("auth_info_access"), entidade.getString("crl_dist_points")); JSONObject cert = new JSONObject(); cert.put("carteirinha_id", carteirinha.getLong("id")); cert.put("certificado", GCABase64.encode(ca.getEncoded())); certificadosJSON.put(cert); System.out.println("Certificado: " + GCABase64.encode(ca.getEncoded())); txtLog.append(" criado certificado para id " + carteirinha.getLong("id") + "\n"); progresbar.setValue(progresbar.getValue() + acrecimo); } txtLog.append(carteirinhas.length() + " Certificados Criados\n"); txtLog.append("Enviando certificados...\n"); // Envia certificados para servidor RemoteHttp.sendCertificados(new JSONObject().put("certificados", certificadosJSON), token); txtLog.append(carteirinhas.length() + " Certificados enviados\n"); txtLog.append("Concludo\n"); progresbar.setValue(100); } catch (IOException ex) { new GCAException(ex.getMessage(), "ERRO", JOptionPane.ERROR_MESSAGE); } catch (Exception ex) { txtLog.append(ex.toString()); progresbar.setValue(0); } }
From source file:org.italiangrid.voms.test.utils.EchoVOMSProtocol.java
License:Apache License
public VOMSResponse doRequest(VOMSServerInfo endpoint, X509Credential credential, VOMSACRequest request) { VOMSAA aa = new VOMSAA(aaCredential, endpoint.getVoName(), endpoint.getURL().getHost(), endpoint.getURL().getPort()); int lifetimeInSeconds = request.getLifetime(); Calendar cal = Calendar.getInstance(); Date now = cal.getTime();// www. j ava2s .c om cal.add(Calendar.SECOND, lifetimeInSeconds); Date endTime = cal.getTime(); List<String> fqans; if (request.getRequestedFQANs().isEmpty()) { fqans = new ArrayList<String>(); fqans.add("/" + request.getVoName()); } else fqans = request.getRequestedFQANs(); AttributeCertificate ac = aa.getAC(credential, fqans, null, request.getTargets(), now, endTime); VOMSResponse r = Mockito.mock(VOMSResponse.class); try { Mockito.when(r.getAC()).thenReturn(ac.getEncoded()); } catch (IOException e) { throw new VOMSError(e.getMessage(), e); } return r; }