All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.dentrassi.crypto.pem.AbstractMutablePemKeyStore Maven / Gradle / Ivy

Go to download

This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and JMS BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up with different versions on classes on the class path).

There is a newer version: 34.0.0.Final
Show newest version
/*
 * Copyright (c) 2019 Sergio Moreno and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Sergio Moreno - Initial implementation
 *    Jens Reimann - minor cleanups
 */

package de.dentrassi.crypto.pem;

import java.io.IOException;
import java.io.OutputStream;
import java.security.Key;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * Class that implements a few mutation methods in the keystore.
* It's abstract to allow to subclasses to choose how have to load its keys and certificates. *

* This is a mutable, but not peristable implementation, of a keystore. It is intended for use cases where an * application expects the keystore to be mutable, and so we try to give our best to fulfill this expectation. However * we do not implement the "store" methods. *

*/ public abstract class AbstractMutablePemKeyStore extends AbstractPemKeyStore { @Override protected Map initializeEmpty() { return new HashMap<>(); } @Override public void engineSetKeyEntry(final String alias, final Key key, final char[] password, final Certificate[] chain) throws KeyStoreException { Objects.requireNonNull(alias); Objects.requireNonNull(key); final Entry entry = new Entry(key, chain.clone()); this.entries.put(alias, entry); } @Override public void engineSetKeyEntry(final String alias, final byte[] key, final Certificate[] chain) throws KeyStoreException { // Actually we should implement this operaton, but currently we don't throw new KeyStoreException("Unsupported operation"); } @Override public void engineSetCertificateEntry(final String alias, final Certificate cert) throws KeyStoreException { Objects.requireNonNull(alias); Objects.requireNonNull(cert); final Entry entry = new Entry(null, new Certificate[] { cert }); this.entries.put(alias, entry); } @Override public void engineDeleteEntry(final String alias) throws KeyStoreException { this.entries.remove(alias); } @Override public void engineStore(final OutputStream stream, final char[] password) throws IOException, NoSuchAlgorithmException, CertificateException { throw new IOException("Unsupported operation"); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy