Search in sources :

Example 11 with P11ObjectIdentifier

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

the class IaikP11Slot method importSecretKey0.

@Override
protected P11Identity importSecretKey0(long keyType, byte[] keyValue, String label, P11NewKeyControl control) throws P11TokenException {
    ValuedSecretKey template = new ValuedSecretKey(keyType);
    template.getToken().setBooleanValue(true);
    template.getLabel().setCharArrayValue(label.toCharArray());
    template.getSign().setBooleanValue(true);
    template.getSensitive().setBooleanValue(true);
    template.getExtractable().setBooleanValue(control.isExtractable());
    template.getValue().setByteArrayValue(keyValue);
    SecretKey key;
    Session session = borrowWritableSession();
    try {
        if (labelExists(session, label)) {
            throw new IllegalArgumentException("label " + label + " exists, please specify another one");
        }
        byte[] id = generateKeyId(session);
        template.getId().setByteArrayValue(id);
        try {
            key = (SecretKey) session.createObject(template);
        } catch (TokenException ex) {
            throw new P11TokenException("could not create secret key", ex);
        }
        P11ObjectIdentifier objId = new P11ObjectIdentifier(id, label);
        P11EntityIdentifier entityId = new P11EntityIdentifier(slotId, objId);
        return new IaikP11Identity(this, entityId, key);
    } finally {
        returnWritableSession(session);
    }
}
Also used : ValuedSecretKey(iaik.pkcs.pkcs11.objects.ValuedSecretKey) ValuedSecretKey(iaik.pkcs.pkcs11.objects.ValuedSecretKey) SecretKey(iaik.pkcs.pkcs11.objects.SecretKey) P11TokenException(org.xipki.security.exception.P11TokenException) TokenException(iaik.pkcs.pkcs11.TokenException) P11TokenException(org.xipki.security.exception.P11TokenException) P11EntityIdentifier(org.xipki.security.pkcs11.P11EntityIdentifier) P11ObjectIdentifier(org.xipki.security.pkcs11.P11ObjectIdentifier) Session(iaik.pkcs.pkcs11.Session)

Example 12 with P11ObjectIdentifier

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

the class ProxyP11Slot method getCertificate.

private X509Cert getCertificate(P11ObjectIdentifier certId) throws P11TokenException {
    P11EntityIdentifier entityId = new P11EntityIdentifier(slotId, certId);
    byte[] resp = module.send(P11ProxyConstants.ACTION_GET_CERT, new Asn1P11EntityIdentifier(entityId));
    if (resp == null) {
        return null;
    }
    try {
        return new X509Cert(X509Util.parseCert(resp), resp);
    } catch (CertificateException ex) {
        throw new P11TokenException("could not parse certificate:" + ex.getMessage(), ex);
    }
}
Also used : Asn1P11EntityIdentifier(org.xipki.p11proxy.msg.Asn1P11EntityIdentifier) X509Cert(org.xipki.security.X509Cert) P11TokenException(org.xipki.security.exception.P11TokenException) Asn1P11EntityIdentifier(org.xipki.p11proxy.msg.Asn1P11EntityIdentifier) P11EntityIdentifier(org.xipki.security.pkcs11.P11EntityIdentifier) CertificateException(java.security.cert.CertificateException)

Example 13 with P11ObjectIdentifier

use of org.xipki.security.pkcs11.P11ObjectIdentifier 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 14 with P11ObjectIdentifier

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

Example 15 with P11ObjectIdentifier

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

P11ObjectIdentifier (org.xipki.security.pkcs11.P11ObjectIdentifier)30 P11EntityIdentifier (org.xipki.security.pkcs11.P11EntityIdentifier)15 P11Slot (org.xipki.security.pkcs11.P11Slot)15 P11TokenException (org.xipki.security.exception.P11TokenException)10 X509Certificate (java.security.cert.X509Certificate)8 Asn1P11EntityIdentifier (org.xipki.p11proxy.msg.Asn1P11EntityIdentifier)6 IllegalCmdParamException (org.xipki.console.karaf.IllegalCmdParamException)5 Session (iaik.pkcs.pkcs11.Session)4 TokenException (iaik.pkcs.pkcs11.TokenException)4 PublicKey (java.security.PublicKey)4 DEROctetString (org.bouncycastle.asn1.DEROctetString)4 X509Cert (org.xipki.security.X509Cert)4 XiSecurityException (org.xipki.security.exception.XiSecurityException)4 SecretKey (iaik.pkcs.pkcs11.objects.SecretKey)3 ValuedSecretKey (iaik.pkcs.pkcs11.objects.ValuedSecretKey)3 InvalidKeyException (java.security.InvalidKeyException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 CertificateException (java.security.cert.CertificateException)3 P11SlotRefreshResult (org.xipki.security.pkcs11.P11SlotRefreshResult)3 Mechanism (iaik.pkcs.pkcs11.Mechanism)2