Esempio n. 1
0
  public void destroy() throws BeeException {
    lib.bee_reset_error();
    lib.bee_destroy_object(bee, handle);
    Errors.checkError();

    handle = null;
    bee = null;
  }
Esempio n. 2
0
 public void setTemplate(Template t) throws BeeException {
   lib.bee_reset_error();
   lib.bee_set_attrs(bee, handle, t.getPointer());
   Errors.checkError();
 }
Esempio n. 3
0
  public Template getTemplate() throws BeeException {
    Pkcs11Class c = null;
    boolean foundClass = true;
    boolean noEx = true;
    Template t = new Template();

    t.addToken();
    t.addPrivate();
    t.addModifiable();
    t.addLabel();
    t.addClass();
    t.addKeyType();
    t.addId();
    t.addDerive();
    t.addLocal();

    lib.bee_reset_error();
    lib.bee_get_attrs(bee, handle, t.getPointer());
    Errors.checkError();

    try {
      c = t.getObjClass();
    } catch (BeeException e) {
      foundClass = false;
    }

    if (foundClass) {
      Template keyAttrs = new Template();
      switch (c.getCl().intValue()) {
        case Pkcs11Class.SECRET_KEY:
          keyAttrs.addEncrypt();
          keyAttrs.addDecrypt();
          keyAttrs.addWrap();
          keyAttrs.addUnwrap();
          keyAttrs.addSign();
          keyAttrs.addVerify();
          keyAttrs.addNeverExtractable();
          keyAttrs.addExtractable();
          keyAttrs.addAlwaysSensitive();
          keyAttrs.addSensitive();

          getByteKeyAttr(t, "Value");
          break;
        case Pkcs11Class.PUBLIC_KEY:
          keyAttrs.addEncrypt();
          keyAttrs.addWrap();
          keyAttrs.addVerify();

          // CKA_MODULUS_BITS
          Template p = new Template();
          p.addModulusBits();
          try {
            lib.bee_get_attrs(bee, handle, p.getPointer());
            Errors.checkError();
          } catch (BeeException e) {
            noEx = false;
            t.setModulusBits(-1);
          }

          if (noEx) t.setModulusBits(p.getModulusBits());

          // CKA_MODULUS
          getByteKeyAttr(t, "Modulus");

          // CKA_PUBLIC_EXPONENT
          getByteKeyAttr(t, "PublicExponent");
          break;
        case Pkcs11Class.PRIVATE_KEY:
          keyAttrs.addDecrypt();
          keyAttrs.addUnwrap();
          keyAttrs.addSign();
          keyAttrs.addNeverExtractable();
          keyAttrs.addExtractable();
          keyAttrs.addAlwaysSensitive();
          keyAttrs.addSensitive();

          // CKA_MODULUS
          getByteKeyAttr(t, "Modulus");
          // CKA_PRIVATE_EXPONENT
          getByteKeyAttr(t, "PrivateExponent");
          break;
      }
      lib.bee_reset_error();
      lib.bee_get_attrs(bee, handle, keyAttrs.getPointer());
      Errors.checkError();
      t.merge(keyAttrs);
    }

    return t;
  }