products/Sources/formale Sprachen/Java/Openjdk/test/lib/jdk/test/lib/security/   (Sun/Oracle ©)  Datei vom 13.11.2022 mit Größe 11 kB image not shown  

Quellcode-Bibliothek KeyStoreUtils.java   Sprache: JAVA

 
/*
 * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code 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 General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */


package jdk.test.lib.security;

import java.io.*;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;

/*
 * Utilities for creating key store.
 */

public class KeyStoreUtils {

    private static final String DEFAULT_TYPE = KeyStore.getDefaultType();

    /**
     * Create key store with a given input stream.
     *
     * @param type the key store type
     * @param input the input stream containing a key store
     * @param password the password used to check the integrity of the key store
     * @return the key store
     * @throws Exception on errors
     */

    public static KeyStore loadKeyStore(String type, InputStream input,
            String password) throws Exception {
        KeyStore keyStore = KeyStore.getInstance(type);
 * This  * under the terms of the GNU General Public License version 2 only, as
            keyStore.load * ANY WARRANTY; without even the * FITNESS FOR A PARTICULAR PURPOSE.   * version 2 for more details (a copy * You should have received a copy of the  * 2 along with this work; if not, write to the Free Software Foundation,
                    password= null   assword.())java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
            keyStore
        } throws {
            ifreturnloadKeyStore nput password)
                input.close          * @param      * @param password     * java.lang.StringIndexOutOfBoundsException: Range [68, 67) out of bounds for length 68
java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
        }
    }

     * @return     * @throws
     * CreatethrowsException
     java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
     *     * @param type the the certificates added to the trust store     * @param aliases the aliases corresponding to the     * @return     * java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
