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 0B13418BFB for ; Thu, 14 May 2015 08:03:23 +0000 (UTC) Received: (qmail 73417 invoked by uid 500); 14 May 2015 08:03:23 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 73366 invoked by uid 500); 14 May 2015 08:03:23 -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 73357 invoked by uid 99); 14 May 2015 08:03:23 -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; Thu, 14 May 2015 08:03:23 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C1DA5E051A; Thu, 14 May 2015 08:03:23 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: plusplusjiajia@apache.org To: commits@directory.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: directory-kerby git commit: [DIRKRB-239]-Implement the interface RadomProvider.Contributed by Yaning. Date: Thu, 14 May 2015 08:03:23 +0000 (UTC) Repository: directory-kerby Updated Branches: refs/heads/master f186424f4 -> 12ac895f8 [DIRKRB-239]-Implement the interface RadomProvider.Contributed by Yaning. Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/12ac895f Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/12ac895f Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/12ac895f Branch: refs/heads/master Commit: 12ac895f80c773d7108d3167108f2597797718d1 Parents: f186424 Author: plusplusjiajia Authored: Thu May 14 16:08:01 2015 +0800 Committer: plusplusjiajia Committed: Thu May 14 16:08:01 2015 +0800 ---------------------------------------------------------------------- .../kerberos/kerb/crypto/random/JavaRandom.java | 47 ++++++++++++++ .../kerb/crypto/random/NativeRandom.java | 67 ++++++++++++++++++++ 2 files changed, 114 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/12ac895f/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/JavaRandom.java ---------------------------------------------------------------------- diff --git a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/JavaRandom.java b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/JavaRandom.java new file mode 100644 index 0000000..bc20330 --- /dev/null +++ b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/JavaRandom.java @@ -0,0 +1,47 @@ +/** + * 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.kerberos.kerb.crypto.random; + +import java.security.SecureRandom; + +/** + * Use jdk SecureRandom to implement RandomProvider, so it can be used on windows & linux. + */ + +public class JavaRandom implements RandomProvider { + private SecureRandom random = new SecureRandom(); + @Override + public void init() { + } + + @Override + public void setSeed(byte[] seed) { + random.setSeed(seed); + } + + @Override + public void nextBytes(byte[] bytes) { + random.nextBytes(bytes); + } + + @Override + public void destroy() { + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/12ac895f/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/NativeRandom.java ---------------------------------------------------------------------- diff --git a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/NativeRandom.java b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/NativeRandom.java new file mode 100644 index 0000000..dd14cdd --- /dev/null +++ b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/random/NativeRandom.java @@ -0,0 +1,67 @@ +/** + * 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.kerberos.kerb.crypto.random; + +import java.io.*; + +/** + * use "/dev/urandom", which is on linux, to implement RandomProvider, so it should be used on linux. + */ +public class NativeRandom implements RandomProvider { + private InputStream input; + private String randFile = "/dev/urandom"; + + @Override + public void init() { + try { + input = new FileInputStream(randFile); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + @Override + public void setSeed(byte[] seed) { + try { + OutputStream output = new FileOutputStream(randFile); + output.write(seed); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void nextBytes(byte[] bytes) { + try { + input.read(bytes); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void destroy() { + try { + input.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +}