Search in sources :

Example 6 with Asn1P11EntityIdentifier

use of org.xipki.p11proxy.msg.Asn1P11EntityIdentifier in project xipki by xipki.

the class ProxyP11Slot method parseGenerateKeypairResult.

private P11Identity parseGenerateKeypairResult(byte[] resp) throws P11TokenException {
    if (resp == null) {
        throw new P11TokenException("server returned no result");
    }
    Asn1P11EntityIdentifier ei;
    try {
        ei = Asn1P11EntityIdentifier.getInstance(resp);
    } catch (BadAsn1ObjectException ex) {
        throw new P11TokenException("invalid ASN1 object Asn1P11EntityIdentifier: " + ex.getMessage(), ex);
    }
    if (!slotId.equals(ei.getSlotId().getSlotId())) {
        throw new P11TokenException("");
    }
    P11EntityIdentifier entityId = ei.getEntityId();
    PublicKey publicKey = getPublicKey(entityId.getObjectId());
    return new ProxyP11Identity(this, entityId, publicKey, null);
}
Also used : Asn1P11EntityIdentifier(org.xipki.p11proxy.msg.Asn1P11EntityIdentifier) PublicKey(java.security.PublicKey) P11TokenException(org.xipki.security.exception.P11TokenException) Asn1P11EntityIdentifier(org.xipki.p11proxy.msg.Asn1P11EntityIdentifier) P11EntityIdentifier(org.xipki.security.pkcs11.P11EntityIdentifier) BadAsn1ObjectException(org.xipki.security.exception.BadAsn1ObjectException)

Example 7 with Asn1P11EntityIdentifier

use of org.xipki.p11proxy.msg.Asn1P11EntityIdentifier in project xipki by xipki.

the class ProxyP11Slot method parseGenerateSecretKeyResult.

private P11Identity parseGenerateSecretKeyResult(byte[] resp) throws P11TokenException {
    if (resp == null) {
        throw new P11TokenException("server returned no result");
    }
    Asn1P11EntityIdentifier ei;
    try {
        ei = Asn1P11EntityIdentifier.getInstance(resp);
    } catch (BadAsn1ObjectException ex) {
        throw new P11TokenException("invalid ASN1 object Asn1P11EntityIdentifier: " + ex.getMessage(), ex);
    }
    if (!slotId.equals(ei.getSlotId().getSlotId())) {
        throw new P11TokenException("");
    }
    P11EntityIdentifier entityId = ei.getEntityId();
    return new ProxyP11Identity(this, entityId);
}
Also used : Asn1P11EntityIdentifier(org.xipki.p11proxy.msg.Asn1P11EntityIdentifier) P11TokenException(org.xipki.security.exception.P11TokenException) Asn1P11EntityIdentifier(org.xipki.p11proxy.msg.Asn1P11EntityIdentifier) P11EntityIdentifier(org.xipki.security.pkcs11.P11EntityIdentifier) BadAsn1ObjectException(org.xipki.security.exception.BadAsn1ObjectException)

Example 8 with Asn1P11EntityIdentifier

use of org.xipki.p11proxy.msg.Asn1P11EntityIdentifier in project xipki by xipki.

the class ProxyP11Slot method removeIdentity0.

@Override
protected void removeIdentity0(P11ObjectIdentifier objectId) throws P11TokenException {
    Asn1P11EntityIdentifier asn1EntityId = new Asn1P11EntityIdentifier(slotId, objectId);
    module.send(P11ProxyConstants.ACTION_REMOVE_IDENTITY, asn1EntityId);
}
Also used : Asn1P11EntityIdentifier(org.xipki.p11proxy.msg.Asn1P11EntityIdentifier)

Example 9 with Asn1P11EntityIdentifier

use of org.xipki.p11proxy.msg.Asn1P11EntityIdentifier in project xipki by xipki.

the class ProxyP11Slot method getPublicKey.

private PublicKey getPublicKey(P11ObjectIdentifier objectId) throws P11UnknownEntityException, P11TokenException {
    P11EntityIdentifier entityId = new P11EntityIdentifier(slotId, objectId);
    byte[] resp = module.send(P11ProxyConstants.ACTION_GET_PUBLICKEY, new Asn1P11EntityIdentifier(entityId));
    if (resp == null) {
        return null;
    }
    SubjectPublicKeyInfo pkInfo = SubjectPublicKeyInfo.getInstance(resp);
    try {
        return KeyUtil.generatePublicKey(pkInfo);
    } catch (NoSuchAlgorithmException | InvalidKeySpecException ex) {
        throw new P11TokenException("could not generate Public Key from SubjectPublicKeyInfo:" + ex.getMessage(), ex);
    }
}
Also used : Asn1P11EntityIdentifier(org.xipki.p11proxy.msg.Asn1P11EntityIdentifier) P11TokenException(org.xipki.security.exception.P11TokenException) Asn1P11EntityIdentifier(org.xipki.p11proxy.msg.Asn1P11EntityIdentifier) P11EntityIdentifier(org.xipki.security.pkcs11.P11EntityIdentifier) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) SubjectPublicKeyInfo(org.bouncycastle.asn1.x509.SubjectPublicKeyInfo)

Aggregations

Asn1P11EntityIdentifier (org.xipki.p11proxy.msg.Asn1P11EntityIdentifier)9 P11TokenException (org.xipki.security.exception.P11TokenException)7 P11EntityIdentifier (org.xipki.security.pkcs11.P11EntityIdentifier)5 BadAsn1ObjectException (org.xipki.security.exception.BadAsn1ObjectException)3 PublicKey (java.security.PublicKey)2 CertificateException (java.security.cert.CertificateException)2 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)2 DEROctetString (org.bouncycastle.asn1.DEROctetString)2 Asn1DigestSecretKeyTemplate (org.xipki.p11proxy.msg.Asn1DigestSecretKeyTemplate)2 Asn1P11Params (org.xipki.p11proxy.msg.Asn1P11Params)2 Asn1SignTemplate (org.xipki.p11proxy.msg.Asn1SignTemplate)2 P11ByteArrayParams (org.xipki.security.pkcs11.P11ByteArrayParams)2 P11IVParams (org.xipki.security.pkcs11.P11IVParams)2 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 X509Certificate (java.security.cert.X509Certificate)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1