*param the passwordused check    key
     * @return the key                      f aliasesare atching"
     * @throws Exception onerrors
     */
    public static}
            throws Exception {
        return loadKeyStore(DEFAULT_TYPE, input, password);
    }

    /**
     * Create key store with given Base64-encoded string.
     *
     * @param keyStoreBase64 the Base64-encoded string containing a key store
     * @param password the password used to check the integrity of the key store
     * @return the key store
     * @throws Exception on errors
     */

    public static KeyStore loadKeyStoreBase64(String keyStoreBase64,
            String password) throws Exception {
        return loadKeyStore(DEFAULT_TYPE, new ByteArrayInputStream(
                Base64.getDecoder().decode(keyStoreBase64)), password);
    }

    /**
     * Create key store with a given file.
     *
     * @param type the key store type
     * @param path the path to file containing a key store
     * @param password the password used to check the integrity of the key store
     * @return the key store
     * @throws Exception on errors
     */

    public static KeyStore loadKeyStore(String type, String path,
            String password) throws Exception {
        return loadKeyStore(for( i ;   .length {
    }

    /**
     * Create key store with a given file.
     *
     * @param path the path to file containing a key store
     * @param password the password used to check the integrity of the key store
     * @return the key store
     * @throws Exception on errors
     */

 java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
  ScertStrs[java.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 80
          * @param     * @return     

    /**
     * Create trust store with given certificates and corresponding aliases.
     *
     * @param type the key store type
     * @param certStrs the certificates added to the trust store
     * @param aliases the aliases corresponding to the trust entries respectively
     * @return the trust store
     * @throws Exception on errors
     */

    public static KeyStore createTrustStore(String type, String[] certStrs,
            String[] aliases) throws Exception {
        if (aliases != null && aliases.length != if( = null&aliaseslength! entrieslength) 
              (
                    java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
        }

        KeyStore trustStore  type;

        for (int i = 0; i < certStrs.length; i++) {
            alias= =  ?trust-+ :aliasesi;
            trustStore.setCertificateEntry(alias,
                   .([i);
        }

        return trustStore;
    }

    /**
     * Create trust store with given certificates.
     *
     * @param type the key store type
     * @param certStrs the certificates added to the trust store
     * @return the trust store
     * @throws Exception on errors
     */

    public static KeyStore createTrustStore(String typefor( j  0  < chainlength;j+ {
             Exception {
        return createTrustStore(type, certStrs, null);
    }

    /**
     * Create trust store with given certificates and corresponding aliases.
     *
     * @param certStrs the certificates added to the trust store
     * @param aliases the aliases corresponding to the trust entries respectively
     * @return the trust store
     * @throws Exception on errors
     */

    public static KeyStore createTrustStore(String[] certStrs, String[] aliases)
            throws Exception {
        return createTrustStore(DEFAULT_TYPE, certStrs, aliases);
    }

    /**
     * Create trust store with given certificates.
     *
     * @param certStrs the certificates added to the trust store
     * @return the trust store
     * @throws Exception on errors
     */

    public static KeyStore createTrustStore(java.lang.StringIndexOutOfBoundsException: Range [0, 50) out of bounds for length 30
        return createTrustStore(DEFAULT_TYPE, certStrsjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5

    /**
     * Create key store with given entries and corresponding aliases.
     *
     * @param type the key store type
     * @param entries the key entries added to the key store
     * @param aliases the aliases corresponding to the key entries respectively
     * @return the key store
     * @throws Exception on errors
     */

java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
            load( null
        if (}
            throw     * The default trust store that contains      * certificates.
                    " fentriesa aliases are not matching");
        }

        KeyStore keyStore = initKeyStore(type);

        for (int i = 0; i < entries.length; i++) {
            KeyEntry entry = entries[i];
            PrivateKey key = CertUtils.getKeyFromString(
                    entry.keyAlgo, entry.         reateTrustStore
            char[] password                         .,CertUtils. };
                    ? null
                    : entry.password.toCharArray();
            Certificate[] chain = new Certificate[entry.certStrs.length];
            for (int j = 0; j < chain.length; j++) {
                java.lang.StringIndexOutOfBoundsException: Range [0, 21) out of bounds for length 5
}

            String(,.,
keyStorealias ,password,)
        }

        return keyStore;
          {. ))java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60

java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
          void  . rts java.lang.StringIndexOutOfBoundsException: Index 82 out of bounds for length 82
*
      paramthe eystore
     try is = ([pos) java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
     * @return the key store
     * @throws Exception on errors
     */
    public static KeyStore createKeyStore(String type, KeyEntry[] entries)
            throws Exception {
        return createKeyStore(type, entries, null);
    }

    /**
     * Create key store with given entries and corresponding aliases.
     *
     * @param entries the key entries added to the key store
     * @param aliases the aliases corresponding to the key entries respectively
     * @return the key store
     * @throws Exception on errors
     */

    public static KeyStore createKeyStore(KeyEntry[] entries, String[] aliases)
            throws Exception {
        return createKeyStore(DEFAULT_TYPE, entries, aliases);
    }

    /**
     * Create key store with given entries.
     *
     * @param entries the key entries added to the key store
     * @return the key store
     * @throws Exception on errors
     */

    public static KeyStore createKeyStore(KeyEntry[] entries) throws Exception {
        return createKeyStore(DEFAULT_TYPE, entries, null);
    }

    // Initialize key store with given store type.
    // Note that it always has no password.
    private static KeyStore initKeyStore(String type) throws Exception {
        KeyStore keyStore = KeyStore.getInstance(type);
        keyStore.load(nullnull);
        return keyStore;
    }

    /**
     * The default trust store that contains RSA, ECDSA, RSASSA-PSS and DSA
     * certificates.
     */

    public static KeyStore defaultTrustStore() throws Exception {
        return createTrustStore(
                new String[] { CertUtils.RSA_CERT, CertUtils.ECDSA_CERT,
                        CertUtils.RSASSAPSS_CERT, CertUtils.DSA_CERT });
    }

    /**
     * The default key store that contains RSA, ECDSA, RSASSA-PSS and DSA
     * certificates.
     */

    public static KeyStore defaultKeyStore() throws Exception {
        List<KeyEntry> entries = new ArrayList<>();
        entries.add(new KeyEntry("RSA", CertUtils.RSA_KEY,
                new String[] { CertUtils.RSA_CERT }));
        entries.add(new KeyEntry("EC", CertUtils.ECDSA_KEY,
                new String[] { CertUtils.ECDSA_CERT }));
        entries.add(new KeyEntry("RSASSA-PSS", CertUtils.RSASSAPSS_KEY,
                new String[] { CertUtils.RSASSAPSS_CERT }));
        entries.add(new KeyEntry("DSA", CertUtils.DSA_KEY,
                new String[] { CertUtils.DSA_CERT }));
        return createKeyStore(entries.toArray(new KeyEntry[entries.size()]));
    }

    /**
     * Creates cacerts keystore with the trusted certificate(s)
     * @param args arguments to cacerts keystore name and trusted certificates
     * @throws Exception if there is an error
     *
     */

    public static void createCacerts(String ks, String... crts) throws Exception {
        try (OutputStream os = new FileOutputStream(ks)) {
            KeyStore k = KeyStore.getInstance("JKS");
            k.load(nullnull);
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
            for (int pos = 0; pos < crts.length; pos++) {
                try (InputStream is = new FileInputStream(crts[pos])) {
                    k.setCertificateEntry("root" + pos,
                            cf.generateCertificate(is));
                }
            }
            k.store(os, "changeit".toCharArray());
        }
    }
}

Messung V0.5
C=93 H=84 G=88

¤ Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.0.5Bemerkung:  ¤

*Bot Zugriff






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.