Ejemplo n.º 1
0
  @Test
  public void testCMD() throws Exception {
    Authentication auth =
        new SkeletonKeyClientBuilder()
            .username("wburke")
            .password("geheim")
            .authentication("Skeleton Key");
    ResteasyClient client = new ResteasyClient();
    WebTarget target = client.target(generateBaseUrl());
    String tiny = target.path("tokens").path("url").request().post(Entity.json(auth), String.class);
    System.out.println(tiny);
    System.out.println("tiny.size: " + tiny.length());
    Security.addProvider(new BouncyCastleProvider());

    KeyPair keyPair = KeyPairGenerator.getInstance("RSA", "BC").generateKeyPair();
    PrivateKey privateKey = keyPair.getPrivate();
    X509Certificate cert = KeyTools.generateTestCertificate(keyPair);

    byte[] signed = p7s(privateKey, cert, null, tiny.getBytes());

    CMSSignedData data = new CMSSignedData(signed);
    byte[] bytes = (byte[]) data.getSignedContent().getContent();
    System.out.println("BYTES: " + new String(bytes));
    System.out.println("size:" + signed.length);
    System.out.println("Base64.size: " + Base64.encodeBytes(signed).length());

    SignerInformation signer =
        (SignerInformation) data.getSignerInfos().getSigners().iterator().next();
    System.out.println("valid: " + signer.verify(cert, "BC"));
  }
Ejemplo n.º 2
0
  @BeforeClass
  public static void before() throws Exception {
    deployment = new ResteasyDeployment();
    deployment.setSecurityEnabled(true);
    deployment.setApplicationClass(SApp.class.getName());

    EmbeddedContainer.start(deployment);
    SkeletonKeyApplication app = ((SApp) deployment.getApplication()).app;

    KeyPair keyPair = KeyPairGenerator.getInstance("RSA", "BC").generateKeyPair();
    privateKey = keyPair.getPrivate();
    certificate = KeyTools.generateTestCertificate(keyPair);
    app.getTokenService().setCertificate(certificate);
    app.getTokenService().setPrivateKey(privateKey);

    StoredUser admin = new StoredUser();
    admin.setName("Bill");
    admin.setUsername("wburke");
    HashMap<String, String> creds = new HashMap<String, String>();
    creds.put("password", "geheim");
    admin.setCredentials(creds);
    app.getUsers().create(admin);

    Project project = new Project();
    project.setName("Skeleton Key");
    project.setEnabled(true);
    app.getProjects().createProject(project);

    Role adminRole = new Role();
    adminRole.setName("admin");
    app.getRoles().create(adminRole);

    app.getProjects().addUserRole(project.getId(), admin.getId(), adminRole.getId());

    // Test export/import
    System.out.println(new Loader().export(app.getCache()));

    try {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      new Loader().export(app.getCache(), baos);
      ByteArrayInputStream bios = new ByteArrayInputStream(baos.toByteArray());
      app.getCache().clear();
      new Loader().importStore(bios, app.getCache());
    } catch (Exception e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
  }