Search in sources :

Example 11 with P11Slot

use of org.xipki.security.pkcs11.P11Slot in project xipki by xipki.

the class BSpeedP11ECSignCmd method nextTester.

@Override
protected LoadExecutor nextTester() throws Exception {
    ECControl control = queue.poll();
    if (control == null) {
        return null;
    }
    P11Slot slot = getSlot();
    return new P11ECSignLoadTest(securityFactory, slot, sigAlgo, control.curveName());
}
Also used : P11Slot(org.xipki.security.pkcs11.P11Slot) P11ECSignLoadTest(org.xipki.security.speed.p11.P11ECSignLoadTest) ECControl(org.xipki.security.speed.cmd.ECControl)

Example 12 with P11Slot

use of org.xipki.security.pkcs11.P11Slot in project xipki by xipki.

the class BSpeedP11RSASignCmd method nextTester.

@Override
protected LoadExecutor nextTester() throws Exception {
    RSAControl control = queue.poll();
    if (control == null) {
        return null;
    }
    P11Slot slot = getSlot();
    return new P11RSASignLoadTest(securityFactory, slot, sigAlgo, control.modulusLen(), toBigInt("0x10001"));
}
Also used : P11RSASignLoadTest(org.xipki.security.speed.p11.P11RSASignLoadTest) P11Slot(org.xipki.security.pkcs11.P11Slot) RSAControl(org.xipki.security.speed.cmd.RSAControl)

Example 13 with P11Slot

use of org.xipki.security.pkcs11.P11Slot in project xipki by xipki.

the class P11DSAKeyGenCmd method execute0.

@Override
protected Object execute0() throws Exception {
    if (plen % 1024 != 0) {
        throw new IllegalCmdParamException("plen is not multiple of 1024: " + plen);
    }
    if (qlen == null) {
        if (plen <= 1024) {
            qlen = 160;
        } else if (plen <= 2048) {
            qlen = 224;
        } else {
            qlen = 256;
        }
    }
    P11Slot slot = getSlot();
    P11ObjectIdentifier objId = slot.generateDSAKeypair(plen, qlen, label, getControl());
    finalize("DSA", objId);
    return null;
}
Also used : P11Slot(org.xipki.security.pkcs11.P11Slot) IllegalCmdParamException(org.xipki.console.karaf.IllegalCmdParamException) P11ObjectIdentifier(org.xipki.security.pkcs11.P11ObjectIdentifier)

Example 14 with P11Slot

use of org.xipki.security.pkcs11.P11Slot in project xipki by xipki.

the class ProxyP11Module method refresh.

public void refresh() throws P11TokenException {
    byte[] resp = send(P11ProxyConstants.ACTION_GET_SERVER_CAPS, null);
    Asn1ServerCaps caps;
    try {
        caps = Asn1ServerCaps.getInstance(resp);
    } catch (BadAsn1ObjectException ex) {
        throw new P11TokenException("response is a valid Asn1ServerCaps", ex);
    }
    if (!caps.getVersions().contains(version)) {
        throw new P11TokenException("Server does not support any version supported by the client");
    }
    this.readOnly = caps.isReadOnly();
    resp = send(P11ProxyConstants.ACTION_GET_SLOT_IDS, null);
    ASN1Sequence seq;
    try {
        seq = ASN1Sequence.getInstance(resp);
    } catch (IllegalArgumentException ex) {
        throw new P11TokenException("response is not ASN1Sequence", ex);
    }
    final int n = seq.size();
    Set<P11Slot> slots = new HashSet<>();
    for (int i = 0; i < n; i++) {
        Asn1P11SlotIdentifier asn1SlotId;
        try {
            ASN1Encodable obj = seq.getObjectAt(i);
            asn1SlotId = Asn1P11SlotIdentifier.getInstance(obj);
        } catch (Exception ex) {
            throw new P11TokenException(ex.getMessage(), ex);
        }
        P11SlotIdentifier slotId = asn1SlotId.getSlotId();
        if (!conf.isSlotIncluded(slotId)) {
            continue;
        }
        if (!conf.isSlotIncluded(slotId)) {
            LOG.info("skipped slot {}", slotId);
            continue;
        }
        P11Slot slot = new ProxyP11Slot(this, slotId, conf.isReadOnly(), conf.getP11MechanismFilter());
        slots.add(slot);
    }
    setSlots(slots);
}
Also used : Asn1ServerCaps(org.xipki.p11proxy.msg.Asn1ServerCaps) Asn1P11SlotIdentifier(org.xipki.p11proxy.msg.Asn1P11SlotIdentifier) P11SlotIdentifier(org.xipki.security.pkcs11.P11SlotIdentifier) P11TokenException(org.xipki.security.exception.P11TokenException) P11Slot(org.xipki.security.pkcs11.P11Slot) P11TokenException(org.xipki.security.exception.P11TokenException) BadAsn1ObjectException(org.xipki.security.exception.BadAsn1ObjectException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) BadAsn1ObjectException(org.xipki.security.exception.BadAsn1ObjectException) HashSet(java.util.HashSet) Asn1P11SlotIdentifier(org.xipki.p11proxy.msg.Asn1P11SlotIdentifier)

Example 15 with P11Slot

use of org.xipki.security.pkcs11.P11Slot in project xipki by xipki.

the class P11CertUpdateCmd method execute0.

@Override
protected Object execute0() throws Exception {
    P11Slot slot = getSlot();
    P11ObjectIdentifier objIdentifier = getObjectIdentifier();
    X509Certificate newCert = X509Util.parseCert(certFile);
    slot.updateCertificate(objIdentifier, newCert);
    println("updated certificate");
    return null;
}
Also used : P11Slot(org.xipki.security.pkcs11.P11Slot) P11ObjectIdentifier(org.xipki.security.pkcs11.P11ObjectIdentifier) X509Certificate(java.security.cert.X509Certificate)

Aggregations

P11Slot (org.xipki.security.pkcs11.P11Slot)24 P11ObjectIdentifier (org.xipki.security.pkcs11.P11ObjectIdentifier)15 IllegalCmdParamException (org.xipki.console.karaf.IllegalCmdParamException)8 P11SlotIdentifier (org.xipki.security.pkcs11.P11SlotIdentifier)8 P11Module (org.xipki.security.pkcs11.P11Module)6 X509Certificate (java.security.cert.X509Certificate)5 P11CryptService (org.xipki.security.pkcs11.P11CryptService)5 P11TokenException (org.xipki.security.exception.P11TokenException)3 PublicKey (java.security.PublicKey)2 HashSet (java.util.HashSet)2 Asn1P11SlotIdentifier (org.xipki.p11proxy.msg.Asn1P11SlotIdentifier)2 Asn1ServerCaps (org.xipki.p11proxy.msg.Asn1ServerCaps)2 BadAsn1ObjectException (org.xipki.security.exception.BadAsn1ObjectException)2 P11Identity (org.xipki.security.pkcs11.P11Identity)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 InvalidKeyException (java.security.InvalidKeyException)1