be.fedict.hsm.ws.impl.WSSecurityCrypto.java Source code

Java tutorial

Introduction

Here is the source code for be.fedict.hsm.ws.impl.WSSecurityCrypto.java

Source

/*
 * HSM Proxy Project.
 * Copyright (C) 2013 FedICT.
 * Copyright (C) 2011-2012 AGIV.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version
 * 3.0 as published by the Free Software Foundation.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, see 
 * http://www.gnu.org/licenses/.
 */

package be.fedict.hsm.ws.impl;

import java.io.InputStream;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

import javax.security.auth.callback.CallbackHandler;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.security.WSSecurityException;
import org.apache.ws.security.components.crypto.Crypto;
import org.apache.ws.security.components.crypto.CryptoType;

import be.fedict.hsm.model.security.SecurityFunction;

@SecurityFunction("SF.I&A.1")
public class WSSecurityCrypto implements Crypto {

    private static final Log LOG = LogFactory.getLog(WSSecurityCrypto.class);

    private final CertificateFactory certificateFactory;

    private X509Certificate certificate;

    public WSSecurityCrypto() {
        try {
            this.certificateFactory = CertificateFactory.getInstance("X.509");
        } catch (CertificateException e) {
            throw new RuntimeException("X.509 algo not available: " + e.getMessage());
        }
    }

    public byte[] getBytesFromCertificates(X509Certificate[] certs) throws WSSecurityException {
        LOG.debug("getBytesFromCertificates");
        return null;
    }

    public CertificateFactory getCertificateFactory() throws WSSecurityException {
        LOG.debug("getCertificateFactory");
        return null;
    }

    public X509Certificate[] getCertificatesFromBytes(byte[] data) throws WSSecurityException {
        LOG.debug("getCertificatesFromBytes");
        return null;
    }

    public String getCryptoProvider() {
        LOG.debug("getCryptoProvider");
        return null;
    }

    public String getDefaultX509Identifier() throws WSSecurityException {
        LOG.debug("getDefaultX509Identifier");
        return null;
    }

    public PrivateKey getPrivateKey(X509Certificate certificate, CallbackHandler callbackHandler)
            throws WSSecurityException {
        LOG.debug("getPrivateKey(cert, callback)");
        return null;
    }

    public PrivateKey getPrivateKey(String identifier, String password) throws WSSecurityException {
        LOG.debug("getPrivateKey(identifier, password)");
        return null;
    }

    public byte[] getSKIBytesFromCert(X509Certificate cert) throws WSSecurityException {
        LOG.debug("getSKIBytesFromCert");
        return null;
    }

    public X509Certificate[] getX509Certificates(CryptoType cryptoType) throws WSSecurityException {
        LOG.debug("getX509Certificates: " + cryptoType.getType());
        return new X509Certificate[] { this.certificate };
    }

    public String getX509Identifier(X509Certificate cert) throws WSSecurityException {
        LOG.debug("getX509Identifier");
        return null;
    }

    public X509Certificate loadCertificate(InputStream in) throws WSSecurityException {
        LOG.debug("loadCertificate");
        X509Certificate certificate;
        try {
            certificate = (X509Certificate) this.certificateFactory.generateCertificate(in);
        } catch (CertificateException e) {
            throw new WSSecurityException("error loading certificate: " + e.getMessage(), e);
        }
        LOG.debug("certificate subject: " + certificate.getSubjectX500Principal());
        /*
         * JAX-WS is not supposed to be used in a multi-threaded fashion, so
         * this should be OK to do.
         */
        this.certificate = certificate;
        return certificate;
    }

    public void setCertificateFactory(String provider, CertificateFactory certFactory) {
        LOG.debug("setCertifiateFactory");
    }

    public void setCryptoProvider(String provider) {
        LOG.debug("setCryptoProvider");
    }

    public void setDefaultX509Identifier(String identifier) {
        LOG.debug("setDefaultX509Identifier");
    }

    public boolean verifyTrust(X509Certificate[] certs) throws WSSecurityException {
        LOG.debug("verifyTrust(certs)");
        return false;
    }

    public boolean verifyTrust(PublicKey publicKey) throws WSSecurityException {
        LOG.debug("verifyTrust(publicKey)");
        return false;
    }

    public boolean verifyTrust(X509Certificate[] certs, boolean enableRevocation) throws WSSecurityException {
        LOG.debug("verifyTrust(certs, enableRevocation)");
        return false;
    }
}