Search in sources :

Example 6 with P11EntityIdentifier

use of org.xipki.security.pkcs11.P11EntityIdentifier 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 P11EntityIdentifier

use of org.xipki.security.pkcs11.P11EntityIdentifier 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 P11EntityIdentifier

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

the class ProxyP11Slot method updateCertificate0.

@Override
protected void updateCertificate0(P11ObjectIdentifier objectId, X509Certificate newCert) throws P11TokenException, CertificateException {
    Asn1EntityIdAndCert asn1 = new Asn1EntityIdAndCert(new P11EntityIdentifier(slotId, objectId), newCert);
    module.send(P11ProxyConstants.ACTION_UPDATE_CERT, asn1);
}
Also used : Asn1EntityIdAndCert(org.xipki.p11proxy.msg.Asn1EntityIdAndCert) Asn1P11EntityIdentifier(org.xipki.p11proxy.msg.Asn1P11EntityIdentifier) P11EntityIdentifier(org.xipki.security.pkcs11.P11EntityIdentifier)

Example 9 with P11EntityIdentifier

use of org.xipki.security.pkcs11.P11EntityIdentifier 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)

Example 10 with P11EntityIdentifier

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

the class ProxyP11Slot method refresh0.

@Override
protected P11SlotRefreshResult refresh0() throws P11TokenException {
    P11SlotRefreshResult refreshResult = new P11SlotRefreshResult();
    // mechanisms
    List<Long> mechs = getMechanismsFromServer();
    for (Long mech : mechs) {
        refreshResult.addMechanism(mech);
    }
    // certificates
    List<P11ObjectIdentifier> certIds = getObjectIdsFromServer(P11ProxyConstants.ACTION_GET_CERT_IDS);
    for (P11ObjectIdentifier certId : certIds) {
        X509Cert cert = getCertificate(certId);
        if (cert != null) {
            refreshResult.addCertificate(certId, cert);
        }
    }
    List<P11ObjectIdentifier> keyIds = getObjectIdsFromServer(P11ProxyConstants.ACTION_GET_IDENTITY_IDS);
    for (P11ObjectIdentifier keyId : keyIds) {
        byte[] id = keyId.getId();
        java.security.PublicKey pubKey = null;
        X509Cert cert = refreshResult.getCertForId(id);
        if (cert != null) {
            pubKey = cert.getCert().getPublicKey();
        } else {
            pubKey = getPublicKey(keyId);
        }
        P11EntityIdentifier entityId = new P11EntityIdentifier(slotId, keyId);
        ProxyP11Identity identity;
        if (pubKey == null) {
            identity = new ProxyP11Identity(this, entityId);
        } else {
            X509Certificate[] certs = (cert == null) ? null : new X509Certificate[] { cert.getCert() };
            identity = new ProxyP11Identity(this, entityId, pubKey, certs);
        }
        refreshResult.addIdentity(identity);
    }
    return refreshResult;
}
Also used : Asn1P11EntityIdentifier(org.xipki.p11proxy.msg.Asn1P11EntityIdentifier) P11EntityIdentifier(org.xipki.security.pkcs11.P11EntityIdentifier) PublicKey(java.security.PublicKey) X509Certificate(java.security.cert.X509Certificate) P11SlotRefreshResult(org.xipki.security.pkcs11.P11SlotRefreshResult) X509Cert(org.xipki.security.X509Cert) P11ObjectIdentifier(org.xipki.security.pkcs11.P11ObjectIdentifier) Asn1P11ObjectIdentifier(org.xipki.p11proxy.msg.Asn1P11ObjectIdentifier)

Aggregations

P11EntityIdentifier (org.xipki.security.pkcs11.P11EntityIdentifier)17 P11ObjectIdentifier (org.xipki.security.pkcs11.P11ObjectIdentifier)11 P11TokenException (org.xipki.security.exception.P11TokenException)10 Asn1P11EntityIdentifier (org.xipki.p11proxy.msg.Asn1P11EntityIdentifier)8 PublicKey (java.security.PublicKey)5 X509Certificate (java.security.cert.X509Certificate)4 X509Cert (org.xipki.security.X509Cert)4 Session (iaik.pkcs.pkcs11.Session)3 TokenException (iaik.pkcs.pkcs11.TokenException)3 InvalidKeyException (java.security.InvalidKeyException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 CertificateException (java.security.cert.CertificateException)3 DEROctetString (org.bouncycastle.asn1.DEROctetString)3 Asn1EntityIdAndCert (org.xipki.p11proxy.msg.Asn1EntityIdAndCert)3 BadAsn1ObjectException (org.xipki.security.exception.BadAsn1ObjectException)3 XiSecurityException (org.xipki.security.exception.XiSecurityException)3 SecretKey (iaik.pkcs.pkcs11.objects.SecretKey)2 ValuedSecretKey (iaik.pkcs.pkcs11.objects.ValuedSecretKey)2 P11SlotRefreshResult (org.xipki.security.pkcs11.P11SlotRefreshResult)2 Mechanism (iaik.pkcs.pkcs11.Mechanism)1