Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AC22F1894D for ; Sat, 26 Dec 2015 21:50:36 +0000 (UTC) Received: (qmail 32997 invoked by uid 500); 26 Dec 2015 21:50:36 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 32944 invoked by uid 500); 26 Dec 2015 21:50:36 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 32935 invoked by uid 99); 26 Dec 2015 21:50:36 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 26 Dec 2015 21:50:36 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5312AE0568; Sat, 26 Dec 2015 21:50:36 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: drankye@apache.org To: commits@directory.apache.org Date: Sat, 26 Dec 2015 21:50:36 -0000 Message-Id: <4cbcbefbc3294cf8aa69978b0d61a49e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] directory-kerby git commit: PKIX. Renamed a package Repository: directory-kerby Updated Branches: refs/heads/master 15bb462ee -> a793d8642 PKIX. Renamed a package Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/f808cf34 Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/f808cf34 Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/f808cf34 Branch: refs/heads/master Commit: f808cf34261a28d822ccaa42ac7415ce74fb8fd2 Parents: 15bb462 Author: Kai Zheng Authored: Sun Dec 27 04:41:40 2015 +0800 Committer: Kai Zheng Committed: Sun Dec 27 04:41:40 2015 +0800 ---------------------------------------------------------------------- .../kerby/kerberos/kdc/PkinitKdcTest.java | 2 +- .../java/org/apache/kerby/pki/PkiLoader.java | 114 ------------------- .../java/org/apache/kerby/pkix/PkiLoader.java | 114 +++++++++++++++++++ .../org/apache/kerby/x509/PkiLoaderTest.java | 2 +- 4 files changed, 116 insertions(+), 116 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/f808cf34/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/PkinitKdcTest.java ---------------------------------------------------------------------- diff --git a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/PkinitKdcTest.java b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/PkinitKdcTest.java index 7a11eff..f226a97 100644 --- a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/PkinitKdcTest.java +++ b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/PkinitKdcTest.java @@ -25,7 +25,7 @@ import org.apache.kerby.kerberos.kerb.server.KdcConfigKey; import org.apache.kerby.kerberos.kerb.server.KdcTestBase; import org.apache.kerby.kerberos.kerb.type.ticket.SgtTicket; import org.apache.kerby.kerberos.kerb.type.ticket.TgtTicket; -import org.apache.kerby.pki.PkiLoader; +import org.apache.kerby.pkix.PkiLoader; import org.junit.Before; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/f808cf34/kerby-pkix/src/main/java/org/apache/kerby/pki/PkiLoader.java ---------------------------------------------------------------------- diff --git a/kerby-pkix/src/main/java/org/apache/kerby/pki/PkiLoader.java b/kerby-pkix/src/main/java/org/apache/kerby/pki/PkiLoader.java deleted file mode 100644 index 7523f39..0000000 --- a/kerby-pkix/src/main/java/org/apache/kerby/pki/PkiLoader.java +++ /dev/null @@ -1,114 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.kerby.pki; - -import org.apache.commons.ssl.PKCS8Key; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.security.GeneralSecurityException; -import java.security.KeyFactory; -import java.security.PrivateKey; -import java.security.cert.Certificate; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; -import java.security.spec.PKCS8EncodedKeySpec; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -public class PkiLoader { - - public List loadCerts(String certFile) throws IOException { - InputStream is; - try { - is = new FileInputStream(new File(certFile)); - } catch (FileNotFoundException e) { - throw new IOException("No cert file found", e); - } - return loadCerts(is); - } - - public List loadCerts(InputStream inputStream) throws IOException { - CertificateFactory certFactory = null; - try { - certFactory = CertificateFactory.getInstance("X.509"); - Collection certs = (Collection) - certFactory.generateCertificates(inputStream); - return new ArrayList(certs); - } catch (CertificateException e) { - throw new IOException("Failed to load certificates", e); - } - } - - public PrivateKey loadPrivateKey(String keyFile, String password) throws IOException { - InputStream in = null; - try { - in = new FileInputStream("/path/to/pkcs8_private_key.der"); - } catch (FileNotFoundException e) { - throw new IOException("No cert file found", e); - } - return loadPrivateKey(in, password); - } - - public PrivateKey loadPrivateKey(InputStream inputStream, String password) throws IOException { - try { - return doLoadPrivateKey(inputStream, password); - } catch (GeneralSecurityException e) { - throw new IOException("Failed to load private key", e); - } catch (IOException e) { - throw new IOException("Failed to load private key", e); - } - } - - private PrivateKey doLoadPrivateKey( - InputStream inputStream, String password) throws GeneralSecurityException, IOException { - if (password == null) { - password = ""; - } - // If the provided InputStream is encrypted, we need a password to decrypt - // it. If the InputStream is not encrypted, then the password is ignored - // (can be null). The InputStream can be DER (raw ASN.1) or PEM (base64). - PKCS8Key pkcs8 = new PKCS8Key(inputStream, password.toCharArray()); - - // If an unencrypted PKCS8 key was provided, then this actually returns - // exactly what was originally passed inputStream (with no changes). If an OpenSSL - // key was provided, it gets reformatted as PKCS #8 first, and so these - // bytes will still be PKCS #8, not OpenSSL. - byte[] decrypted = pkcs8.getDecryptedBytes(); - PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(decrypted); - - // A Java PrivateKey object is born. - PrivateKey pk = null; - if (pkcs8.isDSA()) { - pk = KeyFactory.getInstance("DSA").generatePrivate(spec); - } else if (pkcs8.isRSA()) { - pk = KeyFactory.getInstance("RSA").generatePrivate(spec); - } - - // For lazier types: - pk = pkcs8.getPrivateKey(); - - return pk; - } -} http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/f808cf34/kerby-pkix/src/main/java/org/apache/kerby/pkix/PkiLoader.java ---------------------------------------------------------------------- diff --git a/kerby-pkix/src/main/java/org/apache/kerby/pkix/PkiLoader.java b/kerby-pkix/src/main/java/org/apache/kerby/pkix/PkiLoader.java new file mode 100644 index 0000000..402e5d4 --- /dev/null +++ b/kerby-pkix/src/main/java/org/apache/kerby/pkix/PkiLoader.java @@ -0,0 +1,114 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.kerby.pkix; + +import org.apache.commons.ssl.PKCS8Key; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.security.GeneralSecurityException; +import java.security.KeyFactory; +import java.security.PrivateKey; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.security.spec.PKCS8EncodedKeySpec; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class PkiLoader { + + public List loadCerts(String certFile) throws IOException { + InputStream is; + try { + is = new FileInputStream(new File(certFile)); + } catch (FileNotFoundException e) { + throw new IOException("No cert file found", e); + } + return loadCerts(is); + } + + public List loadCerts(InputStream inputStream) throws IOException { + CertificateFactory certFactory = null; + try { + certFactory = CertificateFactory.getInstance("X.509"); + Collection certs = + certFactory.generateCertificates(inputStream); + return new ArrayList<>(certs); + } catch (CertificateException e) { + throw new IOException("Failed to load certificates", e); + } + } + + public PrivateKey loadPrivateKey(String keyFile, String password) throws IOException { + InputStream in = null; + try { + in = new FileInputStream("/path/to/pkcs8_private_key.der"); + } catch (FileNotFoundException e) { + throw new IOException("No cert file found", e); + } + return loadPrivateKey(in, password); + } + + public PrivateKey loadPrivateKey(InputStream inputStream, String password) throws IOException { + try { + return doLoadPrivateKey(inputStream, password); + } catch (GeneralSecurityException e) { + throw new IOException("Failed to load private key", e); + } catch (IOException e) { + throw new IOException("Failed to load private key", e); + } + } + + private PrivateKey doLoadPrivateKey( + InputStream inputStream, String password) throws GeneralSecurityException, IOException { + if (password == null) { + password = ""; + } + // If the provided InputStream is encrypted, we need a password to decrypt + // it. If the InputStream is not encrypted, then the password is ignored + // (can be null). The InputStream can be DER (raw ASN.1) or PEM (base64). + PKCS8Key pkcs8 = new PKCS8Key(inputStream, password.toCharArray()); + + // If an unencrypted PKCS8 key was provided, then this actually returns + // exactly what was originally passed inputStream (with no changes). If an OpenSSL + // key was provided, it gets reformatted as PKCS #8 first, and so these + // bytes will still be PKCS #8, not OpenSSL. + byte[] decrypted = pkcs8.getDecryptedBytes(); + PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(decrypted); + + // A Java PrivateKey object is born. + PrivateKey pk = null; + if (pkcs8.isDSA()) { + pk = KeyFactory.getInstance("DSA").generatePrivate(spec); + } else if (pkcs8.isRSA()) { + pk = KeyFactory.getInstance("RSA").generatePrivate(spec); + } + + // For lazier types: + pk = pkcs8.getPrivateKey(); + + return pk; + } +} http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/f808cf34/kerby-pkix/src/test/java/org/apache/kerby/x509/PkiLoaderTest.java ---------------------------------------------------------------------- diff --git a/kerby-pkix/src/test/java/org/apache/kerby/x509/PkiLoaderTest.java b/kerby-pkix/src/test/java/org/apache/kerby/x509/PkiLoaderTest.java index b78e466..c150fc4 100644 --- a/kerby-pkix/src/test/java/org/apache/kerby/x509/PkiLoaderTest.java +++ b/kerby-pkix/src/test/java/org/apache/kerby/x509/PkiLoaderTest.java @@ -19,7 +19,7 @@ */ package org.apache.kerby.x509; -import org.apache.kerby.pki.PkiLoader; +import org.apache.kerby.pkix.PkiLoader; import org.junit.Before; import org.junit.Test;