Search in sources :

Example 6 with X509Cert

use of org.xipki.security.X509Cert in project xipki by xipki.

the class IaikP11Slot method updateCertificate0.

@Override
protected void updateCertificate0(P11ObjectIdentifier objectId, X509Certificate newCert) throws P11TokenException {
    removeCerts(objectId);
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
    // CHECKSTYLE:SKIP
    }
    X509PublicKeyCertificate newCertTemp = createPkcs11Template(new X509Cert(newCert), objectId.getId(), objectId.getLabelChars());
    Session session = borrowWritableSession();
    try {
        session.createObject(newCertTemp);
    } catch (TokenException ex) {
        throw new P11TokenException("could not createObject: " + ex.getMessage(), ex);
    } finally {
        returnWritableSession(session);
    }
}
Also used : X509Cert(org.xipki.security.X509Cert) P11TokenException(org.xipki.security.exception.P11TokenException) TokenException(iaik.pkcs.pkcs11.TokenException) P11TokenException(org.xipki.security.exception.P11TokenException) X509PublicKeyCertificate(iaik.pkcs.pkcs11.objects.X509PublicKeyCertificate) Session(iaik.pkcs.pkcs11.Session)

Example 7 with X509Cert

use of org.xipki.security.X509Cert in project xipki by xipki.

the class IaikP11Slot method analyseSingleKey.

private void analyseSingleKey(Session session, PrivateKey privKey, P11SlotRefreshResult refreshResult) throws P11TokenException, XiSecurityException {
    byte[] id = privKey.getId().getByteArrayValue();
    java.security.PublicKey pubKey = null;
    X509Cert cert = refreshResult.getCertForId(id);
    if (cert != null) {
        pubKey = cert.getCert().getPublicKey();
    } else {
        PublicKey p11PublicKey = getPublicKeyObject(session, id, null);
        if (p11PublicKey == null) {
            LOG.info("neither certificate nor public key for the key (" + hex(id) + " is available");
            return;
        }
        pubKey = generatePublicKey(p11PublicKey);
    }
    P11ObjectIdentifier objectId = new P11ObjectIdentifier(id, toString(privKey.getLabel()));
    X509Certificate[] certs = (cert == null) ? null : new X509Certificate[] { cert.getCert() };
    IaikP11Identity identity = new IaikP11Identity(this, new P11EntityIdentifier(slotId, objectId), privKey, pubKey, certs);
    refreshResult.addIdentity(identity);
}
Also used : DSAPublicKey(iaik.pkcs.pkcs11.objects.DSAPublicKey) RSAPublicKey(iaik.pkcs.pkcs11.objects.RSAPublicKey) SM2PublicKey(iaik.pkcs.pkcs11.objects.SM2PublicKey) ECPublicKey(iaik.pkcs.pkcs11.objects.ECPublicKey) PublicKey(iaik.pkcs.pkcs11.objects.PublicKey) X509Cert(org.xipki.security.X509Cert) P11EntityIdentifier(org.xipki.security.pkcs11.P11EntityIdentifier) P11ObjectIdentifier(org.xipki.security.pkcs11.P11ObjectIdentifier) X509Certificate(java.security.cert.X509Certificate)

Example 8 with X509Cert

use of org.xipki.security.X509Cert in project xipki by xipki.

the class IaikP11Slot method addCert0.

@Override
protected void addCert0(P11ObjectIdentifier objectId, X509Certificate cert) throws P11TokenException {
    X509PublicKeyCertificate newCaCertTemp = createPkcs11Template(new X509Cert(cert), objectId.getId(), objectId.getLabelChars());
    Session session = borrowWritableSession();
    try {
        session.createObject(newCaCertTemp);
    } catch (TokenException ex) {
        throw new P11TokenException(ex.getMessage(), ex);
    } finally {
        returnWritableSession(session);
    }
}
Also used : X509Cert(org.xipki.security.X509Cert) P11TokenException(org.xipki.security.exception.P11TokenException) TokenException(iaik.pkcs.pkcs11.TokenException) P11TokenException(org.xipki.security.exception.P11TokenException) X509PublicKeyCertificate(iaik.pkcs.pkcs11.objects.X509PublicKeyCertificate) Session(iaik.pkcs.pkcs11.Session)

Example 9 with X509Cert

use of org.xipki.security.X509Cert 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 10 with X509Cert

use of org.xipki.security.X509Cert in project xipki by xipki.

the class EmulatorP11Slot method readCertificate.

private X509Cert readCertificate(byte[] keyId) throws CertificateException, IOException {
    byte[] encoded = IoUtil.read(new File(certDir, hex(keyId) + VALUE_FILE_SUFFIX));
    X509Certificate cert = X509Util.parseCert(encoded);
    return new X509Cert(cert, encoded);
}
Also used : X509Cert(org.xipki.security.X509Cert) File(java.io.File) X509Certificate(java.security.cert.X509Certificate)

Aggregations

X509Cert (org.xipki.security.X509Cert)14 X509Certificate (java.security.cert.X509Certificate)5 P11EntityIdentifier (org.xipki.security.pkcs11.P11EntityIdentifier)4 CertificateException (java.security.cert.CertificateException)3 P11TokenException (org.xipki.security.exception.P11TokenException)3 P11ObjectIdentifier (org.xipki.security.pkcs11.P11ObjectIdentifier)3 Session (iaik.pkcs.pkcs11.Session)2 TokenException (iaik.pkcs.pkcs11.TokenException)2 X509PublicKeyCertificate (iaik.pkcs.pkcs11.objects.X509PublicKeyCertificate)2 File (java.io.File)2 PublicKey (java.security.PublicKey)2 OperationException (org.xipki.ca.api.OperationException)2 X509Ca (org.xipki.ca.server.impl.X509Ca)2 Asn1P11EntityIdentifier (org.xipki.p11proxy.msg.Asn1P11EntityIdentifier)2 P11SlotRefreshResult (org.xipki.security.pkcs11.P11SlotRefreshResult)2 DSAPublicKey (iaik.pkcs.pkcs11.objects.DSAPublicKey)1 ECPublicKey (iaik.pkcs.pkcs11.objects.ECPublicKey)1 PublicKey (iaik.pkcs.pkcs11.objects.PublicKey)1 RSAPublicKey (iaik.pkcs.pkcs11.objects.RSAPublicKey)1 SM2PublicKey (iaik.pkcs.pkcs11.objects.SM2PublicKey)1